diff --git a/src/Mod/Material/CMakeLists.txt b/src/Mod/Material/CMakeLists.txt index 1d8f096c55..ad4fc01f2e 100644 --- a/src/Mod/Material/CMakeLists.txt +++ b/src/Mod/Material/CMakeLists.txt @@ -9,7 +9,7 @@ SET(Material_SRCS importFCMat.py MaterialEditor.py materials-editor.ui - MatPropDict.xml + Templatematerial.yml ) SOURCE_GROUP("Module" FILES ${Material_SRCS}) diff --git a/src/Mod/Material/MatPropDict.xml b/src/Mod/Material/MatPropDict.xml deleted file mode 100644 index 6665707fb0..0000000000 --- a/src/Mod/Material/MatPropDict.xml +++ /dev/null @@ -1,140 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - https://en.wikipedia.org/wiki/Density - - - https://en.wikipedia.org/wiki/Young%27s_modulus - - - https://en.wikipedia.org/wiki/Shear_modulus - - - https://en.wikipedia.org/wiki/Poisson%27s_ratio - - - https://en.wikipedia.org/wiki/Ultimate_tensile_strength - - - https://en.wikipedia.org/wiki/Compressive_strength - - - https://en.wikipedia.org/wiki/Yield_Strength - - - https://en.wikipedia.org/wiki/Deformation_(mechanics) - - - https://en.wikipedia.org/wiki/Fracture_toughness - - - https://en.wikipedia.org/wiki/Friction#Angle_of_friction - https://en.m.wikipedia.org/wiki/Mohr%E2%80%93Coulomb_theory - - - - - - https://en.wikipedia.org/wiki/Thermal_conductivity - - - https://en.wikipedia.org/wiki/Volumetric_thermal_expansion_coefficient - - - https://en.wikipedia.org/wiki/Heat_capacity - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Mod/Material/Material.py b/src/Mod/Material/Material.py index d62548ca39..8609a3f319 100644 --- a/src/Mod/Material/Material.py +++ b/src/Mod/Material/Material.py @@ -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 diff --git a/src/Mod/Material/MaterialEditor.py b/src/Mod/Material/MaterialEditor.py index 5502c566e7..075dbb208b 100644 --- a/src/Mod/Material/MaterialEditor.py +++ b/src/Mod/Material/MaterialEditor.py @@ -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]) diff --git a/src/Mod/Material/Templatematerial.yml b/src/Mod/Material/Templatematerial.yml new file mode 100644 index 0000000000..286b013612 --- /dev/null +++ b/src/Mod/Material/Templatematerial.yml @@ -0,0 +1,272 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2019 Bernd Hahnebach * +# * * +# * 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: " " diff --git a/src/Mod/Material/importFCMat.py b/src/Mod/Material/importFCMat.py index f6e6ddfe52..798fc6c4b2 100644 --- a/src/Mod/Material/importFCMat.py +++ b/src/Mod/Material/importFCMat.py @@ -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 diff --git a/src/Mod/Material/materialtools/cardutils.py b/src/Mod/Material/materialtools/cardutils.py index e28136440b..b1f6950966 100644 --- a/src/Mod/Material/materialtools/cardutils.py +++ b/src/Mod/Material/materialtools/cardutils.py @@ -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