From 746053eefb94fdbbaa0e634b690c839a0f09eaad Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 23 Oct 2023 16:39:25 +0500 Subject: [PATCH] switch_representation to automatically switch to unresolved mapped representation The cool thing about it now that it will automatically create a new mesh for "unresolved" representation if element has openings, otherwise it'll stick to the same mesh representation as the type object. This fixed a few bugs: - similar to b9a9abd but during extrusion profile edit - applying void to the occurence used to remove the type and other occurences. Apparently it occured after 744c08e - previously we seems to rely on `ifcopenshell.geom.create_shape(settings, element)` to unresolve the representations. Though before 744c08e there still was an issue - it would apply the same opening to the all occurences and the type meshes but wasn't removing them. Probably fixed a few other similar issues. --- src/blenderbim/blenderbim/core/geometry.py | 9 ++++++--- src/blenderbim/blenderbim/tool/geometry.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/blenderbim/blenderbim/core/geometry.py b/src/blenderbim/blenderbim/core/geometry.py index 7f91fd15bc..42a05216a0 100644 --- a/src/blenderbim/blenderbim/core/geometry.py +++ b/src/blenderbim/blenderbim/core/geometry.py @@ -106,10 +106,13 @@ def switch_representation( entity = ifc.get_entity(obj) current_obj_data = obj.data - # doesn't resolve mapped representations in case if it's going to have openings - # otherwise we would also add openings to the type and other occurences mesh data has_openings = apply_openings and getattr(entity, "HasOpenings", None) - if not has_openings: + if has_openings: + # if it has openings make sure to switch to element's mapped representation + representation = geometry.unresolve_type_representation(representation, entity) + else: + # doesn't resolve mapped representations in case if it's going to have openings + # otherwise we would also add openings to the type and other occurences mesh data representation = geometry.resolve_mapped_representation(representation) old_repr_data = geometry.get_representation_data(representation) diff --git a/src/blenderbim/blenderbim/tool/geometry.py b/src/blenderbim/blenderbim/tool/geometry.py index 8ca65ab73c..5dfc29e69a 100644 --- a/src/blenderbim/blenderbim/tool/geometry.py +++ b/src/blenderbim/blenderbim/tool/geometry.py @@ -631,6 +631,18 @@ class Geometry(blenderbim.core.tool.Geometry): return cls.resolve_mapped_representation(representation.Items[0].MappingSource.MappedRepresentation) return representation + @classmethod + def unresolve_type_representation(cls, representation, occurence): + if not ifcopenshell.util.element.get_type(occurence): + return representation + + if representation.RepresentationType == "MappedRepresentation": + return representation + + for mapped_representation in occurence.Representation.Representations: + if cls.resolve_mapped_representation(mapped_representation) == representation: + return mapped_representation + @classmethod def run_geometry_update_representation(cls, obj=None): bpy.ops.bim.update_representation(obj=obj.name, ifc_representation_class="")