Permalink
Browse files

Material: MaterialEditor migrate to model/view

  • Loading branch information...
caceres authored and yorikvanhavre committed Jul 29, 2018
1 parent be5796b commit 195c530c002e7365c88aad8c9ac0eddde230782d
@@ -9,6 +9,7 @@ SET(Material_SRCS
importFCMat.py
MaterialEditor.py
materials-editor.ui
MatPropDict.xml
)
SOURCE_GROUP("Module" FILES ${Material_SRCS})

@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>

<MatPropDict>

<Group Name="Meta">
<Property Name="CardName" Type="String">
</Property>
<Property Name="AuthorAndLicense" Type="String">
</Property>
<Property Name="Source" Type="String">
</Property>
</Group>

<Group Name="General">
<Property Name="Name" Type="String">
</Property>
<Property Name="Father" Type="String">
</Property>
<Property Name="Description" Type="String">
</Property>
<Property Name="Density" Type="Quantity" Units="(-3, 1, 0, 0, 0, 0, 0, 0)">
</Property>
<Property Name="Vendor" Type="String">
</Property>
<Property Name="ProductURL" Type="URL">
</Property>
<Property Name="SpecificPrice" Type="Float">
</Property>
</Group>

<Group Name="Mechanical">
<Property Name="YoungsModulus" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
<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)">
<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)">
<Reference>https://en.wikipedia.org/wiki/Compressive_strength</Reference>
</Property>
<Property Name="YieldStrength" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
<Reference>https://en.wikipedia.org/wiki/Yield_Strength</Reference>
</Property>
<Property Name="UltimateStrain" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
<Reference>https://en.wikipedia.org/wiki/Ultimate_tensile_strength</Reference>
</Property>
<Property Name="FractureToughness" Type="Quantity" Units="(-1, 1, -2, 0, 0, 0, 0, 0)">
<Reference>https://en.wikipedia.org/wiki/Fracture_toughness</Reference>
</Property>
<Property Name="AngleOfFriction" Type="Quantity" Units="(0, 0, 0, 0, 0, 0, 0, 1)">
<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)">
<Reference>https://en.wikipedia.org/wiki/Thermal_conductivity</Reference>
</Property>
<Property Name="ThermalExpansionCoefficient" Type="Quantity" Units="(0, 0, 0, 0, -1, 0, 0, 0)">
<Reference>https://en.wikipedia.org/wiki/Volumetric_thermal_expansion_coefficient</Reference>
</Property>
<Property Name="SpecificHeat" Type="Quantity" Units="(2, 1, -2, 0, -1, 0, 0, 0)">
<Reference>https://en.wikipedia.org/wiki/Heat_capacity</Reference>
</Property>
</Group>

<Group Name="Architectural">
<Property Name="Model" Type="String">
</Property>
<Property Name="ExecutionInstructions" Type="String">
</Property>
<Property Name="FireResistanceClass" Type="String">
</Property>
<Property Name="StandardCode" Type="String">
</Property>
<Property Name="SoundTransmissionClass" Type="String">
</Property>
<Property Name="Color" Type="Color">
</Property>
<Property Name="Finish" Type="String">
</Property>
<Property Name="UnitsPerQuantity" Type="Float">
</Property>
<Property Name="EnvironmentalEfficiencyClass" Type="String">
</Property>
</Group>

<Group Name="Rendering">
<Property Name="DiffuseColor" Type="Color">
</Property>
<Property Name="AmbientColor" Type="Color">
</Property>
<Property Name="SpecularColor" Type="Color">
</Property>
<Property Name="Shininess" Type="Float">
</Property>
<Property Name="EmissiveColor" Type="Color">
</Property>
<Property Name="Transparency" Type="Float">
</Property>
<Property Name="VertexShader" Type="String">
</Property>
<Property Name="FragmentShader" Type="String">
</Property>
<Property Name="TexturePath" Type="File">
</Property>
<Property Name="TextureScaling" Type="Float">
</Property>
</Group>

