From eaaec4a12d9fd1d8da54a08b894fd589aea24522 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 30 Jan 2025 18:44:27 +1100 Subject: [PATCH] Fix ridiculous bug where util.element.get_container didn't consider all parents and therefore didn't correctly contain feature elements in the spatial hierarchy --- src/bonsai/bonsai/bim/module/root/operator.py | 1 + src/bonsai/bonsai/tool/collector.py | 7 +++--- .../ifcopenshell/util/element.py | 25 +++++++------------ 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/root/operator.py b/src/bonsai/bonsai/bim/module/root/operator.py index cdeeaf204d..7cf8bc9f40 100644 --- a/src/bonsai/bonsai/bim/module/root/operator.py +++ b/src/bonsai/bonsai/bim/module/root/operator.py @@ -573,6 +573,7 @@ class AddElement(bpy.types.Operator, tool.Ifc.Operator): new.obj = obj bpy.ops.bim.show_openings() tool.Model.purge_scene_openings() + tool.Collector.assign(obj) bonsai.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj) tool.Blender.set_active_object(obj) diff --git a/src/bonsai/bonsai/tool/collector.py b/src/bonsai/bonsai/tool/collector.py index 215a366424..2f669fe32e 100644 --- a/src/bonsai/bonsai/tool/collector.py +++ b/src/bonsai/bonsai/tool/collector.py @@ -62,10 +62,6 @@ class Collector(bonsai.core.tool.Collector): elif element.is_a("IfcTypeProduct"): collection = cls._create_project_child_collection("IfcTypeProduct") cls.link_collection_object_safe(collection, obj) - elif element.is_a("IfcOpeningElement"): - collection = cls._create_project_child_collection("IfcOpeningElement") - cls.link_collection_object_safe(collection, obj) - obj.display_type = "WIRE" elif element.is_a("IfcSpace"): collection = cls._create_project_child_collection("IfcSpace") cls.link_collection_object_safe(collection, obj) @@ -122,6 +118,9 @@ class Collector(bonsai.core.tool.Collector): collection = cls._create_project_child_collection("Unsorted") cls.link_collection_object_safe(collection, obj) + if element.is_a("IfcFeatureElementSubtraction"): + obj.display_type = "WIRE" + @classmethod def _create_project_child_collection(cls, name: str) -> bpy.types.Collection: """get or create new collection inside project""" diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 4355505f21..fcd350810c 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -926,23 +926,16 @@ def get_container( return container if container.is_a(ifc_class): return container - else: - aggregate = get_aggregate(element) - if aggregate: - return get_container(aggregate, should_get_direct) - nest = get_nest(element) - if nest: - return get_container(nest, should_get_direct) - if ( - contained_in_structure := getattr(element, "ContainedInStructure", None) - ) is not None and contained_in_structure: - container = contained_in_structure[0].RelatingStructure - if not ifc_class: + elif contained_in_structure := getattr(element, "ContainedInStructure", None): + container = contained_in_structure[0].RelatingStructure + if not ifc_class: + return container + while container: + if container.is_a(ifc_class): return container - while container: - if container.is_a(ifc_class): - return container - container = get_aggregate(container) + container = get_aggregate(container) + elif parent := get_parent(element): + return get_container(parent, should_get_direct) def get_referenced_structures(element: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]: