Add support for editing calendar work and exception times and recurring work times

This commit is contained in:
Dion Moult
2021-04-29 13:16:47 +10:00
parent f8eb1c178a
commit 810d36781c
11 changed files with 359 additions and 26 deletions
@@ -1,15 +0,0 @@
import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"work_time": None, "recurrence_type": None}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
recurrence_pattern = self.file.create_entity("IfcRecurrencePattern")
recurrence_pattern.RecurrenceType = self.settings["recurrence_type"]
self.settings["work_time"].RecurrencePattern = recurrence_pattern
return recurrence_pattern
@@ -7,11 +7,11 @@ class Usecase:
def execute(self):
work_time = self.file.create_entity("IfcWorkTime")
if self.settings["type"] == "WorkingTimes":
if self.settings["time_type"] == "WorkingTimes":
working_times = list(self.settings["work_calendar"].WorkingTimes or [])
working_times.append(work_time)
self.settings["work_calendar"].WorkingTimes = working_times
elif self.settings["type"] == "ExceptionTimes":
elif self.settings["time_type"] == "ExceptionTimes":
exception_times = list(self.settings["work_calendar"].ExceptionTimes or [])
exception_times.append(work_time)
self.settings["work_calendar"].ExceptionTimes = exception_times
@@ -8,8 +8,11 @@ class Usecase:
def execute(self):
recurrence = self.file.createIfcRecurrencePattern(self.settings["recurrence_type"])
if self.settings["parent"].is_a("IfcWorkTime") and self.settings["parent"].RecurrencePattern:
if len(self.file.get_inverse(self.settings["parent"].RecurrencePattern)) == 1:
if self.settings["parent"].is_a("IfcWorkTime"):
if (
self.settings["parent"].RecurrencePattern
and len(self.file.get_inverse(self.settings["parent"].RecurrencePattern)) == 1
):
self.file.remove(self.settings["parent"].RecurrencePattern)
self.settings["parent"].RecurrencePattern = recurrence
elif self.settings["parent"].is_a("IfcTaskTimeRecurring"):
@@ -5,6 +5,10 @@ class Data:
is_loaded = False
work_plans = {}
work_schedules = {}
work_calendars = {}
work_times = {}
recurrence_patterns = {}
time_periods = {}
tasks = {}
task_times = {}
@@ -14,6 +18,9 @@ class Data:
cls.work_plans = {}
cls.work_schedules = {}
cls.work_calendars = {}
cls.work_times = {}
cls.recurrence_patterns = {}
cls.time_periods = {}
cls.tasks = {}
cls.task_times = {}
@@ -25,6 +32,9 @@ class Data:
cls.load_work_plans()
cls.load_work_schedules()
cls.load_work_calendars()
cls.load_work_times()
cls.load_recurrence_patterns()
cls.load_time_periods()
cls.load_tasks()
cls.load_task_times()
cls.is_loaded = True
@@ -71,10 +81,37 @@ class Data:
for work_calendar in cls._file.by_type("IfcWorkCalendar"):
data = work_calendar.get_info()
del data["OwnerHistory"]
del data["WorkingTimes"]
del data["ExceptionTimes"]
data["WorkingTimes"] = [t.id() for t in work_calendar.WorkingTimes or []]
data["ExceptionTimes"] = [t.id() for t in work_calendar.ExceptionTimes or []]
cls.work_calendars[work_calendar.id()] = data
@classmethod
def load_work_times(cls):
cls.work_times = {}
for work_time in cls._file.by_type("IfcWorkTime"):
data = work_time.get_info()
data["Start"] = ifcopenshell.util.date.ifc2datetime(data["Start"]) if data["Start"] else None
data["Finish"] = ifcopenshell.util.date.ifc2datetime(data["Finish"]) if data["Finish"] else None
data["RecurrencePattern"] = work_time.RecurrencePattern.id() if work_time.RecurrencePattern else None
cls.work_times[work_time.id()] = data
@classmethod
def load_recurrence_patterns(cls):
cls.recurrence_patterns = {}
for recurrence_pattern in cls._file.by_type("IfcRecurrencePattern"):
data = recurrence_pattern.get_info()
data["TimePeriods"] = [t.id() for t in recurrence_pattern.TimePeriods or []]
cls.recurrence_patterns[recurrence_pattern.id()] = data
@classmethod
def load_time_periods(cls):
cls.time_periods = {}
for time_period in cls._file.by_type("IfcTimePeriod"):
cls.time_periods[time_period.id()] = {
"StartTime": ifcopenshell.util.date.ifc2datetime(time_period.StartTime),
"EndTime": ifcopenshell.util.date.ifc2datetime(time_period.EndTime),
}
@classmethod
def load_tasks(cls):
cls.tasks = {}
@@ -10,6 +10,6 @@ class Usecase:
def execute(self):
for name, value in self.settings["attributes"].items():
if name in ["Start", "Finish"]:
if value and name in ["Start", "Finish"]:
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDate")
setattr(self.settings["work_time"], name, value)