FEM: ccx tools, use working dir prefs from solver framework
This commit is contained in:
@@ -22,82 +22,6 @@
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_1_analysis">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Working directory for ccx tools solver only</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetNoConstraint</enum>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gl_analysis">
|
||||
<item row="2" column="2">
|
||||
<widget class="Gui::PrefFileChooser" name="fc_analysis_working_directory" native="true">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>WorkingDir</cstring>
|
||||
</property>
|
||||
<property name="mode">
|
||||
<enum>Gui::FileChooser::Directory</enum>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Fem/General</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="l_analysis_working_directory">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use custom directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_2_workingdir">
|
||||
<property name="sizePolicy">
|
||||
@@ -107,7 +31,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Working directory for all frame work solver</string>
|
||||
<string>Working directory for solving analysis</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
@@ -312,6 +236,29 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_10">
|
||||
<item>
|
||||
<widget class="Gui::PrefCheckBox" name="cb_overwrite_solver_working_directory">
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Overwrite solver working directory with the directory choosen above</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>OverwriteSolverWorkingDirectory</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Fem/General</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -44,7 +44,6 @@ DlgSettingsFemGeneralImp::~DlgSettingsFemGeneralImp()
|
||||
|
||||
void DlgSettingsFemGeneralImp::saveSettings()
|
||||
{
|
||||
fc_analysis_working_directory->onSave();
|
||||
|
||||
cb_analysis_group_meshing->onSave();
|
||||
|
||||
@@ -56,11 +55,11 @@ void DlgSettingsFemGeneralImp::saveSettings()
|
||||
cb_wd_beside->onSave();
|
||||
cb_wd_custom->onSave();
|
||||
le_wd_custom->onSave();
|
||||
cb_overwrite_solver_working_directory->onSave();
|
||||
}
|
||||
|
||||
void DlgSettingsFemGeneralImp::loadSettings()
|
||||
{
|
||||
fc_analysis_working_directory->onRestore();
|
||||
|
||||
cb_analysis_group_meshing->onRestore();
|
||||
|
||||
@@ -72,6 +71,7 @@ void DlgSettingsFemGeneralImp::loadSettings()
|
||||
cb_wd_beside->onRestore();
|
||||
cb_wd_custom->onRestore();
|
||||
le_wd_custom->onRestore();
|
||||
cb_overwrite_solver_working_directory->onRestore();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -456,54 +456,55 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
|
||||
if inp_file_name is not None:
|
||||
self.inp_file_name = inp_file_name
|
||||
else:
|
||||
# self.working_dir does have a slash at the end
|
||||
self.inp_file_name = self.working_dir + self.base_name + '.inp'
|
||||
self.inp_file_name = os.path.join(self.working_dir, (self.base_name + '.inp'))
|
||||
|
||||
## Sets working dir for solver execution. Called with no working_dir uses WorkingDir from FEM preferences
|
||||
# @param self The python object self
|
||||
# @working_dir directory to be used for writing solver input file or files and executing solver
|
||||
def setup_working_dir(self, working_dir=None):
|
||||
if working_dir is not None:
|
||||
self.working_dir = working_dir
|
||||
# param_working_dir directory to be used for writing solver input file or files and executing solver
|
||||
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 = ''
|
||||
self.fem_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/General")
|
||||
if self.fem_prefs.GetString("WorkingDir"): # if working dir in prefs is not empty
|
||||
if self.solver.WorkingDir != '':
|
||||
# we use error message to get it red, but it is not an error
|
||||
FreeCAD.Console.PrintError('The solver working directory will be overwritten by the FEM preferences working dir.\n')
|
||||
try:
|
||||
self.working_dir = self.fem_prefs.GetString("WorkingDir")
|
||||
except:
|
||||
FreeCAD.Console.PrintError('Could not set working directory to FEM Preferences working directory.\n')
|
||||
else:
|
||||
FreeCAD.Console.PrintMessage('FEM preferences working dir setting is empty, the solver working directory is used.\n')
|
||||
if self.solver.WorkingDir:
|
||||
try:
|
||||
self.working_dir = self.solver.WorkingDir
|
||||
except:
|
||||
FreeCAD.Console.PrintError('Could not set working directory to solver working directory.\n')
|
||||
self.working_dir = femutils.get_pref_working_dir(self.solver)
|
||||
|
||||
# check working_dir exist, if not use a tmp dir and inform the user
|
||||
use_tmp_dir = False
|
||||
if self.working_dir == '':
|
||||
FreeCAD.Console.PrintError("All working Dir settings are empty: \'{}\'.\n".format(self.working_dir))
|
||||
use_tmp_dir = True
|
||||
if not (os.path.isdir(self.working_dir)):
|
||||
FreeCAD.Console.PrintError("Working directory: \'{}\' doesn't exist.\n".format(self.working_dir))
|
||||
use_tmp_dir = True
|
||||
if use_tmp_dir is True:
|
||||
from tempfile import gettempdir
|
||||
self.working_dir = gettempdir()
|
||||
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))
|
||||
FreeCAD.Console.PrintMessage('FemToolsCCx.setup_working_dir() --> self.working_dir = ' + self.working_dir + '\n')
|
||||
|
||||
# check working_dir has a slash at the end, if not add one
|
||||
# check working_dir has a slash at the end, if not add one, needed for inp writer
|
||||
self.working_dir = os.path.join(self.working_dir, '')
|
||||
|
||||
# Update inp file name
|
||||
self.set_inp_file_name()
|
||||
|
||||
def check_working_dir(self):
|
||||
# check if working_dir exist, if not use a tmp dir and inform the user
|
||||
# print(self.working_dir)
|
||||
if os.path.isdir(self.working_dir):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def write_inp_file(self):
|
||||
import femsolver.calculix.writer as iw
|
||||
self.inp_file_name = ""
|
||||
|
||||
@@ -129,7 +129,7 @@ def is_derived_from(obj, t):
|
||||
|
||||
|
||||
# working dir
|
||||
def get_pref_working_dir():
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user