mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Writing qto tests (#2728)
* Update qto tool tests and fix some bugs * complete test_run qto tests
This commit is contained in:
@@ -63,5 +63,5 @@ def calculate_object_base_quantities(ifc, qto, calculator, obj):
|
||||
product=product,
|
||||
name=base_quantity_name,
|
||||
)
|
||||
calculated_quantities = qto.calculate_object_quantities(calculator, base_quantity_name, obj)
|
||||
calculated_quantities = qto.get_calculated_object_quantities(calculator, base_quantity_name, obj)
|
||||
ifc.run("pset.edit_qto", qto=base_qto, properties=calculated_quantities)
|
||||
|
||||
@@ -405,9 +405,9 @@ class Qto:
|
||||
def get_radius_of_selected_vertices(cls, obj): pass
|
||||
def set_qto_result(cls, result): pass
|
||||
def get_applicable_quantity_names(cls, qto_name): pass
|
||||
def get_applicable_base_quantity_name(cls, object): pass
|
||||
def get_applicable_base_quantity_name(cls, product): pass
|
||||
def get_rounded_value(cls, new_quantity): pass
|
||||
def calculate_object_quantities(cls, calculator, baste_qto, object): pass
|
||||
def get_calculated_object_quantities(cls, calculator, baste_qto, object): pass
|
||||
def add_object_base_qto(cls, object): pass
|
||||
def add_product_base_qto(cls, product): pass
|
||||
def get_new_calculated_quantity(cls, qto_name, quantity_name, object): pass
|
||||
|
||||
@@ -45,7 +45,7 @@ class Qto(blenderbim.core.tool.Qto):
|
||||
@classmethod
|
||||
def add_object_base_qto(cls, obj):
|
||||
product = tool.Ifc.get_entity(obj)
|
||||
cls.add_product_base_qto(product)
|
||||
return cls.add_product_base_qto(product)
|
||||
|
||||
@classmethod
|
||||
def add_product_base_qto(cls, product):
|
||||
@@ -86,7 +86,7 @@ class Qto(blenderbim.core.tool.Qto):
|
||||
return round(new_quantity, 3)
|
||||
|
||||
@classmethod
|
||||
def calculate_object_quantities(cls, calculator, qto_name, obj):
|
||||
def get_calculated_object_quantities(cls, calculator, qto_name, obj):
|
||||
return {
|
||||
quantity_name: cls.get_rounded_value(calculator.calculate_quantity(qto_name, quantity_name, obj))
|
||||
for quantity_name in cls.get_applicable_quantity_names(qto_name) or []
|
||||
|
||||
@@ -22,20 +22,123 @@ import test.bim.bootstrap
|
||||
import blenderbim.core.tool
|
||||
import blenderbim.tool as tool
|
||||
from blenderbim.tool.qto import Qto as subject
|
||||
from blenderbim.bim.module.pset.qto_calculator import QtoCalculator
|
||||
|
||||
|
||||
class TestImplementsTool(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
assert isinstance(subject(), blenderbim.core.tool.Qto)
|
||||
|
||||
|
||||
class TestGetRadiusOfSelectedVertices(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
bpy.ops.mesh.primitive_circle_add()
|
||||
assert round(subject.get_radius_of_selected_vertices(bpy.data.objects.get("Circle")), 3) == 1
|
||||
|
||||
|
||||
class TestSetQtoResult(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
subject.set_qto_result(123.4567)
|
||||
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_base_quantity(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
|
||||
|
||||
class TestGetRoundedValue(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
quantity = 1.2345
|
||||
assert subject.get_rounded_value(quantity) == 1.234
|
||||
|
||||
class TestGetCalculatedObjectQuantities(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")
|
||||
ifcopenshell.api.run("unit.assign_unit", ifc)
|
||||
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)
|
||||
calculator = QtoCalculator()
|
||||
base_qto = ifcopenshell.api.run("pset.add_qto", ifc, product=element, name="Qto_WallBaseQuantities")
|
||||
quantities = subject.get_calculated_object_quantities(calculator = calculator, qto_name = "Qto_WallBaseQuantities", obj = obj)
|
||||
assert quantities["Length"] == 2
|
||||
assert quantities["Width"] == 2
|
||||
assert quantities["Height"] == 2
|
||||
assert quantities["GrossFootprintArea"] == 4
|
||||
assert quantities["NetFootprintArea"] == 4
|
||||
assert quantities["GrossSideArea"] == 4
|
||||
assert quantities["NetSideArea"] == 4
|
||||
assert quantities["GrossVolume"] == 8
|
||||
assert quantities["NetVolume"] == 8
|
||||
|
||||
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()
|
||||
tool.Ifc.set(ifc)
|
||||
wall = ifc.createIfcWall()
|
||||
wall_obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
||||
tool.Ifc.link(wall, wall_obj)
|
||||
product = tool.Ifc.get_entity(wall_obj)
|
||||
pset_qto = ifcopenshell.api.run("pset.add_qto", ifc, product=wall, name="Qto_Basefoo")
|
||||
assert subject.get_base_qto(product).id() == pset_qto.get_info()['id']
|
||||
assert subject.get_base_qto(product).Name == pset_qto.Name
|
||||
|
||||
def test_isempty(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
wall = ifc.createIfcWall()
|
||||
wall_obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
||||
tool.Ifc.link(wall, wall_obj)
|
||||
product = tool.Ifc.get_entity(wall_obj)
|
||||
assert not subject.get_base_qto(product) == True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user