Beispiel #1
0
    def setup_working_dir(self, param_working_dir=None, create=False):
        self.working_dir = ''
        # try to use given working dir or overwrite with solver working dir
        fem_general_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/General")
        if param_working_dir is not None:
            self.working_dir = param_working_dir
            if self.check_working_dir() is not True:
                if create is True:
                    FreeCAD.Console.PrintMessage("Dir given as parameter \'{}\' doesn't exist.\n".format(self.working_dir))
                    pass
                else:
                    FreeCAD.Console.PrintError("Dir given as parameter \'{}\' doesn't exist and create parameter is set to False.\n".format(self.working_dir))
                    self.working_dir = femutils.get_pref_working_dir(self.solver)
                    FreeCAD.Console.PrintMessage("Dir \'{}\' will be used instead.\n".format(self.working_dir))
        elif fem_general_prefs.GetBool("OverwriteSolverWorkingDirectory", True) is False:
            self.working_dir = self.solver.WorkingDir
            if self.check_working_dir() is not True:
                FreeCAD.Console.PrintError("Dir from solver object \'{}\' doesn't exist.\n".format(self.working_dir))
                self.working_dir = femutils.get_pref_working_dir(self.solver)
                FreeCAD.Console.PrintMessage("Dir \'{}\' will be used instead.\n".format(self.working_dir))
        else:
            self.working_dir = femutils.get_pref_working_dir(self.solver)

        # check working_dir exist, if not use a tmp dir and inform the user
        if self.check_working_dir() is not True:
            FreeCAD.Console.PrintError("Dir \'{}\' doesn't exist or cannot be created.\n".format(self.working_dir))
            from femsolver.run import _getTempDir
            self.working_dir = _getTempDir(self.solver)
            FreeCAD.Console.PrintMessage("Dir \'{}\' will be used instead.\n".format(self.working_dir))

        # Update inp file name
        self.set_inp_file_name()
Beispiel #2
0
def get_pref_working_dir(solver_obj):
    # _dirTypes from run are not used
    # be aware beside could get an error if the document has not been saved
    from femsolver import settings
    from femsolver import run
    dir_setting = settings.get_dir_setting()
    if dir_setting == settings.TEMPORARY:
        setting_working_dir = run._getTempDir(solver_obj)
    elif dir_setting == settings.BESIDE:
        setting_working_dir = run._getBesideDir(solver_obj)
    elif dir_setting == settings.CUSTOM:
        setting_working_dir = run._getCustomDir(solver_obj)
    else:
        setting_working_dir = ''
    return setting_working_dir
Beispiel #3
0
def get_pref_working_dir(solver_obj):
    # _dirTypes from run are not used
    # be aware beside could get an error if the document has not been saved
    from femsolver import settings
    from femsolver import run
    dir_setting = settings.get_dir_setting()
    if dir_setting == settings.TEMPORARY:
        setting_working_dir = run._getTempDir(solver_obj)
    elif dir_setting == settings.BESIDE:
        setting_working_dir = run._getBesideDir(solver_obj)
    elif dir_setting == settings.CUSTOM:
        setting_working_dir = run._getCustomDir(solver_obj)
    else:
        setting_working_dir = ''
    return setting_working_dir
Beispiel #4
0
    def get_tmp_file_paths(self, param_working_dir=None, create=False):
        self.working_dir = ""
        # try to use given working dir
        if param_working_dir is not None:
            self.working_dir = param_working_dir
            if femutils.check_working_dir(self.working_dir) is not True:
                if create is True:
                    FreeCAD.Console.PrintMessage(
                        "Dir given as parameter \'{}\' doesn't exist.\n".
                        format(self.working_dir))
                else:
                    FreeCAD.Console.PrintError(
                        "Dir given as parameter \'{}\' doesn't exist "
                        "and create parameter is set to False.\n".format(
                            self.working_dir))
                    self.working_dir = femutils.get_pref_working_dir(
                        self.mesh_obj)
                    FreeCAD.Console.PrintMessage(
                        "Dir \'{}\' will be used instead.\n".format(
                            self.working_dir))
        else:
            self.working_dir = femutils.get_pref_working_dir(self.mesh_obj)

        # check working_dir exist, if not use a tmp dir and inform the user
        if femutils.check_working_dir(self.working_dir) is not True:
            FreeCAD.Console.PrintError(
                "Dir \'{}\' doesn't exist or cannot be created.\n".format(
                    self.working_dir))
            from femsolver.run import _getTempDir
            self.working_dir = _getTempDir(self.mesh_obj)
            FreeCAD.Console.PrintMessage(
                "Dir \'{}\' will be used instead.\n".format(self.working_dir))

        # file paths
        _geometry_name = self.part_obj.Name + "_Geometry"
        self.mesh_name = self.part_obj.Name + "_Mesh"
        from os.path import join
        self.temp_file_geometry = join(self.working_dir, _geometry_name +
                                       ".brep")  # geometry file
        self.temp_file_mesh = join(self.working_dir,
                                   self.mesh_name + ".unv")  # mesh file
        self.temp_file_geo = join(self.working_dir,
                                  "shape2mesh.geo")  # Gmsh input file
        print("  " + self.temp_file_geometry)
        print("  " + self.temp_file_mesh)
        print("  " + self.temp_file_geo)