mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-15 18:14:08 +00:00
document.remove_information to support ifc2x3 #4636
This commit is contained in:
@@ -22,7 +22,7 @@ import ifcopenshell.api
|
|||||||
import ifcopenshell.util.element
|
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
|
"""Removes a document information
|
||||||
|
|
||||||
All references and associations are also removed.
|
All references and associations are also removed.
|
||||||
@@ -41,23 +41,32 @@ def remove_information(file, information=None) -> None:
|
|||||||
# ... and remove it!
|
# ... and remove it!
|
||||||
ifcopenshell.api.run("document.remove_information", model, information=document)
|
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)
|
ifcopenshell.api.run("document.remove_reference", file, reference=reference)
|
||||||
|
|
||||||
for rel in settings["information"].IsPointer or []:
|
for rel in information.IsPointer or []:
|
||||||
for information in rel.RelatedDocuments:
|
for info in rel.RelatedDocuments:
|
||||||
ifcopenshell.api.run("document.remove_information", file, information=information)
|
ifcopenshell.api.run("document.remove_information", file, information=info)
|
||||||
|
|
||||||
for rel in settings["information"].IsPointedTo or []:
|
for rel in information.IsPointedTo or []:
|
||||||
if rel.RelatedDocuments == (settings["information"],):
|
if rel.RelatedDocuments == (information,):
|
||||||
# This relationship is non-rooted
|
# This relationship is non-rooted
|
||||||
file.remove(rel)
|
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
|
history = rel.OwnerHistory
|
||||||
file.remove(rel)
|
file.remove(rel)
|
||||||
if history:
|
if history:
|
||||||
ifcopenshell.util.element.remove_deep2(file, history)
|
ifcopenshell.util.element.remove_deep2(file, history)
|
||||||
file.remove(settings["information"])
|
file.remove(information)
|
||||||
|
|||||||
@@ -60,3 +60,7 @@ class TestRemoveInformation(test.bootstrap.IFC4):
|
|||||||
assert len(self.file.by_type("IfcDocumentReference")) == 0
|
assert len(self.file.by_type("IfcDocumentReference")) == 0
|
||||||
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 0
|
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 0
|
||||||
assert len(self.file.by_type("IfcDocumentInformationRelationship")) == 0
|
assert len(self.file.by_type("IfcDocumentInformationRelationship")) == 0
|
||||||
|
|
||||||
|
|
||||||
|
class TestRemoveInformationIFC2X3(test.bootstrap.IFC2X3, TestRemoveInformation):
|
||||||
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user