From 85e7ed380e37a54b4b6ae921a4d7624daa6ac1b2 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Fri, 9 Oct 2020 03:39:36 +0200 Subject: [PATCH] Import materials psets and display it Import psets similarly to objects. Display in the UI similarly to objects. Basic handling for ConstituentSet and MaterialList. --- .../blenderbim/bim/import_ifc.py | 43 ++++++++++++++++++- src/ifcblenderexport/blenderbim/bim/ui.py | 9 ++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/import_ifc.py b/src/ifcblenderexport/blenderbim/bim/import_ifc.py index 05c9dc757d..35fdab80e4 100644 --- a/src/ifcblenderexport/blenderbim/bim/import_ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/import_ifc.py @@ -152,6 +152,10 @@ class MaterialCreator(): self.create_single(material) elif material.is_a('IfcMaterialLayerSet'): self.create_layer_set(material) + elif material.is_a('IfcMaterialConstituentSet'): + self.create_constituent_set(material) + elif material.is_a('IfcMaterialList'): + self.create_material_list(material) def create_single(self, material): if material.Name not in self.materials: @@ -166,8 +170,26 @@ class MaterialCreator(): self.create_new_single(layer.Material) self.assign_material_to_mesh(self.materials[layer.Material.Name]) + def create_constituent_set(self, constituent_set): + for constituent in constituent_set.MaterialConstituents: + if constituent.Material: + if constituent.Material.Name not in self.materials: + # TODO import rest of the layer set data + self.create_new_single(constituent.Material) + self.assign_material_to_mesh(self.materials[constituent.Material.Name]) + + def create_material_list(self, material_list): + for material in material_list.Materials: + if material.Material: + if material.Material.Name not in self.materials: + # TODO import rest of the layer set data + self.create_new_single(material.Material) + self.assign_material_to_mesh(self.materials[material.Material.Name]) + def create_new_single(self, material): - self.materials[material.Name] = bpy.data.materials.new(material.Name) + self.materials[material.Name] = obj = bpy.data.materials.new(material.Name) + for pset in getattr(material, "HasProperties", ()): + self.add_pset(pset, obj) if not material.HasRepresentation \ or not material.HasRepresentation[0].Representations: return @@ -177,7 +199,24 @@ class MaterialCreator(): for item in representation.Items: if not item.is_a('IfcStyledItem'): continue - self.parse_styled_item(item, self.materials[material.Name]) + self.parse_styled_item(item, obj) + + def add_pset(self, pset, obj): + new_pset = obj.BIMMaterialProperties.psets.add() + new_pset.name = pset.Name + if new_pset.name in schema.ifc.psets: + for prop_name in schema.ifc.psets[new_pset.name]['HasPropertyTemplates'].keys(): + prop = new_pset.properties.add() + prop.name = prop_name + for prop in pset.Properties: + if prop.is_a('IfcPropertySingleValue') and prop.NominalValue: + index = new_pset.properties.find(prop.Name) + if index >= 0: + new_pset.properties[index].string_value = str(prop.NominalValue.wrappedValue) + else: + new_prop = new_pset.properties.add() + new_prop.name = prop.Name + new_prop.string_value = str(prop.NominalValue.wrappedValue) def get_material_name(self, styled_item): if styled_item.Name: diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index c4e02d7b04..0c3686f320 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -700,6 +700,15 @@ class BIM_PT_material(Panel): row = layout.row(align=True) row.prop(pset, 'name', text='') row.operator('bim.remove_material_pset', icon='X', text='').pset_index = index + op = row.operator('bim.copy_property_to_selection', icon='COPYDOWN', text='') + for prop in pset.properties: + row = layout.row(align=True) + row.prop(prop, 'name', text='') + row.prop(prop, 'string_value', text='') + op = row.operator('bim.copy_property_to_selection', icon='COPYDOWN', text='') + op.pset_name = pset.name + op.prop_name = prop.name + op.prop_value = prop.string_value row = layout.row() row.prop(props, 'psets', text='')