2020-09-09 11:23:11 +10:00
|
|
|
from behave import step
|
2020-11-26 15:35:53 +01:00
|
|
|
|
2021-01-11 11:39:36 +08:00
|
|
|
import geometric_detail_methods as gdm
|
2020-12-21 10:31:05 +01:00
|
|
|
from utils import assert_elements
|
2020-09-09 11:23:11 +10:00
|
|
|
from utils import IfcFile
|
2020-12-21 10:31:05 +01:00
|
|
|
from utils import switch_locale
|
2020-09-09 11:23:11 +10:00
|
|
|
|
2020-11-01 19:22:49 +07:00
|
|
|
|
2021-01-11 11:39:36 +08:00
|
|
|
the_lang = "en"
|
|
|
|
|
|
|
|
|
|
|
2020-09-09 11:23:11 +10:00
|
|
|
@step("All elements must be under {number} polygons")
|
|
|
|
|
def step_impl(context, number):
|
|
|
|
|
number = int(number)
|
|
|
|
|
errors = []
|
|
|
|
|
for element in IfcFile.get().by_type("IfcElement"):
|
|
|
|
|
if not element.Representation:
|
|
|
|
|
continue
|
|
|
|
|
total_polygons = 0
|
|
|
|
|
tree = IfcFile.get().traverse(element.Representation)
|
|
|
|
|
for e in tree:
|
|
|
|
|
if e.is_a("IfcFace"):
|
|
|
|
|
total_polygons += 1
|
|
|
|
|
elif e.is_a("IfcPolygonalFaceSet"):
|
|
|
|
|
total_polygons += len(e.Faces)
|
|
|
|
|
elif e.is_a("IfcTriangulatedFaceSet"):
|
|
|
|
|
total_polygons += len(e.CoordIndex)
|
|
|
|
|
if total_polygons > number:
|
|
|
|
|
errors.append((total_polygons, element))
|
|
|
|
|
if errors:
|
2020-11-26 15:35:53 +01:00
|
|
|
message = (
|
|
|
|
|
"The following {} elements are over 500 polygons:\n"
|
|
|
|
|
.format(len(errors))
|
|
|
|
|
)
|
2020-09-09 11:23:11 +10:00
|
|
|
for error in errors:
|
|
|
|
|
message += "Polygons: {} - {}\n".format(error[0], error[1])
|
|
|
|
|
assert False, message
|
2020-12-21 10:31:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@step("all {ifc_class} elements have an {representation_class} representation")
|
|
|
|
|
def step_impl(context, ifc_class, representation_class):
|
2021-01-11 11:39:36 +08:00
|
|
|
switch_locale(context.localedir, the_lang)
|
|
|
|
|
gdm.eleclass_has_geometric_representation_of_specific_class(
|
|
|
|
|
context,
|
|
|
|
|
ifc_class,
|
|
|
|
|
representation_class
|
|
|
|
|
)
|