-
-
Notifications
You must be signed in to change notification settings - Fork 902
Expand file tree
/
Copy pathtest.py
More file actions
96 lines (79 loc) · 3.98 KB
/
test.py
File metadata and controls
96 lines (79 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
#
# This file is part of IfcOpenShell.
#
# IfcOpenShell is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IfcOpenShell is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.root
import ifcopenshell.api.unit
import ifcopenshell.util.representation
import ifcdiff
def setup_project() -> ifcopenshell.file:
ifc_file = ifcopenshell.file(schema="IFC4")
ifcopenshell.api.root.create_entity(ifc_file, ifc_class="IfcProject")
unit = ifcopenshell.api.unit.add_si_unit(ifc_file, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc_file, units=[unit])
model = ifcopenshell.api.context.add_context(ifc_file, "Model")
ifcopenshell.api.context.add_context(ifc_file, "Model", "Body", "MODEL_VIEW", parent=model)
return ifc_file
class TestIfcDiff:
def test_add_element(self):
ifc_file = setup_project()
new_file = ifc_file.from_string(ifc_file.to_string())
wall = ifcopenshell.api.root.create_entity(new_file, ifc_class="IfcWall")
ifc_diff = ifcdiff.IfcDiff(ifc_file, new_file)
ifc_diff.diff()
assert ifc_diff.added_elements == {wall.GlobalId}
assert ifc_diff.deleted_elements == set()
assert ifc_diff.change_register == {}
def test_remove_element(self):
ifc_file = setup_project()
wall = ifcopenshell.api.root.create_entity(ifc_file, ifc_class="IfcWall")
new_file = ifc_file.from_string(ifc_file.to_string())
wall_new = new_file.by_id(wall.id())
ifcopenshell.api.root.remove_product(new_file, wall_new)
ifc_diff = ifcdiff.IfcDiff(ifc_file, new_file)
ifc_diff.diff()
assert ifc_diff.added_elements == set()
assert ifc_diff.deleted_elements == {wall.GlobalId}
assert ifc_diff.change_register == {}
def test_changed_attribute(self):
ifc_file = setup_project()
wall = ifcopenshell.api.root.create_entity(ifc_file, ifc_class="IfcWall", name="Foo")
new_file = ifc_file.from_string(ifc_file.to_string())
wall_new = new_file.by_id(wall.id())
wall_new.Name = "Bar"
ifc_diff = ifcdiff.IfcDiff(ifc_file, new_file, relationships=["attributes"])
ifc_diff.diff()
assert ifc_diff.added_elements == set()
assert ifc_diff.deleted_elements == set()
assert ifc_diff.change_register == {wall.GlobalId: {"attributes_changed": True}}
def test_changed_geometry(self):
ifc_file = setup_project()
wall = ifcopenshell.api.root.create_entity(ifc_file, ifc_class="IfcWall", name="Foo")
context = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
assert context
representation = ifcopenshell.api.geometry.add_slab_representation(ifc_file, context, depth=0.2)
ifcopenshell.api.geometry.assign_representation(ifc_file, wall, representation)
new_file = ifc_file.from_string(ifc_file.to_string())
extrusion = new_file.by_type("IfcExtrudedAreaSolid")[0]
extrusion.Depth = 500.0
ifc_diff = ifcdiff.IfcDiff(ifc_file, new_file, relationships=["geometry"])
ifc_diff.diff()
assert ifc_diff.added_elements == set()
assert ifc_diff.deleted_elements == set()
assert ifc_diff.change_register == {wall.GlobalId: {"geometry_changed": True}}