Fixes to editing task times

This commit is contained in:
Dion Moult
2021-04-20 17:11:06 +10:00
parent 544d6ee695
commit 6d9770542f
7 changed files with 241 additions and 139 deletions
@@ -7,31 +7,11 @@ class Usecase:
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
task_time = self.file.create_entity("IfcTaskTime")
self.settings["task"].TaskTime = task_time
return task_time
@@ -15,6 +15,7 @@ class Data:
cls.work_schedules = {}
cls.work_calendars = {}
cls.tasks = {}
cls.task_times = {}
@classmethod
def load(cls, file):
@@ -81,10 +82,7 @@ class Data:
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
data["TaskTime"] = data["TaskTime"].id()
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 []]
@@ -96,11 +94,10 @@ class Data:
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"])
for key, value in data.items():
if not value:
continue
if "Start" in key or "Finish" in key or key == "StatusTime":
data[key] = ifcopenshell.util.date.ifc2datetime(value)
# TODO parse duration
cls.task_times[task_time.id()] = data
@@ -1,10 +1,16 @@
import ifcopenshell.util.date
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"task": None, "attributes": {}}
self.settings = {"task_time": 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)
if "Start" in name or "Finish" in name or name == "StatusTime":
if value:
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDateTime")
setattr(self.settings["task_time"], name, value)