From 6faef6564ed2b7d66b7914ebabdf82b87a22d0b4 Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Mon, 24 Feb 2025 19:38:29 +0000 Subject: [PATCH] s/element/product/ in create_orientation_slots() This method should work with anything that has an ObjectPlacement, ie. an IfcProduct --- .../bonsai/bim/module/spatial/operator.py | 2 +- src/bonsai/bonsai/core/spatial.py | 8 +++---- src/bonsai/bonsai/tool/spatial.py | 22 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/spatial/operator.py b/src/bonsai/bonsai/bim/module/spatial/operator.py index c3016f4cee..009e1739ed 100644 --- a/src/bonsai/bonsai/bim/module/spatial/operator.py +++ b/src/bonsai/bonsai/bim/module/spatial/operator.py @@ -346,7 +346,7 @@ class SetDefaultContainer(bpy.types.Operator): def execute(self, context): core.set_default_container(tool.Spatial, container=tool.Ifc.get().by_id(self.container)) - core.set_orientation_slot(spatial=tool.Spatial, element=tool.Ifc.get().by_id(self.container)) + core.set_orientation_slot(spatial=tool.Spatial, product=tool.Ifc.get().by_id(self.container)) return {"FINISHED"} diff --git a/src/bonsai/bonsai/core/spatial.py b/src/bonsai/bonsai/core/spatial.py index 04ae08ad6f..bdfb410a43 100644 --- a/src/bonsai/bonsai/core/spatial.py +++ b/src/bonsai/bonsai/core/spatial.py @@ -122,12 +122,12 @@ def import_spatial_decomposition(spatial: tool.Spatial) -> None: def create_orientation_slots(ifc: tool.Ifc, spatial: tool.Spatial) -> None: - elements = ifc.get().by_type("IfcSpatialElement") - spatial.create_orientation_slots(elements, use=False) + products = ifc.get().by_type("IfcSpatialElement") + spatial.create_orientation_slots(products, use=False) -def set_orientation_slot(spatial: tool.Spatial, element: ifcopenshell.entity_instance) -> None: - spatial.create_orientation_slots([element], use=True) +def set_orientation_slot(spatial: tool.Spatial, product: ifcopenshell.entity_instance) -> None: + spatial.create_orientation_slots([product], use=True) def edit_container_attributes(spatial: tool.Spatial, entity: ifcopenshell.entity_instance) -> None: diff --git a/src/bonsai/bonsai/tool/spatial.py b/src/bonsai/bonsai/tool/spatial.py index 9c0c3b758d..4d139c0648 100644 --- a/src/bonsai/bonsai/tool/spatial.py +++ b/src/bonsai/bonsai/tool/spatial.py @@ -481,7 +481,7 @@ class Spatial(bonsai.core.tool.Spatial): cls.import_spatial_element(child, level_index + 1) @classmethod - def create_orientation_slots(cls, elements: list[ifcopenshell.entity_instance], use: bool = False) -> None: + def create_orientation_slots(cls, products: list[ifcopenshell.entity_instance], use: bool = False) -> None: active_slot = bpy.context.scene.transform_orientation_slots[0] initial_orientation = active_slot.type @@ -492,23 +492,23 @@ class Spatial(bonsai.core.tool.Spatial): # bpy.ops.transform.create_orientation() requires a dummy object bpy.ops.object.empty_add(type="PLAIN_AXES") - for element in elements: - placement = element.ObjectPlacement + for product in products: + placement = product.ObjectPlacement combined_matrix = ifcopenshell.util.placement.get_local_placement(placement)[:3, :3] if np.allclose(combined_matrix, np.eye(3), atol=1e-6): - # this element has global orientation + # this product has global orientation active_slot.type = "GLOBAL" continue - elif element.Decomposes and hasattr(element.Decomposes[0].RelatingObject, "ObjectPlacement"): - # this element is part of a decomposition - parent_placement = element.Decomposes[0].RelatingObject.ObjectPlacement + elif product.Decomposes and hasattr(product.Decomposes[0].RelatingObject, "ObjectPlacement"): + # this product is part of a decomposition + parent_placement = product.Decomposes[0].RelatingObject.ObjectPlacement parent_matrix = ifcopenshell.util.placement.get_local_placement(parent_placement)[:3, :3] if np.allclose(combined_matrix, parent_matrix, atol=1e-6): - # this element has the same orientation as its parent - cls.create_orientation_slots(elements=[element.Decomposes[0].RelatingObject], use=use) + # this product has the same orientation as its parent + cls.create_orientation_slots(products=[product.Decomposes[0].RelatingObject], use=use) continue - # this element has a unique orientation - orientation_name = element.is_a() + "/" + element.Name + # this product has a unique orientation + orientation_name = product.is_a() + "/" + product.Name bpy.ops.transform.create_orientation(name=orientation_name, overwrite=True) active_slot.type = orientation_name active_slot.custom_orientation.matrix = np.linalg.inv(combined_matrix)