You can now set a default spatial container.

This will supersede having an active Blender collection selected.
This commit is contained in:
Dion Moult
2024-06-07 21:53:21 +10:00
parent 03b2afbb31
commit c9d724fe18
8 changed files with 48 additions and 18 deletions
@@ -37,6 +37,7 @@ classes = (
operator.SelectDecomposedElements, operator.SelectDecomposedElements,
operator.SelectProduct, operator.SelectProduct,
operator.SelectSimilarContainer, operator.SelectSimilarContainer,
operator.SetDefaultContainer,
prop.SpatialElement, prop.SpatialElement,
prop.Element, prop.Element,
prop.BIMSpatialProperties, prop.BIMSpatialProperties,
@@ -92,9 +92,19 @@ class SpatialDecompositionData:
def load(cls): def load(cls):
cls.is_loaded = True cls.is_loaded = True
cls.data = { cls.data = {
"default_container": cls.default_container(),
"subelement_class": cls.subelement_class(), "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 @classmethod
def subelement_class(cls): def subelement_class(cls):
results = [] results = []
@@ -17,16 +17,12 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>. # along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy import bpy
import ifcopenshell.api
import ifcopenshell.util.element
import blenderbim.tool as tool import blenderbim.tool as tool
import blenderbim.core.spatial as core import blenderbim.core.spatial as core
import blenderbim.core.geometry import blenderbim.core.geometry
import blenderbim.core.aggregate import blenderbim.core.aggregate
import blenderbim.core.root import blenderbim.core.root
import blenderbim.bim.handler 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): class ReferenceStructure(bpy.types.Operator, tool.Ifc.Operator):
@@ -235,4 +231,13 @@ class SelectDecomposedElements(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context): def _execute(self, context):
core.select_decomposed_elements(tool.Spatial) 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))
@@ -131,6 +131,7 @@ class BIMSpatialDecompositionProperties(PropertyGroup):
active_element_index: IntProperty(name="Active Element Index") active_element_index: IntProperty(name="Active Element Index")
total_elements: IntProperty(name="Total Elements") total_elements: IntProperty(name="Total Elements")
subelement_class: bpy.props.EnumProperty(items=get_subelement_class, name="Subelement Class") subelement_class: bpy.props.EnumProperty(items=get_subelement_class, name="Subelement Class")
default_container: IntProperty(name="Default Container", default=0)
@property @property
def active_container(self): def active_container(self):
@@ -109,30 +109,34 @@ class BIM_PT_spatial_decomposition(Panel):
SpatialDecompositionData.load() SpatialDecompositionData.load()
self.props = context.scene.BIMSpatialDecompositionProperties self.props = context.scene.BIMSpatialDecompositionProperties
if self.props.active_container: if SpatialDecompositionData.data['default_container']:
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.label( row.label(
text=f"Active: {self.props.active_container.name}", text=f"Default: {SpatialDecompositionData.data['default_container']}",
icon="OUTLINER_COLLECTION", icon="OUTLINER_COLLECTION",
) )
row.operator("bim.import_spatial_decomposition", icon="FILE_REFRESH", text="") 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": if self.props.active_container:
row = self.layout.row(align=True) ifc_definition_id = self.props.active_container.ifc_definition_id if self.props.active_container else 0
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
)
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.prop(self.props, "subelement_class", text="") row.prop(self.props, "subelement_class", text="")
op = row.operator("bim.add_part_to_object", icon="ADD", 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 op.part_class = self.props.subelement_class
else:
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.label(text="Warning: No Active Container", icon="ERROR") if self.props.active_container.ifc_class == "IfcProject":
row.operator("bim.import_spatial_decomposition", icon="FILE_REFRESH", text="") 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( self.layout.template_list(
"BIM_UL_containers_manager", "BIM_UL_containers_manager",
@@ -238,3 +238,7 @@ def toggle_hide_spaces(ifc, spatial):
if not spaces: if not spaces:
return return
spatial.toggle_hide_spaces(spaces) spatial.toggle_hide_spaces(spaces)
def set_default_container(spatial: tool.Spatial, container: ifcopenshell.entity_instance):
spatial.set_default_container(container)
+1
View File
@@ -855,6 +855,7 @@ class Spatial:
def select_products(cls, products, unhide=False): pass def select_products(cls, products, unhide=False): pass
def set_active_object(cls, obj): pass def set_active_object(cls, obj): pass
def set_relative_object_matrix(cls, target_obj, relative_to_obj, matrix): 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 def show_scene_objects(cls): pass
#HERE STARTS SPATIAL TOOL #HERE STARTS SPATIAL TOOL
def is_bounding_class(cls, visible_element): pass def is_bounding_class(cls, visible_element): pass
@@ -826,3 +826,7 @@ class Spatial(blenderbim.core.tool.Spatial):
for space in spaces: for space in spaces:
obj = tool.Ifc.get_object(space) obj = tool.Ifc.get_object(space)
obj.hide_set(False) obj.hide_set(False)
@classmethod
def set_default_container(cls, container):
bpy.context.scene.BIMSpatialDecompositionProperties.default_container = container.id()