mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 09:32:37 +00:00
Feature to add multiple summary cost items and remove cost items
This commit is contained in:
@@ -8,8 +8,10 @@ classes = (
|
|||||||
operator.EnableEditingCostSchedule,
|
operator.EnableEditingCostSchedule,
|
||||||
operator.DisableEditingCostSchedule,
|
operator.DisableEditingCostSchedule,
|
||||||
operator.AddCostItem,
|
operator.AddCostItem,
|
||||||
|
operator.AddSummaryCostItem,
|
||||||
operator.ExpandCostItem,
|
operator.ExpandCostItem,
|
||||||
operator.ContractCostItem,
|
operator.ContractCostItem,
|
||||||
|
operator.RemoveCostItem,
|
||||||
prop.CostItem,
|
prop.CostItem,
|
||||||
prop.BIMCostProperties,
|
prop.BIMCostProperties,
|
||||||
ui.BIM_PT_cost_schedules,
|
ui.BIM_PT_cost_schedules,
|
||||||
|
|||||||
@@ -120,24 +120,37 @@ class EditCostSchedule(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class AddCostItem(bpy.types.Operator):
|
class AddSummaryCostItem(bpy.types.Operator):
|
||||||
bl_idname = "bim.add_cost_item"
|
bl_idname = "bim.add_summary_cost_item"
|
||||||
bl_label = "Add Cost Item"
|
bl_label = "Add Cost Item"
|
||||||
cost_schedule: bpy.props.IntProperty()
|
cost_schedule: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
props = context.scene.BIMCostProperties
|
props = context.scene.BIMCostProperties
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
if len(props.cost_items):
|
ifcopenshell.api.run("cost.add_cost_item", self.file, **{
|
||||||
data = {"cost_item": self.file.by_id(props.cost_items[props.active_cost_item_index].ifc_definition_id)}
|
"cost_schedule": self.file.by_id(self.cost_schedule)
|
||||||
else:
|
})
|
||||||
data = {"cost_schedule": self.file.by_id(self.cost_schedule)}
|
|
||||||
ifcopenshell.api.run("cost.add_cost_item", self.file, **data)
|
|
||||||
Data.load(self.file)
|
Data.load(self.file)
|
||||||
bpy.ops.bim.enable_editing_cost_schedule(cost_schedule = self.cost_schedule)
|
bpy.ops.bim.enable_editing_cost_schedule(cost_schedule = self.cost_schedule)
|
||||||
return {"FINISHED"}
|
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):
|
class ExpandCostItem(bpy.types.Operator):
|
||||||
bl_idname = "bim.expand_cost_item"
|
bl_idname = "bim.expand_cost_item"
|
||||||
bl_label = "Expand Cost Item"
|
bl_label = "Expand Cost Item"
|
||||||
@@ -145,9 +158,11 @@ class ExpandCostItem(bpy.types.Operator):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
props = context.scene.BIMCostProperties
|
props = context.scene.BIMCostProperties
|
||||||
|
self.file = IfcStore.get_file()
|
||||||
contracted_cost_items = json.loads(props.contracted_cost_items)
|
contracted_cost_items = json.loads(props.contracted_cost_items)
|
||||||
contracted_cost_items.remove(self.cost_item)
|
contracted_cost_items.remove(self.cost_item)
|
||||||
props.contracted_cost_items = json.dumps(contracted_cost_items)
|
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)
|
bpy.ops.bim.enable_editing_cost_schedule(cost_schedule = props.active_cost_schedule_id)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
@@ -159,8 +174,31 @@ class ContractCostItem(bpy.types.Operator):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
props = context.scene.BIMCostProperties
|
props = context.scene.BIMCostProperties
|
||||||
|
self.file = IfcStore.get_file()
|
||||||
contracted_cost_items = json.loads(props.contracted_cost_items)
|
contracted_cost_items = json.loads(props.contracted_cost_items)
|
||||||
contracted_cost_items.append(self.cost_item)
|
contracted_cost_items.append(self.cost_item)
|
||||||
props.contracted_cost_items = json.dumps(contracted_cost_items)
|
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)
|
bpy.ops.bim.enable_editing_cost_schedule(cost_schedule = props.active_cost_schedule_id)
|
||||||
return {"FINISHED"}
|
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.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
||||||
|
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
row.label(text="X Cost Items")
|
row.label(text="X Summary Cost Items")
|
||||||
row.operator("bim.add_cost_item", text="", icon="ADD").cost_schedule = cost_schedule_id
|
row.operator("bim.add_summary_cost_item", text="", icon="ADD").cost_schedule = cost_schedule_id
|
||||||
|
|
||||||
self.layout.template_list(
|
self.layout.template_list(
|
||||||
"BIM_UL_cost_items",
|
"BIM_UL_cost_items",
|
||||||
"",
|
"",
|
||||||
@@ -72,10 +71,12 @@ class BIM_UL_cost_items(UIList):
|
|||||||
row.label(text="", icon="BLANK1")
|
row.label(text="", icon="BLANK1")
|
||||||
if item.has_children:
|
if item.has_children:
|
||||||
if item.is_expanded:
|
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:
|
else:
|
||||||
op = row.operator("bim.expand_cost_item", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT")
|
row.operator("bim.expand_cost_item", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT").cost_item = item.ifc_definition_id
|
||||||
op.cost_item = item.ifc_definition_id
|
|
||||||
else:
|
else:
|
||||||
row.label(text="", icon="DOT")
|
row.label(text="", icon="DOT")
|
||||||
row.label(text=item.name)
|
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"])
|
||||||
Reference in New Issue
Block a user