See #3974. WIP review to ensure history removal in API.

This commit is contained in:
Dion Moult
2023-11-27 18:31:42 +11:00
parent f215670381
commit 14f1acadb7
22 changed files with 174 additions and 5 deletions
@@ -18,6 +18,7 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.element
class Usecase:
@@ -138,16 +139,28 @@ class Usecase:
def purge_existing_connections_to_other_ports(self):
for rel in self.settings["port1"].ConnectedTo or []:
if rel.RelatedPort != self.settings["port2"]:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
for rel in self.settings["port1"].ConnectedFrom or []:
if rel.RelatingPort != self.settings["port2"]:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
for rel in self.settings["port2"].ConnectedTo or []:
if rel.RelatedPort != self.settings["port1"]:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
for rel in self.settings["port2"].ConnectedFrom or []:
if rel.RelatingPort != self.settings["port1"]:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
def set_connected_to(self):
if self.settings["port1"].ConnectedTo:
@@ -175,11 +188,17 @@ class Usecase:
def purge_connected_to(self):
for rel in self.settings["port1"].ConnectedTo or []:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
def purge_connected_from(self):
for rel in self.settings["port1"].ConnectedFrom or []:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
def set_realising_element(self):
for rel in self.settings["port1"].ConnectedTo or []:
@@ -18,6 +18,7 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.element
class Usecase:
@@ -76,4 +77,7 @@ class Usecase:
for rel in rels:
rel.RelatingPort.FlowDirection = None
rel.RelatedPort.FlowDirection = None
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -18,6 +18,7 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.element
class Usecase:
@@ -59,7 +60,16 @@ class Usecase:
)
elif inverse.is_a("IfcRelAssignsToGroup"):
if inverse.RelatingGroup == self.settings["system"]:
history = inverse.OwnerHistory
self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
elif len(inverse.RelatedObjects) == 1:
history = inverse.OwnerHistory
self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
history = self.settings["system"].OwnerHistory
self.file.remove(self.settings["system"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -18,6 +18,7 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.element
class Usecase:
@@ -64,7 +65,11 @@ class Usecase:
if assignment.RelatingFlowElement != self.settings["relating_flow_element"]:
return
if len(assignment.RelatedControlElements) == 1:
return self.file.remove(assignment)
history = assignment.OwnerHistory
self.file.remove(assignment)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
return
related_flow_controls = list(assignment.RelatedControlElements)
related_flow_controls.remove(self.settings["related_flow_control"])
assignment.RelatedControlElements = related_flow_controls
@@ -63,7 +63,10 @@ class Usecase:
for rel in self.settings["element"].IsNestedBy or []:
if self.settings["port"] in rel.RelatedObjects:
if len(rel.RelatedObjects) == 1:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
return
related_objects = set(rel.RelatedObjects) or set()
related_objects.remove(self.settings["port"])
@@ -73,5 +76,8 @@ class Usecase:
def execute_ifc2x3(self):
for rel in self.settings["element"].HasPorts or []:
if rel.RelatingPort == self.settings["port"]:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
return
@@ -18,6 +18,7 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.element
class Usecase:
@@ -64,4 +65,7 @@ class Usecase:
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
else:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)