From 4da4b744f072feb58a4f341320d081f63b1b61ad Mon Sep 17 00:00:00 2001 From: marioalexis Date: Sun, 10 Nov 2024 21:09:38 -0300 Subject: [PATCH] Fem: Use quantity spin boxes in material task panel --- src/Mod/Fem/Gui/Resources/ui/Material.ui | 171 ++----- .../Fem/femtaskpanels/task_material_common.py | 441 ++++-------------- 2 files changed, 126 insertions(+), 486 deletions(-) diff --git a/src/Mod/Fem/Gui/Resources/ui/Material.ui b/src/Mod/Fem/Gui/Resources/ui/Material.ui index 69514b5ef5..41bdf99b9a 100755 --- a/src/Mod/Fem/Gui/Resources/ui/Material.ui +++ b/src/Mod/Fem/Gui/Resources/ui/Material.ui @@ -34,15 +34,15 @@ QFormLayout::AllNonFixedFieldsGrow - + - Density + Density: - - + + false @@ -55,27 +55,20 @@ 80 - 20 - - 0 kg/m^3 - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignLeft|Qt::AlignTrailing|Qt::AlignVCenter - 2.000000000000000 + 1.000000000000000 - 99999999999.000000000000000 + 100000000000.00000000000000 kg/m^3 - - 3 - 0.000000000000000 @@ -111,7 +104,7 @@ - + false @@ -124,27 +117,20 @@ 80 - 20 - - 0 Pa - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignLeft|Qt::AlignTrailing|Qt::AlignVCenter - 2.000000000000000 + 1.000000000000000 - 99999999999.000000000000000 + 100000000000.00000000000000 Pa - - 3 - 0.000000000000000 @@ -158,7 +144,7 @@ - + false @@ -171,14 +157,10 @@ 80 - 20 - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - 3 + Qt::AlignLeft|Qt::AlignTrailing|Qt::AlignVCenter 1.000000000000000 @@ -187,7 +169,7 @@ 0.100000000000000 - 0.300000000000000 + 0.000000000000000 @@ -221,7 +203,7 @@ - + false @@ -234,27 +216,20 @@ 80 - 20 - - 0 m^2/s - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignLeft|Qt::AlignTrailing|Qt::AlignVCenter 0.000001000000000 - 99999999999.000000000000000 + 100000000000.00000000000000 m^2/s - - 6 - 0.000000000000000 @@ -290,7 +265,7 @@ - + false @@ -303,27 +278,20 @@ 80 - 20 - - 0 W/m/K - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignLeft|Qt::AlignTrailing|Qt::AlignVCenter - 2.000000000000000 + 1.000000000000000 - 99999999999.000000000000000 + 100000000000.00000000000000 W/m/K - - 3 - 0.000000000000000 @@ -337,7 +305,7 @@ - + false @@ -350,27 +318,20 @@ 80 - 20 - - 0 m/m/K - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignLeft|Qt::AlignTrailing|Qt::AlignVCenter - 2.000000000000000 + 1.000000000000000 - 99999999999.000000000000000 + 100000000000.00000000000000 m/m/K - - 3 - 0.000000000000000 @@ -384,7 +345,7 @@ - + false @@ -397,74 +358,20 @@ 80 - 20 - - 0 J/kg/K - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignLeft|Qt::AlignTrailing|Qt::AlignVCenter - 2.000000000000000 + 1.000000000000000 - 99999999999.000000000000000 + 100000000000.00000000000000 J/kg/K - - 3 - - - 0.000000000000000 - - - - - - - Vol Expansion Coeff - - - - - - - false - - - - 0 - 0 - - - - - 80 - 20 - - - - 0 m/m/K - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - 0.001000000000000 - - - 1.000000000000000 - - - m/m/K - - - 6 - 0.000000000000000 @@ -495,9 +402,9 @@ - Gui::InputField - QLineEdit -
Gui/InputField.h
+ Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
MatGui::MaterialTreeWidget @@ -510,7 +417,7 @@ chbu_allow_edit toggled(bool) - input_fd_density + qsb_density setEnabled(bool) @@ -526,7 +433,7 @@ chbu_allow_edit toggled(bool) - input_fd_young_modulus + qsb_young_modulus setEnabled(bool) @@ -542,7 +449,7 @@ chbu_allow_edit toggled(bool) - spinBox_poisson_ratio + qsb_poisson_ratio setEnabled(bool) @@ -558,7 +465,7 @@ chbu_allow_edit toggled(bool) - input_fd_kinematic_viscosity + qsb_kinematic_viscosity setEnabled(bool) @@ -574,7 +481,7 @@ chbu_allow_edit toggled(bool) - input_fd_thermal_conductivity + qsb_thermal_conductivity setEnabled(bool) @@ -590,7 +497,7 @@ chbu_allow_edit toggled(bool) - input_fd_expansion_coefficient + qsb_expansion_coefficient setEnabled(bool) @@ -606,7 +513,7 @@ chbu_allow_edit toggled(bool) - input_fd_specific_heat + qsb_specific_heat setEnabled(bool) diff --git a/src/Mod/Fem/femtaskpanels/task_material_common.py b/src/Mod/Fem/femtaskpanels/task_material_common.py index 36a1050520..0f501dbe6d 100644 --- a/src/Mod/Fem/femtaskpanels/task_material_common.py +++ b/src/Mod/Fem/femtaskpanels/task_material_common.py @@ -32,7 +32,6 @@ __url__ = "https://www.freecad.org" # \brief task panel for common material object from PySide import QtCore -from PySide import QtGui import FreeCAD import FreeCADGui @@ -73,48 +72,43 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel): ) # basic properties must be provided QtCore.QObject.connect( - self.parameterWidget.input_fd_density, + self.parameterWidget.qsb_density, QtCore.SIGNAL("editingFinished()"), self.density_changed, ) # mechanical properties QtCore.QObject.connect( - self.parameterWidget.input_fd_young_modulus, + self.parameterWidget.qsb_young_modulus, QtCore.SIGNAL("editingFinished()"), self.ym_changed, ) QtCore.QObject.connect( - self.parameterWidget.spinBox_poisson_ratio, + self.parameterWidget.qsb_poisson_ratio, QtCore.SIGNAL("editingFinished()"), self.pr_changed, ) # thermal properties QtCore.QObject.connect( - self.parameterWidget.input_fd_thermal_conductivity, + self.parameterWidget.qsb_thermal_conductivity, QtCore.SIGNAL("editingFinished()"), self.tc_changed, ) QtCore.QObject.connect( - self.parameterWidget.input_fd_expansion_coefficient, + self.parameterWidget.qsb_expansion_coefficient, QtCore.SIGNAL("editingFinished()"), self.tec_changed, ) QtCore.QObject.connect( - self.parameterWidget.input_fd_specific_heat, + self.parameterWidget.qsb_specific_heat, QtCore.SIGNAL("editingFinished()"), self.sh_changed, ) # fluidic properties, only volumetric thermal expansion coeff makes sense QtCore.QObject.connect( - self.parameterWidget.input_fd_kinematic_viscosity, + self.parameterWidget.qsb_kinematic_viscosity, QtCore.SIGNAL("editingFinished()"), self.kinematic_viscosity_changed, ) - QtCore.QObject.connect( - self.parameterWidget.input_fd_vol_expansion_coefficient, - QtCore.SIGNAL("editingFinished()"), - self.vtec_changed, - ) QtCore.QObject.connect( self.parameterWidget.wgt_material_tree, QtCore.SIGNAL("onMaterial(QString)"), @@ -126,17 +120,11 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel): self.toggleInputFieldsReadOnly() # hide some groupBox according to material category - # note: input_fd_vol_expansion_coefficient is currently not used - # it might be used in future for solids if self.obj.Category == "Fluid": self.filter_models(self.obj.Category) self.parameterWidget.groupBox_mechanical.setVisible(0) - self.parameterWidget.label_vol_expansion_coefficient.setVisible(0) - self.parameterWidget.input_fd_vol_expansion_coefficient.setVisible(0) else: self.parameterWidget.groupBox_fluidic.setVisible(0) - self.parameterWidget.label_vol_expansion_coefficient.setVisible(0) - self.parameterWidget.input_fd_vol_expansion_coefficient.setVisible(0) # geometry selection widget self.selectionWidget = selection_widgets.GeometryElementsSelection( @@ -148,7 +136,6 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel): # check references, has to be after initialisation of selectionWidget self.material_tree.UUID = self.get_material_uuid(self.material) - self.check_material_keys() self.set_mat_params_in_input_fields(self.material) self.selectionWidget.has_equal_references_shape_types() @@ -156,20 +143,10 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel): # leave task panel *************************************************************************** def accept(self): if self.selectionWidget.has_equal_references_shape_types(): - self.do_not_set_thermal_zeros() - from materialtools.cardutils import check_mat_units as checkunits + self.obj.Material = self.material + self.obj.UUID = self.uuid + self.obj.References = self.selectionWidget.references - if checkunits(self.material) is True: - self.obj.Material = self.material - self.obj.UUID = self.uuid - self.obj.References = self.selectionWidget.references - else: - error_message = ( - "Due to some wrong material quantity units in the changed " - "material data, the task panel changes where not accepted.\n" - ) - FreeCAD.Console.PrintError(error_message) - QtGui.QMessageBox.critical(None, "Material data not changed", error_message) self.selectionWidget.finish_selection() return super().accept() @@ -177,30 +154,6 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel): self.selectionWidget.finish_selection() return super().reject() - def do_not_set_thermal_zeros(self): - """thermal material parameter are set to 0.0 if not available - this leads to wrong material values and to not finding the card - on reopen the task pane, thus do not write thermal parameter, - if they are 0.0 - """ - if Units.Quantity(self.material["ThermalConductivity"]) == 0.0: - self.material.pop("ThermalConductivity", None) - FreeCAD.Console.PrintMessage( - "Zero ThermalConductivity value. " - "This parameter is not saved in the material data.\n" - ) - if Units.Quantity(self.material["ThermalExpansionCoefficient"]) == 0.0: - self.material.pop("ThermalExpansionCoefficient", None) - FreeCAD.Console.PrintMessage( - "Zero ThermalExpansionCoefficient value. " - "This parameter is not saved in the material data.\n" - ) - if Units.Quantity(self.material["SpecificHeat"]) == 0.0: - self.material.pop("SpecificHeat", None) - FreeCAD.Console.PrintMessage( - "Zero SpecificHeat value. This parameter is not saved in the material data.\n" - ) - def isfloat(self, num): try: float(num) @@ -263,335 +216,115 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel): def toggleInputFieldsReadOnly(self): if self.parameterWidget.chbu_allow_edit.isChecked(): - self.parameterWidget.input_fd_density.setReadOnly(False) - self.parameterWidget.input_fd_young_modulus.setReadOnly(False) - self.parameterWidget.spinBox_poisson_ratio.setReadOnly(False) - self.parameterWidget.input_fd_thermal_conductivity.setReadOnly(False) - self.parameterWidget.input_fd_expansion_coefficient.setReadOnly(False) - self.parameterWidget.input_fd_specific_heat.setReadOnly(False) - self.parameterWidget.input_fd_kinematic_viscosity.setReadOnly(False) - self.parameterWidget.input_fd_vol_expansion_coefficient.setReadOnly(False) + self.parameterWidget.qsb_density.setReadOnly(False) + self.parameterWidget.qsb_young_modulus.setReadOnly(False) + self.parameterWidget.qsb_poisson_ratio.setReadOnly(False) + self.parameterWidget.qsb_thermal_conductivity.setReadOnly(False) + self.parameterWidget.qsb_expansion_coefficient.setReadOnly(False) + self.parameterWidget.qsb_specific_heat.setReadOnly(False) + self.parameterWidget.qsb_kinematic_viscosity.setReadOnly(False) else: - self.parameterWidget.input_fd_density.setReadOnly(True) - self.parameterWidget.input_fd_young_modulus.setReadOnly(True) - self.parameterWidget.spinBox_poisson_ratio.setReadOnly(True) - self.parameterWidget.input_fd_thermal_conductivity.setReadOnly(True) - self.parameterWidget.input_fd_expansion_coefficient.setReadOnly(True) - self.parameterWidget.input_fd_specific_heat.setReadOnly(True) - self.parameterWidget.input_fd_kinematic_viscosity.setReadOnly(True) - self.parameterWidget.input_fd_vol_expansion_coefficient.setReadOnly(True) + self.parameterWidget.qsb_density.setReadOnly(True) + self.parameterWidget.qsb_young_modulus.setReadOnly(True) + self.parameterWidget.qsb_poisson_ratio.setReadOnly(True) + self.parameterWidget.qsb_thermal_conductivity.setReadOnly(True) + self.parameterWidget.qsb_expansion_coefficient.setReadOnly(True) + self.parameterWidget.qsb_specific_heat.setReadOnly(True) + self.parameterWidget.qsb_kinematic_viscosity.setReadOnly(True) # material parameter input fields ************************************************************ - def check_material_keys(self): - # FreeCAD units definition is at file end of src/Base/Unit.cpp - if not self.material: - self.material["Name"] = "NoName" - if "Density" in self.material: - if "Density" not in str(Units.Unit(self.material["Density"])): - FreeCAD.Console.PrintMessage( - "Density in material data seems to have no unit " - "or a wrong unit (reset the value): {}\n".format(self.material["Name"]) - ) - self.material["Density"] = "0 kg/m^3" - else: - if self.material["Name"] != "NoName": - FreeCAD.Console.PrintMessage( - "Density not found in {}\n".format(self.material["Name"]) - ) - self.material["Density"] = "0 kg/m^3" - if self.obj.Category == "Solid": - # mechanical properties - if "YoungsModulus" in self.material: - # unit type of YoungsModulus is Pressure - if "Pressure" not in str(Units.Unit(self.material["YoungsModulus"])): - FreeCAD.Console.PrintMessage( - "YoungsModulus in material data seems to have no unit " - "or a wrong unit (reset the value): {}\n".format(self.material["Name"]) - ) - self.material["YoungsModulus"] = "0 MPa" - else: - if self.material["Name"] != "NoName": - FreeCAD.Console.PrintMessage( - "YoungsModulus not found in {}\n".format(self.material["Name"]) - ) - self.material["YoungsModulus"] = "0 MPa" - if "PoissonRatio" in self.material: - # PoissonRatio does not have a unit, but it is checked if there is no value at all - try: - # next line with float() is ok - # a quantity of a empty string returns very small value, would be wrong here - float(self.material["PoissonRatio"]) - except ValueError: - FreeCAD.Console.PrintMessage( - "PoissonRatio has wrong or no data (reset the value): {}\n".format( - self.material["PoissonRatio"] - ) - ) - self.material["PoissonRatio"] = "0" - else: - if self.material["Name"] != "NoName": - FreeCAD.Console.PrintMessage( - "PoissonRatio not found in {}\n".format(self.material["Name"]) - ) - self.material["PoissonRatio"] = "0" - if self.obj.Category == "Fluid": - # Fluidic properties - if "KinematicViscosity" in self.material: - ki_vis = self.material["KinematicViscosity"] - if "KinematicViscosity" not in str(Units.Unit(ki_vis)): - FreeCAD.Console.PrintMessage( - "KinematicViscosity in material data seems to have no unit " - "or a wrong unit (reset the value): {}\n".format(self.material["Name"]) - ) - self.material["KinematicViscosity"] = "0 m^2/s" - else: - if self.material["Name"] != "NoName": - FreeCAD.Console.PrintMessage( - "KinematicViscosity not found in {}\n".format(self.material["Name"]) - ) - self.material["KinematicViscosity"] = "0 m^2/s" - if "ThermalExpansionCoefficient" in self.material: - vol_ther_ex_co = self.material["ThermalExpansionCoefficient"] - if "ThermalExpansionCoefficient" not in str(Units.Unit(vol_ther_ex_co)): - FreeCAD.Console.PrintMessage( - "ThermalExpansionCoefficient in material data " - "seems to have no unit or a wrong unit (reset the value): {}\n".format( - self.material["Name"] - ) - ) - self.material["ThermalExpansionCoefficient"] = "0 1/K" - else: - if self.material["Name"] != "NoName": - FreeCAD.Console.PrintMessage( - "ThermalExpansionCoefficient not found in {}\n".format( - self.material["Name"] - ) - ) - self.material["ThermalExpansionCoefficient"] = "0 1/K" - if "VolumetricThermalExpansionCoefficient" in self.material: - # unit type VolumetricThermalExpansionCoefficient is ThermalExpansionCoefficient - vol_ther_ex_co = self.material["VolumetricThermalExpansionCoefficient"] - if "ThermalExpansionCoefficient" not in str(Units.Unit(vol_ther_ex_co)): - FreeCAD.Console.PrintMessage( - "VolumetricThermalExpansionCoefficient in material data " - "seems to have no unit or a wrong unit (reset the value): {}\n".format( - self.material["Name"] - ) - ) - self.material["VolumetricThermalExpansionCoefficient"] = "0 1/K" - else: - # as fallback only add VolumetricThermalExpansionCoefficient if there is no - # ThermalExpansionCoefficient - if "ThermalExpansionCoefficient" not in self.material: - self.material["VolumetricThermalExpansionCoefficient"] = "0 1/K" - # Thermal properties - if "ThermalConductivity" in self.material: - # TODO implement for all task panel values - # https://forum.freecad.org/viewtopic.php?f=18&t=56912&p=516826#p516800 - try: - Units.Quantity(self.material["ThermalConductivity"]) - except Exception: - FreeCAD.Console.PrintError( - "Problem with the quantity for ThermalConductivity: '{}' Reset value.\n" - "May try the following in Python console:\n" - "from FreeCAD import Units\n" - "Units.Quantity('{}')\n".format( - self.material["ThermalConductivity"], self.material["ThermalConductivity"] - ) - ) - self.material["ThermalConductivity"] = "0 W/m/K" - if "ThermalConductivity" not in str(Units.Unit(self.material["ThermalConductivity"])): - FreeCAD.Console.PrintMessage( - "ThermalConductivity in material data seems to have no unit " - "or a wrong unit (reset the value): {}\n".format(self.material["Name"]) - ) - self.material["ThermalConductivity"] = "0 W/m/K" - else: - if self.material["Name"] != "NoName": - FreeCAD.Console.PrintMessage( - "ThermalConductivity not found in {}\n".format(self.material["Name"]) - ) - self.material["ThermalConductivity"] = "0 W/m/K" - if "ThermalExpansionCoefficient" in self.material: - the_ex_co = self.material["ThermalExpansionCoefficient"] - if "ThermalExpansionCoefficient" not in str(Units.Unit(the_ex_co)): - FreeCAD.Console.PrintMessage( - "ThermalExpansionCoefficient in material data seems to have no unit " - "or a wrong unit (reset the value): {}\n".format(self.material["Name"]) - ) - self.material["ThermalExpansionCoefficient"] = "0 um/m/K" - else: - if self.material["Name"] != "NoName": - FreeCAD.Console.PrintMessage( - "ThermalExpansionCoefficient not found in {}\n".format(self.material["Name"]) - ) - self.material["ThermalExpansionCoefficient"] = "0 um/m/K" - if "SpecificHeat" in self.material: - if "SpecificHeat" not in str(Units.Unit(self.material["SpecificHeat"])): - FreeCAD.Console.PrintMessage( - "SpecificHeat in material data seems to have no unit " - "or a wrong unit (reset the value): {}\n".format(self.material["Name"]) - ) - self.material["SpecificHeat"] = "0 J/kg/K" - else: - if self.material["Name"] != "NoName": - FreeCAD.Console.PrintMessage( - "SpecificHeat not found in {}\n".format(self.material["Name"]) - ) - self.material["SpecificHeat"] = "0 J/kg/K" - FreeCAD.Console.PrintMessage("\n") - - def update_material_property(self, inputfield_text, matProperty, qUnit, variation=0.001): - # print(inputfield_text) - # this update property works for all Gui::InputField widgets - if qUnit != "": - value = Units.Quantity(inputfield_text).getValueAs(qUnit) - old_value = Units.Quantity(self.material[matProperty]).getValueAs(qUnit) - else: - # for example PoissonRatio - value = Units.Quantity(inputfield_text).Value - old_value = Units.Quantity(self.material[matProperty]).Value - # value = float(inputfield_text) # this fails on locale with comma - # https://forum.freecad.org/viewtopic.php?f=18&t=56912&p=523313#p523313 - - if not (1 - variation < float(old_value) / value < 1 + variation): - material = self.material - if qUnit != "": - material[matProperty] = str(value) + " " + qUnit - else: - material[matProperty] = str(value) - self.material = material - # mechanical input fields def ym_changed(self): - # FreeCADs standard unit for stress is kPa for UnitsSchemeInternal, but MPa can be used - self.update_material_property( - self.parameterWidget.input_fd_young_modulus.text(), - "YoungsModulus", - "kPa", - ) + if self.parameterWidget.chbu_allow_edit.isChecked(): + self.material["YoungsModulus"] = self.parameterWidget.qsb_young_modulus.property( + "value" + ).UserString def density_changed(self): - print( - "String read from density input field: {}".format( - self.parameterWidget.input_fd_density.text() - ) - ) - # FreeCADs standard unit for density is kg/mm^3 for UnitsSchemeInternal - self.update_material_property( - self.parameterWidget.input_fd_density.text(), - "Density", - "kg/m^3", - ) + if self.parameterWidget.chbu_allow_edit.isChecked(): + self.material["Density"] = self.parameterWidget.qsb_density.property("value").UserString def pr_changed(self): - value = self.parameterWidget.spinBox_poisson_ratio.value() - if value: - self.update_material_property( - self.parameterWidget.spinBox_poisson_ratio.text(), - "PoissonRatio", - "", - ) - elif value == 0: - # PoissonRatio was set to 0.0 what is possible - material = self.material - material["PoissonRatio"] = str(value) - self.material = material + if self.parameterWidget.chbu_allow_edit.isChecked(): + self.material["PoissonRatio"] = self.parameterWidget.qsb_poisson_ratio.property( + "value" + ).UserString # thermal input fields def tc_changed(self): - self.update_material_property( - self.parameterWidget.input_fd_thermal_conductivity.text(), - "ThermalConductivity", - "W/m/K", - ) + if self.parameterWidget.chbu_allow_edit.isChecked(): + self.material["ThermalConductivity"] = ( + self.parameterWidget.qsb_thermal_conductivity.property("value").UserString + ) def tec_changed(self): - self.update_material_property( - self.parameterWidget.input_fd_expansion_coefficient.text(), - "ThermalExpansionCoefficient", - "um/m/K", - ) + if self.parameterWidget.chbu_allow_edit.isChecked(): + self.material["ThermalExpansionCoefficient"] = ( + self.parameterWidget.qsb_expansion_coefficient.property("value").UserString + ) def sh_changed(self): - self.update_material_property( - self.parameterWidget.input_fd_specific_heat.text(), - "SpecificHeat", - "J/kg/K", - ) + if self.parameterWidget.chbu_allow_edit.isChecked(): + self.material["SpecificHeat"] = self.parameterWidget.qsb_specific_heat.property( + "value" + ).UserString # fluidic input fields - def vtec_changed(self): - self.update_material_property( - self.parameterWidget.input_fd_vol_expansion_coefficient.text(), - "VolumetricThermalExpansionCoefficient", - "m^3/m^3/K", - ) - def kinematic_viscosity_changed(self): - self.update_material_property( - self.parameterWidget.input_fd_kinematic_viscosity.text(), - "KinematicViscosity", - "m^2/s", - ) + if self.parameterWidget.chbu_allow_edit.isChecked(): + self.material["KinematicViscosity"] = ( + self.parameterWidget.qsb_kinematic_viscosity.property("value").UserString + ) def set_mat_params_in_input_fields(self, matmap): if "YoungsModulus" in matmap: - ym_new_unit = "MPa" - ym = Units.Quantity(matmap["YoungsModulus"]) - ym_with_new_unit = ym.getValueAs(ym_new_unit) - q = Units.Quantity(f"{ym_with_new_unit} {ym_new_unit}") - self.parameterWidget.input_fd_young_modulus.setText(q.UserString) + self.parameterWidget.qsb_young_modulus.setProperty( + "value", Units.Quantity(matmap["YoungsModulus"]) + ) + else: + self.parameterWidget.qsb_young_modulus.setProperty("rawValue", 0.0) + if "PoissonRatio" in matmap: - self.parameterWidget.spinBox_poisson_ratio.setValue(float(matmap["PoissonRatio"])) + self.parameterWidget.qsb_poisson_ratio.setProperty( + "value", Units.Quantity(matmap["PoissonRatio"]) + ) + else: + self.parameterWidget.qsb_poisson_ratio.setProperty("rawValue", 0.0) # Fluidic properties if "KinematicViscosity" in matmap: - nu_new_unit = "m^2/s" - nu = Units.Quantity(matmap["KinematicViscosity"]) - nu_with_new_unit = nu.getValueAs(nu_new_unit) - q = Units.Quantity(f"{nu_with_new_unit} {nu_new_unit}") - self.parameterWidget.input_fd_kinematic_viscosity.setText(q.UserString) - # For isotropic materials and fluidic material - # use the volumetric thermal expansion coefficient - # is approximately three times the linear coefficient for solids - if "VolumetricThermalExpansionCoefficient" in matmap: - vtec_new_unit = "m^3/m^3/K" - vtec = Units.Quantity(matmap["VolumetricThermalExpansionCoefficient"]) - vtec_with_new_unit = vtec.getValueAs(vtec_new_unit) - q = Units.Quantity(f"{vtec_with_new_unit} {vtec_new_unit}") - self.parameterWidget.input_fd_vol_expansion_coefficient.setText(q.UserString) + self.parameterWidget.qsb_kinematic_viscosity.setProperty( + "value", Units.Quantity(matmap["KinematicViscosity"]) + ) + else: + self.parameterWidget.qsb_kinematic_viscosity.setProperty("rawValue", 0.0) + if "Density" in matmap: - density_new_unit = "kg/m^3" - density = Units.Quantity(matmap["Density"]) - density_with_new_unit = density.getValueAs(density_new_unit) - # self.parameterWidget.input_fd_density.setText( - # "{} {}".format(density_with_new_unit, density_new_unit) - # ) - q = Units.Quantity(f"{density_with_new_unit} {density_new_unit}") - self.parameterWidget.input_fd_density.setText(q.UserString) + self.parameterWidget.qsb_density.setProperty("value", Units.Quantity(matmap["Density"])) + else: + self.parameterWidget.qsb_density.setProperty("rawValue", 0.0) # thermal properties if "ThermalConductivity" in matmap: - tc_new_unit = "W/m/K" - tc = Units.Quantity(matmap["ThermalConductivity"]) - tc_with_new_unit = tc.getValueAs(tc_new_unit) - q = Units.Quantity(f"{tc_with_new_unit} {tc_new_unit}") - self.parameterWidget.input_fd_thermal_conductivity.setText(q.UserString) - if "ThermalExpansionCoefficient" in matmap: # linear, only for solid - tec_new_unit = "um/m/K" - tec = Units.Quantity(matmap["ThermalExpansionCoefficient"]) - tec_with_new_unit = tec.getValueAs(tec_new_unit) - q = Units.Quantity(f"{tec_with_new_unit} {tec_new_unit}") - self.parameterWidget.input_fd_expansion_coefficient.setText(q.UserString) + self.parameterWidget.qsb_thermal_conductivity.setProperty( + "value", Units.Quantity(matmap["ThermalConductivity"]) + ) + else: + self.parameterWidget.qsb_thermal_conductivity.setProperty("rawValue", 0.0) + + if "ThermalExpansionCoefficient" in matmap: + v = Units.Quantity(matmap["ThermalExpansionCoefficient"]) + v.Format = {"Precision": 3} + self.parameterWidget.qsb_expansion_coefficient.setProperty("value", v) + else: + self.parameterWidget.qsb_expansion_coefficient.setProperty("rawValue", 0.0) if "SpecificHeat" in matmap: - sh_new_unit = "J/kg/K" - sh = Units.Quantity(matmap["SpecificHeat"]) - sh_with_new_unit = sh.getValueAs(sh_new_unit) - q = Units.Quantity(f"{sh_with_new_unit} {sh_new_unit}") - self.parameterWidget.input_fd_specific_heat.setText(q.UserString) + self.parameterWidget.qsb_specific_heat.setProperty( + "value", Units.Quantity(matmap["SpecificHeat"]) + ) + else: + self.parameterWidget.qsb_specific_heat.setProperty("rawValue", 0.0) def set_from_editor(self, value): mat = self.material_manager.getMaterial(value) self.material = mat.Properties self.uuid = mat.UUID - self.check_material_keys() self.set_mat_params_in_input_fields(self.material)