Files
IfcOpenShell/src/ifcopenshell-python/ifcopenshell/api/sequence/data.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

110 lines
4.1 KiB
Python
Raw Normal View History

import ifcopenshell.util.date
2021-02-17 22:54:11 +11:00
class Data:
is_loaded = False
work_plans = {}
work_schedules = {}
2021-02-17 22:54:11 +11:00
tasks = {}
2021-04-20 05:12:13 +00:00
task_times = {}
2021-02-17 22:54:11 +11:00
@classmethod
def purge(cls):
cls.is_loaded = False
cls.work_plans = {}
cls.work_schedules = {}
cls.work_calendars = {}
2021-02-17 22:54:11 +11:00
cls.tasks = {}
2021-04-20 17:11:06 +10:00
cls.task_times = {}
2021-02-17 22:54:11 +11:00
@classmethod
def load(cls, file):
2021-04-07 00:04:57 +01:00
cls._file = file
if not cls._file:
return
cls.load_work_plans()
cls.load_work_schedules()
cls.load_work_calendars()
2021-04-07 00:04:57 +01:00
cls.load_tasks()
2021-04-20 05:12:13 +00:00
cls.load_task_times()
cls.is_loaded = True
2021-04-07 00:04:57 +01:00
@classmethod
def load_work_plans(cls):
cls.work_plans = {}
2021-04-07 00:04:57 +01:00
for work_plan in cls._file.by_type("IfcWorkPlan"):
data = work_plan.get_info()
del data["OwnerHistory"]
if data["Creators"]:
data["Creators"] = [p.id() for p in data["Creators"]]
data["CreationDate"] = ifcopenshell.util.date.ifc2datetime(data["CreationDate"])
data["StartTime"] = ifcopenshell.util.date.ifc2datetime(data["StartTime"])
if data["FinishTime"]:
data["FinishTime"] = ifcopenshell.util.date.ifc2datetime(data["FinishTime"])
cls.work_plans[work_plan.id()] = data
2021-04-07 00:04:57 +01:00
@classmethod
def load_work_schedules(cls):
cls.work_schedules = {}
for work_schedule in cls._file.by_type("IfcWorkSchedule"):
data = work_schedule.get_info()
del data["OwnerHistory"]
if data["Creators"]:
data["Creators"] = [p.id() for p in data["Creators"]]
data["CreationDate"] = ifcopenshell.util.date.ifc2datetime(data["CreationDate"])
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
def load_work_calendars(cls):
cls.work_calendars = {}
for work_calendar in cls._file.by_type("IfcWorkCalendar"):
data = work_calendar.get_info()
del data["OwnerHistory"]
del data["WorkingTimes"]
del data["ExceptionTimes"]
cls.work_calendars[work_calendar.id()] = data
2021-04-07 00:04:57 +01:00
@classmethod
def load_tasks(cls):
cls.tasks = {}
for task in cls._file.by_type("IfcTask"):
data = task.get_info()
del data["OwnerHistory"]
data["RelatedObjects"] = []
2021-04-21 11:53:33 +10:00
data["RelatingProducts"] = []
data["IsPredecessorTo"] = []
data["IsSuccessorFrom"] = []
2021-04-20 05:12:13 +00:00
if task.TaskTime:
2021-04-20 17:11:06 +10:00
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")]
2021-04-21 11:53:33 +10:00
[
data["RelatingProducts"].append(r.RelatingProduct.id())
for r in task.HasAssignments
if r.is_a("IfcRelAssignsToProduct")
]
[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
2021-04-20 05:12:13 +00:00
@classmethod
def load_task_times(cls):
cls.task_times = {}
for task_time in cls._file.by_type("IfcTaskTime"):
data = task_time.get_info()
2021-04-20 17:11:06 +10:00
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
2021-04-20 05:12:13 +00:00
cls.task_times[task_time.id()] = data