diff --git a/src/blenderbim/blenderbim/bim/module/spatial/__init__.py b/src/blenderbim/blenderbim/bim/module/spatial/__init__.py index 033d7349c0..a0e41976c0 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/__init__.py @@ -37,6 +37,7 @@ classes = ( operator.SelectDecomposedElements, operator.SelectProduct, operator.SelectSimilarContainer, + operator.SetDefaultContainer, prop.SpatialElement, prop.Element, prop.BIMSpatialProperties, diff --git a/src/blenderbim/blenderbim/bim/module/spatial/data.py b/src/blenderbim/blenderbim/bim/module/spatial/data.py index 5b82cdccad..63fe167a81 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/data.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/data.py @@ -92,9 +92,19 @@ class SpatialDecompositionData: def load(cls): cls.is_loaded = True cls.data = { + "default_container": cls.default_container(), "subelement_class": cls.subelement_class(), } + @classmethod + def default_container(cls) -> str: + props = bpy.context.scene.BIMSpatialDecompositionProperties + if props.default_container: + try: + return tool.Ifc.get().by_id(props.default_container).Name + except: + pass + @classmethod def subelement_class(cls): results = [] diff --git a/src/blenderbim/blenderbim/bim/module/spatial/operator.py b/src/blenderbim/blenderbim/bim/module/spatial/operator.py index 9d4038c5e2..14bb84f09d 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/operator.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/operator.py @@ -17,16 +17,12 @@ # along with BlenderBIM Add-on. If not, see . import bpy -import ifcopenshell.api -import ifcopenshell.util.element import blenderbim.tool as tool import blenderbim.core.spatial as core import blenderbim.core.geometry import blenderbim.core.aggregate import blenderbim.core.root import blenderbim.bim.handler -from blenderbim.bim.ifc import IfcStore -from blenderbim.bim.module.spatial.data import SpatialData class ReferenceStructure(bpy.types.Operator, tool.Ifc.Operator): @@ -235,4 +231,13 @@ class SelectDecomposedElements(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): core.select_decomposed_elements(tool.Spatial) - return {"FINISHED"} + + +class SetDefaultContainer(bpy.types.Operator, tool.Ifc.Operator): + bl_idname = "bim.set_default_container" + bl_label = "Set Default Container" + bl_options = {"REGISTER", "UNDO"} + container: bpy.props.IntProperty() + + def _execute(self, context): + core.set_default_container(tool.Spatial, container=tool.Ifc.get().by_id(self.container)) diff --git a/src/blenderbim/blenderbim/bim/module/spatial/prop.py b/src/blenderbim/blenderbim/bim/module/spatial/prop.py index b4badb994b..1e1f6916c1 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/prop.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/prop.py @@ -131,6 +131,7 @@ class BIMSpatialDecompositionProperties(PropertyGroup): active_element_index: IntProperty(name="Active Element Index") total_elements: IntProperty(name="Total Elements") subelement_class: bpy.props.EnumProperty(items=get_subelement_class, name="Subelement Class") + default_container: IntProperty(name="Default Container", default=0) @property def active_container(self): diff --git a/src/blenderbim/blenderbim/bim/module/spatial/ui.py b/src/blenderbim/blenderbim/bim/module/spatial/ui.py index da7a761af9..5f9eabf9d7 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/ui.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/ui.py @@ -109,30 +109,34 @@ class BIM_PT_spatial_decomposition(Panel): SpatialDecompositionData.load() self.props = context.scene.BIMSpatialDecompositionProperties - if self.props.active_container: + if SpatialDecompositionData.data['default_container']: row = self.layout.row(align=True) row.label( - text=f"Active: {self.props.active_container.name}", + text=f"Default: {SpatialDecompositionData.data['default_container']}", icon="OUTLINER_COLLECTION", ) row.operator("bim.import_spatial_decomposition", icon="FILE_REFRESH", text="") + else: + row = self.layout.row(align=True) + row.label(text="Warning: No Default Container", icon="ERROR") + row.operator("bim.import_spatial_decomposition", icon="FILE_REFRESH", text="") - if self.props.active_container.ifc_class != "IfcProject": - row = self.layout.row(align=True) - row.operator("bim.select_decomposed_elements", icon="HIDE_OFF", text=f"Isolate {self.props.active_container.ifc_class}") - row.operator("bim.delete_container", icon="X", text="").container = ( - self.props.active_container.ifc_definition_id - ) - + if self.props.active_container: + ifc_definition_id = self.props.active_container.ifc_definition_id if self.props.active_container else 0 row = self.layout.row(align=True) row.prop(self.props, "subelement_class", text="") op = row.operator("bim.add_part_to_object", icon="ADD", text="") - op.element = self.props.active_container.ifc_definition_id + op.element = ifc_definition_id op.part_class = self.props.subelement_class - else: + row = self.layout.row(align=True) - row.label(text="Warning: No Active Container", icon="ERROR") - row.operator("bim.import_spatial_decomposition", icon="FILE_REFRESH", text="") + if self.props.active_container.ifc_class == "IfcProject": + row.enabled = False + op = row.operator("bim.set_default_container", icon="OUTLINER_COLLECTION", text="Set Default") + op.container = ifc_definition_id + row.operator("bim.select_decomposed_elements", icon="HIDE_OFF", text=f"Isolate {self.props.active_container.ifc_class}") + op = row.operator("bim.delete_container", icon="X", text="") + op.container = ifc_definition_id self.layout.template_list( "BIM_UL_containers_manager", diff --git a/src/blenderbim/blenderbim/core/spatial.py b/src/blenderbim/blenderbim/core/spatial.py index bc22396a28..bc275678da 100644 --- a/src/blenderbim/blenderbim/core/spatial.py +++ b/src/blenderbim/blenderbim/core/spatial.py @@ -238,3 +238,7 @@ def toggle_hide_spaces(ifc, spatial): if not spaces: return spatial.toggle_hide_spaces(spaces) + + +def set_default_container(spatial: tool.Spatial, container: ifcopenshell.entity_instance): + spatial.set_default_container(container) diff --git a/src/blenderbim/blenderbim/core/tool.py b/src/blenderbim/blenderbim/core/tool.py index 7b66ce782e..b849b7b1d3 100644 --- a/src/blenderbim/blenderbim/core/tool.py +++ b/src/blenderbim/blenderbim/core/tool.py @@ -855,6 +855,7 @@ class Spatial: def select_products(cls, products, unhide=False): pass def set_active_object(cls, obj): pass def set_relative_object_matrix(cls, target_obj, relative_to_obj, matrix): pass + def set_default_container(cls, container): pass def show_scene_objects(cls): pass #HERE STARTS SPATIAL TOOL def is_bounding_class(cls, visible_element): pass diff --git a/src/blenderbim/blenderbim/tool/spatial.py b/src/blenderbim/blenderbim/tool/spatial.py index 5c9fa44ff9..f00aa843bd 100644 --- a/src/blenderbim/blenderbim/tool/spatial.py +++ b/src/blenderbim/blenderbim/tool/spatial.py @@ -826,3 +826,7 @@ class Spatial(blenderbim.core.tool.Spatial): for space in spaces: obj = tool.Ifc.get_object(space) obj.hide_set(False) + + @classmethod + def set_default_container(cls, container): + bpy.context.scene.BIMSpatialDecompositionProperties.default_container = container.id()