From 74a9669fa8a06a2cb03ea68752979fddbb80cc0c Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 22 Jan 2025 12:44:29 +0500 Subject: [PATCH] Fix error tabbing into IfcRevolvedAreaSolid with a boolean + add resolve_base_items resolve_items couldn't find IfcRevolvedAreaSolid inside a boolean result --- src/bonsai/bonsai/tool/model.py | 2 +- .../ifcopenshell/util/representation.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/tool/model.py b/src/bonsai/bonsai/tool/model.py index 0c7dbcdc45..999525f360 100644 --- a/src/bonsai/bonsai/tool/model.py +++ b/src/bonsai/bonsai/tool/model.py @@ -657,7 +657,7 @@ class Model(bonsai.core.tool.Model): # so users will be able to at least move IfcRevolvedAreaSolid, until there will be a full support. body = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW") if body and any( - i["item"].is_a("IfcRevolvedAreaSolid") for i in ifcopenshell.util.representation.resolve_items(body) + i.is_a("IfcRevolvedAreaSolid") for i in ifcopenshell.util.representation.resolve_base_items(body) ): return return "PROFILE" diff --git a/src/ifcopenshell-python/ifcopenshell/util/representation.py b/src/ifcopenshell-python/ifcopenshell/util/representation.py index 8bac694d9e..4dcf15b73b 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/representation.py +++ b/src/ifcopenshell-python/ifcopenshell/util/representation.py @@ -320,6 +320,22 @@ def resolve_items( return results +def resolve_base_items( + representation: ifcopenshell.entity_instance, +) -> Generator[ifcopenshell.entity_instance, None, None]: + """Resolve representation to it's base items resolving mapped items and boolean results to it's operands.""" + queue: list[ifcopenshell.entity_instance] = list(representation.Items) + while queue: + item = queue.pop() + if item.is_a("IfcMappedItem"): + yield from resolve_base_items(item.MappingSource.MappedRepresentation) + elif item.is_a("IfcBooleanResult"): + queue.append(item.FirstOperand) + queue.append(item.SecondOperand) + else: + yield item + + def get_prioritised_contexts(ifc_file: ifcopenshell.file) -> list[ifcopenshell.entity_instance]: """Gets a list of contexts ordered from high priority to low priority