2021-08-10 10:55:01 +10:00
|
|
|
import ifcopenshell
|
|
|
|
|
import ifcopenshell.util.date
|
2021-08-27 17:12:21 +10:00
|
|
|
from ifcopenshell.api.cost.data import CostValueTrait
|
2021-08-10 10:55:01 +10:00
|
|
|
|
|
|
|
|
|
2021-08-27 17:12:21 +10:00
|
|
|
class Data(CostValueTrait):
|
2021-04-23 06:38:11 +00:00
|
|
|
is_loaded = False
|
|
|
|
|
resources = {}
|
2021-08-10 00:59:20 +01:00
|
|
|
resource_times = {}
|
2021-08-27 17:12:21 +10:00
|
|
|
cost_values = {}
|
2021-04-23 06:38:11 +00:00
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def purge(cls):
|
2021-08-09 03:13:26 +01:00
|
|
|
cls.is_loaded = False
|
2021-04-23 06:38:11 +00:00
|
|
|
cls.resources = {}
|
2021-08-10 00:59:20 +01:00
|
|
|
cls.resource_times = {}
|
2021-08-27 17:12:21 +10:00
|
|
|
cls.cost_values = {}
|
2021-04-23 06:38:11 +00:00
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def load(cls, file):
|
2021-08-09 03:13:26 +01:00
|
|
|
cls._file = file
|
|
|
|
|
if not cls._file:
|
|
|
|
|
return
|
|
|
|
|
cls.load_resources()
|
2021-08-10 00:59:20 +01:00
|
|
|
cls.load_resource_times()
|
2021-08-09 03:13:26 +01:00
|
|
|
cls.is_loaded=True
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def load_resources(cls):
|
2021-04-23 06:38:11 +00:00
|
|
|
cls.resources = {}
|
2021-08-27 17:12:21 +10:00
|
|
|
cls.cost_values = {}
|
2021-08-09 03:13:26 +01:00
|
|
|
for resource in cls._file.by_type("IfcResource"):
|
2021-04-23 06:38:11 +00:00
|
|
|
data = resource.get_info()
|
|
|
|
|
del data["OwnerHistory"]
|
2021-04-26 09:38:45 +10:00
|
|
|
data["IsNestedBy"] = []
|
2021-04-23 06:38:11 +00:00
|
|
|
for rel in resource.IsNestedBy:
|
2021-04-26 09:38:45 +10:00
|
|
|
[data["IsNestedBy"].append(o.id()) for o in rel.RelatedObjects]
|
2021-08-09 03:13:26 +01:00
|
|
|
data["Nests"] = []
|
|
|
|
|
for rel in resource.Nests:
|
|
|
|
|
[data["Nests"].append(rel.RelatingObject.id())]
|
2021-04-26 09:38:45 +10:00
|
|
|
data["ResourceOf"] = []
|
|
|
|
|
for rel in resource.ResourceOf:
|
|
|
|
|
[data["ResourceOf"].append(o.id()) for o in rel.RelatedObjects]
|
2021-04-25 12:29:11 +10:00
|
|
|
data["HasContext"] = resource.HasContext[0].RelatingContext.id() if resource.HasContext else None
|
2021-08-10 00:59:20 +01:00
|
|
|
if resource.Usage:
|
|
|
|
|
data["Usage"] = data["Usage"].id()
|
2021-08-27 17:12:21 +10:00
|
|
|
data["TotalCostQuantity"] = cls.get_total_quantity(resource)
|
|
|
|
|
if resource.BaseQuantity:
|
|
|
|
|
data["BaseQuantity"] = resource.BaseQuantity.id()
|
|
|
|
|
if resource.BaseCosts:
|
|
|
|
|
data["BaseCosts"] = [e.id() for e in resource.BaseCosts]
|
|
|
|
|
cls.load_cost_values(resource, data)
|
2021-04-23 06:38:11 +00:00
|
|
|
cls.resources[resource.id()] = data
|
2021-08-10 00:59:20 +01:00
|
|
|
|
|
|
|
|
@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
|