| 1 |
# BIMTester - OpenBIM Auditing Tool |
| 2 |
# Copyright (C) 2021 Dion Moult <[email protected]> |
| 3 |
# |
| 4 |
# This file is part of BIMTester. |
| 5 |
# |
| 6 |
# BIMTester is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU Lesser General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# BIMTester is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU Lesser General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU Lesser General Public License |
| 17 |
# along with BIMTester. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
from behave import step |
| 20 |
|
| 21 |
from bimtester import util |
| 22 |
from bimtester.ifc import IfcStore |
| 23 |
from bimtester.lang import _ |
| 24 |
|
| 25 |
|
| 26 |
@step('All elements must be under "{number}" polygons') |
| 27 |
def step_impl(context, number): |
| 28 |
number = int(number) |
| 29 |
errors = [] |
| 30 |
for element in IfcStore.file.by_type("IfcElement"): |
| 31 |
if not element.Representation: |
| 32 |
continue |
| 33 |
total_polygons = 0 |
| 34 |
tree = IfcStore.file.traverse(element.Representation) |
| 35 |
for e in tree: |
| 36 |
if e.is_a("IfcFace"): |
| 37 |
total_polygons += 1 |
| 38 |
elif e.is_a("IfcPolygonalFaceSet"): |
| 39 |
total_polygons += len(e.Faces) |
| 40 |
elif e.is_a("IfcTriangulatedFaceSet"): |
| 41 |
total_polygons += len(e.CoordIndex) |
| 42 |
if total_polygons > number: |
| 43 |
errors.append((total_polygons, element)) |
| 44 |
if errors: |
| 45 |
message = "The following {} elements are over 500 polygons:\n".format(len(errors)) |
| 46 |
for error in errors: |
| 47 |
message += "Polygons: {} - {}\n".format(error[0], error[1]) |
| 48 |
assert False, message |
| 49 |
|
| 50 |
|
| 51 |
@step('All "{ifc_class}" elements have an "{representation_class}" representation') |
| 52 |
def step_impl(context, ifc_class, representation_class): |
| 53 |
eleclass_has_geometric_representation_of_specific_class(context, ifc_class, representation_class) |
| 54 |
|
| 55 |
|
| 56 |
# ************************************************************************************************ |
| 57 |
# helper |
| 58 |
def eleclass_has_geometric_representation_of_specific_class(context, ifc_class, representation_class): |
| 59 |
def is_item_a_representation(item, representation): |
| 60 |
if "/" in representation: |
| 61 |
for cls in representation.split("/"): |
| 62 |
if item.is_a(cls): |
| 63 |
return True |
| 64 |
elif item.is_a(representation): |
| 65 |
return True |
| 66 |
|
| 67 |
context.falseelems = [] |
| 68 |
context.falseguids = [] |
| 69 |
context.falseprops = {} |
| 70 |
rep = None |
| 71 |
|
| 72 |
elements = IfcStore.file.by_type(ifc_class) |
| 73 |
for elem in elements: |
| 74 |
if not elem.Representation: |
| 75 |
continue |
| 76 |
has_representation = False |
| 77 |
for representation in elem.Representation.Representations: |
| 78 |
for item in representation.Items: |
| 79 |
if item.is_a("IfcMappedItem"): |
| 80 |
# We only check one more level deep. |
| 81 |
for item2 in item.MappingSource.MappedRepresentation.Items: |
| 82 |
if is_item_a_representation(item2, representation_class): |
| 83 |
has_representation = True |
| 84 |
rep = item2 |
| 85 |
else: |
| 86 |
if is_item_a_representation(item, representation_class): |
| 87 |
has_representation = True |
| 88 |
rep = item |
| 89 |
if not has_representation: |
| 90 |
context.falseelems.append(str(elem)) |
| 91 |
context.falseguids.append(elem.GlobalId) |
| 92 |
context.falseprops[elem.id()] = str(rep) |
| 93 |
|
| 94 |
context.elemcount = len(elements) |
| 95 |
context.falsecount = len(context.falseelems) |
| 96 |
util.assert_elements( |
| 97 |
ifc_class, |
| 98 |
context.elemcount, |
| 99 |
context.falsecount, |
| 100 |
context.falseelems, |
| 101 |
message_all_falseelems=_("All {elemcount} {ifc_class} elements are not a {parameter} representation."), |
| 102 |
message_some_falseelems=_( |
| 103 |
"The following {falsecount} of {elemcount} {ifc_class} elements are not a {parameter} representation: {falseelems}" |
| 104 |
), |
| 105 |
message_no_elems=_("There are no {ifc_class} elements in the IFC file."), |
| 106 |
parameter=representation_class, |
| 107 |
) |