From 084c2aa25abda2e6f0250a8d94ea1eed09a86bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Fri, 8 Nov 2024 09:52:50 -0300 Subject: [PATCH] Add `AuthoringData.data["ifc_class_current"]` to model data. --- src/bonsai/bonsai/bim/module/model/data.py | 18 ++++++++++++------ src/bonsai/bonsai/bim/module/model/ui.py | 4 ++-- .../bonsai/bim/module/model/workspace.py | 10 +++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/data.py b/src/bonsai/bonsai/bim/module/model/data.py index 8fb018a5db..b1ec23d038 100644 --- a/src/bonsai/bonsai/bim/module/model/data.py +++ b/src/bonsai/bonsai/bim/module/model/data.py @@ -56,6 +56,7 @@ class AuthoringData: cls.data["default_container"] = cls.default_container() cls.data["ifc_element_type"] = cls.ifc_element_type cls.data["ifc_classes"] = cls.ifc_classes() + cls.data["ifc_class_current"] = cls.ifc_class_current() cls.data["relating_type_id"] = cls.relating_type_id() # only after .ifc_classes() cls.data["relating_type_name"] = cls.relating_type_name() # only after .relating_type_id() cls.data["relating_type_description"] = cls.relating_type_description() # only after .relating_type_id() @@ -108,12 +109,12 @@ class AuthoringData: @classmethod def total_types(cls): - ifc_class = cls.props.ifc_class + ifc_class = cls.data["ifc_class_current"] return len(tool.Ifc.get().by_type(ifc_class)) if ifc_class else 0 @classmethod def total_pages(cls): - ifc_class = cls.props.ifc_class + ifc_class = cls.data["ifc_class_current"] total_types = len(tool.Ifc.get().by_type(ifc_class)) if ifc_class else 0 return math.ceil(total_types / cls.types_per_page) @@ -129,7 +130,7 @@ class AuthoringData: @classmethod def paginated_relating_types(cls): - ifc_class = cls.props.ifc_class + ifc_class = cls.data["ifc_class_current"] if not ifc_class: return [] results = [] @@ -226,15 +227,20 @@ class AuthoringData: results.extend([(c, c, "") for c in sorted(classes)]) return results - @classmethod - def relating_type_id(cls): + @classmethod + def ifc_class_current(cls): ifc_classes = cls.data["ifc_classes"] if not ifc_classes: return [] - results = [] ifc_class = tool.Blender.get_enum_safe(cls.props, "ifc_class") if not ifc_class and ifc_classes: ifc_class = ifc_classes[0][0] + return ifc_class + + @classmethod + def relating_type_id(cls): + results = [] + ifc_class = cls.data["ifc_class_current"] if ifc_class: elements = natsorted(tool.Ifc.get().by_type(ifc_class), key=lambda s: (s.Name or "Unnamed").lower()) results.extend(elements) diff --git a/src/bonsai/bonsai/bim/module/model/ui.py b/src/bonsai/bonsai/bim/module/model/ui.py index 7616c04c78..83a0657e2a 100644 --- a/src/bonsai/bonsai/bim/module/model/ui.py +++ b/src/bonsai/bonsai/bim/module/model/ui.py @@ -94,7 +94,7 @@ class LaunchTypeManager(bpy.types.Operator): props = context.scene.BIMModelProperties props.type_page = 1 if get_ifc_class(None, context): - ifc_class = props.ifc_class or AuthoringData.data["ifc_element_type"] + ifc_class = AuthoringData.data["ifc_class_current"] or AuthoringData.data["ifc_element_type"] else: ifc_class = AuthoringData.data["ifc_element_type"] @@ -167,7 +167,7 @@ class LaunchTypeManager(bpy.types.Operator): else: row = box.row() op = box.operator("bim.load_type_thumbnails", text="", icon="FILE_REFRESH", emboss=False) - op.ifc_class = props.ifc_class + op.ifc_class = AuthoringData.data["ifc_class_current"] row = box.row() row.alignment = "CENTER" diff --git a/src/bonsai/bonsai/bim/module/model/workspace.py b/src/bonsai/bonsai/bim/module/model/workspace.py index e27252db08..bfa74713e0 100644 --- a/src/bonsai/bonsai/bim/module/model/workspace.py +++ b/src/bonsai/bonsai/bim/module/model/workspace.py @@ -433,9 +433,7 @@ class CreateObjectUI: if not AuthoringData.data["relating_type_id"]: return - ifc_class = tool.Blender.get_enum_safe(cls.props, "ifc_class") - if not ifc_class: - ifc_class = AuthoringData.data["ifc_classes"][0][0] + ifc_class = AuthoringData.data["ifc_class_current"] if ifc_class == "IfcWallType": row.prop(data=cls.props, property="rl1", text="Relative Level" if ui_context != "TOOL_HEADER" else "RL") row = cls.layout.row(align=True) if ui_context != "TOOL_HEADER" else row @@ -488,9 +486,7 @@ class CreateObjectUI: if not AuthoringData.data["ifc_element_type"]: prop_with_search(row, cls.props, "ifc_class", text="Type Class" if ui_context != "TOOL_HEADER" else "") if AuthoringData.data["ifc_classes"]: - ifc_class = tool.Blender.get_enum_safe(cls.props, "ifc_class") - if not ifc_class: - ifc_class = AuthoringData.data["ifc_classes"][0][0] + ifc_class = AuthoringData.data["ifc_class_current"] if ifc_class: box = cls.layout.box() row = box.row(align=True) @@ -916,7 +912,7 @@ class Hotkey(bpy.types.Operator, tool.Ifc.Operator): if get_ifc_class(None, None): try: - self.has_ifc_class = bool(self.props.ifc_class) + self.has_ifc_class = bool(tool.Blender.get_enum_safe(self.props, "ifc_class")) except: pass getattr(self, f"hotkey_{self.hotkey}")()