Assigning a product to a cost item now also assigns a quantity in one step

This commit is contained in:
Dion Moult
2021-08-11 21:22:23 +10:00
parent e21b4479b2
commit e8e12a567e
6 changed files with 34 additions and 72 deletions
@@ -36,7 +36,7 @@ classes = (
operator.SelectCostItemProducts,
operator.SelectCostScheduleProducts,
operator.ImportCostScheduleCsv,
operator.LoadCostItemProducts,
operator.LoadCostItemQuantities,
prop.CostItem,
prop.CostItemProduct,
prop.BIMCostProperties,
@@ -312,6 +312,7 @@ class AssignCostItemProduct(bpy.types.Operator):
[bpy.data.objects.get(self.related_object)] if self.related_object else context.selected_objects
)
self.file = IfcStore.get_file()
self.props = context.scene.BIMCostProperties
ifcopenshell.api.run(
"cost.assign_cost_item_product",
self.file,
@@ -321,8 +322,10 @@ class AssignCostItemProduct(bpy.types.Operator):
for o in related_objects
if o.BIMObjectProperties.ifc_definition_id
],
prop_name=self.props.quantity_names,
)
Data.load(self.file)
bpy.ops.bim.load_cost_item_quantities()
return {"FINISHED"}
@@ -331,27 +334,21 @@ class UnassignCostItemProduct(bpy.types.Operator):
bl_label = "Unassign Control"
bl_options = {"REGISTER", "UNDO"}
cost_item: bpy.props.IntProperty()
related_object: bpy.props.StringProperty()
related_object: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
related_objects = (
[bpy.data.objects.get(self.related_object)] if self.related_object else context.selected_objects
)
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"cost.unassign_cost_item_product",
self.file,
cost_item=self.file.by_id(self.cost_item),
products=[
self.file.by_id(o.BIMObjectProperties.ifc_definition_id)
for o in related_objects
if o.BIMObjectProperties.ifc_definition_id
],
products=[self.file.by_id(self.related_object)],
)
Data.load(self.file)
bpy.ops.bim.load_cost_item_quantities()
return {"FINISHED"}
@@ -396,21 +393,10 @@ class AddCostItemQuantity(bpy.types.Operator):
def _execute(self, context):
self.file = IfcStore.get_file()
self.props = context.scene.BIMCostProperties
if self.props.quantity_types == "QTO":
self.add_quantities_from_qto_filter()
else:
self.add_manual_quantity()
self.add_manual_quantity()
Data.load(self.file)
return {"FINISHED"}
def add_quantities_from_qto_filter(self):
ifcopenshell.api.run(
"cost.assign_cost_item_product_quantities",
self.file,
cost_item=self.file.by_id(self.cost_item),
prop_name=self.props.quantity_names,
)
def add_manual_quantity(self):
ifcopenshell.api.run(
"cost.add_cost_item_quantity",
@@ -704,12 +690,13 @@ class RemoveCostColumn(bpy.types.Operator):
return {"FINISHED"}
class LoadCostItemProducts(bpy.types.Operator):
bl_idname = "bim.load_cost_item_products"
bl_label = "Load Cost Item Products"
class LoadCostItemQuantities(bpy.types.Operator):
bl_idname = "bim.load_cost_item_quantities"
bl_label = "Load Cost Item Quantities"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
print('EXECUTING')
self.props = context.scene.BIMCostProperties
self.file = IfcStore.get_file()
while len(self.props.cost_item_products) > 0:
@@ -34,7 +34,7 @@ def purge():
def getQuantityTypes(self, context):
global quantitytypes_enum
if len(quantitytypes_enum) == 0 and IfcStore.get_schema():
quantitytypes_enum = [("QTO", "Qto", "Derive quantities from IFC quantity sets")]
quantitytypes_enum = []
quantitytypes_enum.extend(
[
(t.name(), t.name(), "")
@@ -69,7 +69,7 @@ def getQuantityNames(self, context):
def update_cost_item_index(self, context):
bpy.ops.bim.load_cost_item_products()
bpy.ops.bim.load_cost_item_quantities()
def updateCostItemName(self, context):
@@ -400,3 +400,4 @@ class BIM_UL_cost_item_products(UIList):
row.prop(item, "name", emboss=False, text="")
op = row.operator("bim.unassign_cost_item_product", text="", icon="X")
op.cost_item = cost_item.ifc_definition_id
op.related_object = item.ifc_definition_id
@@ -4,16 +4,12 @@ import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"cost_item": None, "products": []}
self.settings = {"cost_item": None, "products": [], "prop_name": ""}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
quantity_names = set()
for quantity in self.settings["cost_item"].CostQuantities or []:
if quantity.Name:
quantity_names.add(quantity.Name)
self.quantities = set(self.settings["cost_item"].CostQuantities or [])
for product in self.settings["products"]:
ifcopenshell.api.run(
"control.assign_control",
@@ -21,11 +17,21 @@ class Usecase:
related_object=product,
relating_control=self.settings["cost_item"],
)
self.add_quantity_from_related_object(product)
self.settings["cost_item"].CostQuantities = list(self.quantities)
for name in quantity_names:
ifcopenshell.api.run(
"cost.assign_cost_item_product_quantities",
self.file,
cost_item=self.settings["cost_item"],
prop_name=name
)
def add_quantity_from_related_object(self, element):
if element.is_a("IfcTypeObject"):
for definition in element.HasPropertySets or []:
self.add_quantity_from_qto(definition)
else:
for relationship in element.IsDefinedBy:
if relationship.is_a("IfcRelDefinesByProperties"):
self.add_quantity_from_qto(relationship.RelatingPropertyDefinition)
def add_quantity_from_qto(self, qto):
if not qto.is_a("IfcElementQuantity"):
return
for prop in qto.Quantities:
if prop.is_a("IfcPhysicalSimpleQuantity") and prop.Name.lower() == self.settings["prop_name"].lower():
self.quantities.add(prop)
@@ -1,32 +0,0 @@
import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"cost_item": None, "prop_name": ""}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
self.quantities = set(self.settings["cost_item"].CostQuantities or [])
for control in self.settings["cost_item"].Controls or []:
for related_object in control.RelatedObjects:
self.add_quantity_from_related_object(related_object)
self.settings["cost_item"].CostQuantities = list(self.quantities)
def add_quantity_from_related_object(self, element):
if element.is_a("IfcTypeObject"):
for definition in element.HasPropertySets or []:
self.add_quantity_from_qto(definition)
else:
for relationship in element.IsDefinedBy:
if relationship.is_a("IfcRelDefinesByProperties"):
self.add_quantity_from_qto(relationship.RelatingPropertyDefinition)
def add_quantity_from_qto(self, qto):
if not qto.is_a("IfcElementQuantity"):
return
for prop in qto.Quantities:
if prop.is_a("IfcPhysicalSimpleQuantity") and prop.Name.lower() == self.settings["prop_name"].lower():
self.quantities.add(prop)