2021-04-15 10:38:45 +10:00
|
|
|
import ifcopenshell
|
|
|
|
|
import ifcopenshell.api
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Usecase:
|
|
|
|
|
def __init__(self, file, **settings):
|
|
|
|
|
self.file = file
|
|
|
|
|
self.settings = {
|
|
|
|
|
"relating_control": None,
|
2021-04-22 00:18:22 +00:00
|
|
|
"related_object": None,
|
2021-04-15 10:38:45 +10:00
|
|
|
}
|
|
|
|
|
for key, value in settings.items():
|
|
|
|
|
self.settings[key] = value
|
|
|
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
|
if self.settings["related_object"].HasAssignments:
|
2021-04-21 11:11:08 +10:00
|
|
|
for assignment in self.settings["related_object"].HasAssignments:
|
|
|
|
|
if (
|
|
|
|
|
assignment.is_a("IfclRelAssignsToControl")
|
|
|
|
|
and assignment.RelatingControl == self.settings["relating_control"]
|
|
|
|
|
):
|
|
|
|
|
return
|
2021-04-15 10:38:45 +10:00
|
|
|
|
|
|
|
|
controls = None
|
2021-04-21 11:11:08 +10:00
|
|
|
if self.settings["relating_control"].Controls:
|
|
|
|
|
controls = self.settings["relating_control"].Controls[0]
|
|
|
|
|
|
2021-04-15 10:38:45 +10:00
|
|
|
if controls:
|
2021-04-27 14:45:14 +10:00
|
|
|
related_objects = set(controls.RelatedObjects)
|
|
|
|
|
related_objects.add(self.settings["related_object"])
|
|
|
|
|
controls.RelatedObjects = list(related_objects)
|
2021-04-15 10:38:45 +10:00
|
|
|
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": controls})
|
|
|
|
|
else:
|
|
|
|
|
controls = self.file.create_entity(
|
|
|
|
|
"IfcRelAssignsToControl",
|
|
|
|
|
**{
|
|
|
|
|
"GlobalId": ifcopenshell.guid.new(),
|
|
|
|
|
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
|
|
|
|
"RelatedObjects": [self.settings["related_object"]],
|
|
|
|
|
"RelatingControl": self.settings["relating_control"],
|
2021-04-22 00:18:22 +00:00
|
|
|
},
|
2021-04-15 10:38:45 +10:00
|
|
|
)
|
|
|
|
|
return controls
|