Material: mat card template for material editor, move to a much more pythonic one

This commit is contained in:
Bernd Hahnebach
2019-04-25 19:47:08 +02:00
parent ae37de1419
commit 3f5f53e91f
7 changed files with 313 additions and 188 deletions

View File

@@ -9,7 +9,7 @@ SET(Material_SRCS
importFCMat.py
MaterialEditor.py
materials-editor.ui
MatPropDict.xml
Templatematerial.yml
)
SOURCE_GROUP("Module" FILES ${Material_SRCS})

View File

@@ -1,140 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<MatPropDict>
<Group Name="Meta">
<Property Name="CardName" Type="String">
</Property>
<Property Name="AuthorAndLicense" 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="ReferenceSource" Type="String">
</Property>
<Property Name="SourceURL" Type="URL">
</Property>
</Group>
<Group Name="Mechanical">
<Property Name="Density" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Density</Reference>
</Property>
<Property Name="YoungsModulus" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Young%27s_modulus</Reference>
</Property>
<Property Name="ShearModulus" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Shear_modulus</Reference>
</Property>
<Property Name="PoissonRatio" Type="Float">
<Reference>https://en.wikipedia.org/wiki/Poisson%27s_ratio</Reference>
</Property>
<Property Name="UltimateTensileStrength" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Ultimate_tensile_strength</Reference>
</Property>
<Property Name="CompressiveStrength" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Compressive_strength</Reference>
</Property>
<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">
<Reference>https://en.wikipedia.org/wiki/Fracture_toughness</Reference>
</Property>
<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">
<Reference>https://en.wikipedia.org/wiki/Thermal_conductivity</Reference>
</Property>
<Property Name="ThermalExpansionCoefficient" Type="Quantity">
<Reference>https://en.wikipedia.org/wiki/Volumetric_thermal_expansion_coefficient</Reference>
</Property>
<Property Name="SpecificHeat" Type="Quantity">
<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="Float">
</Property>
<Property Name="SectionLinewidth" Type="Float">
</Property>
</Group>
<Group Name="Cost">
<Property Name="Vendor" Type="String">
</Property>
<Property Name="SpecificPrice" Type="Float">
</Property>
<Property Name="ProductURL" Type="URL">
</Property>
</Group>
<Group Name="User defined">
</Group>
</MatPropDict>

View File

@@ -111,35 +111,6 @@ def exportFCMat(fileName, matDict):
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:
# https://www.freecadweb.org/wiki/Material_data_model
# https://www.freecadweb.org/wiki/Material
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
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
def read_cards_from_path(cards_path):
from os import listdir
from os.path import isfile, join, basename, splitext

View File

@@ -122,26 +122,23 @@ class MaterialEditor:
treeView.setColumnWidth(1, 250)
treeView.setColumnHidden(2, True)
from Material import getMaterialAttributeStructure
tree = getMaterialAttributeStructure(True)
MatPropDict = tree.getroot()
from materialtools.cardutils import get_material_template
template_data = get_material_template(True)
for group in MatPropDict.getchildren():
gg = group.attrib['Name']
for group in template_data:
gg = list(group.keys())[0] # group dict has only one key
top = QtGui.QStandardItem(gg)
model.appendRow([top])
self.groups.append(gg)
for proper in group.getchildren():
properDict = proper.attrib
pp = properDict['Name']
for properName in group[gg]:
pp = properName # property name
item = QtGui.QStandardItem(pp)
self.internalprops.append(pp)
it = QtGui.QStandardItem()
tt = properDict['Type']
tt = group[gg][properName]['Type']
itType = QtGui.QStandardItem(tt)
top.appendRow([item, it, itType])

View File

