You can now assign summary tasks to a work schedule. Thanks myoualid!

This commit is contained in:
Dion Moult
2021-04-15 10:38:45 +10:00
parent 5dec636584
commit 29b33661d7
7 changed files with 107 additions and 58 deletions
@@ -0,0 +1,52 @@
import ifcopenshell
import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {
"related_object": None,
"relating_control": None,
}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
has_assignments = None
if self.settings["related_object"].HasAssignments:
for assignement in self.settings["related_object"].HasAssignments:
if assignement.is_a("IfclRelAssignsToControl"):
has_assignments = assignement
controls = None
for rel in self.settings["relating_control"].Controls:
if rel.is_a("IfcRelAssignsToControl"):
controls = rel
break
if has_assignments and has_assignments == controls:
return
if has_assignments:
related_objects = list(has_assignments.RelatedObjects)
related_objects.remove(self.settings["related_object"])
if related_objects:
has_assignments.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": has_assignments})
else:
self.file.remove(has_assignments)
if controls:
related_objects = list(controls.RelatedObjects)
related_objects.append(self.settings["related_object"])
controls.RelatedObjects = related_objects
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"],
}
)
return controls
@@ -4,7 +4,14 @@ import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"name": None, "predefined_type": "NOTDEFINED", "is_milestone":False, "identification": "none", "predecessor_to":None, "successor_from":None}
self.settings = {
"name": None,
"predefined_type": "NOTDEFINED",
"is_milestone": False,
"identification": "none",
"predecessor_to": None,
"successor_from": None,
}
for key, value in settings.items():
self.settings[key] = value
@@ -17,4 +24,4 @@ class Usecase:
name=self.settings["name"],
)
task.IsMilestone = self.settings["is_milestone"]
return task
return task
@@ -52,6 +52,11 @@ class Data:
data["StartTime"] = ifcopenshell.util.date.ifc2datetime(data["StartTime"])
if data["FinishTime"]:
data["FinishTime"] = ifcopenshell.util.date.ifc2datetime(data["FinishTime"])
data["RelatedObjects"] = []
for rel in work_schedule.Controls:
for obj in rel.RelatedObjects:
if obj.is_a("IfcTask"):
data["RelatedObjects"].append(obj.id())
cls.work_schedules[work_schedule.id()] = data
@classmethod