def downloadDocker(self): self.signals.status.emit("Downloading Docker run script, please wait...") prefs = CfdTools.getPreferencesLocation() self.user_dir = FreeCAD.ParamGet(prefs).GetString("InstallationPath", "") try: # Download (filename, header) = self.downloadFile(self.docker_url, reporthook=self.downloadStatus) except Exception as ex: raise Exception("Error downloading Docker run script: {}".format(str(ex))) if not os.path.exists(self.user_dir): self.signals.status.emit("Creating {}".format(self.user_dir)) self.signals.status.emit("Saving Docker run script...") # Add output directory volume to docker script prefs = CfdTools.getPreferencesLocation() ds_modified_fname = "{}/bin/{}".format(self.user_dir,self.docker_url.split('/')[-1]) ds_modified = open(ds_modified_fname,'w') ds_original = open(filename,'r') if not ds_modified or not ds_original: self.signals.status.emit("Could not read and modify docker script") return for line in ds_original: if "DOCKER_IMAGE=" in line: FreeCAD.ParamGet(prefs).SetString("DockerImageName",line[14:-2]) # Change -it to -t -d so dthe docker continaer will continue to run as a detached background process line = line.replace('-it ','-t -d ') ds_modified.write(line) if "docker run" in line: # Add the output directory ds_modified.write(" -v {}:/tmp \\\n".format(FreeCAD.ParamGet(prefs).GetString("DefaultOutputPath",""))) ds_modified.close() ds_original.close()
def Initialize(self): # must import QtCore in this function, # not at the beginning of this file for translation support from PySide import QtCore from CfdAnalysis import _CommandCfdAnalysis from CfdMesh import _CommandCfdMeshFromShape from CfdMeshRefinement import _CommandMeshRegion from CfdPhysicsSelection import _CommandCfdPhysicsSelection from CfdFluidMaterial import _CommandCfdFluidMaterial from CfdSolverFoam import _CommandCfdSolverFoam from CfdInitialiseFlowField import _CommandCfdInitialiseInternalFlowField from CfdFluidBoundary import _CommandCfdFluidBoundary from CfdZone import _CommandCfdPorousZone from CfdZone import _CommandCfdInitialisationZone FreeCADGui.addCommand('Cfd_Analysis', _CommandCfdAnalysis()) FreeCADGui.addCommand('Cfd_MeshFromShape', _CommandCfdMeshFromShape()) FreeCADGui.addCommand('Cfd_MeshRegion', _CommandMeshRegion()) cmdlst = [ 'Cfd_Analysis', 'Cfd_MeshFromShape', 'Cfd_MeshRegion', 'Cfd_PhysicsModel', 'Cfd_FluidMaterial', 'Cfd_InitialiseInternal', 'Cfd_FluidBoundary', 'Cfd_InitialisationZone', 'Cfd_PorousZone', 'Cfd_SolverControl' ] self.appendToolbar(str(QtCore.QT_TRANSLATE_NOOP("Cfd", "CfdOF")), cmdlst) self.appendMenu(str(QtCore.QT_TRANSLATE_NOOP("Cfd", "&CfdOF")), cmdlst) import CfdTools prefs = CfdTools.getPreferencesLocation() CfdTools.DockerContainer.usedocker = FreeCAD.ParamGet(prefs).GetBool( "UseDocker", 0)
def downloadHisa(self): self.signals.status.emit("Downloading HiSA, please wait...") usedocker=CfdTools.DockerContainer.usedocker if usedocker: prefs = CfdTools.getPreferencesLocation() self.user_dir = FreeCAD.ParamGet(prefs).GetString("InstallationPath", "") else: self.user_dir = CfdTools.runFoamCommand("echo $WM_PROJECT_USER_DIR").rstrip().split('\n')[-1] self.user_dir = CfdTools.reverseTranslatePath(self.user_dir) try: if hasattr(ssl, 'create_default_context'): context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) else: context = None # Download (filename, header) = self.downloadFile(self.hisa_url, reporthook=self.downloadStatus, context=context) except Exception as ex: raise Exception("Error downloading HiSA: {}".format(str(ex))) self.signals.status.emit("Extracting HiSA...") self.signals.status.emit(self.user_dir) usedocker = CfdTools.DockerContainer.usedocker if usedocker: cmd = 'cd {} && rm -r {}; unzip -o {}'.format(self.user_dir, HISA_FILE_BASE, CfdTools.translatePath(filename)) else: cmd = '{{ mkdir -p "$WM_PROJECT_USER_DIR" && cd "$WM_PROJECT_USER_DIR" && ( rm -r {}; unzip -o "{}"; ); }}'.format(HISA_FILE_BASE, CfdTools.translatePath(filename)) CfdTools.runFoamCommand(cmd, usedocker=False)
def run(self): # If using docker, need to make and set the foam, bin & etc directories if they don't already exist usedocker = CfdTools.DockerContainer.usedocker if usedocker: prefs = CfdTools.getPreferencesLocation() foam_dir = FreeCAD.ParamGet(prefs).GetString("InstallationPath", "") cmd = 'mkdir -p {0}/bin ; mkdir -p {0}/etc'.format(foam_dir) proc = QtCore.QProcess() proc.start(cmd) if not proc.waitForFinished(): self.signals.status.emit("Could not create directories") self.signals.finished.emit(False) return try: if self.task == DOWNLOAD_BLUECFD: self.downloadBlueCFD() elif self.task == DOWNLOAD_CFMESH: self.downloadCfMesh() elif self.task == DOWNLOAD_HISA: self.downloadHisa() elif self.task == DOWNLOAD_DOCKER: self.downloadDocker() except Exception as e: self.signals.error.emit(str(e)) self.signals.finished.emit(False) raise self.signals.finished.emit(True)
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 = CfdTools.getPreferencesLocation() self.foam_dir = FreeCAD.ParamGet(prefs).GetString( "InstallationPath", "") self.form.le_foam_dir.setText(self.foam_dir)
def testGetRuntime(self, disable_exception=True): """ Set the foam dir temporarily and see if we can detect the runtime """ prefs = CfdTools.getPreferencesLocation() prev_foam_dir = FreeCAD.ParamGet(prefs).GetString( "InstallationPath", "") CfdTools.setFoamDir(self.foam_dir) try: runtime = CfdTools.getFoamRuntime() except IOError as e: runtime = None if not disable_exception: raise CfdTools.setFoamDir(prev_foam_dir) return runtime
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 = CfdTools.getPreferencesLocation() self.foam_dir = FreeCAD.ParamGet(prefs).GetString("InstallationPath", "") self.initial_foam_dir = str(self.foam_dir) self.form.le_foam_dir.setText(self.foam_dir) self.paraview_path = CfdTools.getParaviewPath() self.initial_paraview_path = str(self.paraview_path) self.form.le_paraview_path.setText(self.paraview_path) self.output_dir = CfdTools.getDefaultOutputPath() self.form.le_output_dir.setText(self.output_dir)
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 = CfdTools.getPreferencesLocation() self.foam_dir = FreeCAD.ParamGet(prefs).GetString("InstallationPath", "") self.initial_foam_dir = str(self.foam_dir) self.form.le_foam_dir.setText(self.foam_dir) self.output_dir = CfdTools.getDefaultOutputPath() self.form.le_output_dir.setText(self.output_dir) CfdTools.DockerContainer.usedocker = FreeCAD.ParamGet(prefs).GetBool("UseDocker", 0) if CfdTools.DockerContainer.usedocker: self.form.cb_docker_sel.setCheckState(Qt.Checked) else: self.form.pb_download_install_docker.setEnabled(0) if platform.system() == "Linux": self.form.le_docker_url.setText(DOCKER_URL+"linux") elif platform.system() == "Darwin": self.form.le_docker_url.setText(DOCKER_URL+"macos")
def saveSettings(self): CfdTools.setFoamDir(self.foam_dir) prefs = CfdTools.getPreferencesLocation() FreeCAD.ParamGet(prefs).SetString("DefaultOutputPath", self.output_dir)
def saveSettings(self): CfdTools.setFoamDir(self.foam_dir) prefs = CfdTools.getPreferencesLocation() FreeCAD.ParamGet(prefs).SetString("DefaultOutputPath", self.output_dir) FreeCAD.ParamGet(prefs).SetBool("UseDocker",self.form.cb_docker_sel.isChecked()) FreeCAD.ParamGet(prefs).SetString("DockerURL",self.form.le_docker_url.text())