From 66862a6cba2ba8bef3ae2e63a5303d7e0fc01fa7 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 13 May 2021 15:11:45 +1000 Subject: [PATCH] You can now copy cost values from one cost item to another --- .../blenderbim/bim/module/cost/__init__.py | 1 + .../blenderbim/bim/module/cost/operator.py | 23 +++++++++++++++---- .../blenderbim/bim/module/cost/ui.py | 7 +++++- .../api/cost/copy_cost_item_values.py | 17 ++++++++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 src/ifcopenshell-python/ifcopenshell/api/cost/copy_cost_item_values.py diff --git a/src/blenderbim/blenderbim/bim/module/cost/__init__.py b/src/blenderbim/blenderbim/bim/module/cost/__init__.py index 2368b1b783..d4c599e68c 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/cost/__init__.py @@ -30,6 +30,7 @@ classes = ( operator.RemoveCostItemQuantity, operator.AddCostValue, operator.RemoveCostItemValue, + operator.CopyCostItemValues, 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 9348d4d90e..93491d6535 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/operator.py +++ b/src/blenderbim/blenderbim/bim/module/cost/operator.py @@ -458,11 +458,7 @@ class RemoveCostItemValue(bpy.types.Operator): def execute(self, context): self.file = IfcStore.get_file() - ifcopenshell.api.run( - "cost.remove_cost_item_value", - self.file, - cost_value=self.file.by_id(self.cost_value), - ) + ifcopenshell.api.run("cost.remove_cost_item_value", self.file, cost_value=self.file.by_id(self.cost_value)) Data.load(self.file) return {"FINISHED"} @@ -519,3 +515,20 @@ class EditCostValue(bpy.types.Operator): Data.load(IfcStore.get_file()) bpy.ops.bim.disable_editing_cost_item_value() return {"FINISHED"} + + +class CopyCostItemValues(bpy.types.Operator): + bl_idname = "bim.copy_cost_item_values" + bl_label = "Copy Cost Item Values" + source: bpy.props.IntProperty() + destination: bpy.props.IntProperty() + + def execute(self, context): + self.file = IfcStore.get_file() + ifcopenshell.api.run( + "cost.copy_cost_item_values", + self.file, + **{"source": self.file.by_id(self.source), "destination": self.file.by_id(self.destination)}, + ) + 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 index e02226edfa..545edc91f5 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/ui.py +++ b/src/blenderbim/blenderbim/bim/module/cost/ui.py @@ -260,9 +260,14 @@ class BIM_UL_cost_items(UIList): op.cost_item = item.ifc_definition_id if props.active_cost_item_id == item.ifc_definition_id: - row.operator("bim.edit_cost_item", text="", icon="CHECKMARK") + if props.cost_item_editing_type == "ATTRIBUTES": + row.operator("bim.edit_cost_item", text="", icon="CHECKMARK") row.operator("bim.disable_editing_cost_item", text="", icon="CANCEL") elif props.active_cost_item_id: + if props.cost_item_editing_type == "VALUES": + op = row.operator("bim.copy_cost_item_values", text="", icon="COPYDOWN") + op.source = props.active_cost_item_id + op.destination = item.ifc_definition_id row.operator("bim.add_cost_item", text="", icon="ADD").cost_item = item.ifc_definition_id row.operator("bim.remove_cost_item", text="", icon="X").cost_item = item.ifc_definition_id else: diff --git a/src/ifcopenshell-python/ifcopenshell/api/cost/copy_cost_item_values.py b/src/ifcopenshell-python/ifcopenshell/api/cost/copy_cost_item_values.py new file mode 100644 index 0000000000..918a71763d --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/cost/copy_cost_item_values.py @@ -0,0 +1,17 @@ +import ifcopenshell.util.element + + +class Usecase: + def __init__(self, file, **settings): + self.file = file + self.settings = {"source": None, "destination": None} + for key, value in settings.items(): + self.settings[key] = value + + def execute(self): + for cost_value in self.settings["destination"].CostValues or []: + ifcopenshell.api.run("cost.remove_cost_item_value", self.file, cost_value=cost_value) + copied_cost_values = [] + for cost_value in self.settings["source"].CostValues or []: + copied_cost_values.append(ifcopenshell.util.element.copy_deep(self.file, cost_value)) + self.settings["destination"].CostValues = copied_cost_values