mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Deleting an element now also auto deletes its associated distribution ports
This commit is contained in:
@@ -334,6 +334,8 @@ class OverrideDeleteTrait:
|
||||
elif 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)
|
||||
|
||||
def delete_opening_element(self, element):
|
||||
obj = IfcStore.get_element(element.VoidsElements[0].RelatingBuildingElement.id())
|
||||
@@ -343,6 +345,9 @@ class OverrideDeleteTrait:
|
||||
obj = IfcStore.get_element(element.id())
|
||||
bpy.ops.bim.remove_filling(obj=obj.name)
|
||||
|
||||
def remove_port(self, port):
|
||||
blenderbim.core.system.remove_port(tool.Ifc, tool.System, port=port)
|
||||
|
||||
|
||||
class OverrideDelete(bpy.types.Operator, OverrideDeleteTrait):
|
||||
bl_idname = "object.delete"
|
||||
|
||||
@@ -57,4 +57,11 @@ class Usecase:
|
||||
self.file.remove(inverse)
|
||||
elif inverse.is_a("IfcRelVoidsElement"):
|
||||
self.file.remove(inverse)
|
||||
elif inverse.is_a("IfcRelNests"):
|
||||
if inverse.RelatingObject == self.settings["product"]:
|
||||
for subelement in inverse.RelatedObjects:
|
||||
if subelement.is_a("IfcDistributionPort"):
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=subelement)
|
||||
if not inverse.RelatedObjects:
|
||||
self.file.remove(inverse)
|
||||
self.file.remove(self.settings["product"])
|
||||
|
||||
@@ -130,3 +130,13 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(self.file.by_type("IfcDoor")) == 0
|
||||
assert len(self.file.by_type("IfcRelFillsElement")) == 0
|
||||
|
||||
def test_removing_all_distribution_ports(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcChiller")
|
||||
port = ifcopenshell.api.run("system.add_port", self.file, element=element)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||
assert len(list(self.file)) == total_entities - 3
|
||||
assert len(self.file.by_type("IfcChiller")) == 0
|
||||
assert len(self.file.by_type("IfcRelNests")) == 0
|
||||
assert len(self.file.by_type("IfcDistributionPort")) == 0
|
||||
|
||||
Reference in New Issue
Block a user