From 92642e6a6a76f6b62e81354d9df33b0e3c5ece18 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 12 Jan 2022 14:29:02 +1100 Subject: [PATCH] The IFC Class panel now shows inherited predefined types --- .../blenderbim/bim/module/root/data.py | 28 +++++++++++++++++++ .../blenderbim/bim/module/root/ui.py | 28 ++++++------------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/root/data.py b/src/blenderbim/blenderbim/bim/module/root/data.py index fe4fa787c3..365bd4ac54 100644 --- a/src/blenderbim/blenderbim/bim/module/root/data.py +++ b/src/blenderbim/blenderbim/bim/module/root/data.py @@ -17,6 +17,7 @@ # along with BlenderBIM Add-on. If not, see . import bpy +import ifcopenshell.util.element import blenderbim.tool as tool @@ -33,6 +34,9 @@ class IfcClassData: cls.is_loaded = True cls.data = { "contexts": cls.contexts(), + "has_entity": cls.has_entity(), + "name": cls.name(), + "ifc_class": cls.ifc_class(), } @classmethod @@ -53,3 +57,27 @@ class IfcClassData: ) ) return results + + @classmethod + def has_entity(cls): + try: + return tool.Ifc.get_entity(bpy.context.active_object) + except: + pass + + @classmethod + def name(cls): + element = tool.Ifc.get_entity(bpy.context.active_object) + if not element: + return + name = element.is_a() + predefined_type = ifcopenshell.util.element.get_predefined_type(element) + if predefined_type: + name += f"[{predefined_type}]" + return name + + @classmethod + def ifc_class(cls): + element = tool.Ifc.get_entity(bpy.context.active_object) + if element: + return element.is_a() diff --git a/src/blenderbim/blenderbim/bim/module/root/ui.py b/src/blenderbim/blenderbim/bim/module/root/ui.py index 996e1cf12d..9eddd935eb 100644 --- a/src/blenderbim/blenderbim/bim/module/root/ui.py +++ b/src/blenderbim/blenderbim/bim/module/root/ui.py @@ -19,7 +19,6 @@ import bpy import blenderbim.bim.module.root.prop as root_prop from bpy.types import Panel -from ifcopenshell.api.root.data import Data from blenderbim.bim.ifc import IfcStore from blenderbim.bim.module.root.data import IfcClassData @@ -43,14 +42,11 @@ class BIM_PT_class(Panel): IfcClassData.load() props = context.active_object.BIMObjectProperties if props.ifc_definition_id: - if props.ifc_definition_id not in Data.products: - try: - Data.load(IfcStore.get_file(), props.ifc_definition_id) - except: - row = self.layout.row(align=True) - row.label(text="IFC Element Not Found") - row.operator("bim.unlink_object", icon="UNLINKED", text="") - return + if not IfcClassData.data["has_entity"]: + row = self.layout.row(align=True) + row.label(text="IFC Element Not Found") + row.operator("bim.unlink_object", icon="UNLINKED", text="") + return if props.is_reassigning_class: row = self.layout.row(align=True) row.operator("bim.reassign_class", icon="CHECKMARK") @@ -61,18 +57,10 @@ class BIM_PT_class(Panel): should_draw_product=False, ) else: - data = Data.products[props.ifc_definition_id] - name = data["type"] - if data["PredefinedType"] and data["PredefinedType"] == "USERDEFINED": - if data["ObjectType"]: - name += "[{}]".format(data["ObjectType"]) - elif data["ElementType"]: - name += "[{}]".format(data["ElementType"]) - elif data["PredefinedType"]: - name += "[{}]".format(data["PredefinedType"]) row = self.layout.row(align=True) - row.label(text=name) - row.operator("bim.select_ifc_class", text="", icon="RESTRICT_SELECT_OFF").ifc_class = data["type"] + row.label(text=IfcClassData.data["name"]) + op = row.operator("bim.select_ifc_class", text="", icon="RESTRICT_SELECT_OFF") + op.ifc_class = IfcClassData.data["ifc_class"] row.operator("bim.copy_class", icon="DUPLICATE", text="") row.operator("bim.unlink_object", icon="UNLINKED", text="") if IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcRoot"):