Salome HOME
refs #1327: debug of automatic tests
[modules/hydro.git] / src / HYDRO_tests / test_HYDROGUI_BathymetryPrs.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <test_HYDROGUI_BathymetryPrs.h>
20 #include <HYDROGUI_ShapeBathymetry.h>
21 #include <TestViewer.h>
22 #include <AIS_ColorScale.hxx>
23 #include <OCCViewer_ViewWindow.h>
24 #include <OCCViewer_ViewPort3d.h>
25 #include <QTest>
26
27 extern QString REF_DATA_PATH;
28 const double EPS = 1E-3;
29
30 void test_HYDROGUI_BathymetryPrs::importTestBath( const Handle(HYDROData_Document)& theDoc )
31 {
32   myBath = Handle(HYDROData_Bathymetry)::DownCast( theDoc->CreateObject( KIND_BATHYMETRY ) );
33
34   QString fname = (REF_DATA_PATH + "/bathy.xyz");
35   CPPUNIT_ASSERT( myBath->ImportFromFiles( QStringList() << fname ) );
36
37   HYDROData_Bathymetry::AltitudePoints anAltitudePoints = myBath->GetAltitudePoints();
38   CPPUNIT_ASSERT_EQUAL( 14781, (int)anAltitudePoints.size() );
39 }
40
41 void test_HYDROGUI_BathymetryPrs::createBathPrs()
42 {
43   myBathPrs = new HYDROGUI_ShapeBathymetry( 0, TestViewer::context(), myBath );
44   myBathPrs->Build();
45
46   double min, max;
47   myBathPrs->GetRange( min, max );
48   CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
49   CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
50 }
51
52 void test_HYDROGUI_BathymetryPrs::updateColors()
53 {
54   double min, max;
55   myBathPrs->GetRange( min, max );
56
57   TestViewer::colorScale()->SetRange( min, max );
58   myBathPrs->UpdateWithColorScale( TestViewer::colorScale() );
59 }
60
61
62 void test_HYDROGUI_BathymetryPrs::test_presentation()
63 {
64   TestViewer::eraseAll( true );
65   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
66   
67   importTestBath( aDoc );
68   TestViewer::showColorScale( false );
69
70   createBathPrs();
71   updateColors();
72
73   Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
74   CPPUNIT_ASSERT( !bprs.IsNull() );
75
76   TestViewer::show( bprs, 0, 0, true, "bathy_prs" );
77   CPPUNIT_ASSERT_IMAGES
78   //QTest::qWait( 50000 );
79
80   aDoc->Close();
81   TestViewer::eraseAll( true );
82 }
83
84 void select( int x1, int y1, int x2, int y2 )
85 {
86   QPoint p1( x1, y1 ), p2( x2, y2 );
87   QWidget* w = TestViewer::viewWindow()->getViewPort();
88   QTest::mousePress( w, Qt::LeftButton, Qt::NoModifier, p1 );
89   QTest::mouseEvent( QTest::MouseMove, w, Qt::LeftButton, Qt::NoModifier, p2 );
90   QTest::mouseRelease( w, Qt::LeftButton, Qt::NoModifier, p2 );
91   qApp->processEvents();
92 }
93
94 void test_HYDROGUI_BathymetryPrs::test_selection()
95 {
96   TestViewer::eraseAll( true );
97   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
98
99   importTestBath( aDoc );
100   TestViewer::showColorScale( false );
101
102   createBathPrs();
103   updateColors();
104
105   Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
106   CPPUNIT_ASSERT( !bprs.IsNull() );
107
108   TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
109   CPPUNIT_ASSERT_IMAGES;
110
111   select( 150, 5, 350, 140 );
112   TestViewer::setKey( "bathy_selection" );
113   CPPUNIT_ASSERT_IMAGES
114
115   //QTest::qWait( 50000 );
116
117   aDoc->Close();
118   TestViewer::eraseAll( true );
119 }
120
121 void test_HYDROGUI_BathymetryPrs::test_rescale_by_selection()
122 {
123   TestViewer::eraseAll( true );
124   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
125
126   importTestBath( aDoc );
127   TestViewer::showColorScale( false );
128
129   createBathPrs();
130   updateColors();
131
132   Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
133   CPPUNIT_ASSERT( !bprs.IsNull() );
134
135   TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
136   CPPUNIT_ASSERT_IMAGES;
137
138   // 1. Rescale by selection
139   select( 150, 100, 350, 125 );
140   myBathPrs->RescaleBySelection();
141   updateColors(); // In HYDRO GUI it should be done by displayer
142
143   //QTest::qWait( 50000 );
144
145   double min, max;
146   myBathPrs->GetRange( min, max );
147   CPPUNIT_ASSERT_DOUBLES_EQUAL( 177.78, min, EPS );
148   CPPUNIT_ASSERT_DOUBLES_EQUAL( 182.70, max, EPS );
149
150   TestViewer::colorScale()->GetRange( min, max );
151   CPPUNIT_ASSERT_DOUBLES_EQUAL( 177.78, min, EPS );
152   CPPUNIT_ASSERT_DOUBLES_EQUAL( 182.70, max, EPS );
153
154   TestViewer::setKey( "bathy_rescaled_selection" );
155   CPPUNIT_ASSERT_IMAGES;
156
157   //QTest::qWait( 50000 );
158
159   // 2. User rescale
160   myBathPrs->Rescale( 180, 181 );
161   updateColors(); // In HYDRO GUI it should be done by displayer
162
163   myBathPrs->GetRange( min, max );
164   CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
165   CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
166
167   TestViewer::colorScale()->GetRange( min, max );
168   CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
169   CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
170
171   TestViewer::setKey( "bathy_rescaled_user" );
172   CPPUNIT_ASSERT_IMAGES;
173
174   //QTest::qWait( 50000 );
175
176   aDoc->Close();
177   TestViewer::eraseAll( true );
178 }
179
180 void test_HYDROGUI_BathymetryPrs::test_rescale_by_visible()
181 {
182   TestViewer::eraseAll( true );
183   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
184
185   importTestBath( aDoc );
186   TestViewer::showColorScale( false );
187
188   createBathPrs();
189   updateColors();
190
191   Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
192   CPPUNIT_ASSERT( !bprs.IsNull() );
193
194   TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
195   CPPUNIT_ASSERT_IMAGES;
196
197   // Change aspect to see a part of bathymetry
198   OCCViewer_ViewPort3d* vp = TestViewer::viewWindow()->getViewPort();
199   Handle(V3d_View) v = vp->getView();
200   v->SetProj( 1, 1, 1 );
201   vp->fitRect( QRect( 500, 380, 100, 70 ) );
202   qApp->processEvents();
203
204   // Rescale to the visible part of bathymetry
205   myBathPrs->RescaleByVisible( TestViewer::viewWindow() );
206   updateColors(); // In HYDRO GUI it should be done by displayer
207   vp->fitAll(); // Necessary to see the whole presentation
208
209   // Check parameters
210   double min, max;
211   myBathPrs->GetRange( min, max );
212   CPPUNIT_ASSERT_DOUBLES_EQUAL( 176.18, min, EPS );
213   CPPUNIT_ASSERT_DOUBLES_EQUAL( 179.55, max, EPS );
214
215   TestViewer::colorScale()->GetRange( min, max );
216   CPPUNIT_ASSERT_DOUBLES_EQUAL( 176.18, min, EPS );
217   CPPUNIT_ASSERT_DOUBLES_EQUAL( 179.55, max, EPS );
218
219   TestViewer::setKey( "bathy_rescaled_visible" );
220   CPPUNIT_ASSERT_IMAGES;
221
222   //QTest::qWait( 50000 );
223   aDoc->Close();
224   TestViewer::eraseAll( true );
225 }
226
227 void test_HYDROGUI_BathymetryPrs::test_text_presentation()
228 {
229   TestViewer::eraseAll( true );
230   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
231
232   importTestBath( aDoc );
233   TestViewer::showColorScale( false );
234
235   createBathPrs();
236   updateColors();
237
238   Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
239   CPPUNIT_ASSERT( !bprs.IsNull() );
240
241   TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
242   CPPUNIT_ASSERT_IMAGES;
243
244   // Assign text labels
245   int x1 = 150, y1 = 100, x2 = 200, y2 = 150;
246   select( x1, y1, x2, y2 );
247   myBathPrs->TextLabels( true );
248   OCCViewer_ViewPort3d* vp = TestViewer::viewWindow()->getViewPort();
249   vp->fitRect( QRect( x1, y1, x2-x1, y2-y1 ) );
250
251   qApp->processEvents();
252
253   TestViewer::setKey( "bathy_text_labels" );
254   CPPUNIT_ASSERT_IMAGES;
255
256   //QTest::qWait( 50000 );
257
258   aDoc->Close();
259   TestViewer::eraseAll( true );
260 }
261
262 void test_HYDROGUI_BathymetryPrs::test_rescale_default()
263 {
264   TestViewer::eraseAll( true );
265   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
266
267   importTestBath( aDoc );
268   TestViewer::showColorScale( false );
269
270   createBathPrs();
271   updateColors();
272
273   Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
274   CPPUNIT_ASSERT( !bprs.IsNull() );
275
276   TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
277   CPPUNIT_ASSERT_IMAGES;
278
279   double min, max;
280
281   // 1. User rescale
282   myBathPrs->Rescale( 180, 181 );
283   updateColors(); // In HYDRO GUI it should be done by displayer
284
285   myBathPrs->GetRange( min, max );
286   CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
287   CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
288
289   TestViewer::colorScale()->GetRange( min, max );
290   CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
291   CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
292
293   TestViewer::setKey( "bathy_rescaled_user" );
294   CPPUNIT_ASSERT_IMAGES;
295
296   //QTest::qWait( 50000 );
297
298   // 2. Default rescale
299   myBathPrs->RescaleDefault();
300   updateColors(); // In HYDRO GUI it should be done by displayer
301
302   myBathPrs->GetRange( min, max );
303   CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
304   CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
305
306   TestViewer::colorScale()->GetRange( min, max );
307   CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
308   CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
309
310   TestViewer::setKey( "bathy_prs" );
311   CPPUNIT_ASSERT_IMAGES;
312
313   //QTest::qWait( 50000 );
314
315   aDoc->Close();
316   TestViewer::eraseAll( true );
317 }