You can now add and remove work plans with a new UI. Thanks @bosonprojets and @jesusbill!

This commit is contained in:
Dion Moult
2021-03-31 11:35:40 +11:00
parent d2f19e7c28
commit 1631dc39f5
6 changed files with 125 additions and 0 deletions
@@ -0,0 +1,42 @@
import ifcopenshell.api
import ifcopenshell.util.date
from datetime import datetime
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"name": None, "predefined_type": "NOTDEFINED", "start_time": datetime.now()}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
work_plan = ifcopenshell.api.run(
"root.create_entity",
self.file,
ifc_class="IfcWorkPlan",
predefined_type=self.settings["predefined_type"],
name=self.settings["name"],
)
work_plan.CreationDate = ifcopenshell.util.date.datetime2ifc(datetime.now(), "IfcDateTime")
person = ifcopenshell.api.owner.settings.get_person(self.file)
if person:
work_plan.Creators = [person]
work_plan.StartTime = ifcopenshell.util.date.datetime2ifc(self.settings["start_time"], "IfcDateTime")
context = self.file.by_type("IfcContext")[0]
if context.Declares:
rel_declares = context.Declares[0]
ifcopenshell.api.run("owner.update_owner_history", self.file, element=rel_declares)
else:
rel_declares = self.file.create_entity("IfcRelDeclares", **{
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
"RelatingContext": context
})
related_definitions = list(rel_declares.RelatedDefinitions or [])
related_definitions.append(work_plan)
rel_declares.RelatedDefinitions = related_definitions
return work_plan
@@ -1,15 +1,31 @@
import ifcopenshell.util.date
class Data:
is_loaded = False
work_plans = {}
tasks = {}
@classmethod
def purge(cls):
cls.is_loaded = False
cls.work_plans = {}
cls.tasks = {}
@classmethod
def load(cls, file):
cls.work_plans = {}
cls.tasks = {}
for work_plan in 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
for task in file.by_type("IfcTask"):
cls.tasks[task.id()] = {"Name": task.Name, "Identification": task.Identification or ""}
cls.is_loaded=True
@@ -0,0 +1,14 @@
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"work_plan": None}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
# TODO: do a deep purge
if self.settings["work_plan"].HasContext:
rel_declares = self.settings["work_plan"].HasContext[0]
if len(rel_declares.RelatedDefinitions) == 1:
self.file.remove(rel_declares)
self.file.remove(self.settings["work_plan"])