See #5318. Prevent deletion of project or spatial structures.

This commit is contained in:
Dion Moult
2024-09-06 11:44:30 +10:00
parent 977f3c7dcc
commit a4396ee766
2 changed files with 14 additions and 2 deletions
@@ -627,6 +627,8 @@ class OverrideDelete(bpy.types.Operator):
for obj in context.selected_objects:
element = tool.Ifc.get_entity(obj)
if element:
if not tool.Geometry.is_deletable(element):
continue
if ifcopenshell.util.element.get_pset(element, "BBIM_Array"):
self.report({"INFO"}, "Elements that are part of an array cannot be deleted.")
return {"FINISHED"}
@@ -754,7 +756,11 @@ class OverrideOutlinerDelete(bpy.types.Operator):
elif item.bl_rna.identifier == "Object":
objects_to_delete.add(bpy.data.objects.get(item.name))
for obj in objects_to_delete:
if tool.Ifc.get_entity(obj):
if element := tool.Ifc.get_entity(obj):
if not tool.Geometry.is_deletable(element):
if collection := obj.BIMObjectProperties.collection:
collections_to_delete.discard(collection)
continue
tool.Geometry.delete_ifc_object(obj)
else:
bpy.data.objects.remove(obj)
+7 -1
View File
@@ -91,6 +91,12 @@ class Geometry(bonsai.core.tool.Geometry):
def delete_data(cls, data: bpy.types.Mesh) -> None:
bpy.data.meshes.remove(data)
@classmethod
def is_deletable(cls, element: ifcopenshell.entity_instance) -> bool:
if element.is_a("IfcProject") or tool.Root.is_spatial_element(element):
return False
return True
@classmethod
def delete_ifc_object(cls, obj: bpy.types.Object) -> None:
element = tool.Ifc.get_entity(obj)
@@ -138,7 +144,7 @@ class Geometry(bonsai.core.tool.Geometry):
if element.VoidsElements:
bpy.ops.bim.remove_opening(opening_id=element.id())
else:
is_spatial = element.is_a("IfcSpatialElement") or element.is_a("IfcSpatialStructureElement")
is_spatial = tool.Root.is_spatial_element(element)
if getattr(element, "HasOpenings", None):
for rel in element.HasOpenings:
bpy.ops.bim.remove_opening(opening_id=rel.RelatedOpeningElement.id())