From 359dab573bfcbefbaad31848d0bc28ea30cd90b2 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 9 May 2024 13:44:54 +0500 Subject: [PATCH] document.remove_information to support ifc2x3 #4636 --- .../api/document/remove_information.py | 29 ++++++++++++------- .../api/document/test_remove_information.py | 4 +++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/document/remove_information.py b/src/ifcopenshell-python/ifcopenshell/api/document/remove_information.py index 86531252e9..6ee66dd386 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/document/remove_information.py +++ b/src/ifcopenshell-python/ifcopenshell/api/document/remove_information.py @@ -22,7 +22,7 @@ import ifcopenshell.api import ifcopenshell.util.element -def remove_information(file, information=None) -> None: +def remove_information(file: ifcopenshell.file, information: ifcopenshell.entity_instance) -> None: """Removes a document information All references and associations are also removed. @@ -41,23 +41,32 @@ def remove_information(file, information=None) -> None: # ... and remove it! ifcopenshell.api.run("document.remove_information", model, information=document) """ - settings = {"information": information} - for reference in settings["information"].HasDocumentReferences or []: + if file.schema == "IFC2X3": + references = information.DocumentReferences or [] + else: + references = information.HasDocumentReferences + + for reference in references: ifcopenshell.api.run("document.remove_reference", file, reference=reference) - for rel in settings["information"].IsPointer or []: - for information in rel.RelatedDocuments: - ifcopenshell.api.run("document.remove_information", file, information=information) + for rel in information.IsPointer or []: + for info in rel.RelatedDocuments: + ifcopenshell.api.run("document.remove_information", file, information=info) - for rel in settings["information"].IsPointedTo or []: - if rel.RelatedDocuments == (settings["information"],): + for rel in information.IsPointedTo or []: + if rel.RelatedDocuments == (information,): # This relationship is non-rooted file.remove(rel) - for rel in settings["information"].DocumentInfoForObjects or []: + if file.schema == "IFC2X3": + rels = [r for r in file.by_type("IfcRelAssociatesDocument") if r.RelatingDocument == information] + else: + rels = information.DocumentInfoForObjects + + for rel in rels: history = rel.OwnerHistory file.remove(rel) if history: ifcopenshell.util.element.remove_deep2(file, history) - file.remove(settings["information"]) + file.remove(information) diff --git a/src/ifcopenshell-python/test/api/document/test_remove_information.py b/src/ifcopenshell-python/test/api/document/test_remove_information.py index ec2adaf9fb..f84d313fe9 100644 --- a/src/ifcopenshell-python/test/api/document/test_remove_information.py +++ b/src/ifcopenshell-python/test/api/document/test_remove_information.py @@ -60,3 +60,7 @@ class TestRemoveInformation(test.bootstrap.IFC4): assert len(self.file.by_type("IfcDocumentReference")) == 0 assert len(self.file.by_type("IfcRelAssociatesDocument")) == 0 assert len(self.file.by_type("IfcDocumentInformationRelationship")) == 0 + + +class TestRemoveInformationIFC2X3(test.bootstrap.IFC2X3, TestRemoveInformation): + pass