From eab527e7a2762333c65172ee91ffff429eff57a7 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 25 Jan 2025 15:59:11 +1100 Subject: [PATCH] Fix #6033. Add tools for generate slab from wall and vice versa in the toolbox. Still needs a nice icon. --- src/bonsai/bonsai/bim/module/geometry/data.py | 3 ++- src/bonsai/bonsai/bim/module/model/data.py | 18 ++++++++++-------- .../bonsai/bim/module/model/workspace.py | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/geometry/data.py b/src/bonsai/bonsai/bim/module/geometry/data.py index 74bf2ef5ea..9c101c4c65 100644 --- a/src/bonsai/bonsai/bim/module/geometry/data.py +++ b/src/bonsai/bonsai/bim/module/geometry/data.py @@ -164,7 +164,8 @@ class RepresentationsData: if not obj.data: return [] element = tool.Ifc.get_entity(obj) - active_representation_id = obj.data.BIMMeshProperties.ifc_definition_id + if not (active_representation_id := obj.data.BIMMeshProperties.ifc_definition_id): + return [] # Maybe in profile editing mode base_representation = tool.Ifc.get().by_id(active_representation_id) # shape aspects matching context of the active representation diff --git a/src/bonsai/bonsai/bim/module/model/data.py b/src/bonsai/bonsai/bim/module/model/data.py index 4f5aa3aaea..707d8cbed5 100644 --- a/src/bonsai/bonsai/bim/module/model/data.py +++ b/src/bonsai/bonsai/bim/module/model/data.py @@ -66,6 +66,7 @@ class AuthoringData: cls.data["relating_type_id_current"] = cls.relating_type_id_current() cls.data["relating_type_name"] = cls.relating_type_name() cls.data["relating_type_description"] = cls.relating_type_description() + cls.data["relating_type_material_usage"] = cls.relating_type_material_usage() cls.data["predefined_type"] = cls.predefined_type() # Make sure .type_elements_filtered() was run before next lines cls.data["total_types"] = cls.total_types() @@ -231,17 +232,13 @@ class AuthoringData: @classmethod def active_class(cls): - if active_object := tool.Blender.get_active_object(): - element = tool.Ifc.get_entity(active_object) - if element: - return element.is_a() + if (obj := tool.Blender.get_active_object()) and (element := tool.Ifc.get_entity(obj)): + return element.is_a() @classmethod def active_material_usage(cls): - if active_object := tool.Blender.get_active_object(): - element = tool.Ifc.get_entity(active_object) - if element: - return tool.Model.get_usage_type(element) + if (obj := tool.Blender.get_active_object()) and (element := tool.Ifc.get_entity(obj)): + return tool.Model.get_usage_type(element) @classmethod def is_representation_item_active(cls) -> bool: @@ -315,6 +312,11 @@ class AuthoringData: if relating_type_id := cls.data["relating_type_id_current"]: return tool.Ifc.get().by_id(int(relating_type_id)).Description or "No description" + @classmethod + def relating_type_material_usage(cls): + if relating_type_id := cls.data["relating_type_id_current"]: + return tool.Model.get_usage_type(tool.Ifc.get().by_id(int(relating_type_id))) + @classmethod def predefined_type(cls): relating_type_id = tool.Blender.get_enum_safe(cls.props, "relating_type_id") diff --git a/src/bonsai/bonsai/bim/module/model/workspace.py b/src/bonsai/bonsai/bim/module/model/workspace.py index 960bb60b50..9ebe2a579d 100644 --- a/src/bonsai/bonsai/bim/module/model/workspace.py +++ b/src/bonsai/bonsai/bim/module/model/workspace.py @@ -723,11 +723,29 @@ class EditObjectUI: ) row = cls.layout.row(align=True) if ui_context != "TOOL_HEADER" else row add_layout_hotkey_operator(row, "Rotate 90", "S_R", "Rotate the selected Element by 90 degrees", ui_context) + if AuthoringData.data["relating_type_material_usage"] == "LAYER3": + row = cls.layout.row(align=True) if ui_context != "TOOL_HEADER" else row + add_layout_hotkey_operator( + row, + "Add From Closed Loop", + "S_A", + "Generate an element from selected closed walls", + ui_context, + ) elif AuthoringData.data["active_material_usage"] == "LAYER3": if "LAYER2" in AuthoringData.data["selected_material_usages"]: row = cls.layout.row(align=True) if ui_context != "TOOL_HEADER" else row add_layout_hotkey_operator(cls.layout, "Extend Wall To Slab", "S_E", "", ui_context) + if AuthoringData.data["relating_type_material_usage"] == "LAYER2": + row = cls.layout.row(align=True) if ui_context != "TOOL_HEADER" else row + add_layout_hotkey_operator( + row, + "Add From Perimeter", + "S_A", + "Generate elements along the perimeter of the selected element", + ui_context, + ) elif AuthoringData.data["active_material_usage"] == "PROFILE": row = cls.layout.row(align=True) if ui_context != "TOOL_HEADER" else row