mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 08:18:37 +00:00
Add calculate all qtos button: initial fixing (#2456)
This commit is contained in:
@@ -172,7 +172,7 @@ class QuantifyObjects(bpy.types.Operator):
|
|||||||
PsetData.load(self.file, obj.BIMObjectProperties.ifc_definition_id)
|
PsetData.load(self.file, obj.BIMObjectProperties.ifc_definition_id)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
class AssignPsetQto(bpy.types.Operator):
|
class AssignPsetQto(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
bl_idname = "bim.assign_pset_qto"
|
bl_idname = "bim.assign_pset_qto"
|
||||||
bl_label = "Assign Pset Qto"
|
bl_label = "Assign Pset Qto"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
@@ -182,11 +182,11 @@ class AssignPsetQto(bpy.types.Operator):
|
|||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
return context.active_object and context.selected_objects
|
return context.active_object and context.selected_objects
|
||||||
|
|
||||||
def execute(self, context):
|
def _execute(self, context):
|
||||||
core.assign_pset_qto(tool.Qto, selected_objects = context.selected_objects)
|
core.assign_pset_qto(tool.Qto, selected_objects = context.selected_objects)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
class CalculateAllQtos(bpy.types.Operator):
|
class CalculateAllQtos(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
bl_idname = "bim.calculate_all_qtos"
|
bl_idname = "bim.calculate_all_qtos"
|
||||||
bl_label = "Calculate All Qtos"
|
bl_label = "Calculate All Qtos"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
@@ -196,6 +196,6 @@ class CalculateAllQtos(bpy.types.Operator):
|
|||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
return context.active_object and context.selected_objects
|
return context.active_object and context.selected_objects
|
||||||
|
|
||||||
def execute(self, context):
|
def _execute(self, context):
|
||||||
core.calculate_all_qtos(tool.Qto, selected_objects = context.selected_objects)
|
core.calculate_all_qtos(tool.Qto, selected_objects = context.selected_objects)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -23,20 +23,17 @@ def calculate_circle_radius(qto, obj=None):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def assign_pset_qto(qto, selected_objects):
|
def assign_pset_qto(qto, selected_objects):
|
||||||
for object in selected_objects:
|
for obj in selected_objects:
|
||||||
qto.set_active_object(object)
|
qto.assign_pset_qto_to_selected_object(obj)
|
||||||
qto.assign_pset_qto_to_selected_object(object)
|
|
||||||
|
|
||||||
def calculate_all_qtos(qto, selected_objects):
|
def calculate_all_qtos(qto, selected_objects):
|
||||||
for object in selected_objects:
|
for obj in selected_objects:
|
||||||
qto.set_active_object(object)
|
if not qto.get_pset_qto_object_ifc_info(obj):
|
||||||
|
print(f"There is no pset qto instance associated to object {obj.name}")
|
||||||
if not qto.get_pset_qto_object_ifc_info(object):
|
|
||||||
print("There is no pset qto instance associated to object " + object.name)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
pset_qto_properties = qto.get_pset_qto_properties(object)
|
pset_qto_properties = qto.get_pset_qto_properties(obj)
|
||||||
|
|
||||||
calculated_quantities = qto.get_calculated_quantities(object, pset_qto_properties)
|
calculated_quantities = qto.get_calculated_quantities(obj, pset_qto_properties)
|
||||||
|
|
||||||
qto.edit_qto(object, calculated_quantities)
|
qto.edit_qto(obj, calculated_quantities)
|
||||||
|
|||||||
@@ -42,47 +42,43 @@ class Qto(blenderbim.core.tool.Qto):
|
|||||||
bpy.context.scene.BIMQtoProperties.qto_result = str(round(result, 3))
|
bpy.context.scene.BIMQtoProperties.qto_result = str(round(result, 3))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_active_object(cls, object):
|
def get_pset_qto_object_ifc_info(cls, obj):
|
||||||
bpy.context.view_layer.objects.active = object
|
element = tool.Ifc.get_entity(obj)
|
||||||
|
pset_qto_ifc_info = ifcopenshell.util.element.get_psets(element, qtos_only = True)
|
||||||
|
return pset_qto_ifc_info
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_pset_qto_object_ifc_info(cls, object):
|
def get_pset_qto_properties(cls, obj):
|
||||||
element = tool.Ifc.get_entity(object)
|
|
||||||
pset_qto_ifc_instance = ifcopenshell.util.element.get_psets(element, qtos_only = True)
|
|
||||||
return pset_qto_ifc_instance
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_pset_qto_properties(cls, object):
|
|
||||||
file = tool.Ifc.get()
|
file = tool.Ifc.get()
|
||||||
schema = file.schema
|
schema = file.schema
|
||||||
pset_qto = util.pset.PsetQto(schema)
|
pset_qto = util.pset.PsetQto(schema)
|
||||||
pset_qto_name = cls.get_pset_qto_name(object)
|
pset_qto_name = cls.get_pset_qto_name(obj)
|
||||||
pset_qto_properties = pset_qto.get_by_name(pset_qto_name).get_info()['HasPropertyTemplates']
|
pset_qto_properties = pset_qto.get_by_name(pset_qto_name).get_info()['HasPropertyTemplates']
|
||||||
return pset_qto_properties
|
return pset_qto_properties
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_pset_qto_name(cls, object):
|
def get_pset_qto_name(cls, obj):
|
||||||
applicable_pset_names = cls.get_applicable_pset_names(object)
|
applicable_pset_names = cls.get_applicable_pset_names(obj)
|
||||||
for applicable_pset_name in applicable_pset_names:
|
for applicable_pset_name in applicable_pset_names:
|
||||||
if 'Qto_' in applicable_pset_name:
|
if 'Qto_' in applicable_pset_name:
|
||||||
pset_qto_name = applicable_pset_name
|
pset_qto_name = applicable_pset_name
|
||||||
return pset_qto_name
|
return pset_qto_name
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_applicable_pset_names(cls, object):
|
def get_applicable_pset_names(cls, obj):
|
||||||
file = tool.Ifc.get()
|
file = tool.Ifc.get()
|
||||||
schema = file.schema
|
schema = file.schema
|
||||||
pset_qto = util.pset.PsetQto(schema)
|
pset_qto = util.pset.PsetQto(schema)
|
||||||
entity = tool.Ifc.get_entity(object)
|
entity = tool.Ifc.get_entity(obj)
|
||||||
ifc_object_type = entity.get_info()['type']
|
ifc_object_type = entity.get_info()['type']
|
||||||
applicable_pset_names = pset_qto.get_applicable_names(ifc_object_type)
|
applicable_pset_names = pset_qto.get_applicable_names(ifc_object_type)
|
||||||
return applicable_pset_names
|
return applicable_pset_names
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def edit_qto(cls, object, calculated_quantities):
|
def edit_qto(cls, obj, calculated_quantities):
|
||||||
file = tool.Ifc.get()
|
file = tool.Ifc.get()
|
||||||
pset_qto_id = cls.get_pset_qto_id(object)
|
pset_qto_id = cls.get_pset_qto_id(obj)
|
||||||
pset_qto_name = cls.get_pset_qto_name(object)
|
pset_qto_name = cls.get_pset_qto_name(obj)
|
||||||
|
|
||||||
ifcopenshell.api.run("pset.edit_qto",
|
ifcopenshell.api.run("pset.edit_qto",
|
||||||
file,
|
file,
|
||||||
@@ -90,46 +86,42 @@ class Qto(blenderbim.core.tool.Qto):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_pset_qto_id(cls, object):
|
def get_pset_qto_id(cls, obj):
|
||||||
file = tool.Ifc.get()
|
file = tool.Ifc.get()
|
||||||
pset_qto_name = cls.get_pset_qto_name(object)
|
pset_qto_name = cls.get_pset_qto_name(obj)
|
||||||
pset_qto_object_ifc_instance = cls.get_pset_qto_object_ifc_info(object)
|
pset_qto_object_ifc_info = cls.get_pset_qto_object_ifc_info(obj)
|
||||||
pset_qto_id = file.by_id(pset_qto_object_ifc_instance[pset_qto_name]['id'])
|
pset_qto_id = file.by_id(pset_qto_object_ifc_info[pset_qto_name]['id'])
|
||||||
return pset_qto_id
|
return pset_qto_id
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_pset_qto_name(cls, object):
|
def get_pset_qto_name(cls, obj):
|
||||||
applicable_pset_names = cls.get_applicable_pset_names(object)
|
applicable_pset_names = cls.get_applicable_pset_names(obj)
|
||||||
for applicable_pset_name in applicable_pset_names:
|
for applicable_pset_name in applicable_pset_names:
|
||||||
if 'Qto_' in applicable_pset_name:
|
if 'Qto_' in applicable_pset_name:
|
||||||
pset_qto_name = applicable_pset_name
|
pset_qto_name = applicable_pset_name
|
||||||
return pset_qto_name
|
return pset_qto_name
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_new_quantity(cls, object, quantity_name, alternative_prop_names):
|
def get_new_quantity(cls, obj, quantity_name, alternative_prop_names):
|
||||||
calculator = QtoCalculator()
|
calculator = QtoCalculator()
|
||||||
new_quantity = calculator.guess_quantity(quantity_name, alternative_prop_names, object)
|
new_quantity = calculator.guess_quantity(quantity_name, alternative_prop_names, obj)
|
||||||
return new_quantity
|
return new_quantity
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_non_calculated_value(cls):
|
|
||||||
return 0
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_rounded_value(cls, new_quantity):
|
def get_rounded_value(cls, new_quantity):
|
||||||
return round(new_quantity, 3)
|
return round(new_quantity, 3)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_calculated_quantities(cls, object, pset_qto_properties):
|
def get_calculated_quantities(cls, obj, pset_qto_properties):
|
||||||
calculated_quantities = {}
|
calculated_quantities = {}
|
||||||
for pset_qto_property in pset_qto_properties:
|
for pset_qto_property in pset_qto_properties:
|
||||||
quantity_name = pset_qto_property.get_info()['Name']
|
quantity_name = pset_qto_property.get_info()['Name']
|
||||||
alternative_prop_names = [p.get_info()['Name'] for p in pset_qto_properties]
|
alternative_prop_names = [p.get_info()['Name'] for p in pset_qto_properties]
|
||||||
|
|
||||||
new_quantity = cls.get_new_quantity(object, quantity_name, alternative_prop_names)
|
new_quantity = cls.get_new_quantity(obj, quantity_name, alternative_prop_names)
|
||||||
|
|
||||||
if not new_quantity:
|
if not new_quantity:
|
||||||
new_quantity = cls.get_non_calculated_value()
|
new_quantity = 0
|
||||||
else:
|
else:
|
||||||
new_quantity = cls.get_rounded_value(new_quantity)
|
new_quantity = cls.get_rounded_value(new_quantity)
|
||||||
|
|
||||||
@@ -138,10 +130,10 @@ class Qto(blenderbim.core.tool.Qto):
|
|||||||
return calculated_quantities
|
return calculated_quantities
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def assign_pset_qto_to_selected_object(cls, object):
|
def assign_pset_qto_to_selected_object(cls, obj):
|
||||||
file = tool.Ifc.get()
|
file = tool.Ifc.get()
|
||||||
entity = tool.Ifc.get_entity(object)
|
entity = tool.Ifc.get_entity(obj)
|
||||||
pset_qto_name = cls.get_pset_qto_name(object)
|
pset_qto_name = cls.get_pset_qto_name(obj)
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"pset.add_qto",
|
"pset.add_qto",
|
||||||
file,
|
file,
|
||||||
|
|||||||
Reference in New Issue
Block a user