From d02b1fee4367d2a388b738317f22faa56d559c0c Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Sun, 10 Jun 2018 10:03:48 +0200 Subject: [PATCH] Material: move materal property list into material module and use this for material editor ui and writing of mat files --- src/Mod/Material/Material.py | 28 ++++++++++++++++++++++++++++ src/Mod/Material/MaterialEditor.py | 16 ++-------------- src/Mod/Material/importFCMat.py | 16 ++-------------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/Mod/Material/Material.py b/src/Mod/Material/Material.py index da6e24a6df..4d23998c0e 100644 --- a/src/Mod/Material/Material.py +++ b/src/Mod/Material/Material.py @@ -95,6 +95,34 @@ def exportFCMat(fileName, matDict): Config.write(configfile) +def getMaterialAttributeStructure(withSpaces=None): + # material properties + # are there any more resources in FreeCAD source code where known material properties are defined exept the material cards itself? + # we should not have two of these list ... + # withSpaces is used by the material editor ui, without spaces is used to save a material file + if withSpaces: + material_property_groups = ( + ('Meta', ('Card Name', 'Author And License', 'Source')), + ('General', ('Name', 'Father', 'Description', 'Denisty', 'Vendor', 'ProductURL', 'SpecificPrice')), + ('Mechanical', ('Youngs Modulus', 'Poisson Ratio', 'Ultimate Tensile Strength', 'Compressive Strength', 'Elasticity', 'Fracture Toughness')), + ('Architectural', ('Execution Instructions', 'Fire Resistance Class', 'Standard Code', 'Thermal Conductivity', 'Sound Transmission Class', 'Color', 'Finish', 'Units Per Quantity', 'Environmental Efficiency Class')), + ('Rendering', ('Diffuse Color', 'Ambient Color', 'Specular Color', 'Shininess', 'Emissive Color', 'Transparency', 'Vertex Shader', 'Fragment Shader', 'Texture Path', 'Texture Scaling')), + ('Vector rendering', ('View Color', 'Father', 'View Linewidth', 'Section Color', 'Section Fill Pattern', 'Section Linewidth')), + ('User defined', ()) + ) + else: + material_property_groups = ( + ("Meta", ("CardName", "AuthorAndLicense", "Source")), + ("General", ("Name", "Father", "Description", "Density", "Vendor", "ProductURL", "SpecificPrice")), + ("Mechanical", ("YoungsModulus", "PoissonRatio", "UltimateTensileStrength", "CompressiveStrength", "Elasticity", "FractureToughness")), + ("Architectural", ("Model", "ExecutionInstructions", "FireResistanceClass", "StandardCode", "ThermalConductivity", "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", ()) + ) + return material_property_groups + + if __name__ == '__main__': import sys import getopt diff --git a/src/Mod/Material/MaterialEditor.py b/src/Mod/Material/MaterialEditor.py index a70e398efa..ee1905e551 100644 --- a/src/Mod/Material/MaterialEditor.py +++ b/src/Mod/Material/MaterialEditor.py @@ -24,6 +24,7 @@ from __future__ import print_function import FreeCAD import FreeCADGui +from Material import getMaterialAttributeStructure import os from PySide import QtCore, QtGui # from PySide import QtUiTools, QtSvg @@ -70,7 +71,7 @@ class MaterialEditor: QtCore.QObject.connect(self.widget.ButtonSave, QtCore.SIGNAL("clicked()"), self.savefile) # add material properies (the keys) to the editor - for group in material_properties: + for group in getMaterialAttributeStructure(True): # get the mat file structure from material module, use Spaces for better ui # print(group) self.addPropertiesToGroup(group) @@ -359,16 +360,3 @@ def editMaterial(material): return editor.getDict() else: return material - - -# material properties -# are there any more resources in FreeCAD source code where known material properties are defined exept the material cards itself? -material_properties = ( - ('Meta information', ['Card Name', 'Author And License', 'Source']), - ('General', ['Name', 'Father', 'Description', 'Denisty', 'Vendor', 'ProductURL', 'SpecificPrice']), - ('Mechanical', ['Youngs Modulus', 'Poisson Ratio', 'Ultimate Tensile Strength', 'Compressive Strength', 'Elasticity', 'Fracture Toughness']), - ('Architectural', ['Execution Instructions', 'Fire Resistance Class', 'Standard Code', 'Thermal Conductivity', 'Sound Transmission Class', 'Color', 'Finish', 'Units Per Quantity', 'Environmental Efficiency Class']), - ('Rendering', ['Diffuse Color', 'Ambient Color', 'Specular Color', 'Shininess', 'Emissive Color', 'Transparency', 'Vertex Shader', 'Fragment Shader', 'Texture Path', 'Texture Scaling']), - ('Vector rendering', ['View Color', 'Father', 'View Linewidth', 'Section Color', 'Section Fill Pattern', 'Section Linewidth']), - ('User defined', []) -) diff --git a/src/Mod/Material/importFCMat.py b/src/Mod/Material/importFCMat.py index c0011e4e3c..430af4e9a7 100644 --- a/src/Mod/Material/importFCMat.py +++ b/src/Mod/Material/importFCMat.py @@ -23,6 +23,7 @@ import FreeCAD # import Material +from Material import getMaterialAttributeStructure import os @@ -31,19 +32,6 @@ __author__ = "Juergen Riegel" __url__ = "http://www.freecadweb.org" -# file structure - this affects how files are saved -FileStructure = [ - ["Meta", ["CardName", "AuthorAndLicense", "Source"]], - ["General", ["Name", "Father", "Description", "Density", "Vendor", "ProductURL", "SpecificPrice"]], - ["Mechanical", ["YoungsModulus", "UltimateTensileStrength", "CompressiveStrength", "Elasticity", "FractureToughness"]], - ["FEM", ["PoissonRatio"]], - ["Architectural", ["Model", "ExecutionInstructions", "FireResistanceClass", "StandardCode", "ThermalConductivity", "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", []] -] - - # to distinguish python built-in open function from the one declared below if open.__module__ == '__builtin__': pythonopen = open @@ -114,7 +102,7 @@ def write(filename, dictionary): "writes the given dictionary to the given file" # sort the data into sections contents = [] - for key in FileStructure: + for key in getMaterialAttributeStructure(): # get the mat file structure from material module contents.append({"keyname": key[0]}) if key[0] == "Meta": header = contents[-1]