qto_calculator.py black format

This commit is contained in:
Andrej730
2023-04-19 17:04:15 +05:00
parent ac46276748
commit e44f0e2050
@@ -30,7 +30,6 @@ import blenderbim.bim
class QtoCalculator: class QtoCalculator:
def __init__(self): def __init__(self):
self.mapping_dict = {} self.mapping_dict = {}
for key in mapper.keys(): for key in mapper.keys():
@@ -49,9 +48,9 @@ class QtoCalculator:
def convert_to_project_units(self, value, qto_name, quantity_name): def convert_to_project_units(self, value, qto_name, quantity_name):
ifc_file = tool.Ifc.get() ifc_file = tool.Ifc.get()
quantity_to_unit_types = { quantity_to_unit_types = {
'Q_LENGTH': ('LENGTHUNIT', 'METRE'), "Q_LENGTH": ("LENGTHUNIT", "METRE"),
'Q_AREA': ('AREAUNIT', 'SQUARE_METRE'), "Q_AREA": ("AREAUNIT", "SQUARE_METRE"),
'Q_VOLUME': ('VOLUMEUNIT', 'CUBIC_METRE'), "Q_VOLUME": ("VOLUMEUNIT", "CUBIC_METRE"),
} }
qt = blenderbim.bim.schema.ifc.psetqto.get_by_name(qto_name) qt = blenderbim.bim.schema.ifc.psetqto.get_by_name(qto_name)
@@ -64,7 +63,13 @@ class QtoCalculator:
project_unit = ifcopenshell.util.unit.get_project_unit(ifc_file, unit_type) project_unit = ifcopenshell.util.unit.get_project_unit(ifc_file, unit_type)
if not project_unit: if not project_unit:
return return
value = ifcopenshell.util.unit.convert(value, from_prefix=None, from_unit=base_unit, to_prefix=getattr(project_unit, "Prefix", None), to_unit=project_unit.Name) value = ifcopenshell.util.unit.convert(
value,
from_prefix=None,
from_unit=base_unit,
to_prefix=getattr(project_unit, "Prefix", None),
to_unit=project_unit.Name,
)
return value return value
def calculate_quantity(self, qto_name, quantity_name, obj): def calculate_quantity(self, qto_name, quantity_name, obj):
@@ -250,7 +255,10 @@ class QtoCalculator:
decompositions = ifcopenshell.util.element.get_decomposition(element) decompositions = ifcopenshell.util.element.get_decomposition(element)
finish_floor_height = 0 finish_floor_height = 0
for decomposition in decompositions: for decomposition in decompositions:
if decomposition.get_info()['PredefinedType'] == 'FLOORING' and decomposition.get_info()['type'] == 'IfcCovering' : if (
decomposition.get_info()["PredefinedType"] == "FLOORING"
and decomposition.get_info()["type"] == "IfcCovering"
):
floor_obj = tool.Ifc.get_object(decomposition) floor_obj = tool.Ifc.get_object(decomposition)
new_finish_floor_height = self.get_height(floor_obj) new_finish_floor_height = self.get_height(floor_obj)
if new_finish_floor_height > finish_floor_height: if new_finish_floor_height > finish_floor_height:
@@ -263,7 +271,10 @@ class QtoCalculator:
decompositions = ifcopenshell.util.element.get_decomposition(element) decompositions = ifcopenshell.util.element.get_decomposition(element)
finish_ceiling_height = 0 finish_ceiling_height = 0
for decomposition in decompositions: for decomposition in decompositions:
if decomposition.get_info()['PredefinedType'] == 'CEILING' and decomposition.get_info()['type'] == 'IfcCovering' : if (
decomposition.get_info()["PredefinedType"] == "CEILING"
and decomposition.get_info()["type"] == "IfcCovering"
):
ceiling_obj = tool.Ifc.get_object(decomposition) ceiling_obj = tool.Ifc.get_object(decomposition)
new_finish_ceiling_height = self.get_height(ceiling_obj) new_finish_ceiling_height = self.get_height(ceiling_obj)
if new_finish_ceiling_height > finish_ceiling_height: if new_finish_ceiling_height > finish_ceiling_height:
@@ -271,8 +282,6 @@ class QtoCalculator:
return finish_ceiling_height return finish_ceiling_height
def get_net_perimeter(self, o): def get_net_perimeter(self, o):
parsed_edges = [] parsed_edges = []
shared_edges = [] shared_edges = []
@@ -300,7 +309,7 @@ class QtoCalculator:
pass pass
def get_rectangular_perimeter(self, obj): def get_rectangular_perimeter(self, obj):
length = self.get_length(obj, main_axis='x') length = self.get_length(obj, main_axis="x")
height = self.get_height(obj) height = self.get_height(obj)
return (length + height) * 2 return (length + height) * 2
@@ -321,7 +330,6 @@ class QtoCalculator:
return lowest_polygons return lowest_polygons
def get_highest_polygons(self, o): def get_highest_polygons(self, o):
highest_polygons = [] highest_polygons = []
highest_z = None highest_z = None
for polygon in o.data.polygons: for polygon in o.data.polygons:
@@ -351,8 +359,8 @@ class QtoCalculator:
total_net_floor_area = self.get_net_footprint_area(obj) total_net_floor_area = self.get_net_footprint_area(obj)
for decomposition in decompositions: for decomposition in decompositions:
decomposition_type = decomposition.get_info()['type'] decomposition_type = decomposition.get_info()["type"]
if decomposition_type == 'IfcColumn' or decomposition_type == 'IfcColumn': if decomposition_type == "IfcColumn" or decomposition_type == "IfcColumn":
decomposition_obj = tool.Ifc.get_object(decomposition) decomposition_obj = tool.Ifc.get_object(decomposition)
net_footprint_obj_area = self.get_net_footprint_area(decomposition_obj) net_footprint_obj_area = self.get_net_footprint_area(decomposition_obj)
total_net_floor_area -= net_footprint_obj_area total_net_floor_area -= net_footprint_obj_area
@@ -367,9 +375,9 @@ class QtoCalculator:
total_gross_ceiling_area = 0 total_gross_ceiling_area = 0
for decomposition in decompositions: for decomposition in decompositions:
decomposition_type = decomposition.get_info()['type'] decomposition_type = decomposition.get_info()["type"]
decomposition_predefined_type = decomposition.get_info()['PredefinedType'] decomposition_predefined_type = decomposition.get_info()["PredefinedType"]
if decomposition_type == 'IfcCovering' and decomposition_predefined_type == 'CEILING': if decomposition_type == "IfcCovering" and decomposition_predefined_type == "CEILING":
decomposition_obj = tool.Ifc.get_object(decomposition) decomposition_obj = tool.Ifc.get_object(decomposition)
total_gross_ceiling_area += self.get_gross_footprint_area(decomposition_obj) total_gross_ceiling_area += self.get_gross_footprint_area(decomposition_obj)
@@ -383,13 +391,13 @@ class QtoCalculator:
total_net_ceiling_area = 0 total_net_ceiling_area = 0
for decomposition in decompositions: for decomposition in decompositions:
decomposition_type = decomposition.get_info()['type'] decomposition_type = decomposition.get_info()["type"]
decomposition_predefined_type = decomposition.get_info()['PredefinedType'] decomposition_predefined_type = decomposition.get_info()["PredefinedType"]
if decomposition_type == 'IfcCovering' and decomposition_predefined_type == 'CEILING': if decomposition_type == "IfcCovering" and decomposition_predefined_type == "CEILING":
decomposition_obj = tool.Ifc.get_object(decomposition) decomposition_obj = tool.Ifc.get_object(decomposition)
total_net_ceiling_area += self.get_net_footprint_area(decomposition_obj) total_net_ceiling_area += self.get_net_footprint_area(decomposition_obj)
if decomposition_type == 'IfcWall' or decomposition_type == 'IfcColumn': if decomposition_type == "IfcWall" or decomposition_type == "IfcColumn":
decomposition_obj = tool.Ifc.get_object(decomposition) decomposition_obj = tool.Ifc.get_object(decomposition)
total_net_ceiling_area -= self.get_net_roofprint_area(decomposition_obj) total_net_ceiling_area -= self.get_net_roofprint_area(decomposition_obj)
@@ -403,8 +411,8 @@ class QtoCalculator:
total_space_net_volume = self.get_gross_volume(obj) total_space_net_volume = self.get_gross_volume(obj)
for decomposition in decompositions: for decomposition in decompositions:
decomposition_type = decomposition.get_info()['type'] decomposition_type = decomposition.get_info()["type"]
if decomposition_type == 'IfcWall' or decomposition_type == 'IfcColumn': if decomposition_type == "IfcWall" or decomposition_type == "IfcColumn":
decomposition_obj = tool.Ifc.get_object(decomposition) decomposition_obj = tool.Ifc.get_object(decomposition)
total_space_net_volume -= self.get_net_volume(decomposition_obj) total_space_net_volume -= self.get_net_volume(decomposition_obj)
@@ -567,17 +575,19 @@ class QtoCalculator:
): ):
return return
if material.is_a('IfcMaterial'): if material.is_a("IfcMaterial"):
material_mass_density = ifcopenshell.util.element.get_pset(material, "Pset_MaterialCommon", "MassDensity") material_mass_density = ifcopenshell.util.element.get_pset(material, "Pset_MaterialCommon", "MassDensity")
return material_mass_density return material_mass_density
if material.is_a('IfcMaterialLayerSetUsage'): if material.is_a("IfcMaterialLayerSetUsage"):
material_layers = material.ForLayerSet.MaterialLayers material_layers = material.ForLayerSet.MaterialLayers
densities = [] densities = []
thicknesses = [] thicknesses = []
obj_mass_density = 0 obj_mass_density = 0
for material_layer in material_layers: for material_layer in material_layers:
material_mass_density = ifcopenshell.util.element.get_pset(material_layer.Material, "Pset_MaterialCommon", "MassDensity") material_mass_density = ifcopenshell.util.element.get_pset(
material_layer.Material, "Pset_MaterialCommon", "MassDensity"
)
if material_mass_density is None: if material_mass_density is None:
return return
densities.append(material_mass_density) densities.append(material_mass_density)
@@ -588,10 +598,12 @@ class QtoCalculator:
obj_mass_density = obj_mass_density / total_thickness obj_mass_density = obj_mass_density / total_thickness
return obj_mass_density return obj_mass_density
if material.is_a('IfcMaterialProfileSetUsage'): if material.is_a("IfcMaterialProfileSetUsage"):
material_profiles = material.ForProfileSet.MaterialProfiles material_profiles = material.ForProfileSet.MaterialProfiles
if len(material_profiles) == 1: if len(material_profiles) == 1:
material_mass_density = ifcopenshell.util.element.get_pset(material_profiles[0].Material, "Pset_MaterialCommon", "MassDensity") material_mass_density = ifcopenshell.util.element.get_pset(
material_profiles[0].Material, "Pset_MaterialCommon", "MassDensity"
)
return material_mass_density return material_mass_density
else: else:
return return
@@ -681,7 +693,11 @@ class QtoCalculator:
bl_OBB_opening_object = self.get_OBB_object(bl_opening_obj) bl_OBB_opening_object = self.get_OBB_object(bl_opening_obj)
opening_area = self.get_lateral_area( opening_area = self.get_lateral_area(
# self.get_OBB_object(bl_opening_obj), angle_z1=angle_z1, angle_z2=angle_z2, exclude_end_areas=True # self.get_OBB_object(bl_opening_obj), angle_z1=angle_z1, angle_z2=angle_z2, exclude_end_areas=True
bl_OBB_opening_object, angle_z1=angle_z1, angle_z2=angle_z2, exclude_end_areas=True, main_axis = 'x', bl_OBB_opening_object,
angle_z1=angle_z1,
angle_z2=angle_z2,
exclude_end_areas=True,
main_axis="x",
) )
if opening_area >= min_area: if opening_area >= min_area:
total_opening_area += opening_area total_opening_area += opening_area
@@ -756,12 +772,12 @@ class QtoCalculator:
if not self.has_openings(obj): if not self.has_openings(obj):
return self.get_net_side_area(obj) return self.get_net_side_area(obj)
gross_side_area = self.get_lateral_area(obj, exclude_end_areas = True, subtract_openings = False, main_axis = 'x') / 2 gross_side_area = self.get_lateral_area(obj, exclude_end_areas=True, subtract_openings=False, main_axis="x") / 2
return gross_side_area return gross_side_area
def get_net_side_area(self, obj): def get_net_side_area(self, obj):
net_side_area = self.get_lateral_area(obj, exclude_end_areas = True, main_axis = 'x') / 2 net_side_area = self.get_lateral_area(obj, exclude_end_areas=True, main_axis="x") / 2
return net_side_area return net_side_area
def get_outer_surface_area(self, obj): def get_outer_surface_area(self, obj):
@@ -1122,12 +1138,7 @@ class QtoCalculator:
return 0 return 0
# touching polygons should be coplanar: # touching polygons should be coplanar:
plane_intersection = mathutils.geometry.intersect_plane_plane( plane_intersection = mathutils.geometry.intersect_plane_plane(center1, normal1, center2, normal2)
center1,
normal1,
center2,
normal2
)
# sometimes coplanar planes will interesect far off into the distance. This is a crude way of filtering out those intersections. # sometimes coplanar planes will interesect far off into the distance. This is a crude way of filtering out those intersections.
if plane_intersection[0] is None or (plane_intersection[0] - center1).magnitude > 20: if plane_intersection[0] is None or (plane_intersection[0] - center1).magnitude > 20:
@@ -1238,6 +1249,7 @@ class QtoCalculator:
def delete_obj(self, obj): def delete_obj(self, obj):
bpy.data.objects.remove(obj, do_unlink=True) bpy.data.objects.remove(obj, do_unlink=True)
# # Following code is here temporarily to test newly created functions: # # Following code is here temporarily to test newly created functions:
# qto = QtoCalculator() # qto = QtoCalculator()
@@ -1269,5 +1281,3 @@ class QtoCalculator:
# f"get_touching_objects(o, ['IfcElement']): {qto.get_touching_objects(o, ['IfcElement'])}{nl}{nl}" # f"get_touching_objects(o, ['IfcElement']): {qto.get_touching_objects(o, ['IfcElement'])}{nl}{nl}"
# #f"get_contact_area: {qto.get_contact_area(o)}{nl}{nl}" # #f"get_contact_area: {qto.get_contact_area(o)}{nl}{nl}"
# ) # )