BlenderBIM and ifcopenshell.api features to enable adding and editing resource time information

This commit is contained in:
bosonprojets
2021-08-10 00:59:20 +01:00
parent 869bb22830
commit 023dd289fa
9 changed files with 187 additions and 31 deletions
@@ -0,0 +1,15 @@
import ifcopenshell.util.date
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {
"resource": None,
}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
resource_time = self.file.create_entity("IfcResourceTime")
self.settings["resource"].Usage = resource_time
return resource_time
@@ -1,11 +1,13 @@
class Data:
is_loaded = False
resources = {}
resource_times = {}
@classmethod
def purge(cls):
cls.is_loaded = False
cls.resources = {}
cls.resource_times = {}
@classmethod
def load(cls, file):
@@ -13,6 +15,7 @@ class Data:
if not cls._file:
return
cls.load_resources()
cls.load_resource_times()
cls.is_loaded=True
@classmethod
@@ -31,4 +34,20 @@ class Data:
for rel in resource.ResourceOf:
[data["ResourceOf"].append(o.id()) for o in rel.RelatedObjects]
data["HasContext"] = resource.HasContext[0].RelatingContext.id() if resource.HasContext else None
if resource.Usage:
data["Usage"] = data["Usage"].id()
cls.resources[resource.id()] = data
@classmethod
def load_resource_times(cls):
cls.resource_times = {}
for resource_time in cls._file.by_type("IfcResourceTime"):
data = resource_time.get_info()
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)
elif "Work" in key or key =="LevelingDelay":
data[key] = ifcopenshell.util.date.ifc2datetime(value)
cls.resource_times[resource_time.id()] = data
@@ -0,0 +1,36 @@
import datetime
import ifcopenshell.util.date
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"resource_time": None, "attributes": {}}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
self.resource = self.get_resource()
# If the user specifies both an end date and a duration, the duration takes priority
if (
"ScheduleWork" in self.settings["attributes"].keys()
and "ScheduleFinish" in self.settings["attributes"].keys()
):
del self.settings["attributes"]["ScheduleFinish"]
if (
"ActualWork" in self.settings["attributes"].keys()
and "ActualFinish" in self.settings["attributes"].keys()
):
del self.settings["attributes"]["ActualFinish"]
for name, value in self.settings["attributes"].items():
if value:
if "Start" in name or "Finish" in name or name == "StatusTime":
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDateTime")
elif name == "ScheduleWork" or name == "ActualWork" or name == "RemainingTime":
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDuration")
setattr(self.settings["resource_time"], name, value)
def get_resource(self):
return [e for e in self.file.get_inverse(self.settings["resource_time"]) if e.is_a("IfcResource")][0]