def threadFinished(self, status):
        if self.thread.task == DEPENDENCY_CHECK:
            QApplication.restoreOverrideCursor()

        elif self.thread.task == DOWNLOAD_GNUPLOTPY:
            self.consoleMessage("Attempting to install Gnuplot-py package:")

            if platform.system() == 'Windows':
                python_exe = os.path.join(FreeCAD.getHomePath(), 'bin',
                                          'python.exe')
            else:
                python_exe = 'python'
            cmd = [python_exe, '-u', 'setup.py', 'install']

            working_dir = os.path.join(tempfile.gettempdir(),
                                       GNUPLOTPY_FILE_BASE)
            self.install_process = CfdConsoleProcess.CfdConsoleProcess(
                finishedHook=self.installFinished)
            print("Running {} in {}".format(' '.join(cmd), working_dir))

            self.install_process.start(cmd, working_dir=working_dir)
            if not self.install_process.waitForStarted():
                self.consoleMessage("Unable to run command " + ' '.join(cmd),
                                    '#FF0000')

        elif self.thread.task == DOWNLOAD_CFMESH:
            if status:
                self.consoleMessage("Download completed")
                user_dir = self.thread.user_dir
                self.consoleMessage(
                    "Building cfMesh. Lengthy process - please wait...")
                if CfdFoamTools.getFoamRuntime() == "BlueCFD":
                    script_name = "buildCfMeshOnBlueCFD.sh"
                    self.consoleMessage("Log file: {}\\log.{}".format(
                        user_dir, script_name))
                    shutil.copy(
                        os.path.join(CfdTools.getModulePath(), 'data',
                                     script_name),
                        os.path.join(user_dir, script_name))
                    self.install_process = CfdFoamTools.startFoamApplication(
                        "./" + script_name, "$WM_PROJECT_USER_DIR",
                        self.installFinished)
                else:
                    self.consoleMessage("Log file: {}/{}/log.Allwmake".format(
                        user_dir, CFMESH_FILE_BASE))
                    self.install_process = CfdFoamTools.startFoamApplication(
                        "./Allwmake",
                        "$WM_PROJECT_USER_DIR/" + CFMESH_FILE_BASE,
                        self.installFinished)
            else:
                self.consoleMessage("Download unsuccessful")
 def loadSettings(self):
     # Don't set the autodetected location, since the user might want to allow that to vary according
     # to WM_PROJECT_DIR setting
     prefs = CfdFoamTools.getPreferencesLocation()
     self.foam_dir = FreeCAD.ParamGet(prefs).GetString(
         "InstallationPath", "")
     self.form.le_foam_dir.setText(self.foam_dir)
 def dependencyCheck(self):
     self.signals.status.emit("Checking dependencies...")
     msg = CfdTools.checkFreeCADVersion()
     msg += CfdFoamTools.checkCfdDependencies()
     if not msg:
         self.signals.status.emit("No missing dependencies detected")
     else:
         self.signals.status.emit(msg)
    def downloadCfMesh(self):
        self.signals.status.emit("Downloading cfMesh, please wait...")

        self.user_dir = CfdFoamTools.runFoamCommand(
            "echo $WM_PROJECT_USER_DIR").rstrip().split('\n')[-1]
        self.user_dir = CfdFoamTools.reverseTranslatePath(self.user_dir)

        try:
            import urllib
            (filename,
             header) = urllib.urlretrieve(CFMESH_URL,
                                          reporthook=self.downloadStatus)
        except Exception as ex:
            raise Exception("Error downloading cfMesh: {}".format(str(ex)))

        self.signals.status.emit("Extracting cfMesh...")
        CfdFoamTools.runFoamCommand(
            '{{ mkdir -p "$WM_PROJECT_USER_DIR"; cd "$WM_PROJECT_USER_DIR"; tar -xzf "{}"; }}'
            .format(CfdFoamTools.translatePath(filename)))
Example #5
0
    def __init__(self, analysis_obj):
        """ analysis_obj should contains all the information needed,
        boundaryConditionList is a list of all boundary Conditions objects(FemConstraint)
        """
        self.analysis_obj = analysis_obj
        self.solver_obj = CfdTools.getSolver(analysis_obj)
        self.mesh_obj = CfdTools.getMesh(analysis_obj)
        self.material_obj = CfdTools.getMaterial(analysis_obj)
        self.bc_group = CfdTools.getConstraintGroup(analysis_obj)
        self.mesh_generated = False
        # unit schema detection is usful for mesh scaling, boundary type area, pressure calculation
        self.unit_shema = FreeCAD.ParamGet(
            "User parameter:BaseApp/Preferences/Units/").GetInt("UserSchema")

        self.case_folder = self.solver_obj.WorkingDir + os.path.sep + self.solver_obj.InputCaseName
        self.mesh_file_name = self.case_folder + os.path.sep + self.solver_obj.InputCaseName + u".unv"
        if self.solver_obj.HeatTransfering:
            self.builder = fcb.BasicBuilder(
                self.case_folder, CfdTools.getSolverSettings(self.solver_obj))
        else:
            self.builder = fcb.BasicBuilder(
                self.case_folder, CfdTools.getSolverSettings(self.solver_obj))
 def saveSettings(self):
     CfdFoamTools.setFoamDir(self.foam_dir)