diff --git a/src/blenderbim/blenderbim/bim/module/cost/__init__.py b/src/blenderbim/blenderbim/bim/module/cost/__init__.py index d8cd9ada2d..ce2d98dc85 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/cost/__init__.py @@ -8,6 +8,8 @@ classes = ( operator.EnableEditingCostSchedule, operator.DisableEditingCostSchedule, operator.AddCostItem, + operator.ExpandCostItem, + operator.ContractCostItem, 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 bd17d2b79b..afc937ea78 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/operator.py +++ b/src/blenderbim/blenderbim/bim/module/cost/operator.py @@ -65,6 +65,7 @@ class EnableEditingCostSchedule(bpy.types.Operator): while len(self.props.cost_items) > 0: self.props.cost_items.remove(0) + self.contracted_cost_items = json.loads(self.props.contracted_cost_items) for related_object_id in Data.cost_schedules[self.cost_schedule]["RelatedObjects"]: self.create_new_cost_item_li(related_object_id, 0) return {"FINISHED"} @@ -74,12 +75,13 @@ class EnableEditingCostSchedule(bpy.types.Operator): new = self.props.cost_items.add() new.name = cost_item["Name"] or "Unnamed" new.ifc_definition_id = related_object_id - new.is_expanded = False + new.is_expanded = related_object_id not in self.contracted_cost_items new.level_index = level_index if cost_item["RelatedObjects"]: new.has_children = True - for related_object_id in cost_item["RelatedObjects"]: - self.create_new_cost_item_li(related_object_id, level_index + 1) + if new.is_expanded: + for related_object_id in cost_item["RelatedObjects"]: + self.create_new_cost_item_li(related_object_id, level_index + 1) class DisableEditingCostSchedule(bpy.types.Operator): @@ -134,3 +136,31 @@ class AddCostItem(bpy.types.Operator): Data.load(self.file) bpy.ops.bim.enable_editing_cost_schedule(cost_schedule = self.cost_schedule) return {"FINISHED"} + + +class ExpandCostItem(bpy.types.Operator): + bl_idname = "bim.expand_cost_item" + bl_label = "Expand Cost Item" + cost_item: bpy.props.IntProperty() + + def execute(self, context): + props = context.scene.BIMCostProperties + 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) + bpy.ops.bim.enable_editing_cost_schedule(cost_schedule = props.active_cost_schedule_id) + return {"FINISHED"} + + +class ContractCostItem(bpy.types.Operator): + bl_idname = "bim.contract_cost_item" + bl_label = "Contract Cost Item" + cost_item: bpy.props.IntProperty() + + def execute(self, context): + props = context.scene.BIMCostProperties + 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) + 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/prop.py b/src/blenderbim/blenderbim/bim/module/cost/prop.py index 7cc928c95e..b2d2f26832 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/prop.py +++ b/src/blenderbim/blenderbim/bim/module/cost/prop.py @@ -26,3 +26,4 @@ class BIMCostProperties(PropertyGroup): active_cost_schedule_id: IntProperty(name="Active Cost Schedule Id") cost_items: CollectionProperty(name="Work Calendar", type=CostItem) active_cost_item_index: IntProperty(name="Active Cost Item Index") + contracted_cost_items: StringProperty(name="Contracted Cost Items", default="[]") diff --git a/src/blenderbim/blenderbim/bim/module/cost/ui.py b/src/blenderbim/blenderbim/bim/module/cost/ui.py index 655fee9994..abfc20074b 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/ui.py +++ b/src/blenderbim/blenderbim/bim/module/cost/ui.py @@ -72,9 +72,10 @@ class BIM_UL_cost_items(UIList): row.label(text="", icon="BLANK1") if item.has_children: if item.is_expanded: - row.operator("bim.edit_work_calendar", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN") + op = row.operator("bim.contract_cost_item", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN") else: - row.operator("bim.edit_work_calendar", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT") + op = row.operator("bim.expand_cost_item", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT") + op.cost_item = item.ifc_definition_id else: row.label(text="", icon="DOT") row.label(text=item.name)