| 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('IFC data must use the "{schema}" schema') |
| 27 |
def step_impl(context, schema): |
| 28 |
real_schema = IfcStore.file.schema |
| 29 |
assert real_schema == schema, _("We expected a schema of {} but instead got {}").format(schema, real_schema) |
| 30 |
|
| 31 |
|
| 32 |
@step("The IFC file must be valid") |
| 33 |
def step_impl(context): |
| 34 |
errors = util.validate(IfcStore.file) |
| 35 |
assert not errors, "Errors occured:\n{}".format("\n".join(errors)) |
| 36 |
|
| 37 |
|
| 38 |
@step('The IFC file "{file}" is exempt from being provided') |
| 39 |
def step_impl(context, file): |
| 40 |
pass |
| 41 |
|
| 42 |
|
| 43 |
@step('No further requirements are specified because "{reason}"') |
| 44 |
def step_impl(context, reason): |
| 45 |
pass |
| 46 |
|
| 47 |
|
| 48 |
@step('The project must have an identifier of "{guid}"') |
| 49 |
def step_impl(context, guid): |
| 50 |
util.assert_attribute(IfcStore.file.by_type("IfcProject")[0], "GlobalId", guid) |
| 51 |
|
| 52 |
|
| 53 |
@step('The project name, code, or short identifier must be "{value}"') |
| 54 |
def step_impl(context, value): |
| 55 |
util.assert_attribute(IfcStore.file.by_type("IfcProject")[0], "Name", value) |
| 56 |
|
| 57 |
|
| 58 |
@step('The project must have a longer form name of "{value}"') |
| 59 |
def step_impl(context, value): |
| 60 |
util.assert_attribute(IfcStore.file.by_type("IfcProject")[0], "LongName", value) |
| 61 |
|
| 62 |
|
| 63 |
@step('The project must be described as "{value}"') |
| 64 |
def step_impl(context, value): |
| 65 |
util.assert_attribute(IfcStore.file.by_type("IfcProject")[0], "Description", value) |
| 66 |
|
| 67 |
|
| 68 |
@step('The project must be categorised under "{value}"') |
| 69 |
def step_impl(context, value): |
| 70 |
util.assert_attribute(IfcStore.file.by_type("IfcProject")[0], "ObjectType", value) |
| 71 |
|
| 72 |
|
| 73 |
@step('The project must contain information about the "{value}" phase') |
| 74 |
def step_impl(context, value): |
| 75 |
util.assert_attribute(IfcStore.file.by_type("IfcProject")[0], "Phase", value) |
| 76 |
|
| 77 |
|
| 78 |
@step("The project must contain 3D geometry representing the shape of objects") |
| 79 |
def step_impl(context): |
| 80 |
assert get_subcontext("Body", "Model", "MODEL_VIEW") |
| 81 |
|
| 82 |
|
| 83 |
@step("The project must contain 3D geometry representing clearance zones") |
| 84 |
def step_impl(context): |
| 85 |
assert get_subcontext("Clearance", "Model", "MODEL_VIEW") |
| 86 |
|
| 87 |
|
| 88 |
@step("The project must contain 3D geometry representing the center of gravity of objects") |
| 89 |
def step_impl(context): |
| 90 |
assert get_subcontext("CoG", "Model", "MODEL_VIEW") |
| 91 |
|
| 92 |
|
| 93 |
@step("The project must contain 3D geometry representing the object bounding boxes") |
| 94 |
def step_impl(context): |
| 95 |
assert get_subcontext("Box", "Model", "MODEL_VIEW") |
| 96 |
|
| 97 |
|
| 98 |
def get_subcontext(identifier, type, target_view): |
| 99 |
project = IfcStore.file.by_type("IfcProject")[0] |
| 100 |
for rep_context in project.RepresentationContexts: |
| 101 |
for subcontext in rep_context.HasSubContexts: |
| 102 |
if ( |
| 103 |
subcontext.ContextIdentifier == identifier |
| 104 |
and subcontext.ContextType == type |
| 105 |
and subcontext.TargetView == target_view |
| 106 |
): |
| 107 |
return True |
| 108 |
assert False, "The subcontext with identifier {}, type {}, and target view {} could not be found".format( |
| 109 |
identifier, type, target_view |
| 110 |
) |
| 111 |
|
| 112 |
|
| 113 |
@step('the project has a {attribute_name} attribute with a value of "{attribute_value}"') |
| 114 |
def step_impl(context, attribute_name, attribute_value): |
| 115 |
project = IfcStore.file.by_type("IfcProject")[0] |
| 116 |
assert getattr(project, attribute_name) == attribute_value |