Feature to add multiple summary cost items and remove cost items

This commit is contained in:
bosonprojets
2021-04-15 23:08:45 +00:00
parent f4e6e924b1
commit 5f9474acb7
4 changed files with 64 additions and 13 deletions
@@ -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,
@@ -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"}
@@ -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
@@ -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"])