diff --git a/src/blenderbim/blenderbim/bim/module/cost/__init__.py b/src/blenderbim/blenderbim/bim/module/cost/__init__.py index d279ad317c..1d8e59c6fe 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/cost/__init__.py @@ -82,6 +82,7 @@ classes = ( prop.CostItem, prop.CostItemQuantity, prop.CostItemType, + prop.ScheduleColumn, prop.BIMCostProperties, ui.BIM_PT_cost_schedules, ui.BIM_PT_cost_item_quantities, diff --git a/src/blenderbim/blenderbim/bim/module/cost/operator.py b/src/blenderbim/blenderbim/bim/module/cost/operator.py index df1e52523d..3b384cf60c 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/operator.py +++ b/src/blenderbim/blenderbim/bim/module/cost/operator.py @@ -73,7 +73,7 @@ class RemoveCostSchedule(bpy.types.Operator, tool.Ifc.Operator): cost_schedule: bpy.props.IntProperty() def _execute(self, context): - core.remove_cost_schedule(tool.Ifc, cost_schedule=tool.Ifc.get().by_id(self.cost_schedule)) + core.remove_cost_schedule(tool.Ifc, tool.Cost, cost_schedule=tool.Ifc.get().by_id(self.cost_schedule)) class EnableEditingCostSchedule(bpy.types.Operator): diff --git a/src/blenderbim/blenderbim/bim/module/cost/prop.py b/src/blenderbim/blenderbim/bim/module/cost/prop.py index 370b58d9b7..d35cad5446 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/prop.py +++ b/src/blenderbim/blenderbim/bim/module/cost/prop.py @@ -175,6 +175,10 @@ def update_active_cost_item_resources(self, context): bpy.ops.bim.load_cost_item_resource_quantities() +class ScheduleColumn(PropertyGroup): + schedule_id: IntProperty() + + class BIMCostProperties(PropertyGroup): cost_schedule_predefined_types: EnumProperty( items=get_schedule_predefined_types, name="Predefined Type", default=None @@ -216,7 +220,8 @@ class BIMCostProperties(PropertyGroup): default=False, ) should_show_currency_ui: BoolProperty(name="Should Show Currency UI", default=False) - columns: CollectionProperty(name="Columns", type=StrProperty) + columns: CollectionProperty(name="Active Schedule Columns", type=StrProperty) + columns_storage: CollectionProperty(name="Columns", type=ScheduleColumn) active_column_index: IntProperty(name="Active Column Index") cost_item_products: CollectionProperty(name="Cost Item Products", type=CostItemQuantity) active_cost_item_product_index: IntProperty(name="Active Cost Item Product Index") diff --git a/src/blenderbim/blenderbim/core/cost.py b/src/blenderbim/blenderbim/core/cost.py index 9d4c4048f1..f95f70a3b8 100644 --- a/src/blenderbim/blenderbim/core/cost.py +++ b/src/blenderbim/blenderbim/core/cost.py @@ -39,8 +39,9 @@ def disable_editing_cost_schedule(cost: tool.Cost): cost.disable_editing_cost_schedule() -def remove_cost_schedule(ifc: tool.Ifc, cost_schedule: ifcopenshell.entity_instance): +def remove_cost_schedule(ifc: tool.Ifc, cost: tool.Cost, cost_schedule: ifcopenshell.entity_instance) -> None: ifc.run("cost.remove_cost_schedule", cost_schedule=cost_schedule) + cost.remove_stored_schedule_columns(cost_schedule) def enable_editing_cost_schedule_attributes(cost: tool.Cost, cost_schedule: ifcopenshell.entity_instance): @@ -50,6 +51,7 @@ def enable_editing_cost_schedule_attributes(cost: tool.Cost, cost_schedule: ifco def enable_editing_cost_items(cost: tool.Cost, cost_schedule: ifcopenshell.entity_instance): cost.enable_editing_cost_items(cost_schedule) + cost.load_active_schedule_columns() cost.load_cost_schedule_tree() cost.play_sound() diff --git a/src/blenderbim/blenderbim/tool/cost.py b/src/blenderbim/blenderbim/tool/cost.py index 527eadf7dc..9fb849e5c2 100644 --- a/src/blenderbim/blenderbim/tool/cost.py +++ b/src/blenderbim/blenderbim/tool/cost.py @@ -19,9 +19,59 @@ class Cost(blenderbim.core.tool.Cost): @classmethod def disable_editing_cost_schedule(cls): + cls.store_active_schedule_columns() bpy.context.scene.BIMCostProperties.active_cost_schedule_id = 0 cls.disable_editing_cost_item() + @classmethod + def load_active_schedule_columns(cls) -> None: + props = bpy.context.scene.BIMCostProperties + active_columns = props.columns + storage = props.columns_storage + active_cost_schedule_id = cls.get_active_cost_schedule().id() + + # store column names to keep the original order + cols_to_add = [] + + # collection property only support removal by index + for storage_col_i, storage_col in reversed(list(enumerate(storage[:]))): + if storage_col.schedule_id != active_cost_schedule_id: + continue + cols_to_add.insert(0, storage_col.name) + # We don't store active schedule columns in storage + # so it will be easy to edit them. + storage.remove(storage_col_i) + + for col_name in cols_to_add: + col = active_columns.add() + col.name = col_name + + @classmethod + def store_active_schedule_columns(cls) -> None: + props = bpy.context.scene.BIMCostProperties + active_columns = props.columns + storage = props.columns_storage + active_cost_schedule_id = cls.get_active_cost_schedule().id() + + for col in active_columns: + storage_col = storage.add() + storage_col.name = col.name + storage_col.schedule_id = active_cost_schedule_id + + props.columns.clear() + + @classmethod + def remove_stored_schedule_columns(cls, cost_schedule: ifcopenshell.entity_instance) -> None: + props = bpy.context.scene.BIMCostProperties + storage = props.columns_storage + active_cost_schedule_id = cost_schedule.id() + + # collection property only support removal by index + for storage_col_i, storage_col in reversed(list(enumerate(storage[:]))): + if storage_col.schedule_id != active_cost_schedule_id: + continue + storage.remove(storage_col_i) + @classmethod def enable_editing_cost_schedule_attributes(cls, cost_schedule): bpy.context.scene.BIMCostProperties.active_cost_schedule_id = cost_schedule.id()