Fix #3974. Bug where orphaned histories would be left in API remove operations.

This commit is contained in:
Dion Moult
2023-11-28 10:45:49 +11:00
parent 58414777be
commit 6e932ec2fb
50 changed files with 314 additions and 86 deletions
@@ -109,7 +109,10 @@ class Usecase:
decomposes.RelatedObjects = related_objects decomposes.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": decomposes}) ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": decomposes})
else: else:
history = decomposes.OwnerHistory
self.file.remove(decomposes) self.file.remove(decomposes)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
if is_decomposed_by: if is_decomposed_by:
related_objects = set(is_decomposed_by.RelatedObjects) related_objects = set(is_decomposed_by.RelatedObjects)
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -65,7 +66,11 @@ class Usecase:
if not rel.is_a("IfcRelAggregates"): if not rel.is_a("IfcRelAggregates"):
continue continue
if len(rel.RelatedObjects) == 1: if len(rel.RelatedObjects) == 1:
return self.file.remove(rel) history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
return
related_objects = list(rel.RelatedObjects) related_objects = list(rel.RelatedObjects)
related_objects.remove(self.settings["product"]) related_objects.remove(self.settings["product"])
rel.RelatedObjects = related_objects rel.RelatedObjects = related_objects
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, classification=None): def __init__(self, file, classification=None):
@@ -48,7 +51,10 @@ class Usecase:
self.file.remove(self.settings["classification"]) self.file.remove(self.settings["classification"])
for rel in self.file.by_type("IfcRelAssociatesClassification"): for rel in self.file.by_type("IfcRelAssociatesClassification"):
if not rel.RelatingClassification: if not rel.RelatingClassification:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
for rel in self.file.by_type("IfcExternalReferenceRelationship"): for rel in self.file.by_type("IfcExternalReferenceRelationship"):
if not rel.RelatingReference: if not rel.RelatingReference:
self.file.remove(rel) self.file.remove(rel)
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, reference=None, product=None): def __init__(self, file, reference=None, product=None):
@@ -59,7 +62,10 @@ class Usecase:
if len(related_objects): if len(related_objects):
rel.RelatedObjects = related_objects rel.RelatedObjects = related_objects
else: else:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
else: else:
for rel in self.file.by_type("IfcExternalReferenceRelationship"): for rel in self.file.by_type("IfcExternalReferenceRelationship"):
if rel.RelatingReference == self.settings["reference"] and rel.RelatedResourceObjects: if rel.RelatingReference == self.settings["reference"] and rel.RelatedResourceObjects:
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, constraint=None): def __init__(self, file, constraint=None):
@@ -46,4 +49,7 @@ class Usecase:
self.file.remove(self.settings["constraint"]) self.file.remove(self.settings["constraint"])
for rel in self.file.by_type("IfcRelAssociatesConstraint"): for rel in self.file.by_type("IfcRelAssociatesConstraint"):
if not rel.RelatingConstraint: if not rel.RelatingConstraint:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -50,7 +50,10 @@ class Usecase:
self.file.remove(self.settings["metric"]) self.file.remove(self.settings["metric"])
for rel in self.file.by_type("IfcRelAssociatesConstraint"): for rel in self.file.by_type("IfcRelAssociatesConstraint"):
if not rel.RelatingConstraint: if not rel.RelatingConstraint:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
for resource_rel in self.file.by_type("IfcResourceConstraintRelationship"): for resource_rel in self.file.by_type("IfcResourceConstraintRelationship"):
if not resource_rel.RelatingConstraint: if not resource_rel.RelatingConstraint:
self.file.remove(resource_rel) self.file.remove(resource_rel)
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, product=None, constraint=None): def __init__(self, file, product=None, constraint=None):
@@ -40,4 +43,7 @@ class Usecase:
def execute(self): def execute(self):
for rel in self.settings["product"].HasAssociations: for rel in self.settings["product"].HasAssociations:
if rel.is_a("IfcRelAssociatesConstraint") and rel.RelatingConstraint == self.settings["constraint"]: if rel.is_a("IfcRelAssociatesConstraint") and rel.RelatingConstraint == self.settings["constraint"]:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -61,7 +62,11 @@ class Usecase:
if not rel.is_a("IfcRelAssignsToControl") or rel.RelatingControl != self.settings["relating_control"]: if not rel.is_a("IfcRelAssignsToControl") or rel.RelatingControl != self.settings["relating_control"]:
continue continue
if len(rel.RelatedObjects) == 1: if len(rel.RelatedObjects) == 1:
return self.file.remove(rel) history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
return
related_objects = list(rel.RelatedObjects) related_objects = list(rel.RelatedObjects)
related_objects.remove(self.settings["related_object"]) related_objects.remove(self.settings["related_object"])
rel.RelatedObjects = related_objects rel.RelatedObjects = related_objects
@@ -16,7 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -51,7 +53,16 @@ class Usecase:
for related_object in inverse.RelatedObjects: for related_object in inverse.RelatedObjects:
ifcopenshell.api.run("cost.remove_cost_item", self.file, cost_item=related_object) ifcopenshell.api.run("cost.remove_cost_item", self.file, cost_item=related_object)
elif inverse.RelatedObjects == tuple(self.settings["cost_item"]): elif inverse.RelatedObjects == tuple(self.settings["cost_item"]):
history = inverse.OwnerHistory
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
elif inverse.is_a("IfcRelAssignsToControl"): elif inverse.is_a("IfcRelAssignsToControl"):
history = inverse.OwnerHistory
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
history = self.settings["cost_item"].OwnerHistory
self.file.remove(self.settings["cost_item"]) self.file.remove(self.settings["cost_item"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,7 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -53,4 +55,7 @@ class Usecase:
for related_object in inverse.RelatedObjects for related_object in inverse.RelatedObjects
if related_object.is_a("IfcCostItem") if related_object.is_a("IfcCostItem")
] ]
history = self.settings["cost_schedule"].OwnerHistory
self.file.remove(self.settings["cost_schedule"]) self.file.remove(self.settings["cost_schedule"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -55,6 +55,7 @@ class Usecase:
for rel in self.settings["information"].IsPointedTo or []: for rel in self.settings["information"].IsPointedTo or []:
if rel.RelatedDocuments == (self.settings["information"],): if rel.RelatedDocuments == (self.settings["information"],):
# This relationship is non-rooted
self.file.remove(rel) self.file.remove(rel)
for rel in self.settings["information"].DocumentInfoForObjects or []: for rel in self.settings["information"].DocumentInfoForObjects or []:
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, reference=None): def __init__(self, file, reference=None):
@@ -41,5 +44,8 @@ class Usecase:
def execute(self): def execute(self):
for rel in self.settings["reference"].DocumentRefForObjects or []: for rel in self.settings["reference"].DocumentRefForObjects or []:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
self.file.remove(self.settings["reference"]) self.file.remove(self.settings["reference"])
@@ -17,6 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -59,6 +60,9 @@ class Usecase:
for rel in self.settings["product"].HasAssociations: for rel in self.settings["product"].HasAssociations:
if rel.is_a("IfcRelAssociatesDocument") and rel.RelatingDocument == self.settings["document"]: if rel.is_a("IfcRelAssociatesDocument") and rel.RelatingDocument == self.settings["document"]:
if len(rel.RelatedObjects) == 1: if len(rel.RelatedObjects) == 1:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
else: else:
rel.RelatedObjects = [o for o in rel.RelatedObjects if o != self.settings["product"]] rel.RelatedObjects = [o for o in rel.RelatedObjects if o != self.settings["product"]]
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -44,7 +45,10 @@ class Usecase:
if incompatible_connections: if incompatible_connections:
for connection in set(incompatible_connections): for connection in set(incompatible_connections):
history = connection.OwnerHistory
self.file.remove(connection) self.file.remove(connection)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
for rel in self.settings["relating_element"].ConnectedTo: for rel in self.settings["relating_element"].ConnectedTo:
if rel.is_a() == "IfcRelConnectsElements" and rel.RelatedElement == self.settings["related_element"]: if rel.is_a() == "IfcRelConnectsElements" and rel.RelatedElement == self.settings["related_element"]:
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -77,7 +78,10 @@ class Usecase:
if incompatible_connections: if incompatible_connections:
for connection in set(incompatible_connections): for connection in set(incompatible_connections):
history = connection.OwnerHistory
self.file.remove(connection) self.file.remove(connection)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
return self.file.createIfcRelConnectsPathElements( return self.file.createIfcRelConnectsPathElements(
ifcopenshell.guid.new(), ifcopenshell.guid.new(),
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, **settings): def __init__(self, file, **settings):
@@ -48,4 +51,7 @@ class Usecase:
if incompatible_connections: if incompatible_connections:
for connection in set(incompatible_connections): for connection in set(incompatible_connections):
history = connection.OwnerHistory
self.file.remove(connection) self.file.remove(connection)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -51,4 +52,7 @@ class Usecase:
] ]
for connection in set(connections): for connection in set(connections):
history = connection.OwnerHistory
self.file.remove(connection) self.file.remove(connection)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -60,4 +61,7 @@ class Usecase:
rel.RelatedObjects = list(related_objects) rel.RelatedObjects = list(related_objects)
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel}) ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
else: else:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, library=None): def __init__(self, file, library=None):
@@ -45,4 +48,7 @@ class Usecase:
self.file.remove(self.settings["library"]) self.file.remove(self.settings["library"])
for rel in self.file.by_type("IfcRelAssociatesLibrary"): for rel in self.file.by_type("IfcRelAssociatesLibrary"):
if not rel.RelatingLibrary: if not rel.RelatingLibrary:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, reference=None): def __init__(self, file, reference=None):
@@ -43,5 +46,8 @@ class Usecase:
def execute(self): def execute(self):
for rel in self.settings["reference"].LibraryRefForObjects: for rel in self.settings["reference"].LibraryRefForObjects:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
self.file.remove(self.settings["reference"]) self.file.remove(self.settings["reference"])
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, reference=None, product=None): def __init__(self, file, reference=None, product=None):
@@ -62,7 +65,10 @@ class Usecase:
for rel in rels: for rel in rels:
if self.settings["product"] in rel.RelatedObjects: if self.settings["product"] in rel.RelatedObjects:
if len(rel.RelatedObjects) == 1: if len(rel.RelatedObjects) == 1:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
continue continue
related_objects = list(rel.RelatedObjects) related_objects = list(rel.RelatedObjects)
related_objects.remove(self.settings["product"]) related_objects.remove(self.settings["product"])
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -115,7 +116,10 @@ class Usecase:
nests.RelatedObjects = related_objects nests.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": nests}) ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": nests})
else: else:
history = nests.OwnerHistory
self.file.remove(nests) self.file.remove(nests)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
if is_nested_by: if is_nested_by:
related_objects = list(is_nested_by.RelatedObjects) related_objects = list(is_nested_by.RelatedObjects)
@@ -18,6 +18,8 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, item=None, new_parent=None): def __init__(self, file, item=None, new_parent=None):
@@ -35,5 +37,13 @@ class Usecase:
nests.RelatedObjects = related_objects nests.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": nests}) ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": nests})
else: else:
history = nests.OwnerHistory
self.file.remove(nests) self.file.remove(nests)
ifcopenshell.api.run("nest.assign_object", self.file, related_object=self.settings["item"], relating_object=self.settings["new_parent"]) if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
ifcopenshell.api.run(
"nest.assign_object",
self.file,
related_object=self.settings["item"],
relating_object=self.settings["new_parent"],
)
@@ -18,17 +18,18 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, related_object=None): def __init__(self, file, related_object=None):
"""Unassigns a related_object from its nest. """Unassigns a related_object from its nest.
An object (the whole within a decomposition) is Nested by zero or one more smaller objects. An object (the whole within a decomposition) is Nested by zero or one more smaller objects.
This function will remove this nesting relationship. This function will remove this nesting relationship.
If the object is not part of a nesting relationship, nothing will happen. If the object is not part of a nesting relationship, nothing will happen.
:param related_object: The child of the nesting relationship, typically :param related_object: The child of the nesting relationship, typically
an IfcElement. an IfcElement.
:type related_object: ifcopenshell.entity_instance.entity_instance :type related_object: ifcopenshell.entity_instance.entity_instance
@@ -56,11 +57,13 @@ class Usecase:
if not rel.is_a("IfcRelNests"): if not rel.is_a("IfcRelNests"):
continue continue
if len(rel.RelatedObjects) == 1: if len(rel.RelatedObjects) == 1:
return self.file.remove(rel) history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
return
related_objects = list(rel.RelatedObjects) related_objects = list(rel.RelatedObjects)
related_objects.remove(self.settings["related_object"]) related_objects.remove(self.settings["related_object"])
rel.RelatedObjects = related_objects rel.RelatedObjects = related_objects
ifcopenshell.api.run( ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
"owner.update_owner_history", self.file, **{"element": rel}
)
return rel return rel
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -65,7 +66,11 @@ class Usecase:
if not rel.is_a("IfcRelAssignsToActor") or rel.RelatingActor != self.settings["relating_actor"]: if not rel.is_a("IfcRelAssignsToActor") or rel.RelatingActor != self.settings["relating_actor"]:
continue continue
if len(rel.RelatedObjects) == 1: if len(rel.RelatedObjects) == 1:
return self.file.remove(rel) history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
return
related_objects = list(rel.RelatedObjects) related_objects = list(rel.RelatedObjects)
related_objects.remove(self.settings["related_object"]) related_objects.remove(self.settings["related_object"])
rel.RelatedObjects = related_objects rel.RelatedObjects = related_objects
@@ -16,7 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -47,10 +49,16 @@ class Usecase:
self.file, self.file,
resource=related_object, resource=related_object,
) )
history = inverse.OwnerHistory
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
elif inverse.is_a("IfcRelAssignsToControl"): elif inverse.is_a("IfcRelAssignsToControl"):
if len(inverse.RelatedObjects) == 1: if len(inverse.RelatedObjects) == 1:
history = inverse.OwnerHistory
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
else: else:
related_objects = list(inverse.RelatedObjects) related_objects = list(inverse.RelatedObjects)
related_objects.remove(self.settings["resource"]) related_objects.remove(self.settings["resource"])
@@ -65,7 +73,10 @@ class Usecase:
resource=self.settings["resource"], resource=self.settings["resource"],
) )
elif inverse.RelatedObjects == tuple(self.settings["resource"]): elif inverse.RelatedObjects == tuple(self.settings["resource"]):
history = inverse.OwnerHistory
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
if self.settings["resource"].Usage: if self.settings["resource"].Usage:
self.file.remove(self.settings["resource"].Usage) self.file.remove(self.settings["resource"].Usage)
if self.settings["resource"].BaseQuantity: if self.settings["resource"].BaseQuantity:
@@ -74,4 +85,7 @@ class Usecase:
self.file, self.file,
resource=self.settings["resource"], resource=self.settings["resource"],
) )
history = self.settings["resource"].OwnerHistory
self.file.remove(self.settings["resource"]) self.file.remove(self.settings["resource"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,7 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -69,7 +71,11 @@ class Usecase:
): ):
continue continue
if len(rel.RelatedObjects) == 1: if len(rel.RelatedObjects) == 1:
return self.file.remove(rel) history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
return
related_objects = list(rel.RelatedObjects) related_objects = list(rel.RelatedObjects)
related_objects.remove(self.settings["related_object"]) related_objects.remove(self.settings["related_object"])
rel.RelatedObjects = related_objects rel.RelatedObjects = related_objects
@@ -20,9 +20,7 @@ import ifcopenshell.util.date
class Usecase: class Usecase:
def __init__( def __init__(self, file, rel_sequence=None, lag_value=None, duration_type="WORKTIME"):
self, file, rel_sequence=None, lag_value=None, duration_type="WORKTIME"
):
"""Assign a lag time to a sequence relationship between tasks """Assign a lag time to a sequence relationship between tasks
A task sequence (e.g. finish to start) may optionally have a lag time A task sequence (e.g. finish to start) may optionally have a lag time
@@ -94,22 +92,15 @@ class Usecase:
def execute(self): def execute(self):
lag_value = self.file.createIfcDuration( lag_value = self.file.createIfcDuration(
ifcopenshell.util.date.datetime2ifc( ifcopenshell.util.date.datetime2ifc(self.settings["lag_value"], "IfcDuration")
self.settings["lag_value"], "IfcDuration"
)
) )
lag_time = self.file.create_entity( lag_time = self.file.create_entity(
"IfcLagTime", "IfcLagTime", DurationType=self.settings["duration_type"], LagValue=lag_value
**{
"DurationType": self.settings["duration_type"],
"LagValue": lag_value,
}
) )
if self.settings["rel_sequence"].is_a("IfcRelSequence"): if self.settings["rel_sequence"].is_a("IfcRelSequence"):
if ( if (
self.settings["rel_sequence"].TimeLag self.settings["rel_sequence"].TimeLag
and len(self.file.get_inverse(self.settings["rel_sequence"].TimeLag)) and len(self.file.get_inverse(self.settings["rel_sequence"].TimeLag)) == 1
== 1
): ):
self.file.remove(self.settings["rel_sequence"].TimeLag) self.file.remove(self.settings["rel_sequence"].TimeLag)
self.settings["rel_sequence"].TimeLag = lag_time self.settings["rel_sequence"].TimeLag = lag_time
@@ -16,7 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -67,15 +69,19 @@ class Usecase:
self.file.remove(self.settings["task"].TaskTime) self.file.remove(self.settings["task"].TaskTime)
for inverse in self.file.get_inverse(self.settings["task"]): for inverse in self.file.get_inverse(self.settings["task"]):
if inverse.is_a("IfcRelSequence"): if inverse.is_a("IfcRelSequence"):
history = inverse.OwnerHistory
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
elif inverse.is_a("IfcRelNests"): elif inverse.is_a("IfcRelNests"):
if inverse.RelatingObject == self.settings["task"]: if inverse.RelatingObject == self.settings["task"]:
for related_object in inverse.RelatedObjects: for related_object in inverse.RelatedObjects:
ifcopenshell.api.run( ifcopenshell.api.run("sequence.remove_task", self.file, task=related_object)
"sequence.remove_task", self.file, task=related_object
)
elif not inverse.RelatedObjects: elif not inverse.RelatedObjects:
history = inverse.OwnerHistory
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
elif self.settings["task"] in inverse.RelatedObjects: elif self.settings["task"] in inverse.RelatedObjects:
related_objects = list(inverse.RelatedObjects) related_objects = list(inverse.RelatedObjects)
related_objects.remove(self.settings["task"]) related_objects.remove(self.settings["task"])
@@ -84,17 +90,16 @@ class Usecase:
else: else:
inverse.RelatedObjects = related_objects inverse.RelatedObjects = related_objects
elif inverse.is_a("IfcRelAssignsToControl"): elif inverse.is_a("IfcRelAssignsToControl"):
if ( if inverse.RelatingControl == self.settings["task"] or len(inverse.RelatedObjects) == 1:
inverse.RelatingControl == self.settings["task"] history = inverse.OwnerHistory
or len(inverse.RelatedObjects) == 1
):
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
else: else:
related_objects = list(inverse.RelatedObjects) related_objects = list(inverse.RelatedObjects)
related_objects.remove(self.settings["task"]) related_objects.remove(self.settings["task"])
inverse.RelatedObjects = related_objects inverse.RelatedObjects = related_objects
elif inverse.is_a("IfcRelDefinesByProperties"): elif inverse.is_a("IfcRelDefinesByProperties"):
print(inverse.RelatingPropertyDefinition.Name)
ifcopenshell.api.run( ifcopenshell.api.run(
"pset.remove_pset", "pset.remove_pset",
self.file, self.file,
@@ -102,32 +107,38 @@ class Usecase:
pset=inverse.RelatingPropertyDefinition, pset=inverse.RelatingPropertyDefinition,
) )
elif inverse.is_a("IfcRelAssignsToProcess"): elif inverse.is_a("IfcRelAssignsToProcess"):
if ( if inverse.RelatingProcess == self.settings["task"] or len(inverse.RelatedObjects) == 1:
inverse.RelatingProcess == self.settings["task"] history = inverse.OwnerHistory
or len(inverse.RelatedObjects) == 1
):
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
elif inverse.is_a("IfcRelAssignsToProduct"): elif inverse.is_a("IfcRelAssignsToProduct"):
if ( if inverse.RelatingProduct == self.settings["task"] or len(inverse.RelatedObjects) == 1:
inverse.RelatingProduct == self.settings["task"] history = inverse.OwnerHistory
or len(inverse.RelatedObjects) == 1
):
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
else: else:
related_objects = list(inverse.RelatedObjects) related_objects = list(inverse.RelatedObjects)
related_objects.remove(self.settings["task"]) related_objects.remove(self.settings["task"])
inverse.RelatedObjects = related_objects inverse.RelatedObjects = related_objects
elif inverse.is_a("IfcRelAssignsToObject"): elif inverse.is_a("IfcRelAssignsToObject"):
if ( if inverse.RelatingObject == self.settings["task"] or len(inverse.RelatedObjects) == 1:
inverse.RelatingObject == self.settings["task"] history = inverse.OwnerHistory
or len(inverse.RelatedObjects) == 1
):
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
else: else:
related_objects = list(inverse.RelatedObjects) related_objects = list(inverse.RelatedObjects)
related_objects.remove(self.settings["task"]) related_objects.remove(self.settings["task"])
inverse.RelatedObjects = related_objects inverse.RelatedObjects = related_objects
elif inverse.is_a("IfcRelAssignsToProcess"): elif inverse.is_a("IfcRelAssignsToProcess"):
history = inverse.OwnerHistory
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
history = self.settings["task"].OwnerHistory
self.file.remove(self.settings["task"]) self.file.remove(self.settings["task"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -17,6 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -54,13 +55,14 @@ class Usecase:
) )
if self.settings["work_calendar"].Controls: if self.settings["work_calendar"].Controls:
for rel in self.settings["work_calendar"].Controls: for rel in self.settings["work_calendar"].Controls:
for object in rel.RelatedObjects: for related_object in rel.RelatedObjects:
ifcopenshell.api.run( ifcopenshell.api.run(
"control.unassign_control", "control.unassign_control",
self.file, self.file,
**{ relating_control=self.settings["work_calendar"],
"relating_control": self.settings["work_calendar"], related_object=related_object,
"related_object": object,
}
) )
history = self.settings["work_calendar"].OwnerHistory
self.file.remove(self.settings["work_calendar"]) self.file.remove(self.settings["work_calendar"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -17,6 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -52,4 +53,7 @@ class Usecase:
definition=self.settings["work_plan"], definition=self.settings["work_plan"],
relating_context=self.file.by_type("IfcContext")[0], relating_context=self.file.by_type("IfcContext")[0],
) )
history = self.settings["work_plan"].OwnerHistory
self.file.remove(self.settings["work_plan"]) self.file.remove(self.settings["work_plan"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,7 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -65,22 +67,23 @@ class Usecase:
) )
for inverse in self.file.get_inverse(self.settings["work_schedule"]): for inverse in self.file.get_inverse(self.settings["work_schedule"]):
if inverse.is_a("IfcRelDefinesByObject"): if inverse.is_a("IfcRelDefinesByObject"):
if ( if inverse.RelatingObject == self.settings["work_schedule"] or len(inverse.RelatedObjects) == 1:
inverse.RelatingObject == self.settings["work_schedule"] history = inverse.OwnerHistory
or len(inverse.RelatedObjects) == 1
):
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
else: else:
related_objects = list(inverse.RelatedObjects) related_objects = list(inverse.RelatedObjects)
related_objects.remove(self.settings["work_schedule"]) related_objects.remove(self.settings["work_schedule"])
inverse.RelatedObjects = related_objects inverse.RelatedObjects = related_objects
elif inverse.is_a("IfcRelAssignsToControl"): elif inverse.is_a("IfcRelAssignsToControl"):
[ [
ifcopenshell.api.run( ifcopenshell.api.run("sequence.remove_task", self.file, task=related_object)
"sequence.remove_task", self.file, task=related_object
)
for related_object in inverse.RelatedObjects for related_object in inverse.RelatedObjects
if related_object.is_a("IfcTask") if related_object.is_a("IfcTask")
] ]
history = self.settings["work_schedule"].OwnerHistory
self.file.remove(self.settings["work_schedule"]) self.file.remove(self.settings["work_schedule"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -63,17 +64,16 @@ class Usecase:
def execute(self): def execute(self):
for rel in self.settings["related_object"].HasAssignments or []: for rel in self.settings["related_object"].HasAssignments or []:
if ( if not rel.is_a("IfcRelAssignsToProcess") or rel.RelatingProcess != self.settings["relating_process"]:
not rel.is_a("IfcRelAssignsToProcess")
or rel.RelatingProcess != self.settings["relating_process"]
):
continue continue
if len(rel.RelatedObjects) == 1: if len(rel.RelatedObjects) == 1:
return self.file.remove(rel) history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
return
related_objects = list(rel.RelatedObjects) related_objects = list(rel.RelatedObjects)
related_objects.remove(self.settings["related_object"]) related_objects.remove(self.settings["related_object"])
rel.RelatedObjects = related_objects rel.RelatedObjects = related_objects
ifcopenshell.api.run( ifcopenshell.api.run("owner.update_owner_history", self.file, element=rel)
"owner.update_owner_history", self.file, **{"element": rel}
)
return rel return rel
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -63,17 +64,16 @@ class Usecase:
def execute(self): def execute(self):
for rel in self.settings["related_object"].HasAssignments or []: for rel in self.settings["related_object"].HasAssignments or []:
if ( if not rel.is_a("IfcRelAssignsToProduct") or rel.RelatingProduct != self.settings["relating_product"]:
not rel.is_a("IfcRelAssignsToProduct")
or rel.RelatingProduct != self.settings["relating_product"]
):
continue continue
if len(rel.RelatedObjects) == 1: if len(rel.RelatedObjects) == 1:
return self.file.remove(rel) history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
return
related_objects = list(rel.RelatedObjects) related_objects = list(rel.RelatedObjects)
related_objects.remove(self.settings["related_object"]) related_objects.remove(self.settings["related_object"])
rel.RelatedObjects = related_objects rel.RelatedObjects = related_objects
ifcopenshell.api.run( ifcopenshell.api.run("owner.update_owner_history", self.file, element=rel)
"owner.update_owner_history", self.file, **{"element": rel}
)
return rel return rel
@@ -16,8 +16,6 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell.api
class Usecase: class Usecase:
def __init__(self, file, recurrence_pattern=None): def __init__(self, file, recurrence_pattern=None):
@@ -53,4 +51,6 @@ class Usecase:
self.settings = {"recurrence_pattern": recurrence_pattern} self.settings = {"recurrence_pattern": recurrence_pattern}
def execute(self): def execute(self):
for time_period in self.settings["recurrence_pattern"].TimePeriods or []:
self.file.remove(time_period)
self.file.remove(self.settings["recurrence_pattern"]) self.file.remove(self.settings["recurrence_pattern"])
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -65,9 +66,8 @@ class Usecase:
def execute(self): def execute(self):
for rel in self.settings["related_process"].IsSuccessorFrom or []: for rel in self.settings["related_process"].IsSuccessorFrom or []:
if rel.RelatingProcess == self.settings["relating_process"]: if rel.RelatingProcess == self.settings["relating_process"]:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
ifcopenshell.api.run( if history:
"sequence.cascade_schedule", ifcopenshell.util.element.remove_deep2(self.file, history)
self.file, ifcopenshell.api.run("sequence.cascade_schedule", self.file, task=self.settings["related_process"])
task=self.settings["related_process"],
)
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
import ifcopenshell.util.placement import ifcopenshell.util.placement
@@ -120,7 +121,10 @@ class Usecase:
contained_in_structure[0].RelatedElements = related_elements contained_in_structure[0].RelatedElements = related_elements
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": contained_in_structure[0]}) ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": contained_in_structure[0]})
else: else:
history = contained_in_structure[0].OwnerHistory
self.file.remove(contained_in_structure[0]) self.file.remove(contained_in_structure[0])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
if contains_elements: if contains_elements:
related_elements = list(contains_elements[0].RelatedElements) related_elements = list(contains_elements[0].RelatedElements)
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -77,4 +78,7 @@ class Usecase:
rel.RelatedElements = related_elements rel.RelatedElements = related_elements
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel}) ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
else: else:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -70,4 +71,7 @@ class Usecase:
contained_in_structure[0].RelatedElements = related_elements contained_in_structure[0].RelatedElements = related_elements
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": contained_in_structure[0]}) ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": contained_in_structure[0]})
else: else:
history = contained_in_structure[0].OwnerHistory
self.file.remove(contained_in_structure[0]) self.file.remove(contained_in_structure[0])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -67,4 +68,7 @@ class Usecase:
rel.RelatedElements = related_elements rel.RelatedElements = related_elements
ifcopenshell.api.run("owner.update_owner_history", self.file, element=rel) ifcopenshell.api.run("owner.update_owner_history", self.file, element=rel)
else: else:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, structural_analysis_model=None): def __init__(self, file, structural_analysis_model=None):
@@ -34,5 +37,11 @@ class Usecase:
def execute(self): def execute(self):
for rel in self.settings["structural_analysis_model"].IsGroupedBy or []: for rel in self.settings["structural_analysis_model"].IsGroupedBy or []:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
history = self.settings["structural_analysis_model"].OwnerHistory
self.file.remove(self.settings["structural_analysis_model"]) self.file.remove(self.settings["structural_analysis_model"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,7 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -38,6 +40,9 @@ class Usecase:
ifcopenshell.api.run( ifcopenshell.api.run(
"structural.remove_structural_boundary_condition", "structural.remove_structural_boundary_condition",
self.file, self.file,
**{"connection": self.settings["relation"].RelatedStructuralConnection} connection=self.settings["relation"].RelatedStructuralConnection
) )
history = self.settings["relation"].OwnerHistory
self.file.remove(self.settings["relation"]) self.file.remove(self.settings["relation"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,7 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -34,5 +36,10 @@ class Usecase:
def execute(self): def execute(self):
# TODO: do a deep purge # TODO: do a deep purge
for rel in self.settings["load_case"].IsGroupedBy or []: for rel in self.settings["load_case"].IsGroupedBy or []:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
history = self.settings["load_case"].OwnerHistory
self.file.remove(self.settings["load_case"]) self.file.remove(self.settings["load_case"])
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,7 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -35,5 +37,11 @@ class Usecase:
# TODO: do a deep purge # TODO: do a deep purge
for inverse in self.file.get_inverse(self.settings["load_group"]): for inverse in self.file.get_inverse(self.settings["load_group"]):
if inverse.is_a("IfcRelAssignsToGroup") and len(inverse.RelatedObjects) == 1: if inverse.is_a("IfcRelAssignsToGroup") and len(inverse.RelatedObjects) == 1:
history = inverse.OwnerHistory
self.file.remove(inverse) self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
history = self.settings["load_group"].OwnerHistory
self.file.remove(self.settings["load_group"]) self.file.remove(self.settings["load_group"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -48,4 +49,7 @@ class Usecase:
rel.RelatedObjects = list(related_objects) rel.RelatedObjects = list(related_objects)
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel}) ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
else: else:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element import ifcopenshell.util.element
@@ -17,6 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
@@ -108,13 +109,14 @@ class Usecase:
if fills_voids: if fills_voids:
if fills_voids[0].RelatingOpeningElement == self.settings["opening"]: if fills_voids[0].RelatingOpeningElement == self.settings["opening"]:
return return
history = fills_voids[0].OwnerHistory
self.file.remove(fills_voids[0]) self.file.remove(fills_voids[0])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
self.file.create_entity( self.file.create_entity(
"IfcRelFillsElement", "IfcRelFillsElement",
**{ GlobalId=ifcopenshell.guid.new(),
"GlobalId": ifcopenshell.guid.new(), RelatingOpeningElement=self.settings["opening"],
"RelatingOpeningElement": self.settings["opening"], RelatedBuildingElement=self.settings["element"],
"RelatedBuildingElement": self.settings["element"],
}
) )
@@ -18,6 +18,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element
import ifcopenshell.util.placement import ifcopenshell.util.placement
@@ -108,7 +109,10 @@ class Usecase:
if voids_elements: if voids_elements:
if voids_elements[0].RelatingBuildingElement == self.settings["element"]: if voids_elements[0].RelatingBuildingElement == self.settings["element"]:
return return
history = voids_elements[0].OwnerHistory
self.file.remove(voids_elements[0]) self.file.remove(voids_elements[0])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
self.file.create_entity( self.file.create_entity(
"IfcRelVoidsElement", "IfcRelVoidsElement",
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>. # along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, element=None): def __init__(self, file, element=None):
@@ -56,5 +59,8 @@ class Usecase:
def execute(self): def execute(self):
for rel in self.file.by_type("IfcRelFillsElement"): for rel in self.file.by_type("IfcRelFillsElement"):
if rel.RelatedBuildingElement == self.settings["element"]: if rel.RelatedBuildingElement == self.settings["element"]:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
break break
@@ -49,8 +49,14 @@ class Usecase:
def execute(self): def execute(self):
for rel in self.settings["opening"].VoidsElements: for rel in self.settings["opening"].VoidsElements:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
if self.settings["opening"].is_a("IfcOpeningElement"): if self.settings["opening"].is_a("IfcOpeningElement"):
for rel in self.settings["opening"].HasFillings: for rel in self.settings["opening"].HasFillings:
history = rel.OwnerHistory
self.file.remove(rel) self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
ifcopenshell.api.run("root.remove_product", self.file, product=self.settings["opening"]) ifcopenshell.api.run("root.remove_product", self.file, product=self.settings["opening"])