Support resource level classifications in IfcOpenShell API

This commit is contained in:
Dion Moult
2022-09-02 18:23:49 +10:00
parent ffa3aae132
commit fdfaf54698
6 changed files with 228 additions and 62 deletions
@@ -25,20 +25,30 @@ class Usecase:
self.settings[key] = value
def execute(self):
total_related_objects = 0
for association in self.file.by_type("IfcRelAssociatesClassification"):
if association.RelatingClassification == self.settings["reference"] and association.RelatedObjects:
total_related_objects += len(association.RelatedObjects)
related_objects = list(association.RelatedObjects)
try:
related_objects.remove(self.settings["product"])
except:
continue
if len(related_objects):
association.RelatedObjects = related_objects
else:
self.file.remove(association)
if self.settings["product"].is_a("IfcRoot"):
for rel in self.file.by_type("IfcRelAssociatesClassification"):
if rel.RelatingClassification == self.settings["reference"] and rel.RelatedObjects:
if self.settings["product"] in rel.RelatedObjects:
related_objects = list(rel.RelatedObjects)
related_objects.remove(self.settings["product"])
if len(related_objects):
rel.RelatedObjects = related_objects
else:
self.file.remove(rel)
else:
for rel in self.file.by_type("IfcExternalReferenceRelationship"):
if rel.RelatingReference == self.settings["reference"] and rel.RelatedResourceObjects:
if self.settings["product"] in rel.RelatedResourceObjects:
related_objects = list(rel.RelatedResourceObjects)
related_objects.remove(self.settings["product"])
if len(related_objects):
rel.RelatedResourceObjects = related_objects
else:
self.file.remove(rel)
# TODO: we only handle lightweight classifications here
if total_related_objects == 1:
if (
not self.settings["reference"].ClassificationRefForObjects
and not self.settings["reference"].ExternalReferenceForResources
):
self.file.remove(self.settings["reference"])