mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
Purge calculate quantities operator - to be replaced with new ifc5d qto tool
The calculate quantities operator assumes a single mapper, not a configurable calculator.
This commit is contained in:
@@ -27,7 +27,6 @@ classes = (
|
||||
operator.DisablePsetEditing,
|
||||
operator.EditPset,
|
||||
operator.EnablePsetEditing,
|
||||
operator.CalculateQuantity,
|
||||
operator.RemovePset,
|
||||
operator.TogglePsetExpansion,
|
||||
operator.BIM_OT_add_property_to_edit,
|
||||
|
||||
@@ -214,33 +214,6 @@ class AddQto(bpy.types.Operator, Operator):
|
||||
)
|
||||
|
||||
|
||||
class CalculateQuantity(bpy.types.Operator):
|
||||
bl_idname = "bim.calculate_quantity"
|
||||
bl_label = "Calculate Quantity"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
bl_description = "Calculates the quantity with a defined formula for this exact entity and quantity"
|
||||
prop: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
self.qto_calculator = QtoCalculator()
|
||||
obj = context.active_object
|
||||
prop = obj.PsetProperties.properties.get(self.prop)
|
||||
quantity = self.calculate_quantity(obj, context)
|
||||
|
||||
if quantity is None:
|
||||
self.report({"ERROR"}, "Could not calculate quantity")
|
||||
return {"CANCELLED"}
|
||||
|
||||
prop.metadata.float_value = quantity
|
||||
return {"FINISHED"}
|
||||
|
||||
def calculate_quantity(self, obj, context):
|
||||
quantity = self.qto_calculator.calculate_quantity(obj.PsetProperties.active_pset_name, self.prop, obj)
|
||||
if quantity is None:
|
||||
return
|
||||
return round(quantity, 3)
|
||||
|
||||
|
||||
class CopyPropertyToSelection(bpy.types.Operator, Operator):
|
||||
bl_idname = "bim.copy_property_to_selection"
|
||||
bl_label = "Copy Property To Selection"
|
||||
|
||||
@@ -53,19 +53,6 @@ class QtoCalculator:
|
||||
else:
|
||||
self.mapping_dict[key][item] = None
|
||||
|
||||
def calculate_quantity(self, qto_name: str, quantity_name: str, obj: bpy.types.Object) -> float:
|
||||
"""calculates the value of the quantity in the project units"""
|
||||
string = "self.mapping_dict[qto_name][quantity_name](obj"
|
||||
if isinstance(mapper[qto_name][quantity_name], dict):
|
||||
args = mapper[qto_name][quantity_name]["args"]
|
||||
else:
|
||||
args = ""
|
||||
string += args
|
||||
string += ")"
|
||||
value: float = eval(string)
|
||||
|
||||
return tool.Qto.convert_to_project_units(value, qto_name, quantity_name) or value
|
||||
|
||||
def get_units(self, o: bpy.types.Object, vg_index: int) -> int:
|
||||
return len([v for v in o.data.vertices if vg_index in [g.group for g in v.groups]])
|
||||
|
||||
|
||||
@@ -160,9 +160,6 @@ def draw_psetqto_ui(context, pset_id, pset, props, layout, obj_type, allow_remov
|
||||
def draw_psetqto_editable_ui(box, props, prop):
|
||||
row = box.row(align=True)
|
||||
draw_property(prop, row, copy_operator="bim.copy_property_to_selection")
|
||||
if prop.metadata.has_calculator:
|
||||
op = row.operator("bim.calculate_quantity", icon="MOD_EDGESPLIT", text="")
|
||||
op.prop = prop.name
|
||||
|
||||
|
||||
class BIM_PT_object_psets(Panel):
|
||||
|
||||
@@ -21,7 +21,6 @@ from . import ui, prop, operator
|
||||
|
||||
classes = (
|
||||
operator.AssignBaseQto,
|
||||
operator.CalculateAllQuantities,
|
||||
operator.CalculateCircleRadius,
|
||||
operator.CalculateEdgeLengths,
|
||||
operator.CalculateFaceAreas,
|
||||
|
||||
@@ -186,23 +186,6 @@ class AssignBaseQto(bpy.types.Operator, tool.Ifc.Operator):
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class CalculateAllQuantities(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.calculate_all_quantities"
|
||||
bl_label = "Calculate All Quantities"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
bl_description = "Calculate all possible quantities and assign them to selected object"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return tool.Ifc.get() and context.selected_objects
|
||||
|
||||
def _execute(self, context):
|
||||
core.calculate_all_quantities(
|
||||
tool.Ifc, tool.Cost, tool.Qto, QtoCalculator(), selected_objects=context.selected_objects
|
||||
)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class PerformQuantityTakeOff(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.perform_quantity_take_off"
|
||||
bl_label = "Perform Quantity Take-off"
|
||||
|
||||
@@ -263,7 +263,6 @@ class Attribute(PropertyGroup):
|
||||
is_optional: BoolProperty(name="Is Optional")
|
||||
is_uri: BoolProperty(name="Is Uri", default=False)
|
||||
is_selected: BoolProperty(name="Is Selected", default=False)
|
||||
has_calculator: BoolProperty(name="Has Calculator", default=False)
|
||||
value_min: FloatProperty(description="This is used to validate int_value and float_value")
|
||||
value_min_constraint: BoolProperty(default=False, description="True if the numerical value has a lower bound")
|
||||
value_max: FloatProperty(description="This is used to validate int_value and float_value")
|
||||
|
||||
@@ -49,33 +49,3 @@ def assign_object_base_qto(ifc: tool.Ifc, qto: tool.Qto, obj: bpy.types.Object)
|
||||
product=product,
|
||||
name=base_quantity_name,
|
||||
)
|
||||
|
||||
|
||||
def calculate_all_quantities(
|
||||
ifc: tool.Ifc, cost: tool.Cost, qto: tool.Qto, calculator: QtoCalculator, selected_objects: list[bpy.types.Object]
|
||||
) -> None:
|
||||
if selected_objects:
|
||||
for obj in selected_objects:
|
||||
calculate_object_base_quantities(ifc, cost, qto, calculator, obj)
|
||||
|
||||
|
||||
def calculate_object_base_quantities(
|
||||
ifc: tool.Ifc, cost: tool.Cost, qto: tool.Qto, calculator: QtoCalculator, obj: bpy.types.Object
|
||||
) -> None:
|
||||
product = ifc.get_entity(obj)
|
||||
if not product:
|
||||
return
|
||||
base_quantity_name = qto.get_applicable_base_quantity_name(product)
|
||||
if not base_quantity_name:
|
||||
print(f"There is no base quantity")
|
||||
return
|
||||
base_qto = qto.get_base_qto(product)
|
||||
if not base_qto:
|
||||
base_qto = ifc.run(
|
||||
"pset.add_qto",
|
||||
product=product,
|
||||
name=base_quantity_name,
|
||||
)
|
||||
calculated_quantities = qto.get_calculated_object_quantities(calculator, base_quantity_name, obj)
|
||||
ifc.run("pset.edit_qto", qto=base_qto, properties=calculated_quantities)
|
||||
cost.update_cost_items(product=product)
|
||||
|
||||
@@ -640,8 +640,6 @@ class Qto:
|
||||
def add_product_base_qto(cls, product): pass
|
||||
def get_applicable_base_quantity_name(cls, product): pass
|
||||
def get_applicable_quantity_names(cls, qto_name): pass
|
||||
def get_calculated_object_quantities(cls, calculator, baste_qto, object): pass
|
||||
def get_new_calculated_quantity(cls, qto_name, quantity_name, object): pass
|
||||
def get_radius_of_selected_vertices(cls, obj): pass
|
||||
def get_related_cost_item_quantities(cls, product): pass
|
||||
def get_rounded_value(cls, new_quantity): pass
|
||||
|
||||
@@ -177,7 +177,6 @@ class Pset(blenderbim.core.tool.Pset):
|
||||
metadata.is_null = data.get(prop_template.Name, None) is None
|
||||
metadata.is_optional = True
|
||||
metadata.is_uri = prop_template.PrimaryMeasureType == "IfcURIReference"
|
||||
metadata.has_calculator = bool(mapper.get(pset_template.Name, {}).get(prop_template.Name, None))
|
||||
metadata.data_type = cls.get_prop_template_primitive_type(prop_template)
|
||||
|
||||
special_type = ""
|
||||
|
||||
@@ -91,29 +91,10 @@ class Qto(blenderbim.core.tool.Qto):
|
||||
applicable_qto = qto_name
|
||||
return applicable_qto
|
||||
|
||||
@classmethod
|
||||
def get_new_calculated_quantity(cls, qto_name: str, quantity_name: str, obj: bpy.types.Object) -> float:
|
||||
return QtoCalculator().calculate_quantity(qto_name, quantity_name, obj)
|
||||
|
||||
@classmethod
|
||||
def get_rounded_value(cls, new_quantity: float) -> float:
|
||||
return round(new_quantity, 3)
|
||||
|
||||
@classmethod
|
||||
def get_calculated_object_quantities(
|
||||
cls, calculator: QtoCalculator, qto_name: str, obj: bpy.types.Object
|
||||
) -> dict[str, float]:
|
||||
return {
|
||||
quantity_name: cls.get_rounded_value(value)
|
||||
for quantity_name in cls.get_applicable_quantity_names(qto_name) or []
|
||||
if cls.has_calculator(qto_name, quantity_name)
|
||||
and (value := calculator.calculate_quantity(qto_name, quantity_name, obj)) is not None
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def has_calculator(cls, qto_name: str, quantity_name: str) -> bool:
|
||||
return bool(mapper.get(qto_name, {}).get(quantity_name, None))
|
||||
|
||||
@classmethod
|
||||
def convert_to_project_units(
|
||||
cls,
|
||||
|
||||
Reference in New Issue
Block a user