mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Updating either a duration, start, or finish date for a task now auto-updates the other attribute
This commit is contained in:
@@ -104,6 +104,7 @@ def updateTaskTimeDateTime(self, context, startfinish):
|
||||
**{"task_time": task_time, "attributes": {startfinish_key: startfinish_datetime}},
|
||||
)
|
||||
Data.load(IfcStore.get_file())
|
||||
bpy.ops.bim.load_task_properties(task=props.active_task_id)
|
||||
setattr(self, startfinish, canonicalise_time(startfinish_datetime))
|
||||
|
||||
|
||||
@@ -127,6 +128,7 @@ def updateTaskduration(self, context):
|
||||
if props.active_task_id == self.ifc_definition_id:
|
||||
attribute = props.task_attributes.get("Duration")
|
||||
attribute.string_value = self.duration
|
||||
bpy.ops.bim.load_task_properties(task=props.active_task_id)
|
||||
|
||||
|
||||
def updateVisualisationStart(self, context):
|
||||
|
||||
@@ -30,24 +30,48 @@ class Usecase:
|
||||
and self.settings["task_time"].ScheduleDuration
|
||||
and self.settings["task_time"].ScheduleStart
|
||||
):
|
||||
start = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart)
|
||||
current_date = datetime.date(start.year, start.month, start.day)
|
||||
duration = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleDuration).days
|
||||
self.calculate_finish()
|
||||
elif "ScheduleStart" in self.settings["attributes"].keys() and self.settings["task_time"].ScheduleDuration:
|
||||
self.calculate_finish()
|
||||
elif "ScheduleFinish" in self.settings["attributes"].keys() and self.settings["task_time"].ScheduleStart:
|
||||
self.calculate_duration()
|
||||
|
||||
task = [e for e in self.file.get_inverse(self.settings["task_time"]) if e.is_a("IfcTask")]
|
||||
if not task:
|
||||
return
|
||||
else:
|
||||
task = task[0]
|
||||
def calculate_finish(self):
|
||||
start = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart)
|
||||
current_date = datetime.date(start.year, start.month, start.day)
|
||||
duration = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleDuration).days
|
||||
|
||||
calendar = ifcopenshell.util.sequence.derive_calendar(task)
|
||||
calendar = self.get_calendar()
|
||||
|
||||
while duration >= 0:
|
||||
if self.settings["task_time"].DurationType == "ELAPSEDTIME" or not calendar:
|
||||
duration -= 1
|
||||
elif ifcopenshell.util.sequence.is_working_day(current_date, calendar):
|
||||
duration -= 1
|
||||
current_date += datetime.timedelta(days=1)
|
||||
while duration >= 0:
|
||||
if self.settings["task_time"].DurationType == "ELAPSEDTIME" or not calendar:
|
||||
duration -= 1
|
||||
elif ifcopenshell.util.sequence.is_working_day(current_date, calendar):
|
||||
duration -= 1
|
||||
current_date += datetime.timedelta(days=1)
|
||||
|
||||
current_date -= datetime.timedelta(days=1)
|
||||
self.settings["task_time"].ScheduleFinish = ifcopenshell.util.date.datetime2ifc(current_date, "IfcDateTime")
|
||||
current_date -= datetime.timedelta(days=1)
|
||||
self.settings["task_time"].ScheduleFinish = ifcopenshell.util.date.datetime2ifc(current_date, "IfcDateTime")
|
||||
|
||||
def calculate_duration(self):
|
||||
start = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart)
|
||||
finish = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleFinish)
|
||||
current_date = datetime.date(start.year, start.month, start.day)
|
||||
finish_date = datetime.date(finish.year, finish.month, finish.day)
|
||||
calendar = self.get_calendar()
|
||||
duration = datetime.timedelta()
|
||||
while current_date < finish_date:
|
||||
if self.settings["task_time"].DurationType == "ELAPSEDTIME" or not calendar:
|
||||
duration += datetime.timedelta(days=1)
|
||||
elif ifcopenshell.util.sequence.is_working_day(current_date, calendar):
|
||||
duration += datetime.timedelta(days=1)
|
||||
current_date += datetime.timedelta(days=1)
|
||||
self.settings["task_time"].ScheduleDuration = ifcopenshell.util.date.datetime2ifc(duration, "IfcDuration")
|
||||
|
||||
def get_calendar(self):
|
||||
task = [e for e in self.file.get_inverse(self.settings["task_time"]) if e.is_a("IfcTask")]
|
||||
if not task:
|
||||
return
|
||||
else:
|
||||
task = task[0]
|
||||
return ifcopenshell.util.sequence.derive_calendar(task)
|
||||
|
||||
Reference in New Issue
Block a user