From 966af5a757b608cf394bffd54d8c5056500415f1 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 3 Apr 2021 19:46:39 +1100 Subject: [PATCH] You can now add / remove cost schedules --- src/blenderbim/blenderbim/bim/__init__.py | 1 + .../blenderbim/bim/module/cost/__init__.py | 16 ++++++++++ .../blenderbim/bim/module/cost/operator.py | 29 +++++++++++++++++++ .../blenderbim/bim/module/cost/ui.py | 29 +++++++++++++++++++ .../api/cost/add_cost_schedule.py | 22 ++++++++++++++ .../ifcopenshell/api/cost/data.py | 24 +++++++++++++++ .../api/cost/remove_cost_schedule.py | 10 +++++++ 7 files changed, 131 insertions(+) create mode 100644 src/blenderbim/blenderbim/bim/module/cost/__init__.py create mode 100644 src/blenderbim/blenderbim/bim/module/cost/operator.py create mode 100644 src/blenderbim/blenderbim/bim/module/cost/ui.py create mode 100644 src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_schedule.py create mode 100644 src/ifcopenshell-python/ifcopenshell/api/cost/data.py create mode 100644 src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_schedule.py diff --git a/src/blenderbim/blenderbim/bim/__init__.py b/src/blenderbim/blenderbim/bim/__init__.py index 1678d8999d..121342189f 100644 --- a/src/blenderbim/blenderbim/bim/__init__.py +++ b/src/blenderbim/blenderbim/bim/__init__.py @@ -25,6 +25,7 @@ if bpy is not None: "geometry": None, "cobie": None, "sequence": None, + "cost": None, "group": None, "structural": None, "material": None, diff --git a/src/blenderbim/blenderbim/bim/module/cost/__init__.py b/src/blenderbim/blenderbim/bim/module/cost/__init__.py new file mode 100644 index 0000000000..2605c0910c --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/cost/__init__.py @@ -0,0 +1,16 @@ +import bpy +from . import ui, operator + +classes = ( + operator.AddCostSchedule, + operator.RemoveCostSchedule, + ui.BIM_PT_cost_schedules, +) + + +def register(): + pass + + +def unregister(): + pass diff --git a/src/blenderbim/blenderbim/bim/module/cost/operator.py b/src/blenderbim/blenderbim/bim/module/cost/operator.py new file mode 100644 index 0000000000..ef6997b9ad --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/cost/operator.py @@ -0,0 +1,29 @@ +import bpy +import ifcopenshell.api +from blenderbim.bim.ifc import IfcStore +from ifcopenshell.api.cost.data import Data + + +class AddCostSchedule(bpy.types.Operator): + bl_idname = "bim.add_cost_schedule" + bl_label = "Add Cost Schedule" + + def execute(self, context): + ifcopenshell.api.run("cost.add_cost_schedule", IfcStore.get_file()) + Data.load(IfcStore.get_file()) + return {"FINISHED"} + + +class RemoveCostSchedule(bpy.types.Operator): + bl_idname = "bim.remove_cost_schedule" + bl_label = "Remove Cost Schedule" + cost_schedule: bpy.props.IntProperty() + + def execute(self, context): + ifcopenshell.api.run( + "cost.remove_cost_schedule", + IfcStore.get_file(), + cost_schedule=IfcStore.get_file().by_id(self.cost_schedule), + ) + Data.load(IfcStore.get_file()) + return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/cost/ui.py b/src/blenderbim/blenderbim/bim/module/cost/ui.py new file mode 100644 index 0000000000..43ecd1bf19 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/cost/ui.py @@ -0,0 +1,29 @@ +from bpy.types import Panel, UIList +from blenderbim.bim.ifc import IfcStore +from ifcopenshell.api.cost.data import Data + + +class BIM_PT_cost_schedules(Panel): + bl_label = "IFC Cost Schedules" + bl_idname = "BIM_PT_cost_schedules" + bl_options = {"DEFAULT_CLOSED"} + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "scene" + + @classmethod + def poll(cls, context): + return IfcStore.get_file() + + def draw(self, context): + if not Data.is_loaded: + Data.load(IfcStore.get_file()) + + row = self.layout.row() + row.operator("bim.add_cost_schedule", icon="ADD") + + for cost_schedule_id, cost_schedule in Data.cost_schedules.items(): + row = self.layout.row(align=True) + row.label(text=cost_schedule["Name"] or "Unnamed", icon="LINENUMBERS_ON") + row.operator("bim.add_cost_schedule", text="", icon="GREASEPENCIL") + row.operator("bim.remove_cost_schedule", text="", icon="X").cost_schedule = cost_schedule_id diff --git a/src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_schedule.py b/src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_schedule.py new file mode 100644 index 0000000000..9111cd0cb6 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_schedule.py @@ -0,0 +1,22 @@ +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): + cost_schedule = ifcopenshell.api.run( + "root.create_entity", + self.file, + ifc_class="IfcCostSchedule", + predefined_type=self.settings["predefined_type"], + name=self.settings["name"], + ) + cost_schedule.UpdateDate = ifcopenshell.util.date.datetime2ifc(datetime.now(), "IfcDateTime") + return cost_schedule diff --git a/src/ifcopenshell-python/ifcopenshell/api/cost/data.py b/src/ifcopenshell-python/ifcopenshell/api/cost/data.py new file mode 100644 index 0000000000..ee934a5c76 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/cost/data.py @@ -0,0 +1,24 @@ +import ifcopenshell.util.date + + +class Data: + is_loaded = False + cost_schedules = {} + + @classmethod + def purge(cls): + cls.is_loaded = False + cls.cost_schedules = {} + + @classmethod + def load(cls, file): + cls.cost_schedules = {} + for cost_schedule in file.by_type("IfcCostSchedule"): + data = cost_schedule.get_info() + del data["OwnerHistory"] + if data["SubmittedOn"]: + data["SubmittedOn"] = ifcopenshell.util.date.ifc2datetime(data["SubmittedOn"]) + if data["UpdateDate"]: + data["UpdateDate"] = ifcopenshell.util.date.ifc2datetime(data["UpdateDate"]) + cls.cost_schedules[cost_schedule.id()] = data + cls.is_loaded=True diff --git a/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_schedule.py b/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_schedule.py new file mode 100644 index 0000000000..36d300c283 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_schedule.py @@ -0,0 +1,10 @@ +class Usecase: + def __init__(self, file, **settings): + self.file = file + self.settings = {"cost_schedule": None} + for key, value in settings.items(): + self.settings[key] = value + + def execute(self): + # TODO: do a deep purge + self.file.remove(self.settings["cost_schedule"])