Salome HOME
39b7b9c9bbff892787b687f9805cc34de215e825
[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   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
97
98   importTestBath( aDoc );
99   TestViewer::showColorScale( false );
100
101   createBathPrs();
102   updateColors();
103
104   Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
105   CPPUNIT_ASSERT( !bprs.IsNull() );
106
107   TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
108   CPPUNIT_ASSERT_IMAGES;
109
110   select( 150, 5, 350, 140 );
111   TestViewer::setKey( "bathy_selection" );
112   CPPUNIT_ASSERT_IMAGES
113
114   //QTest::qWait( 50000 );
115
116   aDoc->Close();
117   TestViewer::eraseAll( true );
118 }
119
120 void test_HYDROGUI_BathymetryPrs::test_rescale_by_selection()
121 {
122   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
123
124   importTestBath( aDoc );
125   TestViewer::showColorScale( false );
126
127   createBathPrs();
128   updateColors();
129
130   Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
131   CPPUNIT_ASSERT( !bprs.IsNull() );
132
133   TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
134   CPPUNIT_ASSERT_IMAGES;
135
136   // 1. Rescale by selection
137   select( 150, 100, 350, 125 );
138   myBathPrs->RescaleBySelection();
139   updateColors(); // In HYDRO GUI it should be done by displayer
140
141   double min, max;
142   myBathPrs->GetRange( min, max );
143   CPPUNIT_ASSERT_DOUBLES_EQUAL( 177.78, min, EPS );
144   CPPUNIT_ASSERT_DOUBLES_EQUAL( 182.70, max, EPS );
145
146   TestViewer::colorScale()->GetRange( min, max );
147   CPPUNIT_ASSERT_DOUBLES_EQUAL( 177.78, min, EPS );
148   CPPUNIT_ASSERT_DOUBLES_EQUAL( 182.70, max, EPS );
149
150   TestViewer::setKey( "bathy_rescaled_selection" );
151   CPPUNIT_ASSERT_IMAGES;
152
153   //QTest::qWait( 50000 );
154
155   // 2. User rescale
156   myBathPrs->Rescale( 180, 181 );
157   updateColors(); // In HYDRO GUI it should be done by displayer
158
159   myBathPrs->GetRange( min, max );
160   CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
161   CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
162
163   TestViewer::colorScale()->GetRange( min, max );
164   CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
165   CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
166
167   TestViewer::setKey( "bathy_rescaled_user" );
168   CPPUNIT_ASSERT_IMAGES;
169
170   //QTest::qWait( 50000 );
171
172   aDoc->Close();
173   TestViewer::eraseAll( true );
174 }
175
176 void test_HYDROGUI_BathymetryPrs::test_rescale_by_visible()
177 {
178   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
179
180   importTestBath( aDoc );
181   TestViewer::showColorScale( false );
182
183   createBathPrs();
184   updateColors();
185
186   Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
187   CPPUNIT_ASSERT( !bprs.IsNull() );
188
189   TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
190   CPPUNIT_ASSERT_IMAGES;
191
192   // Change aspect to see a part of bathymetry
193   OCCViewer_ViewPort3d* vp = TestViewer::viewWindow()->getViewPort();
194   Handle(V3d_View) v = vp->getView();
195   v->SetProj( 1, 1, 1 );
196   vp->fitRect( QRect( 500, 380, 100, 70 ) );
197   qApp->processEvents();
198
199   // Rescale to the visible part of bathymetry
200   myBathPrs->RescaleByVisible( TestViewer::viewWindow() );
201   updateColors(); // In HYDRO GUI it should be done by displayer
202   vp->fitAll(); // Necessary to see the whole presentation
203
204   // Check parameters
205   double min, max;
206   myBathPrs->GetRange( min, max );
207   CPPUNIT_ASSERT_DOUBLES_EQUAL( 176.18, min, EPS );
208   CPPUNIT_ASSERT_DOUBLES_EQUAL( 179.55, max, EPS );
209
210   TestViewer::colorScale()->GetRange( min, max );
211   CPPUNIT_ASSERT_DOUBLES_EQUAL( 176.18, min, EPS );
212   CPPUNIT_ASSERT_DOUBLES_EQUAL( 179.55, max, EPS );
213
214   TestViewer::setKey( "bathy_rescaled_visible" );
215   CPPUNIT_ASSERT_IMAGES;
216
217   //QTest::qWait( 50000 );
218 }
219
220 void test_HYDROGUI_BathymetryPrs::test_text_presentation()
221 {
222   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
223
224   importTestBath( aDoc );
225   TestViewer::showColorScale( false );
226
227   createBathPrs();
228   updateColors();
229
230   Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
231   CPPUNIT_ASSERT( !bprs.IsNull() );
232
233   TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
234   CPPUNIT_ASSERT_IMAGES;
235
236   // Assign text labels
237   int x1 = 150, y1 = 100, x2 = 200, y2 = 150;
238   select( x1, y1, x2, y2 );
239   myBathPrs->TextLabels( true );
240   OCCViewer_ViewPort3d* vp = TestViewer::viewWindow()->getViewPort();
241   vp->fitRect( QRect( x1, y1, x2-x1, y2-y1 ) );
242
243   qApp->processEvents();
244
245   TestViewer::setKey( "bathy_text_labels" );
246   CPPUNIT_ASSERT_IMAGES;
247
248   //QTest::qWait( 50000 );
249
250   aDoc->Close();
251   TestViewer::eraseAll( true );
252 }
253
254 void test_HYDROGUI_BathymetryPrs::test_rescale_default()
255 {
256   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
257
258   importTestBath( aDoc );
259   TestViewer::showColorScale( false );
260
261   createBathPrs();
262   updateColors();
263
264   Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
265   CPPUNIT_ASSERT( !bprs.IsNull() );
266
267   TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
268   CPPUNIT_ASSERT_IMAGES;
269
270   double min, max;
271
272   // 1. User rescale
273   myBathPrs->Rescale( 180, 181 );
274   updateColors(); // In HYDRO GUI it should be done by displayer
275
276   myBathPrs->GetRange( min, max );
277   CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
278   CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
279
280   TestViewer::colorScale()->GetRange( min, max );
281   CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
282   CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
283
284   TestViewer::setKey( "bathy_rescaled_user" );
285   CPPUNIT_ASSERT_IMAGES;
286
287   //QTest::qWait( 50000 );
288
289   // 2. Default rescale
290   myBathPrs->RescaleDefault();
291   updateColors(); // In HYDRO GUI it should be done by displayer
292
293   myBathPrs->GetRange( min, max );
294   CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
295   CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
296
297   TestViewer::colorScale()->GetRange( min, max );
298   CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
299   CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
300
301   TestViewer::setKey( "bathy_prs" );
302   CPPUNIT_ASSERT_IMAGES;
303
304   //QTest::qWait( 50000 );
305
306   aDoc->Close();
307   TestViewer::eraseAll( true );
308 }