From 7e8060b224f64b5919444352da70790c28fc0dc7 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 3 Jun 2024 14:32:01 +1000 Subject: [PATCH] Fix #4791. Hide irrelevant spatial containment panel for spatial elements. --- .../blenderbim/bim/module/spatial/data.py | 27 ++++++++++++++----- .../blenderbim/bim/module/spatial/ui.py | 24 +++++++---------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/spatial/data.py b/src/blenderbim/blenderbim/bim/module/spatial/data.py index 78d3777295..e1a3a114cb 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/data.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/data.py @@ -31,14 +31,27 @@ class SpatialData: @classmethod def load(cls): - cls.data = { - "parent_container_id": cls.parent_container_id(), - "is_directly_contained": cls.is_directly_contained(), - "label": cls.label(), - "references": cls.references(), - "containers": cls.containers(), - } cls.is_loaded = True + cls.data["poll"] = cls.poll() + if cls.data["poll"]: + cls.data.update({ + "parent_container_id": cls.parent_container_id(), + "is_directly_contained": cls.is_directly_contained(), + "label": cls.label(), + "references": cls.references(), + "containers": cls.containers(), + }) + + @classmethod + def poll(cls): + if not bpy.context.active_object: + return False + element = tool.Ifc.get_entity(bpy.context.active_object) + if not element: + return False + if element.is_a("IfcElement") or element.is_a("IfcAnnotation") or element.is_a("IfcGrid"): + return True + return False @classmethod def containers(cls): diff --git a/src/blenderbim/blenderbim/bim/module/spatial/ui.py b/src/blenderbim/blenderbim/bim/module/spatial/ui.py index 04dfd23926..cc6687ca59 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/ui.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/ui.py @@ -17,7 +17,6 @@ # along with BlenderBIM Add-on. If not, see . from bpy.types import Panel, UIList -from blenderbim.bim.ifc import IfcStore from blenderbim.bim.module.spatial.data import SpatialData import blenderbim.tool as tool @@ -32,14 +31,9 @@ class BIM_PT_spatial(Panel): @classmethod def poll(cls, context): - if not context.active_object: - return False - oprops = context.active_object.BIMObjectProperties - if not oprops.ifc_definition_id: - return False - if not IfcStore.get_element(oprops.ifc_definition_id): - return False - return True + if not SpatialData.is_loaded: + SpatialData.load() + return SpatialData.data["poll"] def draw(self, context): if not SpatialData.is_loaded: @@ -156,12 +150,12 @@ class BIM_UL_containers_manager(UIList): row.label(text="", icon="BLANK1") if item.has_children: if item.is_expanded: - row.operator( - "bim.contract_container", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN" - ).container = item.ifc_definition_id + row.operator("bim.contract_container", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN").container = ( + item.ifc_definition_id + ) else: - row.operator( - "bim.expand_container", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT" - ).container = item.ifc_definition_id + row.operator("bim.expand_container", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT").container = ( + item.ifc_definition_id + ) else: row.label(text="", icon="DOT")