@@ -0,0 +1,272 @@
# ***************************************************************************
# * *
# * Copyright (c) 2019 Bernd Hahnebach <bernd@bimstatik.org> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
# material template for reading and writing FreeCAD material cards
# information about FreeCAD material module and material cards can be found here:
# http://www.freecadweb.org/wiki/index.php?title=Material
# localized Name, Description and KindOfMaterial uses 2 letter codes
# defined in ISO-639-1, see https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
# find unit information in src/App/FreeCADInit.py
# TODO: make multiple line strings out of the long ones, see module ccxtools.py
# Use " for descriptions because there a ' can be inside. May be switch to " for all Strings?!
# matdata
- Meta:
CardName: # first in group
Type: 'String'
URL: ''
Description: " "
AuthorAndLicense:
Type: 'String'
URL: ''
Description: " "
- General:
Name: # first in group
Type: 'String'
URL: ''
Description: "General name" # used to be equal with card name, TODO: should all cards be changed back to this?
NameDE:
Type: 'String'
URL: ''
Description: "German localized name"
NamePL:
Type: 'String'
URL: ''
Description: "Polish localized name"
Description:
Type: 'String'
URL: ''
Description: "A more elaborate description of the material"
DescriptionDE:
Type: 'String'
URL: ''
Description: "German localized description"
DescriptionPL:
Type: 'String'
URL: ''
Description: "Polish localized description"
Father:
Type: 'String'
URL: ''
Description: "Father of the material, i.e. for PLA is Thermoplast, for Steel is Metal"
KindOfMaterial:
Type: 'String'
URL: ''
Description: " "
KindOfMaterialDE:
Type: 'String'
URL: ''
Description: "Germand localized kind of material"
MaterialNumber:
Type: 'String'
URL: ''
Description: " "
Norm: # should be merged with StandardCode
Type: 'String'
URL: ''
Description: " "
ReferenceSource:
Type: 'String'
URL: ''
Description: " "
SourceURL:
Type: 'URL'
URL: ''
Description: " "
StandardCode:
Type: 'String'
URL: ''
Description: " "
- Mechanical:
AngleOfFriction:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Friction#Angle_of_friction'
Description: "Further information can be found at https://en.wikipedia.org/wiki/Mohr%E2%80%93Coulomb_theory"
CompressiveStrength:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Compressive_strength'
Description: "Compressive strength in [FreeCAD Pressure unit]"
Density:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Density'
Description: "Density in [FreeCAD Density unit]"
FractureToughness:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Fracture_toughness'
Description: " "
PoissonRatio:
Type: 'Float'
URL: 'https://en.wikipedia.org/wiki/Poisson%27s_ratio'
Description: "Poisson's ratio [unitless]"
ShearModulus:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Shear_modulus'
Description: "Shear modulus in [FreeCAD Pressure unit]"
UltimateStrain:
Type: 'Float'
URL: 'https://en.wikipedia.org/wiki/Deformation_(mechanics)'
Description: " "
UltimateTensileStrength:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Ultimate_tensile_strength'
Description: "Ultimate tensile strength in [FreeCAD Pressure unit]"
YieldStrength:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Yield_Strength'
Description: "Yield strength in [FreeCAD Pressure unit]"
YoungsModulus:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Young%27s_modulus'
Description: "Young's modulus (or E-Module) in [FreeCAD Pressure unit]"
- Thermal:
SpecificHeat:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Heat_capacity'
Description: " "
ThermalConductivity:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Thermal_conductivity'
Description: "Thermal conductivity in [FreCAD ThermalConductivity unit]"
ThermalExpansionCoefficient:
Type: 'Quantity'
URL: 'https://en.wikipedia.org/wiki/Volumetric_thermal_expansion_coefficient'
Description: "Thermal expansion coefficient (linear) in [FreeCAD ThermalExpansionCoefficient unit]"
- Architectural:
Color:
Type: 'String'
URL: ''
Description: " "
EnvironmentalEfficiencyClass:
Type: 'String'
URL: ''
Description: " "
ExecutionInstructions:
Type: 'String'
URL: ''
Description: " "
Finish:
Type: 'String'
URL: ''
Description: " "
FireResistanceClass:
Type: 'String'
URL: ''
Description: " "
Model:
Type: 'String'
URL: ''
Description: " "
SoundTransmissionClass:
URL: ''
Description: " "
Type: 'String'
URL: ''
Description: " "
UnitsPerQuantity:
Type: 'Float'
URL: ''
Description: " "
- Rendering:
AmbientColor:
Type: 'Color'
URL: ''
Description: " "
DiffuseColor:
Type: 'Color'
URL: ''
Description: " "
EmissiveColor:
Type: 'Color'
URL: ''
Description: " "
FragmentShader:
Type: 'String'
URL: ''
Description: " "
Shininess:
Type: 'Float'
URL: ''
Description: " "
SpecularColor:
Type: 'Color'
URL: ''
Description: " "
TexturePath:
Type: 'File'
URL: ''
Description: " "
TextureScaling:
Type: 'Float'
URL: ''
Description: " "
Transparency:
Type: 'Float'
URL: ''
Description: " "
VertexShader:
Type: 'String'
URL: ''
Description: " "
- Vector rendering:
SectionFillPattern:
Type: 'File'
URL: ''
Description: " "
SectionLinewidth:
Type: 'Float'
URL: ''
Description: " "
ViewColor:
Type: 'Color'
URL: ''
Description: " "
ViewFillPattern:
Type: 'Boolean'
URL: ''
Description: " "
ViewLinewidth:
Type: 'Float'
URL: ''
Description: " "
- Cost:
ProductURL:
Type: 'URL'
URL: 'https://de.wikipedia.org/wiki/Hyperlink'
Description: "Product URL, recommended are wikipedia links"
SpecificPrice:
Type: 'Float'
URL: ''
Description: "Specific price in currency / mass. A currency is not supported by FreeCAD unit system. Will be empty in all FreeCAD cards. Means the user needs to put in himself."
Vendor:
Type: 'String'
URL: ''
Description: "Vendor of the material"
- UserDefined:
None: # Python needs something to iterate over
Type: ''
URL: ''
Description: " "

View File

@@ -22,7 +22,7 @@
import FreeCAD
import Material
from materialtools.cardutils import get_material_template
import os
import sys
if sys.version_info.major >= 3:
@@ -151,17 +151,15 @@ def write(filename, dictionary, write_group_section=True):
# sort the data into sections
contents = []
tree = Material.getMaterialAttributeStructure()
MatPropDict = tree.getroot()
for group in MatPropDict.getchildren():
groupName = group.attrib['Name']
template_data = get_material_template()
for group in template_data:
groupName = list(group.keys())[0] # group dict has only one key
contents.append({"keyname": groupName})
if groupName == "Meta":
header = contents[-1]
elif groupName == "User defined":
elif groupName == 'UserDefined':
user = contents[-1]
for proper in group.getchildren():
properName = proper.attrib['Name']
for properName in group[groupName]:
contents[-1][properName] = ''
for k, i in dictionary.items():
found = False

View File

@@ -179,3 +179,30 @@ def output_material_param(mat_dict):
for p in mat_dict:
FreeCAD.Console.PrintMessage(' {} --> {}\n'.format(p, mat_dict[p]))
FreeCAD.Console.PrintMessage('\n')
# ***** material card template *******************************************************************
def get_material_template(withSpaces=False):
# material properties
# see the following resources in the FreeCAD wiki for more
# information about the material specific properties:
# https://www.freecadweb.org/wiki/Material_data_model
# https://www.freecadweb.org/wiki/Material
import yaml
template_data = yaml.safe_load(
open(join(FreeCAD.ConfigGet('AppHomePath'), 'Mod/Material/Templatematerial.yml'))
)
if withSpaces:
# on attributes, add a space before a capital letter
# will be used for better display in the ui
import re
for group in template_data:
gg = list(group.keys())[0] # group dict has only one key
# iterating over a dict and changing it is not allowed
# thus it is iterated over a list of the keys
for proper in list(group[gg].keys()):
new_proper = re.sub(r"(\w)([A-Z]+)", r"\1 \2", proper)
group[gg][new_proper] = group[gg][proper]
del group[gg][proper]
return template_data