Skip to content

Commit

Permalink
Material: editor, get rid of duplicate unit definition
Browse files Browse the repository at this point in the history
- in mat editor xml file and in FreeCAD unit system
- remove it from material editor xml file and get it from FreeCAD unit system
  • Loading branch information
berndhahnebach authored and wwmayer committed Feb 14, 2019
1 parent 96a1007 commit 0000732
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
20 changes: 10 additions & 10 deletions src/Mod/Material/MatPropDict.xml
Expand Up @@ -23,44 +23,44 @@
</Group>

<Group Name="Mechanical">
<Property Name="Density" Type="Quantity" Units="(-3, 1, 0, 0, 0, 0, 0, 0)">
<Property Name="Density" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Density</Reference>
</Property>
<Property Name="YoungsModulus" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
<Property Name="YoungsModulus" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Young%27s_modulus</Reference>
</Property>
<Property Name="PoissonRatio" Type="Float">
<Reference>https://en.wikipedia.org/wiki/Poisson%27s_ratio</Reference>
</Property>
<Property Name="UltimateTensileStrength" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
<Property Name="UltimateTensileStrength" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Ultimate_tensile_strength</Reference>
</Property>
<Property Name="CompressiveStrength" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
<Property Name="CompressiveStrength" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Compressive_strength</Reference>
</Property>
<Property Name="YieldStrength" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
<Property Name="YieldStrength" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Yield_Strength</Reference>
</Property>
<Property Name="UltimateStrain" Type="Float">
<Reference>https://en.wikipedia.org/wiki/Deformation_(mechanics)</Reference>
</Property>
<Property Name="FractureToughness" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
<Property Name="FractureToughness" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Fracture_toughness</Reference>
</Property>
<Property Name="AngleOfFriction" Type="Quantity" Units="(0, 0, 0, 0, 0, 0, 0, 1)">
<Property Name="AngleOfFriction" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Friction#Angle_of_friction</Reference>
<Reference>https://en.m.wikipedia.org/wiki/Mohr%E2%80%93Coulomb_theory</Reference>
</Property>
</Group>

<Group Name="Thermal">
<Property Name="ThermalConductivity" Type="Quantity" Units="(1, 1, -3, 0, -1, 0, 0, 0)">
<Property Name="ThermalConductivity" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Thermal_conductivity</Reference>
</Property>
<Property Name="ThermalExpansionCoefficient" Type="Quantity" Units="(0, 0, 0, 0, -1, 0, 0, 0)">
<Property Name="ThermalExpansionCoefficient" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Volumetric_thermal_expansion_coefficient</Reference>
</Property>
<Property Name="SpecificHeat" Type="Quantity" Units="(2, 0, -2, 0, -1, 0, 0, 0)">
<Property Name="SpecificHeat" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Heat_capacity</Reference>
</Property>
</Group>
Expand Down
35 changes: 12 additions & 23 deletions src/Mod/Material/MaterialEditor.py
Expand Up @@ -112,13 +112,11 @@ def implementModel(self):
widget = self.widget
treeView = widget.treeView
model = treeView.model()
model.setHorizontalHeaderLabels(["Property", "Value",
"Type", "Units"])
model.setHorizontalHeaderLabels(["Property", "Value", "Type"])

treeView.setColumnWidth(0, 250)
treeView.setColumnWidth(1, 250)
treeView.setColumnHidden(2, True)
treeView.setColumnHidden(3, True)

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

try:
uu = properDict['Units']
itUnit = QtGui.QStandardItem(uu)
except KeyError:
itUnit = QtGui.QStandardItem()

top.appendRow([item, it, itType, itUnit])
top.appendRow([item, it, itType])

top.sortChildren(0)

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

row = index.row()

PP = group.child(row, 0)
matproperty = PP.text().replace(" ", "") # remove spaces

TT = group.child(row, 2)

if TT:
Type = TT.text()
UU = group.child(row, 3)
if UU:
Units = UU.text()
else:
Units = None

else:
Type = "String"
Units = None

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

editor = matProperWidget(parent, Type, Units, Value)
editor = matProperWidget(parent, matproperty, Type, Value)

elif column == 0:

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


def matProperWidget(parent=None, Type="String", Units=None, Value=None,
def matProperWidget(parent=None, matproperty=None, Type="String", Value=None,
minimum=None, maximum=None, stepsize=None, precision=None):

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

widget = ui.createWidget("Gui::InputField")
if Units:
vv = string2tuple(Units)
unit = FreeCAD.Units.Unit(
vv[0], vv[1], vv[2], vv[3], vv[4], vv[5], vv[6], vv[7]
)
if hasattr(FreeCAD.Units, matproperty):
unit = getattr(FreeCAD.Units, matproperty)
quantity = FreeCAD.Units.Quantity(1, unit)
widget.setProperty('unit', quantity.getUserPreferred()[2])
else:
FreeCAD.Console.PrintError('Not known unit for property: ' + matproperty + '\n')

elif Type == "Integer":

Expand Down

0 comments on commit 0000732

Please sign in to comment.