mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Remove empty IfcDocumentInformationRelationship #3581
This commit is contained in:
@@ -46,10 +46,17 @@ class Usecase:
|
||||
def execute(self):
|
||||
for reference in self.settings["information"].HasDocumentReferences or []:
|
||||
ifcopenshell.api.run("document.remove_reference", self.file, reference=reference)
|
||||
|
||||
for rel in self.settings["information"].IsPointer or []:
|
||||
for information in rel.RelatedDocuments:
|
||||
ifcopenshell.api.run("document.remove_information", self.file, information=information)
|
||||
self.file.remove(rel)
|
||||
|
||||
# remove IfcDocumentInformationRelationship so it won't become invalid
|
||||
for rel in self.settings["information"].IsPointedTo or []:
|
||||
if rel.RelatedDocuments == (self.settings["information"],):
|
||||
self.file.remove(rel)
|
||||
|
||||
for rel in self.settings["information"].DocumentInfoForObjects or []:
|
||||
self.file.remove(rel)
|
||||
self.file.remove(self.settings["information"])
|
||||
|
||||
@@ -37,6 +37,19 @@ class TestRemoveInformation(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcDocumentReference")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 0
|
||||
|
||||
# test removing relationship to another information if it was the only relating element
|
||||
information = ifcopenshell.api.run("document.add_information", self.file, parent=None)
|
||||
information1 = ifcopenshell.api.run("document.add_information", self.file, parent=information)
|
||||
information2 = ifcopenshell.api.run("document.add_information", self.file, parent=information)
|
||||
|
||||
ifcopenshell.api.run("document.remove_information", self.file, information=information1)
|
||||
assert len(self.file.by_type("IfcDocumentInformation")) == 2
|
||||
assert len(self.file.by_type("IfcDocumentInformationRelationship")) == 1
|
||||
|
||||
ifcopenshell.api.run("document.remove_information", self.file, information=information2)
|
||||
assert len(self.file.by_type("IfcDocumentInformation")) == 1
|
||||
assert len(self.file.by_type("IfcDocumentInformationRelationship")) == 0
|
||||
|
||||
def test_removing_all_subdocuments_and_their_references_too(self):
|
||||
project = self.file.createIfcProject()
|
||||
information = ifcopenshell.api.run("document.add_information", self.file, parent=None)
|
||||
|
||||
Reference in New Issue
Block a user