mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
WIP spatial operator now updates the blender collection structure. See #1222.
This commit is contained in:
@@ -3,6 +3,8 @@ from . import ui, operator
|
||||
|
||||
classes = (
|
||||
operator.AssignContainer,
|
||||
operator.EnableEditingContainer,
|
||||
operator.DisableEditingContainer,
|
||||
ui.BIM_PT_spatial,
|
||||
)
|
||||
|
||||
|
||||
@@ -7,26 +7,49 @@ from blenderbim.bim.module.spatial.data import Data
|
||||
class AssignContainer(bpy.types.Operator):
|
||||
bl_idname = "bim.assign_container"
|
||||
bl_label = "Assign Container"
|
||||
relating_structure: bpy.props.StringProperty()
|
||||
related_element: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
self.file = IfcStore.get_file()
|
||||
obj = bpy.context.active_object
|
||||
props = obj.BIMObjectProperties
|
||||
relating_structure = None
|
||||
for collection in obj.users_collection:
|
||||
if "Ifc" in collection.name:
|
||||
relating_structure = self.file.by_id(
|
||||
bpy.data.objects.get(collection.name).BIMObjectProperties.ifc_definition_id
|
||||
)
|
||||
break
|
||||
if not relating_structure:
|
||||
related_element = bpy.data.objects.get(self.related_element) if self.related_element else bpy.context.active_object
|
||||
props = related_element.BIMObjectProperties
|
||||
relating_structure = bpy.data.objects.get(self.relating_structure) if self.relating_structure else props.relating_structure
|
||||
if not relating_structure or not relating_structure.BIMObjectProperties.ifc_definition_id:
|
||||
return {"FINISHED"}
|
||||
assign_container.Usecase(
|
||||
self.file,
|
||||
{
|
||||
"product": self.file.by_id(props.ifc_definition_id),
|
||||
"relating_structure": relating_structure,
|
||||
"relating_structure": self.file.by_id(relating_structure.BIMObjectProperties.ifc_definition_id),
|
||||
},
|
||||
).execute()
|
||||
Data.load(props.ifc_definition_id)
|
||||
bpy.ops.bim.disable_editing_container(obj=related_element.name)
|
||||
|
||||
for collection in related_element.users_collection:
|
||||
collection.objects.unlink(related_element)
|
||||
collection = bpy.data.collections.get(relating_structure.name)
|
||||
collection.objects.link(related_element)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class EnableEditingContainer(bpy.types.Operator):
|
||||
bl_idname = "bim.enable_editing_container"
|
||||
bl_label = "Enable Editing Container"
|
||||
|
||||
def execute(self, context):
|
||||
bpy.context.active_object.BIMObjectProperties.relating_structure = None
|
||||
bpy.context.active_object.BIMObjectProperties.is_editing_container = True
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class DisableEditingContainer(bpy.types.Operator):
|
||||
bl_idname = "bim.disable_editing_container"
|
||||
bl_label = "Disable Editing Container"
|
||||
obj: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else bpy.context.active_object
|
||||
obj.BIMObjectProperties.is_editing_container = False
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -27,11 +27,17 @@ class BIM_PT_spatial(Panel):
|
||||
if props.ifc_definition_id not in Data.products:
|
||||
Data.load(props.ifc_definition_id)
|
||||
|
||||
row = self.layout.row(align=True)
|
||||
name = "{}/{}".format(
|
||||
Data.products[props.ifc_definition_id]["type"], Data.products[props.ifc_definition_id]["Name"]
|
||||
)
|
||||
if name == "None/None":
|
||||
name = "This object is not spatially contained"
|
||||
row.label(text=name)
|
||||
row.operator("bim.assign_container", icon="FILE_REFRESH", text="")
|
||||
if props.is_editing_container:
|
||||
row = self.layout.row(align=True)
|
||||
row.prop(props, "relating_structure", text="")
|
||||
row.operator("bim.assign_container", icon="CHECKMARK", text="")
|
||||
row.operator("bim.disable_editing_container", icon="X", text="")
|
||||
else:
|
||||
row = self.layout.row(align=True)
|
||||
name = "{}/{}".format(
|
||||
Data.products[props.ifc_definition_id]["type"], Data.products[props.ifc_definition_id]["Name"]
|
||||
)
|
||||
if name == "None/None":
|
||||
name = "This object is not spatially contained"
|
||||
row.label(text=name)
|
||||
row.operator("bim.enable_editing_container", icon="GREASEPENCIL", text="")
|
||||
|
||||
Reference in New Issue
Block a user