| 1 |
############################################################################### |
| 2 |
# # |
| 3 |
# This file is part of IfcOpenShell. # |
| 4 |
# # |
| 5 |
# IfcOpenShell is free software: you can redistribute it and/or modify # |
| 6 |
# it under the terms of the Lesser GNU General Public License as published by # |
| 7 |
# the Free Software Foundation, either version 3.0 of the License, or # |
| 8 |
# (at your option) any later version. # |
| 9 |
# # |
| 10 |
# IfcOpenShell is distributed in the hope that it will be useful, # |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
| 13 |
# Lesser GNU General Public License for more details. # |
| 14 |
# # |
| 15 |
# You should have received a copy of the Lesser GNU General Public License # |
| 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
| 17 |
# # |
| 18 |
############################################################################### |
| 19 |
|
| 20 |
# Some basic tests. Currently only covering basic I/O. |
| 21 |
|
| 22 |
import os |
| 23 |
import uuid |
| 24 |
|
| 25 |
import ifcopenshell |
| 26 |
import ifcopenshell.geom |
| 27 |
import ifcopenshell.guid |
| 28 |
|
| 29 |
f = ifcopenshell.open("input/acad2010_walls.ifc") |
| 30 |
|
| 31 |
# Some operations on ifcopenshell.file |
| 32 |
assert f[1].is_a("IfcCartesianPoint") |
| 33 |
assert f[1].is_a("IfcRepresentationItem") |
| 34 |
assert f[1].is_a() == "IfcCartesianPoint" |
| 35 |
assert f.by_id(1).is_a("IfcCartesianPoint") |
| 36 |
assert f["28pa2ppDf1IA$BaQrvAf48"].is_a("IfcProject") |
| 37 |
assert f.by_guid("28pa2ppDf1IA$BaQrvAf48").is_a("IfcProject") |
| 38 |
assert f.createIfcCartesianPoint((0., 0., 0.)).is_a("IfcCartesianPoint") |
| 39 |
assert f.by_type("IfcProject")[0].is_a("IfcProject") |
| 40 |
assert f.traverse(f[16])[-1].is_a("IFCSIUNIT") |
| 41 |
assert len(f.traverse(f[35], 1)) == 2 |
| 42 |
assert len(f.traverse(f[35])) == 3 |
| 43 |
assert f[16] in f.get_inverse(f[15]) |
| 44 |
assert f[16].UnitComponent is not None |
| 45 |
f.remove(f[15]) |
| 46 |
assert f[16].UnitComponent is None |
| 47 |
prop = f.by_type("IfcPropertySingleValue")[0] |
| 48 |
assert prop.NominalValue.wrappedValue in str(prop) |
| 49 |
|
| 50 |
# An instance added to a new file yields the same string |
| 51 |
# representation, except for any instance name identifiers. |
| 52 |
f2 = ifcopenshell.file(schema=f.schema) |
| 53 |
prop2 = f2.add(prop) |
| 54 |
assert str(prop) == str(prop2).replace(str(prop2.id()), str(prop.id())) |
| 55 |
assert prop2.id() == 1 |
| 56 |
|
| 57 |
# A recursively obtained python dictionary representation |
| 58 |
# matches for copied instances as well |
| 59 |
app = f.by_type("IfcApplication")[0] |
| 60 |
assert f2.add(app).get_info(False, True) == app.get_info(False, True) |
| 61 |
assert "Version" in dir(app) |
| 62 |
|
| 63 |
# Enumeration of entity type names |
| 64 |
g = ifcopenshell.file(schema=f.schema) |
| 65 |
p = g.createIfcCartesianPoint((0.,0.)) |
| 66 |
assert len(g.types()) == 1 |
| 67 |
assert "IfcPoint" in g.types_with_super() |
| 68 |
g.remove(p) |
| 69 |
assert len(g.types()) == 0 |
| 70 |
assert len(g.types_with_super()) == 0 |
| 71 |
|
| 72 |
# Some operations on ifcopenshell.entity_instance |
| 73 |
assert f[22].Id == '' |
| 74 |
assert f[22].Addresses is None |
| 75 |
assert f[23] in f[22].EngagedIn |
| 76 |
f[22].Id = '123' |
| 77 |
assert '123' in str(f[22]) |
| 78 |
f[22].MiddleNames = 'John', 'Matthew' |
| 79 |
assert "('John','Matthew')" in str(f[22]) |
| 80 |
assert ("Id", "123") in list(f[22].get_info().items()) |
| 81 |
|
| 82 |
# Assignment of instances and implications on inverse attributes |
| 83 |
assert f[288].ConnectedTo[0].RelatingElement == f[288] |
| 84 |
num_connections_1 = len(f[340].ConnectedTo + f[340].ConnectedFrom) |
| 85 |
f[288].ConnectedTo[0].RelatingElement = f[340] |
| 86 |
num_connections_2 = len(f[340].ConnectedTo + f[340].ConnectedFrom) |
| 87 |
assert num_connections_2 == num_connections_1 + 1 |
| 88 |
assert f[288].ConnectedTo == () |
| 89 |
rel = f.createIfcRelConnectsPathElements(RelatingElement=f[288]) |
| 90 |
assert f[288].ConnectedTo == (rel,) |
| 91 |
|
| 92 |
# Some operations on ifcopenshell.guid |
| 93 |
assert len(ifcopenshell.guid.compress(uuid.uuid1().hex)) == 22 |
| 94 |
|
| 95 |
# Test the BVH tree |
| 96 |
tree_settings = ifcopenshell.geom.settings() |
| 97 |
tree_settings.set(tree_settings.DISABLE_OPENING_SUBTRACTIONS, True) |
| 98 |
t = ifcopenshell.geom.tree(f, tree_settings) |
| 99 |
# This wall is connected to two other walls |
| 100 |
assert len(t.select_box(f[48], extend=0.1)) == 3 |
| 101 |
|
| 102 |
# Test serialization |
| 103 |
f.write("output.ifc") |
| 104 |
with open("output.ifc") as txt: |
| 105 |
assert '123' in txt.read() |
| 106 |
os.unlink("output.ifc") |