Add IfcTaskTime to IfckTask

This commit is contained in:
bosonprojets
2021-04-20 05:12:13 +00:00
parent b8963b3d6e
commit 544d6ee695
7 changed files with 166 additions and 3 deletions
@@ -0,0 +1,37 @@
import ifcopenshell.util.date
from datetime import datetime
from datetime import timedelta
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {
"task": None,
"name": "Unnamed",
"duration_type": "NOTDEFINED",
"schedule_duration": None,
"schedule_start_time": datetime.now(),
"schedule_finish_time": datetime.now() + timedelta(days=5),
}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
task_time = self.file.create_entity("IfcTaskTime", **{"Name": self.settings["name"]})
task_time.DurationType = self.settings["duration_type"]
task_time.ScheduleStart = ifcopenshell.util.date.datetime2ifc(self.settings["schedule_start_time"], "IfcDateTime")
duration = self.settings["schedule_duration"]
if duration:
task_time.ScheduleDuration = ifcopenshell.util.date.datetime2ifc(duration, "IfcTime")
task_time.ScheduleFinish = ifcopenshell.util.date.datetime2ifc(
self.settings["schedule_start"] + duration,
"IfcDateTime"
)
else:
duration = self.settings["schedule_finish_time"] - self.settings["schedule_start_time"]
# task_time.ScheduleDuration = ifcopenshell.util.date.datetime2ifc(duration.days, "IfcTime")
task_time.ScheduleFinish = ifcopenshell.util.date.datetime2ifc(self.settings["schedule_finish_time"], "IfcDateTime")
task = self.settings["task"]
if task:
task.TaskTime = task_time
return task_time
@@ -6,6 +6,7 @@ class Data:
work_plans = {}
work_schedules = {}
tasks = {}
task_times = {}
@classmethod
def purge(cls):
@@ -24,6 +25,7 @@ class Data:
cls.load_work_schedules()
cls.load_work_calendars()
cls.load_tasks()
cls.load_task_times()
cls.is_loaded = True
@classmethod
@@ -78,8 +80,27 @@ class Data:
data["RelatedObjects"] = []
data["IsPredecessorTo"] = []
data["IsSuccessorFrom"] = []
if task.TaskTime:
data["TaskTime"] = task.TaskTime
data["ScheduleStart"] = task.TaskTime.ScheduleStart
data["ScheduleFinish"] = task.TaskTime.ScheduleFinish
data["ScheduleDuration"] = task.TaskTime.ScheduleDuration
for rel in task.IsNestedBy:
[data["RelatedObjects"].append(o.id()) for o in rel.RelatedObjects if o.is_a("IfcTask")]
[data["IsPredecessorTo"].append(rel.RelatedProcess.id()) for rel in task.IsPredecessorTo or []]
[data["IsSuccessorFrom"].append(rel.RelatingProcess.id()) for rel in task.IsSuccessorFrom or []]
cls.tasks[task.id()] = data
@classmethod
def load_task_times(cls):
cls.task_times = {}
for task_time in cls._file.by_type("IfcTaskTime"):
data = task_time.get_info()
data["ScheduleStart"] = ifcopenshell.util.date.ifc2datetime(data["ScheduleStart"])
data["ScheduleFinish"] = ifcopenshell.util.date.ifc2datetime(data["ScheduleFinish"])
data["EarlyStart"] = ifcopenshell.util.date.ifc2datetime(data["EarlyStart"])
data["EarlyFinish"] = ifcopenshell.util.date.ifc2datetime(data["EarlyFinish"])
data["LateStart"] = ifcopenshell.util.date.ifc2datetime(data["LateStart"])
data["LateFinish"] = ifcopenshell.util.date.ifc2datetime(data["LateFinish"])
data["EarlyFinish"] = ifcopenshell.util.date.ifc2datetime(data["EarlyFinish"])
cls.task_times[task_time.id()] = data
@@ -0,0 +1,10 @@
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"task": None, "attributes": {}}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
for name, value in self.settings["attributes"].items():
setattr(self.settings["task"].TaskTime, name, value)