mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 11:36:59 +00:00
WIP spatial operator now updates the blender collection structure. See #1222.
This commit is contained in:
@@ -1835,8 +1835,6 @@ class IfcImporter:
|
|||||||
):
|
):
|
||||||
container = element.ContainedInStructure[0].RelatingStructure
|
container = element.ContainedInStructure[0].RelatingStructure
|
||||||
if container.is_a("IfcSpace"):
|
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)
|
return self.place_object_in_spatial_tree(container, obj)
|
||||||
elif element.is_a("IfcGrid"):
|
elif element.is_a("IfcGrid"):
|
||||||
grid_collection = bpy.data.collections.get(obj.name)
|
grid_collection = bpy.data.collections.get(obj.name)
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ from . import ui, operator
|
|||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
operator.AssignContainer,
|
operator.AssignContainer,
|
||||||
|
operator.EnableEditingContainer,
|
||||||
|
operator.DisableEditingContainer,
|
||||||
ui.BIM_PT_spatial,
|
ui.BIM_PT_spatial,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -7,26 +7,49 @@ from blenderbim.bim.module.spatial.data import Data
|
|||||||
class AssignContainer(bpy.types.Operator):
|
class AssignContainer(bpy.types.Operator):
|
||||||
bl_idname = "bim.assign_container"
|
bl_idname = "bim.assign_container"
|
||||||
bl_label = "Assign Container"
|
bl_label = "Assign Container"
|
||||||
|
relating_structure: bpy.props.StringProperty()
|
||||||
|
related_element: bpy.props.StringProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
obj = bpy.context.active_object
|
related_element = bpy.data.objects.get(self.related_element) if self.related_element else bpy.context.active_object
|
||||||
props = obj.BIMObjectProperties
|
props = related_element.BIMObjectProperties
|
||||||
relating_structure = None
|
relating_structure = bpy.data.objects.get(self.relating_structure) if self.relating_structure else props.relating_structure
|
||||||
for collection in obj.users_collection:
|
if not relating_structure or not relating_structure.BIMObjectProperties.ifc_definition_id:
|
||||||
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:
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
assign_container.Usecase(
|
assign_container.Usecase(
|
||||||
self.file,
|
self.file,
|
||||||
{
|
{
|
||||||
"product": self.file.by_id(props.ifc_definition_id),
|
"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()
|
).execute()
|
||||||
Data.load(props.ifc_definition_id)
|
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"}
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -27,11 +27,17 @@ class BIM_PT_spatial(Panel):
|
|||||||
if props.ifc_definition_id not in Data.products:
|
if props.ifc_definition_id not in Data.products:
|
||||||
Data.load(props.ifc_definition_id)
|
Data.load(props.ifc_definition_id)
|
||||||
|
|
||||||
row = self.layout.row(align=True)
|
if props.is_editing_container:
|
||||||
name = "{}/{}".format(
|
row = self.layout.row(align=True)
|
||||||
Data.products[props.ifc_definition_id]["type"], Data.products[props.ifc_definition_id]["Name"]
|
row.prop(props, "relating_structure", text="")
|
||||||
)
|
row.operator("bim.assign_container", icon="CHECKMARK", text="")
|
||||||
if name == "None/None":
|
row.operator("bim.disable_editing_container", icon="X", text="")
|
||||||
name = "This object is not spatially contained"
|
else:
|
||||||
row.label(text=name)
|
row = self.layout.row(align=True)
|
||||||
row.operator("bim.assign_container", icon="FILE_REFRESH", text="")
|
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")
|
is_editing_attributes: BoolProperty(name="Is Editing Attributes")
|
||||||
relating_object: PointerProperty(name="Aggregate", type=bpy.types.Object)
|
relating_object: PointerProperty(name="Aggregate", type=bpy.types.Object)
|
||||||
is_editing_aggregate: BoolProperty(name="Is Editing Aggregate")
|
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_type: PointerProperty(name="Type Product", type=bpy.types.Object)
|
||||||
relating_structure: PointerProperty(name="Spatial Container", type=bpy.types.Object)
|
relating_structure: PointerProperty(name="Spatial Container", type=bpy.types.Object)
|
||||||
psets: CollectionProperty(name="Psets", type=PsetQto)
|
psets: CollectionProperty(name="Psets", type=PsetQto)
|
||||||
|
|||||||
Reference in New Issue
Block a user