From 9cfcaeb5875912fe910ffd30b42e6205b67bcfe3 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 11 Mar 2025 21:14:11 +1100 Subject: [PATCH] Fix bug and add boolean tests where if you added a boolean that fully clipped something you couldn't edit it due to lack of item ids. --- .../bonsai/bim/module/geometry/operator.py | 9 ++++ src/bonsai/pytest.ini | 1 + src/bonsai/test/bim/feature/boolean.feature | 49 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/bonsai/test/bim/feature/boolean.feature diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index 18372e40fd..f1c6d8630f 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -2888,6 +2888,15 @@ class ImportRepresentationItems(bpy.types.Operator, tool.Ifc.Operator): else: assert False, "Unexpected mesh type." + if not item_ids: + # It is possible that the user has created a shape that + # IfcOpenShell cannot render (i.e. boolean clipped everything), but + # we still want to edit items. I'm not sure the best way to handle + # this, but for now perhaps we can detect when there are no + # item_ids at all. + representation = tool.Ifc.get_entity(data) + item_ids = [i["item"].id() for i in ifcopenshell.util.representation.resolve_items(representation)] + queue = list(set(item_ids)) processed_ids = set() boolean_ids = set() diff --git a/src/bonsai/pytest.ini b/src/bonsai/pytest.ini index eee9c46ded..f3a641a5c4 100644 --- a/src/bonsai/pytest.ini +++ b/src/bonsai/pytest.ini @@ -2,6 +2,7 @@ markers = aggregate attribute + boolean brick classification context diff --git a/src/bonsai/test/bim/feature/boolean.feature b/src/bonsai/test/bim/feature/boolean.feature new file mode 100644 index 0000000000..9b06580172 --- /dev/null +++ b/src/bonsai/test/bim/feature/boolean.feature @@ -0,0 +1,49 @@ +@boolean +Feature: Boolean + Manage boolean hierarchies and boolean results + +Scenario: Ensure added booleans are marked as manual + Given an empty IFC project + And I open the "Add" menu + And I trigger "Add Element" + And I set the "Definition" property to "IfcElement" + And I set the "Class" property to "IfcFurniture" + And I set the "Representation" property to "Custom Extruded Solid" + And I click "OK" + And the object "IfcFurniture/Unnamed" exists + And I toggle edit mode + And the object "Item/IfcExtrudedAreaSolid/77" exists + And I open the "Add Item" menu + When I click "Half Space Solid" + And the object "Item/IfcHalfSpaceSolid/90" exists + And I deselect all objects + And I toggle edit mode + And I select the object "IfcFurniture/Unnamed" + And I look at the "Property Sets" panel + Then I see "BBIM_Boolean" + And I see "[91]" + +Scenario: Ensure removed booleans are unmarked as manual + Given an empty IFC project + And I open the "Add" menu + And I trigger "Add Element" + And I set the "Definition" property to "IfcElement" + And I set the "Class" property to "IfcFurniture" + And I set the "Representation" property to "Custom Extruded Solid" + And I click "OK" + And the object "IfcFurniture/Unnamed" exists + And I toggle edit mode + And the object "Item/IfcExtrudedAreaSolid/77" exists + And I open the "Add Item" menu + And I click "Half Space Solid" + And I deselect all objects + And I toggle edit mode + And I select the object "IfcFurniture/Unnamed" + And I toggle edit mode + And I select the object "Item/IfcHalfSpaceSolid/90" + When I delete the selected objects + And I toggle edit mode + And I select the object "IfcFurniture/Unnamed" + And I look at the "Property Sets" panel + Then I don't see "BBIM_Boolean" + And I don't see "[91]"