Minor fixes to new presentation layer features by Krande

This commit is contained in:
Dion Moult
2020-11-14 22:17:56 +11:00
parent 9dcb2f9094
commit 9080744669
10 changed files with 101 additions and 132 deletions
@@ -480,6 +480,7 @@ class IfcImporter:
self.add_project_to_scene()
self.profile_code("Add project to scene")
self.get_presentation_layers()
self.profile_code("Get presentation layers")
if self.ifc_import_settings.should_clean_mesh and len(self.file.by_type("IfcElement")) < 10000:
self.clean_mesh()
self.profile_code("Mesh cleaning")
@@ -1328,23 +1329,31 @@ class IfcImporter:
].hide_viewport = True
def get_presentation_layers(self):
for f in self.file.by_type("IfcPresentationLayerAssignment"):
pl = bpy.context.scene.BIMProperties.presentation_layers.add()
pl.name = f.Name
pl.description = f.Description
pl.identifier = f.Identifier
if f.is_a() == "IfcPresentationLayerWithStyle":
pl.layer_on = f.LayerOn if f.LayerOn is not None else True
pl.layer_frozen = f.LayerFrozen if f.LayerFrozen is not None else False
pl.layer_blocked = f.LayerBlocked if f.LayerBlocked is not None else False
for assignment in self.file.by_type("IfcPresentationLayerAssignment"):
layer = bpy.context.scene.BIMProperties.presentation_layers.add()
layer.name = assignment.Name
layer.description = assignment.Description or ""
layer.identifier = assignment.Identifier or ""
if assignment.is_a() == "IfcPresentationLayerWithStyle":
layer.layer_on = assignment.LayerOn if assignment.LayerOn is not None else True
layer.layer_frozen = assignment.LayerFrozen if assignment.LayerFrozen is not None else False
layer.layer_blocked = assignment.LayerBlocked if assignment.LayerBlocked is not None else False
for item in f.AssignedItems:
guid = item.OfProductRepresentation[0].ShapeOfProduct[0].GlobalId
for item in assignment.AssignedItems:
# TODO: This is a simplified and incorrect implementation of assigning presentation layers to objects
# themselves, and will need to be rewritten in the future. See bug #1109. This code also does not
# consider mapped representations.
guids = []
if not hasattr(item, "OfProductRepresentation"):
continue # TODO: At the moment we ignore representation items
for product_representation in item.OfProductRepresentation:
for product in product_representation.ShapeOfProduct:
guids.append(product.GlobalId)
for obj in bpy.context.selectable_objects:
global_id = obj.BIMObjectProperties.attributes.get("GlobalId")
if global_id and global_id.string_value == guid:
obj.BIMObjectProperties.presentation_layer.name = pl.name
obj.hide_set(not pl.layer_on)
if global_id and global_id.string_value in guids:
obj.BIMObjectProperties.presentation_layer.name = layer.name
obj.hide_set(not layer.layer_on)
def clean_mesh(self):
obj = None