| 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, use_step_matcher |
| 20 |
|
| 21 |
from bimtester import util |
| 22 |
from bimtester.ifc import IfcStore |
| 23 |
from bimtester.lang import _ |
| 24 |
|
| 25 |
|
| 26 |
def get_ifc_class_from_spatial_type(spatial_type): |
| 27 |
if spatial_type == "site": |
| 28 |
return "IfcSite" |
| 29 |
elif spatial_type == "building": |
| 30 |
return "IfcBuilding" |
| 31 |
return "IfcFacility" |
| 32 |
|
| 33 |
|
| 34 |
def check_geocode_attribute(guid, spatial_type, name, value): |
| 35 |
element = util.assert_guid(IfcStore.file, guid) |
| 36 |
util.assert_type(element, get_ifc_class_from_spatial_type(spatial_type)) |
| 37 |
util.assert_attribute(element, name, value) |
| 38 |
|
| 39 |
|
| 40 |
def check_geocode_address(guid, spatial_type, name, value): |
| 41 |
element = util.assert_guid(IfcStore.file, guid) |
| 42 |
ifc_class = get_ifc_class_from_spatial_type(spatial_type) |
| 43 |
util.assert_type(element, ifc_class) |
| 44 |
if ifc_class == "IfcSite": |
| 45 |
address_name = "SiteAddress" |
| 46 |
elif ifc_class == "IfcBuilding": |
| 47 |
address_name = "BuildingAddress" |
| 48 |
util.assert_attribute(element, address_name) |
| 49 |
util.assert_attribute(getattr(element, address_name), name, value) |
| 50 |
|
| 51 |
|
| 52 |
use_step_matcher("re") |
| 53 |
|
| 54 |
|
| 55 |
@step('The (site|building|facility) "(?P<guid>.*)" has a name of "(?P<name>.*)"') |
| 56 |
def step_impl(context, spatial_type, guid, name): |
| 57 |
check_geocode_attribute(guid, spatial_type, "Name", name) |
| 58 |
|
| 59 |
|
| 60 |
@step('The (site|building|facility) "(?P<guid>.*)" has a description of "(?P<description>.*)"') |
| 61 |
def step_impl(context, spatial_type, guid, description): |
| 62 |
check_geocode_attribute(guid, spatial_type, "Description", description) |
| 63 |
|
| 64 |
|
| 65 |
@step('The site "(?P<guid>.*)" has a land title number of "(?P<land_title_number>.*)"') |
| 66 |
def step_impl(context, guid, land_title_number): |
| 67 |
check_geocode_attribute(guid, "site", "LandTitleNumber", land_title_number) |
| 68 |
|
| 69 |
|
| 70 |
@step('The (site|building) "(?P<guid>.*)" has the address "(?P<address_lines>.*)"') |
| 71 |
def step_impl(context, spatial_type, guid, address_lines): |
| 72 |
check_geocode_address(guid, spatial_type, "AddressLines", address_lines.split("\\n")) |
| 73 |
|
| 74 |
|
| 75 |
@step('The (site|building) "(?P<guid>.*)" has a postal box of "(?P<postal_box>.*)"') |
| 76 |
def step_impl(context, spatial_type, guid, postal_box): |
| 77 |
check_geocode_address(guid, spatial_type, "PostalBox", postal_box) |
| 78 |
|
| 79 |
|
| 80 |
@step('The (site|building) "(?P<guid>.*)" is in the town "(?P<town>.*)"') |
| 81 |
def step_impl(context, spatial_type, guid, town): |
| 82 |
check_geocode_address(guid, spatial_type, "Town", town) |
| 83 |
|
| 84 |
|
| 85 |
@step('The (site|building) "(?P<guid>.*)" is in the region "(?P<region>.*)"') |
| 86 |
def step_impl(context, spatial_type, guid, region): |
| 87 |
check_geocode_address(guid, spatial_type, "Region", region) |
| 88 |
|
| 89 |
|
| 90 |
@step('The (site|building) "(?P<guid>.*)" has a post code of "(?P<post_code>.*)"') |
| 91 |
def step_impl(context, spatial_type, guid, post_code): |
| 92 |
check_geocode_address(guid, spatial_type, "PostalCode", post_code) |
| 93 |
|
| 94 |
|
| 95 |
@step('The (site|building) "(?P<guid>.*)" is in the country "(?P<country>.*)"') |
| 96 |
def step_impl(context, spatial_type, guid, country): |
| 97 |
check_geocode_address(guid, spatial_type, "Country", country) |
| 98 |
|
| 99 |
|
| 100 |
@step('The (site|building) "(?P<guid>.*)" has an address description of "(?P<description>.*)"') |
| 101 |
def step_impl(context, spatial_type, guid, description): |
| 102 |
check_geocode_address(guid, spatial_type, "Description", description) |