Fem: Use new material editor in Reinforced material task panel - fixes #18692
This commit is contained in:
committed by
Chris Hennes
parent
738a044f3c
commit
bf1ea8e223
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FemMaterial</class>
|
||||
<widget class="QWidget" name="FemMaterial">
|
||||
<class>FemMaterialReinforcement</class>
|
||||
<widget class="QWidget" name="FemMaterialReinforcement">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
@@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>FEM material</string>
|
||||
<string>FEM material reinforcement</string>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
@@ -30,63 +30,22 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="MatGui::MaterialTreeWidget" name="wgt_material_tree"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="lbl_material_descr">
|
||||
<property name="text">
|
||||
<string>Material</string>
|
||||
<string></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cb_materials_m">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Choose</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Properties</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="pb_edit_m">
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="l_name_m">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="l_description_m">
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -104,62 +63,21 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="MatGui::MaterialTreeWidget" name="wgt_reinf_tree"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<widget class="QLabel" name="lbl_reinf_descr">
|
||||
<property name="text">
|
||||
<string>Material</string>
|
||||
<string></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cb_materials_r">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Choose</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Properties</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="pb_edit_r">
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="l_name_r">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="l_description_r">
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -178,6 +96,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>MatGui::MaterialTreeWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>Mod/Material/Gui/MaterialTreeWidget.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@@ -128,7 +128,7 @@ def setup(doc=None, solvertype="ccxtools"):
|
||||
|
||||
# material
|
||||
matrixprop = {}
|
||||
matrixprop["Name"] = "Concrete-EN-C35/45"
|
||||
matrixprop["Name"] = "Concrete-EN-C35_45"
|
||||
matrixprop["YoungsModulus"] = "32000 MPa"
|
||||
matrixprop["PoissonRatio"] = "0.17"
|
||||
matrixprop["CompressiveStrength"] = "15.75 MPa"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2013 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
# * Copyright (c) 2016 Bernd Hahnebach <bernd@bimstatik.org> *
|
||||
# * Copyright (c) 2024 Mario Passaglia <mpassaglia[at]cbc.uba.ar> *
|
||||
# * *
|
||||
# * This file is part of the FreeCAD CAx development system. *
|
||||
# * *
|
||||
@@ -23,14 +24,16 @@
|
||||
# ***************************************************************************
|
||||
|
||||
__title__ = "FreeCAD FEM material document object"
|
||||
__author__ = "Juergen Riegel, Bernd Hahnebach"
|
||||
__author__ = "Juergen Riegel, Bernd Hahnebach, Mario Passaglia"
|
||||
__url__ = "https://www.freecad.org"
|
||||
|
||||
## @package material_common
|
||||
# \ingroup FEM
|
||||
# \brief material common object
|
||||
|
||||
from FreeCAD import Base
|
||||
from FreeCAD import Base, Units
|
||||
import Materials
|
||||
|
||||
from . import base_fempythonobject
|
||||
|
||||
_PropHelper = base_fempythonobject._PropHelper
|
||||
@@ -97,9 +100,42 @@ class MaterialCommon(base_fempythonobject.BaseFemPythonObject):
|
||||
# change References to App::PropertyLinkSubListGlobal
|
||||
prop.handle_change_type(obj, old_type="App::PropertyLinkSubList")
|
||||
|
||||
# try update UUID from Material
|
||||
if not obj.UUID:
|
||||
obj.UUID = self._get_material_uuid(obj.Material)
|
||||
|
||||
if not obj.hasExtension("App::SuppressibleExtensionPython"):
|
||||
obj.addExtension("App::SuppressibleExtensionPython")
|
||||
|
||||
def _get_material_uuid(self, material):
|
||||
if not material:
|
||||
return ""
|
||||
|
||||
material_manager = Materials.MaterialManager()
|
||||
|
||||
for a_mat in material_manager.Materials:
|
||||
unmatched_item = True
|
||||
a_mat_prop = material_manager.getMaterial(a_mat).Properties
|
||||
for it in material:
|
||||
if it in a_mat_prop:
|
||||
# first try to compare quantities
|
||||
try:
|
||||
unmatched_item = Units.Quantity(material[it]) != Units.Quantity(
|
||||
a_mat_prop[it]
|
||||
)
|
||||
except ValueError:
|
||||
# if there is no quantity, compare values directly
|
||||
unmatched_item = material[it] != a_mat_prop[it]
|
||||
|
||||
if unmatched_item:
|
||||
break
|
||||
|
||||
if not unmatched_item:
|
||||
# all material items are found in a_mat
|
||||
return a_mat
|
||||
|
||||
return ""
|
||||
|
||||
"""
|
||||
Some remarks to the category. Not finished, thus to be continued.
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2019 Bernd Hahnebach <bernd@bimstatik.org> *
|
||||
# * Copyright (c) 2024 Mario Passaglia <mpassaglia[at]cbc.uba.ar> *
|
||||
# * *
|
||||
# * This file is part of the FreeCAD CAx development system. *
|
||||
# * *
|
||||
@@ -22,7 +23,7 @@
|
||||
# ***************************************************************************
|
||||
|
||||
__title__ = "FreeCAD FEM reinforced material"
|
||||
__author__ = "Bernd Hahnebach"
|
||||
__author__ = "Bernd Hahnebach, Mario Passaglia"
|
||||
__url__ = "https://www.freecad.org"
|
||||
|
||||
## @package material_reinforced
|
||||
@@ -30,6 +31,7 @@ __url__ = "https://www.freecad.org"
|
||||
# \brief reinforced object
|
||||
|
||||
from . import material_common
|
||||
from .base_fempythonobject import _PropHelper
|
||||
|
||||
|
||||
class MaterialReinforced(material_common.MaterialCommon):
|
||||
@@ -42,10 +44,37 @@ class MaterialReinforced(material_common.MaterialCommon):
|
||||
def __init__(self, obj):
|
||||
super().__init__(obj)
|
||||
|
||||
obj.addProperty(
|
||||
"App::PropertyMap", "Reinforcement", "Composites", "Reinforcement material properties"
|
||||
)
|
||||
obj.setPropertyStatus("Reinforcement", "LockDynamic")
|
||||
|
||||
# overwrite Category enumeration
|
||||
obj.Category = ["Solid"]
|
||||
|
||||
def _get_properties(self):
|
||||
prop = super()._get_properties()
|
||||
|
||||
prop.append(
|
||||
_PropHelper(
|
||||
type="App::PropertyMap",
|
||||
name="Reinforcement",
|
||||
group="Composites",
|
||||
doc="Reinforcement material properties",
|
||||
value={},
|
||||
)
|
||||
)
|
||||
prop.append(
|
||||
_PropHelper(
|
||||
type="App::PropertyString",
|
||||
name="ReinforcementUUID",
|
||||
group="Composites",
|
||||
doc="Reinforcement material UUID",
|
||||
hidden=True,
|
||||
value="",
|
||||
)
|
||||
)
|
||||
|
||||
return prop
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
|
||||
# try update Reinforcement UUID from Reinforcement
|
||||
if not obj.ReinforcementUUID:
|
||||
obj.ReinforcementUUID = self._get_material_uuid(obj.Reinforcement)
|
||||
|
||||
@@ -135,7 +135,7 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
|
||||
self.form = [self.parameterWidget, self.selectionWidget]
|
||||
|
||||
# check references, has to be after initialisation of selectionWidget
|
||||
self.material_tree.UUID = self.get_material_uuid(self.material)
|
||||
self.material_tree.UUID = self.uuid
|
||||
self.set_mat_params_in_input_fields(self.material)
|
||||
|
||||
self.selectionWidget.has_equal_references_shape_types()
|
||||
@@ -170,50 +170,6 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
|
||||
material_filter.RequiredModels = [uuids.Fluid]
|
||||
self.material_tree.setFilter(material_filter)
|
||||
|
||||
def get_material_uuid(self, material):
|
||||
if self.uuid:
|
||||
try:
|
||||
self.material_manager.getMaterial(self.uuid)
|
||||
return self.uuid
|
||||
except:
|
||||
return ""
|
||||
|
||||
if not self.material:
|
||||
return ""
|
||||
|
||||
for a_mat in self.material_manager.Materials:
|
||||
# check if every item of the current material fits to a known material card
|
||||
# if all items were found we know it is the right card
|
||||
# we can hereby not simply perform
|
||||
# set(self.materials[a_mat].items()) ^ set(material.items())
|
||||
# because entries are often identical, just appear in the set in a different order
|
||||
unmatched_item = False
|
||||
a_mat_prop = self.material_manager.getMaterial(a_mat).Properties.items()
|
||||
for item in material.items():
|
||||
if item not in a_mat_prop:
|
||||
unmatched_item = True
|
||||
# often the difference is just a decimal e.g. "120" to "120.0"
|
||||
# therefore first check if the item name exists
|
||||
for a_mat_item in a_mat_prop:
|
||||
if item[0] == a_mat_item[0]:
|
||||
# now check if we have a number value in a unit
|
||||
if item[1].split() and not self.isfloat(item[1].split()[0]):
|
||||
break
|
||||
if item[1].split() and float(item[1].split()[0]) == float(
|
||||
a_mat_item[1].split()[0]
|
||||
):
|
||||
unmatched_item = False
|
||||
elif not item[1].split():
|
||||
# handle the case where item[1] is an empty string
|
||||
if not self.isfloat(item[1]):
|
||||
break
|
||||
if float(item[1]) == float(a_mat_item[1]):
|
||||
unmatched_item = False
|
||||
break
|
||||
if not unmatched_item:
|
||||
return a_mat
|
||||
return ""
|
||||
|
||||
def toggleInputFieldsReadOnly(self):
|
||||
if self.parameterWidget.chbu_allow_edit.isChecked():
|
||||
self.parameterWidget.qsb_density.setReadOnly(False)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2019 Bernd Hahnebach <bernd@bimstatik.org> *
|
||||
# * Copyright (c) 2024 Mario Passaglia <mpassaglia[at]cbc.uba.ar> *
|
||||
# * *
|
||||
# * This file is part of the FreeCAD CAx development system. *
|
||||
# * *
|
||||
@@ -22,7 +23,7 @@
|
||||
# ***************************************************************************
|
||||
|
||||
__title__ = "FreeCAD FEM material reinforced task panel for the document object"
|
||||
__author__ = "Bernd Hahnebach"
|
||||
__author__ = "Bernd Hahnebach, Mario Passaglia"
|
||||
__url__ = "https://www.freecad.org"
|
||||
|
||||
## @package task_material_reinforced
|
||||
@@ -34,6 +35,9 @@ from PySide import QtGui
|
||||
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
import Materials
|
||||
import MatGui
|
||||
|
||||
from . import base_femtaskpanel
|
||||
|
||||
|
||||
@@ -45,349 +49,64 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
|
||||
def __init__(self, obj):
|
||||
super().__init__(obj)
|
||||
|
||||
# init matrix and reinforcement material
|
||||
self.material_m = self.obj.Material
|
||||
self.card_path_m = ""
|
||||
self.has_transient_mat_m = False
|
||||
self.material_r = self.obj.Reinforcement
|
||||
self.card_path_r = ""
|
||||
self.has_transient_mat_r = False
|
||||
# mat_card is the FCMat file
|
||||
# card_name is the file name of the mat_card
|
||||
# card_path is the whole file path of the mat_card
|
||||
# material_name is the value of the key name in FreeCAD material dictionary
|
||||
# they might not match because of special letters in the material_name which are
|
||||
# changed in the card_name to english standard characters
|
||||
|
||||
# init for collecting all mat data and icons
|
||||
self.materials = {} # { card_path : FreeCAD material dict }
|
||||
self.cards = {} # { card_path : card_names, ... }
|
||||
self.icons = {} # { card_path : icon_path }
|
||||
self.material = self.obj.Material
|
||||
self.uuid = self.obj.UUID
|
||||
self.reinf = self.obj.Reinforcement
|
||||
self.reinf_uuid = self.obj.ReinforcementUUID
|
||||
self.material_manager = Materials.MaterialManager()
|
||||
|
||||
# parameter widget
|
||||
self.parameterWidget = FreeCADGui.PySideUic.loadUi(
|
||||
self.parameter_widget = FreeCADGui.PySideUic.loadUi(
|
||||
FreeCAD.getHomePath() + "Mod/Fem/Resources/ui/MaterialReinforcement.ui"
|
||||
)
|
||||
|
||||
# globals
|
||||
self.material_tree = MatGui.MaterialTreeWidget(self.parameter_widget.wgt_material_tree)
|
||||
self.material_tree.expanded = False
|
||||
self.material_tree.IncludeEmptyFolders = False
|
||||
self.material_tree.IncludeEmptyLibraries = False
|
||||
|
||||
self.reinf_tree = MatGui.MaterialTreeWidget(self.parameter_widget.wgt_reinf_tree)
|
||||
self.reinf_tree.expanded = False
|
||||
self.reinf_tree.IncludeEmptyFolders = False
|
||||
self.reinf_tree.IncludeEmptyLibraries = False
|
||||
|
||||
self.form = self.parameter_widget
|
||||
|
||||
QtCore.QObject.connect(
|
||||
self.parameterWidget.cb_materials_m,
|
||||
QtCore.SIGNAL("activated(int)"),
|
||||
self.choose_material_m,
|
||||
)
|
||||
QtCore.QObject.connect(
|
||||
self.parameterWidget.pb_edit_m, QtCore.SIGNAL("clicked()"), self.edit_material_m
|
||||
)
|
||||
QtCore.QObject.connect(
|
||||
self.parameterWidget.cb_materials_r,
|
||||
QtCore.SIGNAL("activated(int)"),
|
||||
self.choose_material_r,
|
||||
)
|
||||
QtCore.QObject.connect(
|
||||
self.parameterWidget.pb_edit_r, QtCore.SIGNAL("clicked()"), self.edit_material_r
|
||||
self.parameter_widget.wgt_material_tree,
|
||||
QtCore.SIGNAL("onMaterial(QString)"),
|
||||
self.set_material,
|
||||
)
|
||||
|
||||
# get all available materials (fill self.materials, self.cards and self.icons)
|
||||
from materialtools.cardutils import import_materials as getmats
|
||||
QtCore.QObject.connect(
|
||||
self.parameter_widget.wgt_reinf_tree,
|
||||
QtCore.SIGNAL("onMaterial(QString)"),
|
||||
self.set_reinforcement,
|
||||
)
|
||||
|
||||
self.materials, self.cards, self.icons = getmats()
|
||||
# fill the material comboboxes with material cards
|
||||
self.add_cards_to_combo_boxes()
|
||||
self.material_tree.UUID = self.uuid
|
||||
self.reinf_tree.UUID = self.reinf_uuid
|
||||
|
||||
# search for exact the mat_card_m and mat_card_r in all known cards
|
||||
# choose the current matrix material
|
||||
self.card_path_m = self.get_material_card(self.material_m)
|
||||
FreeCAD.Console.PrintLog(f"card_path: {self.card_path_m}\n")
|
||||
if not self.card_path_m:
|
||||
# we have not found our material in self.materials dict :-(
|
||||
# we're going to add a user-defined temporary material: a document material
|
||||
FreeCAD.Console.PrintMessage(
|
||||
"Previously used material card cannot be found in material directories. "
|
||||
"Add document material.\n"
|
||||
)
|
||||
self.card_path_m = "_Document_Matrix_Material"
|
||||
self.materials[self.card_path_m] = self.material_m
|
||||
self.parameterWidget.cb_materials_m.addItem(
|
||||
QtGui.QIcon(":/icons/help-browser.svg"), self.card_path_m, self.card_path_m
|
||||
)
|
||||
index = self.parameterWidget.cb_materials_m.findData(self.card_path_m)
|
||||
# fill input fields and set the current material in the cb widget
|
||||
self.choose_material_m(index)
|
||||
else:
|
||||
# we found our exact material in self.materials dict :-)
|
||||
FreeCAD.Console.PrintLog(
|
||||
"Previously used material card was found in material directories. "
|
||||
"We will use this material.\n"
|
||||
)
|
||||
index = self.parameterWidget.cb_materials_m.findData(self.card_path_m)
|
||||
# set the current material in the cb widget
|
||||
self.choose_material_m(index)
|
||||
|
||||
# choose the current reinforcement material
|
||||
self.card_path_r = self.get_material_card(self.material_r)
|
||||
FreeCAD.Console.PrintLog(f"card_path: {self.card_path_r}\n")
|
||||
if not self.card_path_r:
|
||||
# we have not found our material in self.materials dict :-(
|
||||
# we're going to add a user-defined temporary material: a document material
|
||||
FreeCAD.Console.PrintMessage(
|
||||
"Previously used material card cannot be found in material directories. "
|
||||
"Add document material.\n"
|
||||
)
|
||||
self.card_path_r = "_Document_Reinforcement_Material"
|
||||
self.materials[self.card_path_r] = self.material_r
|
||||
self.parameterWidget.cb_materials_r.addItem(
|
||||
QtGui.QIcon(":/icons/help-browser.svg"), self.card_path_r, self.card_path_r
|
||||
)
|
||||
index = self.parameterWidget.cb_materials_r.findData(self.card_path_r)
|
||||
# set the current material in the cb widget
|
||||
self.choose_material_r(index)
|
||||
else:
|
||||
# we found our exact material in self.materials dict :-)
|
||||
FreeCAD.Console.PrintLog(
|
||||
"Previously used material card was found in material directories. "
|
||||
"We will use this material.\n"
|
||||
)
|
||||
index = self.parameterWidget.cb_materials_r.findData(self.card_path_r)
|
||||
# fill input fields and set the current material in the cb widget
|
||||
self.choose_material_r(index)
|
||||
|
||||
# set up the form
|
||||
self.form = self.parameterWidget
|
||||
|
||||
# leave task panel ***************************************************************************
|
||||
def accept(self):
|
||||
from materialtools.cardutils import check_mat_units as checkunits
|
||||
self.obj.Material = self.material
|
||||
self.obj.UUID = self.uuid
|
||||
self.obj.Reinforcement = self.reinf
|
||||
self.obj.ReinforcementUUID = self.reinf_uuid
|
||||
|
||||
if checkunits(self.material_m) is True and checkunits(self.material_r) is True:
|
||||
self.obj.Material = self.material_m
|
||||
self.obj.Reinforcement = self.material_r
|
||||
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)
|
||||
return super().accept()
|
||||
|
||||
def reject(self):
|
||||
return super().reject()
|
||||
|
||||
# choose material card ***********************************************************************
|
||||
def get_material_card(self, material):
|
||||
for a_mat in self.materials:
|
||||
unmatched_items = set(self.materials[a_mat].items()) ^ set(material.items())
|
||||
# print(a_mat + " --> unmatched_items = " + str(len(unmatched_items)))
|
||||
if len(unmatched_items) < 4:
|
||||
FreeCAD.Console.PrintLog(f"{unmatched_items}\n")
|
||||
if len(unmatched_items) == 0:
|
||||
return a_mat
|
||||
return ""
|
||||
|
||||
def choose_material_m(self, index):
|
||||
if index < 0:
|
||||
def set_material(self, value):
|
||||
if not value:
|
||||
return
|
||||
# get the whole card path
|
||||
self.card_path_m = self.parameterWidget.cb_materials_m.itemData(index)
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f"choose_material in FEM material task panel:\n {self.card_path_m}\n"
|
||||
)
|
||||
self.material_m = self.materials[self.card_path_m]
|
||||
self.parameterWidget.cb_materials_m.setCurrentIndex(index)
|
||||
gen_mat_desc = ""
|
||||
gen_mat_name = ""
|
||||
if "Description" in self.material_m:
|
||||
gen_mat_desc = self.material_m["Description"]
|
||||
if "Name" in self.material_m:
|
||||
gen_mat_name = self.material_m["Name"]
|
||||
self.parameterWidget.l_description_m.setText(gen_mat_desc)
|
||||
self.parameterWidget.l_name_m.setText(gen_mat_name)
|
||||
mat = self.material_manager.getMaterial(value)
|
||||
self.material = mat.Properties
|
||||
self.uuid = mat.UUID
|
||||
self.parameter_widget.lbl_material_descr.setText(self.material["Description"])
|
||||
|
||||
def choose_material_r(self, index):
|
||||
if index < 0:
|
||||
def set_reinforcement(self, value):
|
||||
if not value:
|
||||
return
|
||||
# get the whole card path
|
||||
self.card_path_r = self.parameterWidget.cb_materials_r.itemData(index)
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f"choose_material in FEM material task panel:\n {self.card_path_r}\n"
|
||||
)
|
||||
self.material_r = self.materials[self.card_path_r]
|
||||
self.parameterWidget.cb_materials_r.setCurrentIndex(index)
|
||||
gen_mat_desc = ""
|
||||
gen_mat_name = ""
|
||||
if "Description" in self.material_r:
|
||||
gen_mat_desc = self.material_r["Description"]
|
||||
if "Name" in self.material_r:
|
||||
gen_mat_name = self.material_r["Name"]
|
||||
self.parameterWidget.l_description_r.setText(gen_mat_desc)
|
||||
self.parameterWidget.l_name_r.setText(gen_mat_name)
|
||||
|
||||
# transient material is needed if the user changed mat parameter by the mat editor
|
||||
def set_transient_material_m(self):
|
||||
self.card_path_m = "_Transient_Matrix_Material"
|
||||
self.materials[self.card_path_m] = self.material_m # = the current matrix mat dict
|
||||
index = self.parameterWidget.cb_materials_m.findData(self.card_path_m)
|
||||
self.choose_material_m(index)
|
||||
|
||||
def add_transient_material_m(self):
|
||||
self.has_transient_mat_m = True
|
||||
self.card_path_m = "_Transient_Matrix_Material"
|
||||
self.parameterWidget.cb_materials_m.addItem(
|
||||
QtGui.QIcon(":/icons/help-browser.svg"), self.card_path_m, self.card_path_m
|
||||
)
|
||||
self.set_transient_material_m()
|
||||
|
||||
def set_transient_material_r(self):
|
||||
self.card_path_r = "_Transient_Reinforcement_Material"
|
||||
self.materials[self.card_path_r] = self.material_r # = the current reinforced mat dict
|
||||
index = self.parameterWidget.cb_materials_r.findData(self.card_path_r)
|
||||
self.choose_material_r(index)
|
||||
|
||||
def add_transient_material_r(self):
|
||||
self.has_transient_mat_r = True
|
||||
self.card_path_r = "_Transient_Reinforcement_Material"
|
||||
self.parameterWidget.cb_materials_r.addItem(
|
||||
QtGui.QIcon(":/icons/help-browser.svg"), self.card_path_r, self.card_path_r
|
||||
)
|
||||
self.set_transient_material_r()
|
||||
|
||||
# edit material parameter ********************************************************************
|
||||
# TODO, also all mat parameter checks should be moved to material editor
|
||||
# and mat parameter checks should be done on analysis precheck in according to the analysis
|
||||
# should be checked if all needed parameter are defined and have all right values and units
|
||||
def edit_material_m(self):
|
||||
# opens the material editor to choose a material or edit material params
|
||||
import MaterialEditor
|
||||
|
||||
if self.card_path_m not in self.cards:
|
||||
FreeCAD.Console.PrintLog(
|
||||
"Card path not in cards, material dict will be used to open Material Editor.\n"
|
||||
)
|
||||
new_material_params = MaterialEditor.editMaterial(material=self.material_m)
|
||||
else:
|
||||
new_material_params = MaterialEditor.editMaterial(card_path=self.card_path_m)
|
||||
# material editor returns the mat_dict only, not a card_path
|
||||
# if the material editor was canceled a empty dict will be returned
|
||||
# do not change the self.material
|
||||
# check if dict is not empty (do not use "is True")
|
||||
if new_material_params:
|
||||
# check material quantity units
|
||||
from materialtools.cardutils import check_mat_units as checkunits
|
||||
|
||||
if checkunits(new_material_params) is True:
|
||||
self.material_m = new_material_params
|
||||
self.card_path_m = self.get_material_card(self.material_m)
|
||||
FreeCAD.Console.PrintMessage(f"card_path: {self.card_path_m}\n")
|
||||
if not self.card_path_m:
|
||||
FreeCAD.Console.PrintMessage(
|
||||
"Material card chosen by the material editor "
|
||||
"was not found in material directories.\n"
|
||||
"Either the card does not exist or some material "
|
||||
"parameter where changed in material editor.\n"
|
||||
)
|
||||
if self.has_transient_mat_m is False:
|
||||
self.add_transient_material_m()
|
||||
else:
|
||||
self.set_transient_material_m()
|
||||
else:
|
||||
# we found our exact material in self.materials dict :-)
|
||||
FreeCAD.Console.PrintLog(
|
||||
"Material card chosen by the material editor "
|
||||
"was found in material directories. "
|
||||
"The found material card will be used.\n"
|
||||
)
|
||||
index = self.parameterWidget.cb_materials_m.findData(self.card_path_m)
|
||||
# set the current material in the cb widget
|
||||
self.choose_material_m(index)
|
||||
else:
|
||||
error_message = (
|
||||
"Due to some wrong material quantity units in data passed "
|
||||
"by the material editor, the material data was not changed.\n"
|
||||
)
|
||||
FreeCAD.Console.PrintError(error_message)
|
||||
QtGui.QMessageBox.critical(None, "Material data not changed", error_message)
|
||||
else:
|
||||
FreeCAD.Console.PrintMessage("No changes where made by the material editor.\n")
|
||||
|
||||
def edit_material_r(self):
|
||||
# opens the material editor to choose a material or edit material params
|
||||
import MaterialEditor
|
||||
|
||||
if self.card_path_r not in self.cards:
|
||||
FreeCAD.Console.PrintLog(
|
||||
"Card path not in cards, material dict will be used to open Material Editor.\n"
|
||||
)
|
||||
new_material_params = MaterialEditor.editMaterial(material=self.material_r)
|
||||
else:
|
||||
new_material_params = MaterialEditor.editMaterial(card_path=self.card_path_r)
|
||||
# material editor returns the mat_dict only, not a card_path
|
||||
# if the material editor was canceled a empty dict will be returned
|
||||
# do not change the self.material
|
||||
# check if dict is not empty (do not use "is True")
|
||||
if new_material_params:
|
||||
# check material quantity units
|
||||
from materialtools.cardutils import check_mat_units as checkunits
|
||||
|
||||
if checkunits(new_material_params) is True:
|
||||
self.material_r = new_material_params
|
||||
self.card_path_r = self.get_material_card(self.material_r)
|
||||
FreeCAD.Console.PrintMessage(f"card_path: {self.card_path_r}\n")
|
||||
if not self.card_path_r:
|
||||
FreeCAD.Console.PrintMessage(
|
||||
"Material card chosen by the material editor "
|
||||
"was not found in material directories.\n"
|
||||
"Either the card does not exist or some material "
|
||||
"parameter where changed in material editor.\n"
|
||||
)
|
||||
if self.has_transient_mat_r is False:
|
||||
self.add_transient_material_r()
|
||||
else:
|
||||
self.set_transient_material_r()
|
||||
else:
|
||||
# we found our exact material in self.materials dict :-)
|
||||
FreeCAD.Console.PrintLog(
|
||||
"Material card chosen by the material editor "
|
||||
"was found in material directories. "
|
||||
"The found material card will be used.\n"
|
||||
)
|
||||
index = self.parameterWidget.cb_materials_r.findData(self.card_path_r)
|
||||
# set the current material in the cb widget
|
||||
self.choose_material_r(index)
|
||||
else:
|
||||
error_message = (
|
||||
"Due to some wrong material quantity units in data passed "
|
||||
"by the material editor, the material data was not changed.\n"
|
||||
)
|
||||
FreeCAD.Console.PrintError(error_message)
|
||||
QtGui.QMessageBox.critical(None, "Material data not changed", error_message)
|
||||
else:
|
||||
FreeCAD.Console.PrintMessage("No changes where made by the material editor.\n")
|
||||
|
||||
# fill the combo box with cards **************************************************************
|
||||
def add_cards_to_combo_boxes(self):
|
||||
# fill comboboxes, in combo box the card name is used not the material name
|
||||
self.parameterWidget.cb_materials_m.clear()
|
||||
self.parameterWidget.cb_materials_r.clear()
|
||||
|
||||
mat_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Material/Cards")
|
||||
sort_by_resources = mat_prefs.GetBool("SortByResources", False)
|
||||
|
||||
card_name_list = [] # [ [card_name, card_path, icon_path], ... ]
|
||||
|
||||
if sort_by_resources is True:
|
||||
for a_path in sorted(self.materials):
|
||||
card_name_list.append([self.cards[a_path], a_path, self.icons[a_path]])
|
||||
else:
|
||||
card_names_tmp = {}
|
||||
for path, name in self.cards.items():
|
||||
card_names_tmp[name] = path
|
||||
for a_name in sorted(card_names_tmp):
|
||||
a_path = card_names_tmp[a_name]
|
||||
card_name_list.append([a_name, a_path, self.icons[a_path]])
|
||||
|
||||
for mat in card_name_list:
|
||||
self.parameterWidget.cb_materials_m.addItem(QtGui.QIcon(mat[2]), mat[0], mat[1])
|
||||
self.parameterWidget.cb_materials_r.addItem(QtGui.QIcon(mat[2]), mat[0], mat[1])
|
||||
# the whole card path is added to the combo box to make it unique
|
||||
# see def choose_material:
|
||||
# for assignment of self.card_path the path form the parameterWidget is used
|
||||
mat = self.material_manager.getMaterial(value)
|
||||
self.reinf = mat.Properties
|
||||
self.reinf_uuid = mat.UUID
|
||||
self.parameter_widget.lbl_reinf_descr.setText(self.reinf["Description"])
|
||||
|
||||
Reference in New Issue
Block a user