Skip to content

Commit 0000732

Browse files
berndhahnebachwwmayer
authored andcommitted
Material: editor, get rid of duplicate unit definition
- in mat editor xml file and in FreeCAD unit system - remove it from material editor xml file and get it from FreeCAD unit system
1 parent 96a1007 commit 0000732

File tree

2 files changed

+22
-33
lines changed

2 files changed

+22
-33
lines changed

src/Mod/Material/MatPropDict.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,44 @@
2323
</Group>
2424

2525
<Group Name="Mechanical">
26-
<Property Name="Density" Type="Quantity" Units="(-3, 1, 0, 0, 0, 0, 0, 0)">
26+
<Property Name="Density" Type="Quantity">
2727
<Reference>https://en.wikipedia.org/wiki/Density</Reference>
2828
</Property>
29-
<Property Name="YoungsModulus" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
29+
<Property Name="YoungsModulus" Type="Quantity">
3030
<Reference>https://en.wikipedia.org/wiki/Young%27s_modulus</Reference>
3131
</Property>
3232
<Property Name="PoissonRatio" Type="Float">
3333
<Reference>https://en.wikipedia.org/wiki/Poisson%27s_ratio</Reference>
3434
</Property>
35-
<Property Name="UltimateTensileStrength" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
35+
<Property Name="UltimateTensileStrength" Type="Quantity">
3636
<Reference>https://en.wikipedia.org/wiki/Ultimate_tensile_strength</Reference>
3737
</Property>
38-
<Property Name="CompressiveStrength" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
38+
<Property Name="CompressiveStrength" Type="Quantity">
3939
<Reference>https://en.wikipedia.org/wiki/Compressive_strength</Reference>
4040
</Property>
41-
<Property Name="YieldStrength" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
41+
<Property Name="YieldStrength" Type="Quantity">
4242
<Reference>https://en.wikipedia.org/wiki/Yield_Strength</Reference>
4343
</Property>
4444
<Property Name="UltimateStrain" Type="Float">
4545
<Reference>https://en.wikipedia.org/wiki/Deformation_(mechanics)</Reference>
4646
</Property>
47-
<Property Name="FractureToughness" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
47+
<Property Name="FractureToughness" Type="Quantity">
4848
<Reference>https://en.wikipedia.org/wiki/Fracture_toughness</Reference>
4949
</Property>
50-
<Property Name="AngleOfFriction" Type="Quantity" Units="(0, 0, 0, 0, 0, 0, 0, 1)">
50+
<Property Name="AngleOfFriction" Type="Quantity">
5151
<Reference>https://en.wikipedia.org/wiki/Friction#Angle_of_friction</Reference>
5252
<Reference>https://en.m.wikipedia.org/wiki/Mohr%E2%80%93Coulomb_theory</Reference>
5353
</Property>
5454
</Group>
5555

5656
<Group Name="Thermal">
57-
<Property Name="ThermalConductivity" Type="Quantity" Units="(1, 1, -3, 0, -1, 0, 0, 0)">
57+
<Property Name="ThermalConductivity" Type="Quantity">
5858
<Reference>https://en.wikipedia.org/wiki/Thermal_conductivity</Reference>
5959
</Property>
60-
<Property Name="ThermalExpansionCoefficient" Type="Quantity" Units="(0, 0, 0, 0, -1, 0, 0, 0)">
60+
<Property Name="ThermalExpansionCoefficient" Type="Quantity">
6161
<Reference>https://en.wikipedia.org/wiki/Volumetric_thermal_expansion_coefficient</Reference>
6262
</Property>
63-
<Property Name="SpecificHeat" Type="Quantity" Units="(2, 0, -2, 0, -1, 0, 0, 0)">
63+
<Property Name="SpecificHeat" Type="Quantity">
6464
<Reference>https://en.wikipedia.org/wiki/Heat_capacity</Reference>
6565
</Property>
6666
</Group>

src/Mod/Material/MaterialEditor.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,11 @@ def implementModel(self):
112112
widget = self.widget
113113
treeView = widget.treeView
114114
model = treeView.model()
115-
model.setHorizontalHeaderLabels(["Property", "Value",
116-
"Type", "Units"])
115+
model.setHorizontalHeaderLabels(["Property", "Value", "Type"])
117116

118117
treeView.setColumnWidth(0, 250)
119118
treeView.setColumnWidth(1, 250)
120119
treeView.setColumnHidden(2, True)
121-
treeView.setColumnHidden(3, True)
122120

123121
tree = getMaterialAttributeStructure(True)
124122
MatPropDict = tree.getroot()
@@ -141,13 +139,7 @@ def implementModel(self):
141139
tt = properDict['Type']
142140
itType = QtGui.QStandardItem(tt)
143141

144-
try:
145-
uu = properDict['Units']
146-
itUnit = QtGui.QStandardItem(uu)
147-
except KeyError:
148-
itUnit = QtGui.QStandardItem()
149-
150-
top.appendRow([item, it, itType, itUnit])
142+
top.appendRow([item, it, itType])
151143

152144
top.sortChildren(0)
153145

@@ -486,24 +478,22 @@ def createEditor(self, parent, option, index):
486478
if column == 1:
487479

488480
row = index.row()
481+
482+
PP = group.child(row, 0)
483+
matproperty = PP.text().replace(" ", "") # remove spaces
484+
489485
TT = group.child(row, 2)
490486

491487
if TT:
492488
Type = TT.text()
493-
UU = group.child(row, 3)
494-
if UU:
495-
Units = UU.text()
496-
else:
497-
Units = None
498489

499490
else:
500491
Type = "String"
501-
Units = None
502492

503493
VV = group.child(row, 1)
504494
Value = VV.text()
505495

506-
editor = matProperWidget(parent, Type, Units, Value)
496+
editor = matProperWidget(parent, matproperty, Type, Value)
507497

508498
elif column == 0:
509499

@@ -546,7 +536,7 @@ def setEditorData(self, editor, index):
546536
ui = FreeCADGui.UiLoader()
547537

548538

549-
def matProperWidget(parent=None, Type="String", Units=None, Value=None,
539+
def matProperWidget(parent=None, matproperty=None, Type="String", Value=None,
550540
minimum=None, maximum=None, stepsize=None, precision=None):
551541

552542
'''customs widgets for the material stuff.'''
@@ -569,13 +559,12 @@ def matProperWidget(parent=None, Type="String", Units=None, Value=None,
569559
elif Type == "Quantity":
570560

571561
widget = ui.createWidget("Gui::InputField")
572-
if Units:
573-
vv = string2tuple(Units)
574-
unit = FreeCAD.Units.Unit(
575-
vv[0], vv[1], vv[2], vv[3], vv[4], vv[5], vv[6], vv[7]
576-
)
562+
if hasattr(FreeCAD.Units, matproperty):
563+
unit = getattr(FreeCAD.Units, matproperty)
577564
quantity = FreeCAD.Units.Quantity(1, unit)
578565
widget.setProperty('unit', quantity.getUserPreferred()[2])
566+
else:
567+
FreeCAD.Console.PrintError('Not known unit for property: ' + matproperty + '\n')
579568

580569
elif Type == "Integer":
581570

0 commit comments

Comments
 (0)