<Group Name="Vector rendering">
<Property Name="ViewColor" Type="Color">
</Property>
<Property Name="ViewFillPattern" Type="Boolean">
</Property>
<Property Name="SectionFillPattern" Type="File">
</Property>
<Property Name="ViewLinewidth" Type="Quantity" Units="(1, 0, 0, 0, 0, 0, 0, 0)">
</Property>
<Property Name="SectionLinewidth" Type="Quantity" Units="(1, 0, 0, 0, 0, 0, 0, 0)">
</Property>
</Group>

<Group Name="User defined">
</Group>

</MatPropDict>
@@ -94,87 +94,31 @@ def exportFCMat(fileName, matDict):
configfile.write(Preamble)
Config.write(configfile)


def getMaterialAttributeStructure(withSpaces=None):

''''''

# material properties
# see the following resources in the FreeCAD wiki for more information about the material specific properties:
# see the following resources in the FreeCAD wiki for more informations about the material specific properties:
# https://www.freecadweb.org/wiki/Material_data_model
# https://www.freecadweb.org/wiki/Material
materialPropertyGroups = (
("Meta", (
"CardName",
"AuthorAndLicense",
"Source"
)),
("General", (
"Name",
"Father",
"Description",
"Density",
"Vendor",
"ProductURL",
"SpecificPrice"
)),
("Mechanical", (
"YoungsModulus", # https://en.wikipedia.org/wiki/Young%27s_modulus
"PoissonRatio", # https://en.wikipedia.org/wiki/Poisson%27s_ratio
"UltimateTensileStrength", # https://en.wikipedia.org/wiki/Ultimate_tensile_strength
"CompressiveStrength", # https://en.wikipedia.org/wiki/Compressive_strength
"YieldStrength", # https://en.wikipedia.org/wiki/Yield_Strength
"UltimateStrain", # https://en.wikipedia.org/wiki/Ultimate_tensile_strength
"FractureToughness", # https://en.wikipedia.org/wiki/Fracture_toughness
"AngleOfFriction" # https://en.wikipedia.org/wiki/Friction#Angle_of_friction and https://en.m.wikipedia.org/wiki/Mohr%E2%80%93Coulomb_theory
)),
("Thermal", (
"ThermalConductivity", # https://en.wikipedia.org/wiki/Thermal_conductivity
"ThermalExpansionCoefficient", # https://en.wikipedia.org/wiki/Volumetric_thermal_expansion_coefficient
"SpecificHeat" # https://en.wikipedia.org/wiki/Heat_capacity
)),
("Architectural", (
"Model",
"ExecutionInstructions",
"FireResistanceClass",
"StandardCode",
"SoundTransmissionClass",
"Color",
"Finish",
"UnitsPerQuantity",
"EnvironmentalEfficiencyClass"
)),
("Rendering", (
"DiffuseColor",
"AmbientColor",
"SpecularColor",
"Shininess",
"EmissiveColor",
"Transparency",
"VertexShader",
"FragmentShader",
"TexturePath",
"TextureScaling"
)),
("Vector rendering", (
"ViewColor",
"ViewFillPattern",
"SectionFillPattern",
"ViewLinewidth",
"SectionLinewidth"
)),
("User defined", (
))
)

import os
import xml.etree.ElementTree as ElementTree

infile = os.path.dirname(__file__) + os.sep + "MatPropDict.xml"
tree = ElementTree.parse(infile)

if withSpaces:
# on attributes, add a space before a capital letter, will be used for better display in the ui
import re
newMatProp = []
for group in materialPropertyGroups:
newAttr = []
for attr in group[1]:
newAttr.append(re.sub(r"(\w)([A-Z])", r"\1 \2", attr))
newMatProp.append([group[0], newAttr])
materialPropertyGroups = newMatProp
# print(materialPropertyGroups)
return materialPropertyGroups
root = tree.getroot()
for group in root.getchildren():
for proper in group.getchildren():
proper.set('Name', re.sub(r"(\w)([A-Z]+)", r"\1 \2",
proper.attrib['Name']))

return tree


if __name__ == '__main__':
Oops, something went wrong.

0 comments on commit 195c530

Please sign in to comment.