[Material] allow to use vectorial properties

- for electromagnetics we have vector fields and thus need to specify components
- as first step use the new material "Magnetization"

- also get rid of annoying debug messages output on normal use in the material dialog
This commit is contained in:
Uwe
2023-02-09 04:23:25 +01:00
parent 436703e8ce
commit cbe634719d
4 changed files with 56 additions and 28 deletions

View File

@@ -592,7 +592,6 @@ class MaterialsDelegate(QtGui.QStyledItemDelegate):
return
if column == 1:
row = index.row()
PP = group.child(row, 0)
@@ -602,7 +601,6 @@ class MaterialsDelegate(QtGui.QStyledItemDelegate):
if TT:
Type = TT.text()
else:
Type = "String"
@@ -612,15 +610,12 @@ class MaterialsDelegate(QtGui.QStyledItemDelegate):
editor = matProperWidget(parent, matproperty, Type, Value)
elif column == 0:
if group.text() == "User defined":
editor = matProperWidget(parent)
else:
return
else:
return
return editor
@@ -632,21 +627,17 @@ class MaterialsDelegate(QtGui.QStyledItemDelegate):
Type = editor.property("Type")
model = index.model()
item = model.itemFromIndex(index)
print("item1={}".format(item.text()))
if Type == "Color":
color = editor.property("color")
color = tuple([v/255.0 for v in color.getRgb()])
item.setText(str(color))
elif Type == "File":
lineEdit = editor.children()[1]
item.setText(lineEdit.text())
else:
super(MaterialsDelegate, self).setEditorData(editor, index)
@@ -670,31 +661,36 @@ def matProperWidget(parent=None, matproperty=None, Type="String", Value=None,
# the user defined properties are of Type String and thus uses a "Gui::PrefLineEdit"
print(matproperty)
print(Type)
print(Value)
ui = FreeCADGui.UiLoader()
if Type == "String":
widget = ui.createWidget("Gui::PrefLineEdit")
elif Type == "URL":
widget = ui.createWidget("Gui::PrefLineEdit")
elif Type == "File":
widget = ui.createWidget("Gui::FileChooser")
if Value:
lineEdit = widget.children()[1]
lineEdit.setText(Value)
elif Type == "Quantity" or Type == "Float":
# the Gui::InputField is used for Floats too, because of the digits
widget = ui.createWidget("Gui::InputField")
# print(matproperty)
# for properties with an underscored number (vectorial values),
# we must strip the part after the first underscore to obtain the bound unit
# since in cardutils.py in def get_material_template
# the underscores were removed, we must first check for numbers
# and then for "Im" (denotes an imaginery value)
import re
if re.search(r'\d', matproperty):
matpropertyNum = matproperty.rstrip('0123456789')
matproperty = matpropertyNum
if matproperty.find("Im") != -1:
matproperty = matproperty.split("Im")[0]
if hasattr(FreeCAD.Units, matproperty):
unit = getattr(FreeCAD.Units, matproperty)
quantity = FreeCAD.Units.Quantity(1, unit)
@@ -704,34 +700,27 @@ def matProperWidget(parent=None, matproperty=None, Type="String", Value=None,
"Not known unit for property: {}. Probably the Quantity does not have a unit.\n"
.format(matproperty)
)
# the Gui::InputField is used for Floats too, because of the digits
elif Type == "Integer":
widget = ui.createWidget("Gui::UIntSpinBox")
# elif Type == "Float":
# widget = ui.createWidget("Gui::PrefDoubleSpinBox")
# has only 2 digit precision, but for example RelativePermittivity needs much more
# see material card for Air, thus Workaround
# a "Gui::InputField" without unit is used
elif Type == "Enumerator":
widget = ui.createWidget("Gui::PrefComboBox")
elif Type == "Boolean":
widget = ui.createWidget("Gui::PrefComboBox")
widget.insertItems(0, ["", "False", "True"])
elif Type == "Vector":
widget = ui.createWidget("Gui::PrefLineEdit")
elif Type == "Color":
widget = ui.createWidget("Gui::PrefColorButton")
if Value:
value = string2tuple(Value)
@@ -740,7 +729,6 @@ def matProperWidget(parent=None, matproperty=None, Type="String", Value=None,
widget.setProperty("color", color)
else:
widget = QtGui.QLineEdit()
if minimum is not None:

View File

@@ -123,6 +123,14 @@ ElectricalConductivity =
; https://en.wikipedia.org/wiki/Permeability_(electromagnetism)
RelativePermeability =
; The magnetization in [FreeCAD Magnetization unit]"
; https://en.wikipedia.org/wiki/Magnetization
Magnetization_1 =
Magnetization_2 =
Magnetization_3 =
Magnetization_Im_1 =
Magnetization_Im_2 =
Magnetization_Im_3 =
[Architectural]
; Description to be updated

View File

@@ -113,7 +113,7 @@
FractureToughness:
Type: 'Float'
URL: 'https://en.wikipedia.org/wiki/Fracture_toughness'
Description: "Unit MPa * m^0.5 is not possible ATM in FreeCAD nicht moeglich thus String. Keep in mind the unit is fixed MPa * m^0.5. https://github.com/FreeCAD/FreeCAD/pull/2156"
Description: "Unit MPa * m^0.5 is not possible ATM in FreeCAD thus String. Keep in mind the unit is fixed MPa * m^0.5. https://github.com/FreeCAD/FreeCAD/pull/2156"
PoissonRatio:
Type: 'Float'
URL: 'https://en.wikipedia.org/wiki/Poisson%27s_ratio'
@@ -168,6 +168,30 @@
Type: 'Float'
URL: 'https://en.wikipedia.org/wiki/Permeability_(electromagnetism)'
Description: "The ratio to the permeability of the vacuum"
Magnetization_1:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Magnetization'
Description: "Magnetization in x-direction in [FreeCAD Magnetization unit]"
Magnetization_2:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Magnetization'
Description: "Magnetization in y-direction in [FreeCAD Magnetization unit]"
Magnetization_3:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Magnetization'
Description: "Magnetization in z-direction in [FreeCAD Magnetization unit]"
Magnetization_Im_1:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Magnetization'
Description: "Magnetization, imagaginary part, in x-direction in [FreeCAD Magnetization unit]"
Magnetization_Im_2:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Magnetization'
Description: "Magnetization, imagaginary part, in y-direction in [FreeCAD Magnetization unit]"
Magnetization_Im_3:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Magnetization'
Description: "Magnetization, imagaginary part, in z-direction in [FreeCAD Magnetization unit]"
- Architectural:
Color:
Type: 'String'

View File

@@ -237,6 +237,11 @@ def get_material_template(withSpaces=False):
new_group[gg] = {}
for proper in list(group[gg].keys()):
new_proper = re.sub(r"(\w)([A-Z]+)", r"\1 \2", proper)
# strip underscores of vectorial properties
new_proper = new_proper.replace("_", " ")
# this can lead to double spaces for imaginary properties
# e.g. "_Im_1", therefore remove one
new_proper = new_proper.replace(" ", " ")
new_group[gg][new_proper] = group[gg][proper]
new_template.append(new_group)
template_data = new_template
@@ -439,8 +444,11 @@ def write_cards_to_path(cards_path, cards_data, write_group_section=True, write_
# ***** material parameter units *********************************************
def check_parm_unit(param):
# check if this parameter is known to FreeCAD unit system
# for properties with underscores (vectorial values), we must
# strip the part after the first underscore to obtain the bound unit
from FreeCAD import Units
# FreeCAD.Console.PrintMessage('{}\n'.format(param))
if param.find("_") != -1:
param = param.split("_")[0]
if hasattr(Units, param):
return True
else: