From 5f9474acb7eeea6f169d0f2617cf28a3560382dd Mon Sep 17 00:00:00 2001 From: bosonprojets Date: Thu, 15 Apr 2021 23:08:45 +0000 Subject: [PATCH] Feature to add multiple summary cost items and remove cost items --- .../blenderbim/bim/module/cost/__init__.py | 2 + .../blenderbim/bim/module/cost/operator.py | 52 ++++++++++++++++--- .../blenderbim/bim/module/cost/ui.py | 13 ++--- .../ifcopenshell/api/cost/remove_cost_item.py | 10 ++++ 4 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_item.py diff --git a/src/blenderbim/blenderbim/bim/module/cost/__init__.py b/src/blenderbim/blenderbim/bim/module/cost/__init__.py index ce2d98dc85..7a8a31b1d3 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/cost/__init__.py @@ -8,8 +8,10 @@ classes = ( operator.EnableEditingCostSchedule, operator.DisableEditingCostSchedule, operator.AddCostItem, + operator.AddSummaryCostItem, operator.ExpandCostItem, operator.ContractCostItem, + operator.RemoveCostItem, prop.CostItem, prop.BIMCostProperties, ui.BIM_PT_cost_schedules, diff --git a/src/blenderbim/blenderbim/bim/module/cost/operator.py b/src/blenderbim/blenderbim/bim/module/cost/operator.py index afc937ea78..86e0cf03df 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/operator.py +++ b/src/blenderbim/blenderbim/bim/module/cost/operator.py @@ -120,24 +120,37 @@ class EditCostSchedule(bpy.types.Operator): return {"FINISHED"} -class AddCostItem(bpy.types.Operator): - bl_idname = "bim.add_cost_item" +class AddSummaryCostItem(bpy.types.Operator): + bl_idname = "bim.add_summary_cost_item" bl_label = "Add Cost Item" cost_schedule: bpy.props.IntProperty() def execute(self, context): props = context.scene.BIMCostProperties self.file = IfcStore.get_file() - if len(props.cost_items): - data = {"cost_item": self.file.by_id(props.cost_items[props.active_cost_item_index].ifc_definition_id)} - else: - data = {"cost_schedule": self.file.by_id(self.cost_schedule)} - ifcopenshell.api.run("cost.add_cost_item", self.file, **data) + ifcopenshell.api.run("cost.add_cost_item", self.file, **{ + "cost_schedule": self.file.by_id(self.cost_schedule) + }) Data.load(self.file) bpy.ops.bim.enable_editing_cost_schedule(cost_schedule = self.cost_schedule) return {"FINISHED"} +class AddCostItem(bpy.types.Operator): + bl_idname = "bim.add_cost_item" + bl_label = "Add Cost Item" + cost_item: bpy.props.IntProperty() + + def execute(self, context): + props = context.scene.BIMCostProperties + self.file = IfcStore.get_file() + data = {"cost_item": self.file.by_id(self.cost_item)} + ifcopenshell.api.run("cost.add_cost_item", self.file, **data) + Data.load(self.file) + bpy.ops.bim.enable_editing_cost_schedule(cost_schedule = props.active_cost_schedule_id) + return {"FINISHED"} + + class ExpandCostItem(bpy.types.Operator): bl_idname = "bim.expand_cost_item" bl_label = "Expand Cost Item" @@ -145,9 +158,11 @@ class ExpandCostItem(bpy.types.Operator): def execute(self, context): props = context.scene.BIMCostProperties + self.file = IfcStore.get_file() contracted_cost_items = json.loads(props.contracted_cost_items) contracted_cost_items.remove(self.cost_item) props.contracted_cost_items = json.dumps(contracted_cost_items) + Data.load(self.file) bpy.ops.bim.enable_editing_cost_schedule(cost_schedule = props.active_cost_schedule_id) return {"FINISHED"} @@ -159,8 +174,31 @@ class ContractCostItem(bpy.types.Operator): def execute(self, context): props = context.scene.BIMCostProperties + self.file = IfcStore.get_file() contracted_cost_items = json.loads(props.contracted_cost_items) contracted_cost_items.append(self.cost_item) props.contracted_cost_items = json.dumps(contracted_cost_items) + Data.load(self.file) + bpy.ops.bim.enable_editing_cost_schedule(cost_schedule = props.active_cost_schedule_id) + return {"FINISHED"} + + +class RemoveCostItem(bpy.types.Operator): + bl_idname = "bim.remove_cost_item" + bl_label = "Remove Cost item" + cost_item: bpy.props.IntProperty() + + def execute(self, context): + props = context.scene.BIMCostProperties + self.file = IfcStore.get_file() + ifcopenshell.api.run( + "cost.remove_cost_item", + self.file, + cost_item=IfcStore.get_file().by_id(self.cost_item), + ) + Data.load(self.file) + # contracted_cost_items = json.loads(props.contracted_cost_items) + # contracted_cost_items.remove(props.active_cost_item_index) + # props.contracted_cost_items = json.dumps(contracted_cost_items) bpy.ops.bim.enable_editing_cost_schedule(cost_schedule = props.active_cost_schedule_id) return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/cost/ui.py b/src/blenderbim/blenderbim/bim/module/cost/ui.py index abfc20074b..7c9edc329e 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/ui.py +++ b/src/blenderbim/blenderbim/bim/module/cost/ui.py @@ -51,9 +51,8 @@ class BIM_PT_cost_schedules(Panel): row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="") row = self.layout.row(align=True) - row.label(text="X Cost Items") - row.operator("bim.add_cost_item", text="", icon="ADD").cost_schedule = cost_schedule_id - + row.label(text="X Summary Cost Items") + row.operator("bim.add_summary_cost_item", text="", icon="ADD").cost_schedule = cost_schedule_id self.layout.template_list( "BIM_UL_cost_items", "", @@ -72,10 +71,12 @@ class BIM_UL_cost_items(UIList): row.label(text="", icon="BLANK1") if item.has_children: if item.is_expanded: - op = row.operator("bim.contract_cost_item", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN") + row.operator("bim.contract_cost_item", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN").cost_item = item.ifc_definition_id else: - op = row.operator("bim.expand_cost_item", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT") - op.cost_item = item.ifc_definition_id + row.operator("bim.expand_cost_item", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT").cost_item = item.ifc_definition_id else: row.label(text="", icon="DOT") row.label(text=item.name) + row.operator("bim.add_cost_item", text="", icon="ADD").cost_item = item.ifc_definition_id + op = row.operator("bim.remove_cost_item", text="", icon="X") + op.cost_item = item.ifc_definition_id diff --git a/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_item.py b/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_item.py new file mode 100644 index 0000000000..003cf31931 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_item.py @@ -0,0 +1,10 @@ +class Usecase: + def __init__(self, file, **settings): + self.file = file + self.settings = {"cost_item": 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_item"])