diff --git a/src/bonsai/bonsai/bim/module/model/data.py b/src/bonsai/bonsai/bim/module/model/data.py index 797f72714f..5cc0f64699 100644 --- a/src/bonsai/bonsai/bim/module/model/data.py +++ b/src/bonsai/bonsai/bim/module/model/data.py @@ -26,7 +26,7 @@ from ifcopenshell.util.doc import get_entity_doc, get_predefined_type_doc import bonsai.tool as tool from math import degrees from natsort import natsorted -from typing import Union +from typing import Union, Optional def refresh(): @@ -45,17 +45,14 @@ class AuthoringData: data = {} type_thumbnails = {} types_per_page = 9 - ifc_element_type = None is_loaded = False @classmethod - def load(cls, ifc_element_type=None): + def load(cls, ifc_element_type: Optional[str] = None): cls.is_loaded = True cls.props = tool.Model.get_model_props() - if ifc_element_type: - cls.ifc_element_type = None if ifc_element_type == "all" else ifc_element_type cls.data["default_container"] = cls.default_container() - cls.data["ifc_element_type"] = cls.ifc_element_type + cls.data["ifc_element_type"] = ifc_element_type cls.data["ifc_classes"] = cls.ifc_classes() cls.data["ifc_class_current"] = cls.ifc_class_current() # Make sure .ifc_classes() was run before next lines diff --git a/src/bonsai/bonsai/bim/module/model/workspace.py b/src/bonsai/bonsai/bim/module/model/workspace.py index 11f4fe73c5..014ebd013b 100644 --- a/src/bonsai/bonsai/bim/module/model/workspace.py +++ b/src/bonsai/bonsai/bim/module/model/workspace.py @@ -97,14 +97,15 @@ class BimTool(WorkSpaceTool): cls, context: bpy.types.Context, layout: bpy.types.UILayout, ws_tool: bpy.types.WorkSpaceTool ) -> None: props = tool.Geometry.get_geometry_props() + ifc_element_type = None if cls.ifc_element_type == "all" else cls.ifc_element_type if props.mode == "ITEM": EditItemUI.draw(context, layout) elif ( active_ifc_object := (context.active_object and tool.Ifc.get_entity(context.active_object)) ) and context.selected_objects: - EditObjectUI.draw(context, layout, ifc_element_type=cls.ifc_element_type) + EditObjectUI.draw(context, layout, ifc_element_type=ifc_element_type) else: - CreateObjectUI.draw(context, layout, ifc_element_type=cls.ifc_element_type) + CreateObjectUI.draw(context, layout, ifc_element_type=ifc_element_type) class WallTool(BimTool): @@ -500,9 +501,7 @@ class CreateObjectUI: layout: bpy.types.UILayout @classmethod - def draw( - cls, context: bpy.types.Context, layout: bpy.types.UILayout, ifc_element_type: Optional[str] = None - ) -> None: + def draw(cls, context: bpy.types.Context, layout: bpy.types.UILayout, ifc_element_type: Union[str, None]) -> None: cls.layout = layout cls.props = tool.Model.get_model_props() @@ -516,15 +515,13 @@ class CreateObjectUI: if not AuthoringData.is_loaded: AuthoringData.load(ifc_element_type) - elif ifc_element_type == "all" and AuthoringData.data["ifc_element_type"] is not None: - AuthoringData.load("all") elif AuthoringData.data["ifc_element_type"] != ifc_element_type: AuthoringData.load(ifc_element_type) - if ifc_element_type and context.region.type == "TOOL_HEADER": + if context.region.type == "TOOL_HEADER": tool_name = ( "Multi Object Tool" - if ifc_element_type == "all" + if ifc_element_type is None else format_ifc_camel_case(ifc_element_type.removesuffix("Type")) + " Tool" ) cls.layout.label(text=tool_name, icon="TOOL_SETTINGS") @@ -747,8 +744,6 @@ class EditObjectUI: if not AuthoringData.is_loaded: AuthoringData.load(ifc_element_type) - elif ifc_element_type == "all" and AuthoringData.data["ifc_element_type"] is not None: - AuthoringData.load("all") elif AuthoringData.data["ifc_element_type"] != ifc_element_type: AuthoringData.load(ifc_element_type)