From 8935a17844134d2e486ad615ae4fabea83e588d9 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 27 May 2021 13:54:18 +1000 Subject: [PATCH] Really barebones UI to list space boundaries. --- src/blenderbim/blenderbim/bim/__init__.py | 1 + .../bim/module/boundary/__init__.py | 14 ++++++++ .../blenderbim/bim/module/boundary/ui.py | 34 +++++++++++++++++++ .../blenderbim/bim/module/structural/ui.py | 11 +++--- .../ifcopenshell/api/boundary/data.py | 33 ++++++++++++++++++ 5 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 src/blenderbim/blenderbim/bim/module/boundary/__init__.py create mode 100644 src/blenderbim/blenderbim/bim/module/boundary/ui.py create mode 100644 src/ifcopenshell-python/ifcopenshell/api/boundary/data.py diff --git a/src/blenderbim/blenderbim/bim/__init__.py b/src/blenderbim/blenderbim/bim/__init__.py index dd182b00c8..9672810e0b 100644 --- a/src/blenderbim/blenderbim/bim/__init__.py +++ b/src/blenderbim/blenderbim/bim/__init__.py @@ -31,6 +31,7 @@ if bpy is not None: "sequence": None, "group": None, "structural": None, + "boundary": None, "material": None, "style": None, "layer": None, diff --git a/src/blenderbim/blenderbim/bim/module/boundary/__init__.py b/src/blenderbim/blenderbim/bim/module/boundary/__init__.py new file mode 100644 index 0000000000..aab371b6fe --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/boundary/__init__.py @@ -0,0 +1,14 @@ +import bpy +from . import ui + +classes = ( + ui.BIM_PT_boundary, +) + + +def register(): + pass + + +def unregister(): + pass diff --git a/src/blenderbim/blenderbim/bim/module/boundary/ui.py b/src/blenderbim/blenderbim/bim/module/boundary/ui.py new file mode 100644 index 0000000000..cafe32f382 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/boundary/ui.py @@ -0,0 +1,34 @@ +import bpy +import blenderbim.bim.helper +from bpy.types import Panel, UIList +from blenderbim.bim.ifc import IfcStore +from ifcopenshell.api.boundary.data import Data + + +class BIM_PT_boundary(Panel): + bl_label = "IFC Space Boundaries" + bl_idname = "BIM_PT_boundary" + bl_options = {"DEFAULT_CLOSED"} + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "object" + + @classmethod + def poll(cls, context): + if not context.active_object: + return False + props = context.active_object.BIMObjectProperties + if not props.ifc_definition_id: + return False + if IfcStore.get_file().by_id(props.ifc_definition_id).is_a() not in ["IfcSpace", "IfcExternalSpatialElement"]: + return False + return True + + def draw(self, context): + self.oprops = context.active_object.BIMObjectProperties + if not Data.is_loaded: + Data.load(IfcStore.get_file()) + for boundary_id in Data.spaces.get(self.oprops.ifc_definition_id, []): + boundary = Data.boundaries[boundary_id] + row = self.layout.row() + row.label(text=f"{boundary_id}", icon="GHOST_ENABLED") diff --git a/src/blenderbim/blenderbim/bim/module/structural/ui.py b/src/blenderbim/blenderbim/bim/module/structural/ui.py index 6a1737f457..0e7f37f834 100644 --- a/src/blenderbim/blenderbim/bim/module/structural/ui.py +++ b/src/blenderbim/blenderbim/bim/module/structural/ui.py @@ -47,6 +47,7 @@ def draw_boundary_condition_editable_ui(layout, props): if attribute.is_optional: row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="") + def draw_boundary_condition_read_only_ui(layout, boundary_condition_data): for key, value in boundary_condition_data.items(): if key == "id" or key == "type" or value == None: @@ -59,7 +60,6 @@ def draw_boundary_condition_read_only_ui(layout, boundary_condition_data): row.label(text=str(value)) - class BIM_PT_structural_boundary_conditions(Panel): bl_label = "IFC Structural Boundary Conditions" bl_idname = "BIM_PT_structural_boundary_conditions" @@ -231,7 +231,9 @@ class BIM_PT_structural_connection(Panel): row.prop(self.props, "ccs_z_angle", text="Z Angle") else: row = self.layout.row() - row.operator("bim.enable_editing_structural_connection_cs", text="Edit Connection CS", icon="GREASEPENCIL") + row.operator( + "bim.enable_editing_structural_connection_cs", text="Edit Connection CS", icon="GREASEPENCIL" + ) else: row = self.layout.row() row.label(text="TODO") @@ -417,7 +419,6 @@ class BIM_PT_structural_load_cases(Panel): ) - class BIM_UL_structural_activities(UIList): def draw_item(self, context, layout, data, item, icon, active_data, active_propname): if item: @@ -444,9 +445,7 @@ class BIM_PT_structural_loads(Panel): self.props = context.scene.BIMStructuralProperties row = self.layout.row(align=True) - row.label( - text="{} Structural Loads Found".format(len(Data.structural_loads)), icon="GHOST_ENABLED" - ) + row.label(text="{} Structural Loads Found".format(len(Data.structural_loads)), icon="GHOST_ENABLED") if self.props.is_editing_loads: row.prop(self.props, "structural_load_types", text="") row.operator("bim.add_structural_load", text="", icon="ADD").ifc_class = self.props.structural_load_types diff --git a/src/ifcopenshell-python/ifcopenshell/api/boundary/data.py b/src/ifcopenshell-python/ifcopenshell/api/boundary/data.py new file mode 100644 index 0000000000..2ac4e6d7ca --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/boundary/data.py @@ -0,0 +1,33 @@ +class Data: + is_loaded = False + boundaries = {} + spaces = {} + + @classmethod + def purge(cls): + cls.is_loaded = False + cls.boundaries = {} + cls.spaces = {} + + @classmethod + def load(cls, file): + cls._file = file + for boundary in cls._file.by_type("IfcRelSpaceBoundary"): + data = boundary.get_info() + data["RelatingSpace"] = data["RelatingSpace"].id() if data["RelatingSpace"] else None + data["RelatedBuildingElement"] = ( + data["RelatedBuildingElement"].id() if data["RelatedBuildingElement"] else None + ) + del data["ConnectionGeometry"] + if cls._file.schema == "IFC2X3": + pass + else: + if boundary.is_a("IfcRelSpaceBoundary1stLevel"): + data["ParentBoundary"] = data["ParentBoundary"].id() if data["ParentBoundary"] else None + if boundary.is_a("IfcRelSpaceBoundary2ndLevel"): + data["CorrespondingBoundary"] = ( + data["CorrespondingBoundary"].id() if data["CorrespondingBoundary"] else None + ) + cls.boundaries[boundary.id()] = data + cls.spaces.setdefault(data["RelatingSpace"], []).append(boundary.id()) + cls.is_loaded = True