From c16d8a39e93c2fe5e4fcd6f628cff3ab33dd7bf4 Mon Sep 17 00:00:00 2001 From: "Sigma Dimensions (Yass)" <79010126+myoualid@users.noreply.github.com> Date: Mon, 21 Aug 2023 01:12:57 +0100 Subject: [PATCH] ligten up add cost schedule UI --- .../blenderbim/bim/module/cost/operator.py | 23 +++++++++++++++++-- .../blenderbim/bim/module/cost/ui.py | 13 ++++------- .../bim/module/resource/operator.py | 2 +- .../blenderbim/bim/module/sequence/helper.py | 1 + .../blenderbim/bim/module/sequence/ui.py | 4 ++-- src/blenderbim/blenderbim/core/cost.py | 4 ++-- .../api/cost/add_cost_schedule.py | 6 +++-- 7 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/cost/operator.py b/src/blenderbim/blenderbim/bim/module/cost/operator.py index 91bf921347..f1629b25a7 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/operator.py +++ b/src/blenderbim/blenderbim/bim/module/cost/operator.py @@ -33,9 +33,26 @@ class AddCostSchedule(bpy.types.Operator, tool.Ifc.Operator): bl_label = "Add Cost Schedule" bl_options = {"REGISTER", "UNDO"} bl_description = "Add a new cost schedule" + name: bpy.props.StringProperty() + object_type: bpy.props.StringProperty() def _execute(self, context): - core.add_cost_schedule(tool.Ifc, predefined_type=context.scene.BIMCostProperties.cost_schedule_predefined_types) + core.add_cost_schedule( + tool.Ifc, + name=self.name, + predefined_type=context.scene.BIMCostProperties.cost_schedule_predefined_types, + object_type=self.object_type, + ) + + def draw(self, context): + layout = self.layout + layout.prop(self, "name", text="Name") + layout.prop(context.scene.BIMCostProperties, "cost_schedule_predefined_types", text="Type") + if context.scene.BIMCostProperties.cost_schedule_predefined_types == "USERDEFINED": + layout.prop(self, "object_type", text="Object type") + + def invoke(self, context, event): + return context.window_manager.invoke_props_dialog(self) class EditCostSchedule(bpy.types.Operator, tool.Ifc.Operator): @@ -646,7 +663,9 @@ class ExportCostSchedules(bpy.types.Operator): def execute(self, context): cost_schedule = tool.Ifc.get().by_id(self.cost_schedule) if self.cost_schedule else None - r = core.export_cost_schedules(tool.Cost, filepath=self.filepath, format=self.format, cost_schedule=cost_schedule) + r = core.export_cost_schedules( + tool.Cost, filepath=self.filepath, format=self.format, cost_schedule=cost_schedule + ) if isinstance(r, str): self.report({"ERROR"}, r) return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/cost/ui.py b/src/blenderbim/blenderbim/bim/module/cost/ui.py index bdf2e7ef8b..d7e82122b7 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/ui.py +++ b/src/blenderbim/blenderbim/bim/module/cost/ui.py @@ -41,20 +41,19 @@ class BIM_PT_cost_schedules(Panel): CostSchedulesData.load() self.props = context.scene.BIMCostProperties - row = self.layout.row() + row = self.layout.row(align=True) if not self.props.active_cost_schedule_id: if CostSchedulesData.data["total_cost_schedules"]: row.label(text=f"{CostSchedulesData.data['total_cost_schedules']} Cost Schedules Found", icon="TEXT") - row.operator("bim.export_cost_schedules", text="Export as spreadsheet", icon="EXPORT") else: row.label(text="No Cost Schedules found.", icon="TEXT") - row = self.layout.row(align=True) - row.alignment = "RIGHT" - row.prop(self.props, "cost_schedule_predefined_types") - row.operator("bim.add_cost_schedule", icon="ADD", text="Add") + row.operator("bim.add_cost_schedule", icon="ADD", text="") for schedule in CostSchedulesData.data["schedules"]: self.draw_cost_schedule_ui(schedule) + row2 = self.layout.row() + row2.alignment = "RIGHT" + row2.operator("bim.export_cost_schedules", text="Export all", icon="EXPORT") def draw_cost_schedule_ui(self, cost_schedule): row = self.layout.row(align=True) @@ -665,8 +664,6 @@ class BIM_UL_cost_items_trait: op.new_index = cost_item["NestingIndex"] - 1 - - class BIM_UL_cost_items(BIM_UL_cost_items_trait, UIList): def __init__(self): self.contract_operator = "bim.contract_cost_item" diff --git a/src/blenderbim/blenderbim/bim/module/resource/operator.py b/src/blenderbim/blenderbim/bim/module/resource/operator.py index b41bb69c2c..9d9d0aeb07 100644 --- a/src/blenderbim/blenderbim/bim/module/resource/operator.py +++ b/src/blenderbim/blenderbim/bim/module/resource/operator.py @@ -334,7 +334,7 @@ class EditResourceQuantity(bpy.types.Operator, tool.Ifc.Operator): class ImportResources(bpy.types.Operator, tool.Ifc.Operator, ImportHelper): bl_idname = "import_resources.bim" - bl_label = "Import P6" + bl_label = "Import Resources" bl_options = {"REGISTER", "UNDO"} filename_ext = ".csv" filter_glob: bpy.props.StringProperty(default="*.csv", options={"HIDDEN"}) diff --git a/src/blenderbim/blenderbim/bim/module/sequence/helper.py b/src/blenderbim/blenderbim/bim/module/sequence/helper.py index 99d61c7611..2e1cfed447 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/helper.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/helper.py @@ -35,6 +35,7 @@ def parse_datetime(value): def parse_duration(value): return ifcopenshell.util.date.parse_duration(value) + def canonicalise_time(time): if not time: return "-" diff --git a/src/blenderbim/blenderbim/bim/module/sequence/ui.py b/src/blenderbim/blenderbim/bim/module/sequence/ui.py index 8afd221482..e41e143e9b 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/ui.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/ui.py @@ -54,7 +54,7 @@ class BIM_PT_work_plans(Panel): row.label(text=f"{WorkPlansData.data['total_work_plans']} Work Plans Found", icon="TEXT") else: row.label(text="No Work Plans found.", icon="TEXT") - row.operator("bim.add_work_plan", icon="ADD", text="") + row.operator("bim.add_work_plan", icon="", text="") for work_plan in WorkPlansData.data["work_plans"]: self.draw_work_plan_ui(work_plan) @@ -131,7 +131,7 @@ class BIM_PT_work_schedules(Panel): ) else: row.label(text="No Work Schedules found.", icon="TEXT") - row.operator("bim.add_work_schedule", text="Add", icon="ADD") + row.operator("bim.add_work_schedule", text="", icon="ADD") for work_schedule_id, work_schedule in SequenceData.data["work_schedules"].items(): self.draw_work_schedule_ui(work_schedule_id, work_schedule) diff --git a/src/blenderbim/blenderbim/core/cost.py b/src/blenderbim/blenderbim/core/cost.py index e0afbe999e..d8f5d9166b 100644 --- a/src/blenderbim/blenderbim/core/cost.py +++ b/src/blenderbim/blenderbim/core/cost.py @@ -1,5 +1,5 @@ -def add_cost_schedule(ifc, predefined_type): - ifc.run("cost.add_cost_schedule", predefined_type=predefined_type) +def add_cost_schedule(ifc, name, predefined_type,object_type): + ifc.run("cost.add_cost_schedule", name=name, predefined_type=predefined_type, object_type=object_type) def edit_cost_schedule(ifc, cost, cost_schedule): diff --git a/src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_schedule.py b/src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_schedule.py index 1d9882ff45..2ceff0b955 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_schedule.py +++ b/src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_schedule.py @@ -22,7 +22,7 @@ from datetime import datetime class Usecase: - def __init__(self, file, name=None, predefined_type="NOTDEFINED"): + def __init__(self, file, name=None, predefined_type="NOTDEFINED", object_type=None): """Add a new cost schedule A cost schedule is a group of cost items which typically represent a @@ -54,7 +54,7 @@ class Usecase: item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule) """ self.file = file - self.settings = {"name": name, "predefined_type": predefined_type} + self.settings = {"name": name, "predefined_type": predefined_type, "object_type": object_type} def execute(self): cost_schedule = ifcopenshell.api.run( @@ -65,4 +65,6 @@ class Usecase: name=self.settings["name"], ) cost_schedule.UpdateDate = ifcopenshell.util.date.datetime2ifc(datetime.now(), "IfcDateTime") + if self.settings["object_type"]: + cost_schedule.ObjectType = self.settings["object_type"] return cost_schedule