2020import ifcopenshell
2121import ifcopenshell .api .georeference
2222import ifcopenshell .util .placement
23+ import ifcopenshell .util .shape_builder
2324import test .bootstrap
2425import tempfile
2526import numpy as np
@@ -81,31 +82,60 @@ def test_using_the_georeferencing_of_the_original_project(self):
8182 assert len (output .by_type ("IfcProjectedCRS" )) == 1
8283 assert len (output .by_type ("IfcMapConversion" )) == 1
8384
84- def test_shifting_the_source_project_to_match_the_original_project_origin (self ):
85+ def test_shifting_the_other_project_to_match_the_original_project_origin (self ):
8586 self .file = self .setup_project (self .file )
8687 second_file = self .setup_project ()
8788 ifcopenshell .api .georeference .add_georeferencing (self .file )
89+ xaa1 , xao1 = ifcopenshell .util .geolocation .angle2xaxis (10 )
8890 ifcopenshell .api .georeference .edit_georeferencing (
89- self .file , coordinate_operation = {"Eastings" : 10 , "Northings" : 20 }, projected_crs = {"Name" : "EPSG:1234" }
91+ self .file ,
92+ coordinate_operation = {"Eastings" : 10 , "Northings" : 20 , "XAxisAbscissa" : xaa1 , "XAxisOrdinate" : xao1 },
93+ projected_crs = {"Name" : "EPSG:1234" },
9094 )
9195 ifcopenshell .api .georeference .add_georeferencing (second_file )
96+ xaa , xao = ifcopenshell .util .geolocation .angle2xaxis (30 )
9297 ifcopenshell .api .georeference .edit_georeferencing (
93- second_file , coordinate_operation = {"Eastings" : 30000 , "Northings" : 40000 }, projected_crs = {"Name" : "EPSG:0" }
98+ second_file ,
99+ coordinate_operation = {"Eastings" : 30000 , "Northings" : 40000 , "XAxisAbscissa" : xaa , "XAxisOrdinate" : xao },
100+ projected_crs = {"Name" : "EPSG:0" },
94101 )
95102
103+ builder1 = ifcopenshell .util .shape_builder .ShapeBuilder (self .file )
104+ builder2 = ifcopenshell .util .shape_builder .ShapeBuilder (second_file )
105+ o1 = builder1 .create_axis2_placement_3d ()
106+ o2 = builder2 .create_axis2_placement_3d ()
107+ body1 = ifcopenshell .util .representation .get_context (self .file , "Model" , "Body" , "MODEL_VIEW" )
108+ body2 = ifcopenshell .util .representation .get_context (second_file , "Model" , "Body" , "MODEL_VIEW" )
109+
96110 # Original file is in meters
97111 wall1 = self .file .by_type ("IfcWall" )[0 ]
98112 m1 = ifcopenshell .util .placement .get_local_placement (wall1 .ObjectPlacement )
99113 assert np .allclose (m1 [:, 3 ], (1 , 2 , 3 , 1 ))
100114 global_m1 = ifcopenshell .util .geolocation .auto_local2global (self .file , m1 , should_return_in_map_units = False )
101- assert np .allclose (global_m1 [:, 3 ], (11 , 22 , 3 , 1 ))
115+ assert np .allclose (global_m1 [:, 3 ], (11.332 , 21.796 , 3 , 1 ))
116+
117+ block = self .file .createIfcCsgSolid (self .file .createIfcBlock (o1 , 2 , 2 , 2 ))
118+ rep = builder1 .get_representation (context = body1 , items = [block ])
119+ ifcopenshell .api .geometry .assign_representation (self .file , product = wall1 , representation = rep )
120+ shape = ifcopenshell .geom .create_shape (ifcopenshell .geom .settings (), wall1 )
121+ verts = ifcopenshell .util .shape .get_shape_vertices (shape , shape .geometry )
122+ assert np .any (np .all (np .isclose (np .array ((1. , 2. , 3. )), verts ), axis = 1 ))
123+ assert np .any (np .all (np .isclose (np .array ((3. , 4. , 5. )), verts ), axis = 1 ))
102124
103125 # Second file is in millimeters with a different false origin
104126 wall1 = second_file .by_type ("IfcWall" )[0 ]
105127 m1 = ifcopenshell .util .placement .get_local_placement (wall1 .ObjectPlacement )
106128 assert np .allclose (m1 [:, 3 ], (1000 , 2000 , 3000 , 1 ))
107129 global_m1 = ifcopenshell .util .geolocation .auto_local2global (second_file , m1 , should_return_in_map_units = False )
108- assert np .allclose (global_m1 [:, 3 ], (31000 , 42000 , 3000 , 1 ))
130+ assert np .allclose (global_m1 [:, 3 ], (31866 , 41232 , 3000 , 1 ))
131+
132+ block = second_file .createIfcCsgSolid (second_file .createIfcBlock (o2 , 2000 , 2000 , 2000 ))
133+ rep = builder2 .get_representation (context = body2 , items = [block ])
134+ ifcopenshell .api .geometry .assign_representation (second_file , product = wall1 , representation = rep )
135+ shape = ifcopenshell .geom .create_shape (ifcopenshell .geom .settings (), wall1 )
136+ verts = ifcopenshell .util .shape .get_shape_vertices (shape , shape .geometry )
137+ assert np .any (np .all (np .isclose (np .array ((1. , 2. , 3. )), verts ), axis = 1 ))
138+ assert np .any (np .all (np .isclose (np .array ((3. , 4. , 5. )), verts ), axis = 1 ))
109139
110140 output = ifcpatch .execute ({"file" : self .file , "recipe" : "MergeProject" , "arguments" : [second_file ]})
111141
@@ -117,11 +147,25 @@ def test_shifting_the_source_project_to_match_the_original_project_origin(self):
117147 params = ifcopenshell .util .geolocation .get_helmert_transformation_parameters (output )
118148 assert params .e == 10
119149 assert params .n == 20
150+ assert params .xaa == xaa1
151+ assert params .xao == xao1
152+
120153 wall1 , wall2 = output .by_type ("IfcWall" )
121154 m1 = ifcopenshell .util .placement .get_local_placement (wall1 .ObjectPlacement )
122155 m2 = ifcopenshell .util .placement .get_local_placement (wall2 .ObjectPlacement )
123156 assert np .allclose (m1 [:, 3 ], (1 , 2 , 3 , 1 ))
124- assert np .allclose (m2 [:, 3 ], (21 , 22 , 3 , 1 ))
157+ # assert np.allclose(m2[:, 3], (8.321, 29.321, 3, 1), atol=1e-3)
158+ assert np .allclose (m2 [:, 3 ], (17.847 , 24.707 , 3. , 1. ), atol = 1e-3 )
159+
160+ shape = ifcopenshell .geom .create_shape (ifcopenshell .geom .settings (), wall1 )
161+ verts = ifcopenshell .util .shape .get_shape_vertices (shape , shape .geometry )
162+ assert np .any (np .all (np .isclose (np .array ((1. , 2. , 3. )), verts ), axis = 1 ))
163+ assert np .any (np .all (np .isclose (np .array ((3. , 4. , 5. )), verts ), axis = 1 ))
164+
165+ shape = ifcopenshell .geom .create_shape (ifcopenshell .geom .settings (), wall2 )
166+ verts = ifcopenshell .util .shape .get_shape_vertices (shape , shape .geometry )
167+ assert np .any (np .all (np .isclose (np .array ((17.847 , 24.707 , 3. )), verts , atol = 1e-3 ), axis = 1 ))
168+ assert np .any (np .all (np .isclose (np .array ((20.410 , 25.902 , 5. )), verts , atol = 1e-3 ), axis = 1 ))
125169
126170
127171class TestMergeProjectIFC2X3 (test .bootstrap .IFC2X3 , TestMergeProject ):
0 commit comments