Add support of exporting material sets for construction types

This commit is contained in:
Dion Moult
2020-11-30 11:28:32 +11:00
parent 9ca124bf2f
commit 7b7f756506
2 changed files with 11 additions and 11 deletions
@@ -68,9 +68,9 @@ class IfcParser:
self.rel_associates_classification_object = {} self.rel_associates_classification_object = {}
self.rel_associates_classification_type = {} self.rel_associates_classification_type = {}
self.rel_associates_material = {} self.rel_associates_material = {}
self.rel_associates_material_layer_set = {} self.rel_associates_material_layer_set = []
self.rel_associates_material_constituent_set = {} self.rel_associates_material_constituent_set = []
self.rel_associates_material_profile_set = {} self.rel_associates_material_profile_set = []
self.rel_associates_constraint_object = {} self.rel_associates_constraint_object = {}
self.rel_associates_constraint_type = {} self.rel_associates_constraint_type = {}
self.rel_aggregates = {} self.rel_aggregates = {}
@@ -433,11 +433,11 @@ class IfcParser:
if obj.BIMObjectProperties.material_type == "IfcMaterial" and obj.BIMObjectProperties.material: if obj.BIMObjectProperties.material_type == "IfcMaterial" and obj.BIMObjectProperties.material:
self.rel_associates_material.setdefault(obj.BIMObjectProperties.material.name, []).append(product) self.rel_associates_material.setdefault(obj.BIMObjectProperties.material.name, []).append(product)
elif obj.BIMObjectProperties.material_type == "IfcMaterialConstituentSet": elif obj.BIMObjectProperties.material_type == "IfcMaterialConstituentSet":
self.rel_associates_material_constituent_set[self.product_index] = obj.BIMObjectProperties.material_set self.rel_associates_material_constituent_set.append((obj.BIMObjectProperties.material_set, product))
elif obj.BIMObjectProperties.material_type == "IfcMaterialLayerSet": elif obj.BIMObjectProperties.material_type == "IfcMaterialLayerSet":
self.rel_associates_material_layer_set[self.product_index] = obj.BIMObjectProperties.material_set self.rel_associates_material_layer_set.append((obj.BIMObjectProperties.material_set, product))
elif obj.BIMObjectProperties.material_type == "IfcMaterialProfileSet": elif obj.BIMObjectProperties.material_type == "IfcMaterialProfileSet":
self.rel_associates_material_profile_set[self.product_index] = obj.BIMObjectProperties.material_set self.rel_associates_material_profile_set.append((obj.BIMObjectProperties.material_set, product))
return product return product
@@ -3205,7 +3205,7 @@ class IfcExporter:
return return
if self.file.schema == "IFC2X3": if self.file.schema == "IFC2X3":
return self.relate_objects_to_material_sets_ifc2x3(set_type) return self.relate_objects_to_material_sets_ifc2x3(set_type)
for product_index, material_set in getattr(self.ifc_parser, f"rel_associates_material_{set_type}_set").items(): for material_set, product in getattr(self.ifc_parser, f"rel_associates_material_{set_type}_set"):
if set_type == "constituent": if set_type == "constituent":
materials = self.create_material_constituents(material_set.material_constituents) materials = self.create_material_constituents(material_set.material_constituents)
elif set_type == "layer": elif set_type == "layer":
@@ -3231,13 +3231,13 @@ class IfcExporter:
self.owner_history, self.owner_history,
None, None,
None, None,
[self.ifc_parser.products[product_index]["ifc"]], [product["ifc"]],
material_set, material_set,
) )
def relate_objects_to_material_sets_ifc2x3(self, set_type): def relate_objects_to_material_sets_ifc2x3(self, set_type):
# IFC2X3 has a very different way of handling materials, so we have a dedicated function # IFC2X3 has a very different way of handling materials, so we have a dedicated function
for product_index, material_set in getattr(self.ifc_parser, f"rel_associates_material_{set_type}_set").items(): for material_set, product in getattr(self.ifc_parser, f"rel_associates_material_{set_type}_set"):
if set_type == "constituent": if set_type == "constituent":
# IFC2X3 only supports lists, so we gracefully downgrade # IFC2X3 only supports lists, so we gracefully downgrade
material_select = self.file.create_entity( material_select = self.file.create_entity(
@@ -3260,7 +3260,7 @@ class IfcExporter:
self.owner_history, self.owner_history,
None, None,
None, None,
[self.ifc_parser.products[product_index]["ifc"]], [product["ifc"]],
material_select, material_select,
) )
@@ -45,11 +45,11 @@ class MaterialCreator:
def create(self, element, obj, mesh): def create(self, element, obj, mesh):
self.obj = obj self.obj = obj
self.mesh = mesh self.mesh = mesh
self.parse_material(element)
if (hasattr(element, "Representation") and not element.Representation) or ( if (hasattr(element, "Representation") and not element.Representation) or (
hasattr(element, "RepresentationMaps") and not element.RepresentationMaps hasattr(element, "RepresentationMaps") and not element.RepresentationMaps
): ):
return return
self.parse_material(element)
if not self.mesh: if not self.mesh:
return return
if self.mesh.name in self.parsed_meshes: if self.mesh.name in self.parsed_meshes: