Implement arithmetic formulas for cost value components

This commit is contained in:
Dion Moult
2021-05-08 12:18:27 +10:00
parent 46bc688f26
commit a80fbdbc1d
8 changed files with 99 additions and 53 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ from blenderbim.bim.ifc import IfcStore
def import_attributes(ifc_class, props, data, callback=None):
for attribute in IfcStore.get_schema().declaration_by_name(ifc_class).all_attributes():
data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
if data_type == "entity":
if data_type == "entity" or (isinstance(data_type, tuple) and "entity" in ".".join(data_type)):
continue
new = props.add()
new.name = attribute.name()
@@ -7,7 +7,7 @@ classes = (
operator.EditCostSchedule,
operator.EditCostItem,
operator.EditCostItemQuantity,
operator.EditCostItemValue,
operator.EditCostValue,
operator.EnableEditingCostSchedule,
operator.EnableEditingCostItems,
operator.EnableEditingCostItem,
@@ -28,7 +28,7 @@ classes = (
operator.UnassignControl,
operator.AddCostItemQuantity,
operator.RemoveCostItemQuantity,
operator.AddCostItemValue,
operator.AddCostValue,
operator.RemoveCostItemValue,
prop.CostItem,
prop.BIMCostProperties,
@@ -423,10 +423,10 @@ class EditCostItemQuantity(bpy.types.Operator):
return {"FINISHED"}
class AddCostItemValue(bpy.types.Operator):
bl_idname = "bim.add_cost_item_value"
bl_label = "Add Cost Item Value"
cost_item: bpy.props.IntProperty()
class AddCostValue(bpy.types.Operator):
bl_idname = "bim.add_cost_value"
bl_label = "Add Cost Value"
parent: bpy.props.IntProperty()
cost_type: bpy.props.StringProperty()
cost_category: bpy.props.StringProperty()
@@ -438,9 +438,9 @@ class AddCostItemValue(bpy.types.Operator):
category = "*"
elif self.cost_type == "CATEGORY":
category = self.cost_category
value = ifcopenshell.api.run("cost.add_cost_item_value", self.file, cost_item=self.file.by_id(self.cost_item))
value = ifcopenshell.api.run("cost.add_cost_value", self.file, parent=self.file.by_id(self.parent))
ifcopenshell.api.run(
"cost.edit_cost_item_value", self.file, cost_value=value, attributes={"Category": category}
"cost.edit_cost_value", self.file, cost_value=value, attributes={"Category": category}
)
Data.load(self.file)
return {"FINISHED"}
@@ -497,8 +497,8 @@ class DisableEditingCostItemValue(bpy.types.Operator):
return {"FINISHED"}
class EditCostItemValue(bpy.types.Operator):
bl_idname = "bim.edit_cost_item_value"
class EditCostValue(bpy.types.Operator):
bl_idname = "bim.edit_cost_value"
bl_label = "Edit Cost Item Value"
cost_value: bpy.props.IntProperty()
@@ -507,7 +507,7 @@ class EditCostItemValue(bpy.types.Operator):
attributes = blenderbim.bim.helper.export_attributes(props.cost_value_attributes)
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"cost.edit_cost_item_value",
"cost.edit_cost_value",
self.file,
**{"cost_value": self.file.by_id(self.cost_value), "attributes": attributes},
)
+47 -22
View File
@@ -149,35 +149,59 @@ class BIM_PT_cost_schedules(Panel):
row.prop(self.props, "cost_types", text="")
if self.props.cost_types == "CATEGORY":
row.prop(self.props, "cost_category", text="")
op = row.operator("bim.add_cost_item_value", text="", icon="ADD")
op.cost_item = self.props.active_cost_item_id
op = row.operator("bim.add_cost_value", text="", icon="ADD")
op.parent = self.props.active_cost_item_id
op.cost_type = self.props.cost_types
if self.props.cost_types == "CATEGORY":
op.cost_category = self.props.cost_category
for cost_value_id in Data.cost_items[self.props.active_cost_item_id]["CostValues"]:
cost_value = Data.cost_values[cost_value_id]
row = self.layout.row(align=True)
row.label(text=str(cost_value["Category"]))
row.label(text=str(cost_value["AppliedValue"]))
if self.props.active_cost_item_value_id and self.props.active_cost_item_value_id == cost_value_id:
op = row.operator("bim.edit_cost_item_value", text="", icon="CHECKMARK")
op.cost_value = cost_value_id
row.operator("bim.disable_editing_cost_item_value", text="", icon="CANCEL")
elif self.props.active_cost_item_value_id:
op = row.operator("bim.remove_cost_item_value", text="", icon="X")
op.cost_value = cost_value_id
else:
op = row.operator("bim.enable_editing_cost_item_value", text="", icon="GREASEPENCIL")
op.cost_value = cost_value_id
op = row.operator("bim.remove_cost_item_value", text="", icon="X")
op.cost_value = cost_value_id
self.draw_readonly_cost_value_ui(self.layout, cost_value_id)
if self.props.active_cost_item_value_id and self.props.active_cost_item_value_id == cost_value_id:
box = self.layout.box()
self.draw_editable_cost_item_value_ui(box)
if self.props.active_cost_item_value_id:
box = self.layout.box()
self.draw_editable_cost_value_ui(box, Data.cost_values[self.props.active_cost_item_value_id])
def draw_editable_cost_item_value_ui(self, layout):
def draw_readonly_cost_value_ui(self, layout, cost_value_id):
cost_value = Data.cost_values[cost_value_id]
row = layout.row(align=True)
row.label(text=str(cost_value["Category"]), icon="DISC")
row.label(text=str(cost_value["AppliedValue"]))
if self.props.active_cost_item_value_id and self.props.active_cost_item_value_id == cost_value_id:
op = row.operator("bim.edit_cost_value", text="", icon="CHECKMARK")
op.cost_value = cost_value_id
op = row.operator("bim.add_cost_value", text="", icon="ADD")
op.parent = cost_value_id
op.cost_type = self.props.cost_types
if self.props.cost_types == "CATEGORY":
op.cost_category = self.props.cost_category
row.operator("bim.disable_editing_cost_item_value", text="", icon="CANCEL")
elif self.props.active_cost_item_value_id:
op = row.operator("bim.add_cost_value", text="", icon="ADD")
op.parent = cost_value_id
op.cost_type = self.props.cost_types
if self.props.cost_types == "CATEGORY":
op.cost_category = self.props.cost_category
op = row.operator("bim.remove_cost_item_value", text="", icon="X")
op.cost_value = cost_value_id
else:
op = row.operator("bim.enable_editing_cost_item_value", text="", icon="GREASEPENCIL")
op.cost_value = cost_value_id
op = row.operator("bim.add_cost_value", text="", icon="ADD")
op.parent = cost_value_id
op.cost_type = self.props.cost_types
if self.props.cost_types == "CATEGORY":
op.cost_category = self.props.cost_category
op = row.operator("bim.remove_cost_item_value", text="", icon="X")
op.cost_value = cost_value_id
if len(cost_value["Components"]):
box = layout.box()
for component_id in cost_value["Components"]:
self.draw_readonly_cost_value_ui(box, component_id)
def draw_editable_cost_value_ui(self, layout, cost_value):
for attribute in self.props.cost_value_attributes:
row = layout.row(align=True)
if attribute.data_type == "string":
@@ -194,6 +218,7 @@ class BIM_PT_cost_schedules(Panel):
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
class BIM_UL_cost_items(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
if item: