mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-17 02:49:12 +00:00
Migrate test qto tool to new qto calculator
This commit is contained in:
@@ -24,8 +24,8 @@ import test.bim.bootstrap
|
||||
import blenderbim.core.tool
|
||||
import blenderbim.core.root
|
||||
import blenderbim.tool as tool
|
||||
import blenderbim.bim.module.qto.calculator as calculator
|
||||
from blenderbim.tool.qto import Qto as subject
|
||||
from blenderbim.bim.module.pset.qto_calculator import QtoCalculator
|
||||
|
||||
|
||||
class TestImplementsTool(test.bim.bootstrap.NewFile):
|
||||
@@ -45,48 +45,6 @@ class TestSetQtoResult(test.bim.bootstrap.NewFile):
|
||||
assert bpy.context.scene.BIMQtoProperties.qto_result == "123.457"
|
||||
|
||||
|
||||
class TestGetApplicableQuantityNames(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
schema = ifc.schema
|
||||
properties_templates = (
|
||||
ifcopenshell.util.pset.PsetQto(schema)
|
||||
.get_by_name("Qto_WallBaseQuantities")
|
||||
.get_info()["HasPropertyTemplates"]
|
||||
)
|
||||
applicable_quantity_names = [a.Name for a in properties_templates]
|
||||
assert subject.get_applicable_quantity_names("Qto_WallBaseQuantities") == applicable_quantity_names
|
||||
|
||||
|
||||
class TestGetApplicableBaseQuantityName(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
wall = ifc.createIfcWall()
|
||||
assert subject.get_applicable_base_quantity_name(wall) == "Qto_WallBaseQuantities"
|
||||
|
||||
def test_no_quantities(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
|
||||
product = ifc.by_type("IfcProject")[0]
|
||||
assert subject.get_applicable_base_quantity_name(product) == None
|
||||
|
||||
def test_anomaly_named_quantities(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
product = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBuildingElementProxy")
|
||||
# Prioritized over Qto_BodyGeometryValidation.
|
||||
assert subject.get_applicable_base_quantity_name(product) == "Qto_BuildingElementProxyQuantities"
|
||||
|
||||
def test_prioritize_base_over_other_qto(self):
|
||||
ifc = ifcopenshell.file(schema="IFC4X3")
|
||||
tool.Ifc.set(ifc)
|
||||
product = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
|
||||
assert subject.get_applicable_base_quantity_name(product) == "Qto_WallBaseQuantities"
|
||||
|
||||
|
||||
class TestGetRoundedValue(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
quantity = 1.2345
|
||||
@@ -97,12 +55,14 @@ class TestGetCalculatedObjectQuantities(test.bim.bootstrap.NewFile):
|
||||
def setup_file(self):
|
||||
self.ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(self.ifc)
|
||||
project = ifcopenshell.api.run("root.create_entity", self.ifc, ifc_class="IfcProject", name="My Project")
|
||||
ifcopenshell.api.run("root.create_entity", self.ifc, ifc_class="IfcProject", name="My Project")
|
||||
|
||||
def setup_units(self, units):
|
||||
ifcopenshell.api.run("unit.assign_unit", self.ifc, **units)
|
||||
|
||||
def calculate_quantities(self, obj):
|
||||
import ifc5d.qto
|
||||
|
||||
context = ifcopenshell.api.run("context.add_context", self.ifc, context_type="Model")
|
||||
bpy.ops.mesh.primitive_cube_add(location=(0.0, 0.0, 0.0), size=2)
|
||||
obj = bpy.context.active_object
|
||||
@@ -115,12 +75,32 @@ class TestGetCalculatedObjectQuantities(test.bim.bootstrap.NewFile):
|
||||
predefined_type="ELEMENTEDWALL",
|
||||
context=context,
|
||||
)
|
||||
calculator = QtoCalculator()
|
||||
base_qto = ifcopenshell.api.run("pset.add_qto", self.ifc, product=element, name="Qto_WallBaseQuantities")
|
||||
quantities = subject.get_calculated_object_quantities(
|
||||
calculator=calculator, qto_name="Qto_WallBaseQuantities", obj=obj
|
||||
)
|
||||
return quantities
|
||||
|
||||
rules = {
|
||||
"calculators": {
|
||||
"Blender": {
|
||||
"IfcWall": {
|
||||
"Qto_WallBaseQuantities": {
|
||||
"GrossFootprintArea": "get_gross_footprint_area",
|
||||
"GrossSideArea": "get_gross_side_area",
|
||||
"GrossVolume": "get_gross_volume",
|
||||
"GrossWeight": "get_gross_weight",
|
||||
"Height": "get_height",
|
||||
"Length": "get_length",
|
||||
"NetFootprintArea": "get_net_footprint_area",
|
||||
"NetSideArea": "get_net_side_area",
|
||||
"NetVolume": "get_net_volume",
|
||||
"NetWeight": "get_net_weight",
|
||||
"Width": "get_width",
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ifc_file = tool.Ifc.get()
|
||||
results = ifc5d.qto.quantify(ifc_file, {element}, rules)
|
||||
return {k: round(v, 3) for k, v in results[element]["Qto_WallBaseQuantities"].items() if v is not None}
|
||||
|
||||
def test_meters_project_unit(self):
|
||||
self.setup_file()
|
||||
@@ -186,35 +166,6 @@ class TestGetCalculatedObjectQuantities(test.bim.bootstrap.NewFile):
|
||||
assert quantities["NetVolume"] == 282.517
|
||||
|
||||
|
||||
class TestAddObjectBaseQto(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
project = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject", name="My Project")
|
||||
context = ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
|
||||
bpy.ops.mesh.primitive_cube_add(location=(0.0, 0.0, 0.0), size=2)
|
||||
obj = bpy.context.active_object
|
||||
element = blenderbim.core.root.assign_class(
|
||||
tool.Ifc,
|
||||
tool.Collector,
|
||||
tool.Root,
|
||||
obj=obj,
|
||||
ifc_class="IfcWall",
|
||||
predefined_type="ELEMENTEDWALL",
|
||||
context=context,
|
||||
)
|
||||
assert subject.add_object_base_qto(obj).Name == "Qto_WallBaseQuantities"
|
||||
|
||||
|
||||
class TestAddProductBaseQto(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
wall = ifc.createIfcWall()
|
||||
base_qto = subject.add_product_base_qto(wall)
|
||||
assert base_qto.Name == "Qto_WallBaseQuantities"
|
||||
|
||||
|
||||
class TestGetBaseQto(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -236,46 +187,6 @@ class TestGetBaseQto(test.bim.bootstrap.NewFile):
|
||||
product = tool.Ifc.get_entity(wall_obj)
|
||||
assert not subject.get_base_qto(product) == True
|
||||
|
||||
def test_anomaly_named_quantities(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
product = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBuildingElementProxy")
|
||||
tool.Ifc.run(
|
||||
"pset.add_qto",
|
||||
product=product,
|
||||
name="EQto_BodyGeometryValidation",
|
||||
)
|
||||
tool.Ifc.run(
|
||||
"pset.add_qto",
|
||||
product=product,
|
||||
name="Qto_BuildingElementProxyQuantities",
|
||||
)
|
||||
# Prioritized over Qto_BodyGeometryValidation.
|
||||
base_qto_name = subject.get_base_qto(product).Name
|
||||
assert base_qto_name == "Qto_BuildingElementProxyQuantities"
|
||||
# Ensure methods are in sync.
|
||||
assert base_qto_name == subject.get_applicable_base_quantity_name(product)
|
||||
|
||||
def test_prioritize_base_over_other_qto(self):
|
||||
ifc = ifcopenshell.file(schema="IFC4X3")
|
||||
tool.Ifc.set(ifc)
|
||||
product = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
|
||||
tool.Ifc.run(
|
||||
"pset.add_qto",
|
||||
product=product,
|
||||
name="Qto_BodyGeometryValidation",
|
||||
)
|
||||
tool.Ifc.run(
|
||||
"pset.add_qto",
|
||||
product=product,
|
||||
name="Qto_WallBaseQuantities",
|
||||
)
|
||||
# Prioritized over Qto_BodyGeometryValidation.
|
||||
base_qto_name = subject.get_base_qto(product).Name
|
||||
assert base_qto_name == "Qto_WallBaseQuantities"
|
||||
# Ensure methods are in sync.
|
||||
assert base_qto_name == subject.get_applicable_base_quantity_name(product)
|
||||
|
||||
|
||||
class TestGetRelatedCostItemQuantities(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
|
||||
Reference in New Issue
Block a user