WIP spatial operator now updates the blender collection structure. See #1222.

This commit is contained in:
Dion Moult
2021-01-06 11:06:59 +11:00
parent 8eb9973045
commit cac635107e
5 changed files with 51 additions and 21 deletions
@@ -1835,8 +1835,6 @@ class IfcImporter:
):
container = element.ContainedInStructure[0].RelatingStructure
if container.is_a("IfcSpace"):
if self.ifc_import_settings.should_import_spaces and container.GlobalId in self.added_data:
obj.BIMObjectProperties.relating_structure = self.added_data[container.GlobalId]
return self.place_object_in_spatial_tree(container, obj)
elif element.is_a("IfcGrid"):
grid_collection = bpy.data.collections.get(obj.name)
@@ -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="")
@@ -1469,6 +1469,7 @@ class BIMObjectProperties(PropertyGroup):
is_editing_attributes: BoolProperty(name="Is Editing Attributes")
relating_object: PointerProperty(name="Aggregate", type=bpy.types.Object)
is_editing_aggregate: BoolProperty(name="Is Editing Aggregate")
is_editing_container: BoolProperty(name="Is Editing Container")
relating_type: PointerProperty(name="Type Product", type=bpy.types.Object)
relating_structure: PointerProperty(name="Spatial Container", type=bpy.types.Object)
psets: CollectionProperty(name="Psets", type=PsetQto)