mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 19:07:57 +00:00
Import materials psets and display it
Import psets similarly to objects. Display in the UI similarly to objects. Basic handling for ConstituentSet and MaterialList.
This commit is contained in:
committed by
Dion Moult
parent
fcc056e204
commit
85e7ed380e
@@ -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:
|
||||
|
||||
@@ -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='')
|
||||
|
||||
Reference in New Issue
Block a user