mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
Fix #2980. Array deletion now uses delete tool. Delete moved into tool so it can be used by other functions.
This commit is contained in:
@@ -360,52 +360,7 @@ class CopyRepresentation(bpy.types.Operator, Operator):
|
|||||||
return r.MappedRepresentation
|
return r.MappedRepresentation
|
||||||
|
|
||||||
|
|
||||||
class OverrideDeleteTrait:
|
class OverrideDelete(bpy.types.Operator):
|
||||||
def delete_ifc_object(self, obj):
|
|
||||||
element = tool.Ifc.get_entity(obj)
|
|
||||||
if not element:
|
|
||||||
return
|
|
||||||
if element.is_a("IfcAnnotation") and element.ObjectType == "DRAWING":
|
|
||||||
return blenderbim.core.drawing.remove_drawing(tool.Ifc, tool.Drawing, drawing=element)
|
|
||||||
if obj.users_collection and obj.users_collection[0].name == obj.name:
|
|
||||||
parent = ifcopenshell.util.element.get_aggregate(element)
|
|
||||||
if not parent:
|
|
||||||
parent = ifcopenshell.util.element.get_container(element)
|
|
||||||
if parent:
|
|
||||||
parent_obj = tool.Ifc.get_object(parent)
|
|
||||||
if parent_obj:
|
|
||||||
parent_collection = bpy.data.collections.get(parent_obj.name)
|
|
||||||
for child in obj.users_collection[0].children:
|
|
||||||
parent_collection.children.link(child)
|
|
||||||
bpy.data.collections.remove(obj.users_collection[0])
|
|
||||||
if getattr(element, "FillsVoids", None):
|
|
||||||
self.remove_filling(element)
|
|
||||||
if element.is_a("IfcOpeningElement"):
|
|
||||||
if element.HasFillings:
|
|
||||||
for rel in element.HasFillings:
|
|
||||||
self.remove_filling(rel.RelatedBuildingElement)
|
|
||||||
else:
|
|
||||||
if element.VoidsElements:
|
|
||||||
self.delete_opening_element(element)
|
|
||||||
else:
|
|
||||||
if getattr(element, "HasOpenings", None):
|
|
||||||
for rel in element.HasOpenings:
|
|
||||||
self.delete_opening_element(rel.RelatedOpeningElement)
|
|
||||||
for port in ifcopenshell.util.system.get_ports(element):
|
|
||||||
self.remove_port(port)
|
|
||||||
ifcopenshell.api.run("root.remove_product", tool.Ifc.get(), product=element)
|
|
||||||
|
|
||||||
def delete_opening_element(self, element):
|
|
||||||
bpy.ops.bim.remove_opening(opening_id=element.id())
|
|
||||||
|
|
||||||
def remove_filling(self, element):
|
|
||||||
bpy.ops.bim.remove_filling(filling=element.id())
|
|
||||||
|
|
||||||
def remove_port(self, port):
|
|
||||||
blenderbim.core.system.remove_port(tool.Ifc, tool.System, port=port)
|
|
||||||
|
|
||||||
|
|
||||||
class OverrideDelete(bpy.types.Operator, OverrideDeleteTrait):
|
|
||||||
bl_idname = "bim.override_object_delete"
|
bl_idname = "bim.override_object_delete"
|
||||||
bl_label = "IFC Delete"
|
bl_label = "IFC Delete"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
@@ -434,18 +389,13 @@ class OverrideDelete(bpy.types.Operator, OverrideDeleteTrait):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
for obj in context.selected_objects:
|
for obj in context.selected_objects:
|
||||||
self.delete_ifc_object(obj)
|
tool.Geometry.delete_ifc_object(obj)
|
||||||
try:
|
|
||||||
obj.name
|
|
||||||
bpy.data.objects.remove(obj)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
# Required otherwise gizmos are still visible
|
# Required otherwise gizmos are still visible
|
||||||
context.view_layer.objects.active = None
|
context.view_layer.objects.active = None
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class OverrideOutlinerDelete(bpy.types.Operator, OverrideDeleteTrait):
|
class OverrideOutlinerDelete(bpy.types.Operator):
|
||||||
bl_idname = "bim.override_outliner_delete"
|
bl_idname = "bim.override_outliner_delete"
|
||||||
bl_label = "IFC Delete"
|
bl_label = "IFC Delete"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
@@ -496,8 +446,7 @@ class OverrideOutlinerDelete(bpy.types.Operator, OverrideDeleteTrait):
|
|||||||
objects_to_delete.add(bpy.data.objects.get(item.name))
|
objects_to_delete.add(bpy.data.objects.get(item.name))
|
||||||
for obj in objects_to_delete:
|
for obj in objects_to_delete:
|
||||||
# This is the only difference
|
# This is the only difference
|
||||||
self.delete_ifc_object(obj)
|
tool.Geometry.delete_ifc_object(obj)
|
||||||
bpy.data.objects.remove(obj)
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def get_collection_objects_and_children(self, collection):
|
def get_collection_objects_and_children(self, collection):
|
||||||
|
|||||||
@@ -64,6 +64,46 @@ class Geometry(blenderbim.core.tool.Geometry):
|
|||||||
def delete_data(cls, data):
|
def delete_data(cls, data):
|
||||||
bpy.data.meshes.remove(data)
|
bpy.data.meshes.remove(data)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def delete_ifc_object(cls, obj):
|
||||||
|
element = tool.Ifc.get_entity(obj)
|
||||||
|
if not element:
|
||||||
|
return
|
||||||
|
if element.is_a("IfcAnnotation") and element.ObjectType == "DRAWING":
|
||||||
|
return blenderbim.core.drawing.remove_drawing(tool.Ifc, tool.Drawing, drawing=element)
|
||||||
|
if obj.users_collection and obj.users_collection[0].name == obj.name:
|
||||||
|
parent = ifcopenshell.util.element.get_aggregate(element)
|
||||||
|
if not parent:
|
||||||
|
parent = ifcopenshell.util.element.get_container(element)
|
||||||
|
if parent:
|
||||||
|
parent_obj = tool.Ifc.get_object(parent)
|
||||||
|
if parent_obj:
|
||||||
|
parent_collection = bpy.data.collections.get(parent_obj.name)
|
||||||
|
for child in obj.users_collection[0].children:
|
||||||
|
parent_collection.children.link(child)
|
||||||
|
bpy.data.collections.remove(obj.users_collection[0])
|
||||||
|
if getattr(element, "FillsVoids", None):
|
||||||
|
bpy.ops.bim.remove_filling(filling=element.id())
|
||||||
|
if element.is_a("IfcOpeningElement"):
|
||||||
|
if element.HasFillings:
|
||||||
|
for rel in element.HasFillings:
|
||||||
|
bpy.ops.bim.remove_filling(filling=rel.RelatedBuildingElement.id())
|
||||||
|
else:
|
||||||
|
if element.VoidsElements:
|
||||||
|
bpy.ops.bim.remove_opening(opening_id=element.id())
|
||||||
|
else:
|
||||||
|
if getattr(element, "HasOpenings", None):
|
||||||
|
for rel in element.HasOpenings:
|
||||||
|
bpy.ops.bim.remove_opening(opening_id=rel.RelatedOpeningElement.id())
|
||||||
|
for port in ifcopenshell.util.system.get_ports(element):
|
||||||
|
blenderbim.core.system.remove_port(tool.Ifc, tool.System, port=port)
|
||||||
|
ifcopenshell.api.run("root.remove_product", tool.Ifc.get(), product=element)
|
||||||
|
try:
|
||||||
|
obj.name
|
||||||
|
bpy.data.objects.remove(obj)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def does_representation_id_exist(cls, representation_id):
|
def does_representation_id_exist(cls, representation_id):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -420,14 +420,14 @@ class Model(blenderbim.core.tool.Model):
|
|||||||
element = tool.Ifc.get().by_guid(removed_child)
|
element = tool.Ifc.get().by_guid(removed_child)
|
||||||
obj = tool.Ifc.get_object(element)
|
obj = tool.Ifc.get_object(element)
|
||||||
if obj:
|
if obj:
|
||||||
bpy.data.objects.remove(obj)
|
tool.Geometry.delete_ifc_object(obj)
|
||||||
|
|
||||||
child_i = 0
|
child_i = 0
|
||||||
existing_children = set(array["children"])
|
existing_children = set(array["children"])
|
||||||
total_existing_children = len(array["children"])
|
total_existing_children = len(array["children"])
|
||||||
children_elements = []
|
children_elements = []
|
||||||
children_objs = []
|
children_objs = []
|
||||||
if array['dimension_input_type'] == "Total":
|
if array["dimension_input_type"] == "Total":
|
||||||
divider = 1 if ((array["count"] - 1) == 0) else (array["count"] - 1)
|
divider = 1 if ((array["count"] - 1) == 0) else (array["count"] - 1)
|
||||||
base_offset = Vector([array["x"] / divider, array["y"] / divider, array["z"] / divider]) * unit_scale
|
base_offset = Vector([array["x"] / divider, array["y"] / divider, array["z"] / divider]) * unit_scale
|
||||||
else:
|
else:
|
||||||
@@ -478,8 +478,7 @@ class Model(blenderbim.core.tool.Model):
|
|||||||
element = tool.Ifc.get().by_guid(removed_child)
|
element = tool.Ifc.get().by_guid(removed_child)
|
||||||
obj = tool.Ifc.get_object(element)
|
obj = tool.Ifc.get_object(element)
|
||||||
if obj:
|
if obj:
|
||||||
bpy.data.objects.remove(obj)
|
tool.Geometry.delete_ifc_object(obj)
|
||||||
# TODO: Not sufficient, refactor OverrideDeleteTrait
|
|
||||||
|
|
||||||
bpy.context.view_layer.update()
|
bpy.context.view_layer.update()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user