You can now add / remove cost schedules

This commit is contained in:
Dion Moult
2021-04-03 19:46:39 +11:00
parent 89557460c8
commit 966af5a757
7 changed files with 131 additions and 0 deletions
@@ -25,6 +25,7 @@ if bpy is not None:
"geometry": None,
"cobie": None,
"sequence": None,
"cost": None,
"group": None,
"structural": None,
"material": None,
@@ -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
@@ -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"}
@@ -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
@@ -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
@@ -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
@@ -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"])