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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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_ViewFrame.h>
25 #include <OCCViewer_ViewPort3d.h>
28 extern QString REF_DATA_PATH;
29 const double EPS = 1E-3;
31 void test_HYDROGUI_BathymetryPrs::importTestBath( const Handle(HYDROData_Document)& theDoc )
33 myBath = Handle(HYDROData_Bathymetry)::DownCast( theDoc->CreateObject( KIND_BATHYMETRY ) );
35 QString fname = (REF_DATA_PATH + "/bathy.xyz");
36 CPPUNIT_ASSERT( myBath->ImportFromFiles( QStringList() << fname ) );
38 HYDROData_Bathymetry::AltitudePoints anAltitudePoints = myBath->GetAltitudePoints();
39 CPPUNIT_ASSERT_EQUAL( 14781, (int)anAltitudePoints.size() );
42 void test_HYDROGUI_BathymetryPrs::createBathPrs()
44 myBathPrs = new HYDROGUI_ShapeBathymetry( 0, TestViewer::context(), myBath );
46 myBathPrs->getAISObjects()[0]->SetAutoHilight( Standard_False );
49 myBathPrs->GetRange( min, max );
50 CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
51 CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
54 void test_HYDROGUI_BathymetryPrs::updateColors()
57 myBathPrs->GetRange( min, max );
59 TestViewer::colorScale()->SetRange( min, max );
60 myBathPrs->UpdateWithColorScale( TestViewer::colorScale() );
64 void test_HYDROGUI_BathymetryPrs::test_presentation()
66 TestViewer::eraseAll( true );
67 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
69 importTestBath( aDoc );
70 TestViewer::showColorScale( false );
75 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
76 CPPUNIT_ASSERT( !bprs.IsNull() );
78 TestViewer::show( bprs, 0, 0, true, "bathy_prs" );
80 //QTest::qWait( 50000 );
83 TestViewer::eraseAll( true );
86 void select( int x1, int y1, int x2, int y2 )
88 QPoint p1( x1, y1 ), p2( x2, y2 );
89 QWidget* w = TestViewer::viewWindow()->getViewPort();
90 QTest::mousePress( w, Qt::LeftButton, Qt::NoModifier, p1 );
91 QTest::mouseEvent( QTest::MouseMove, w, Qt::LeftButton, Qt::NoModifier, p2 );
92 QTest::mouseRelease( w, Qt::LeftButton, Qt::NoModifier, p2 );
93 qApp->processEvents();
96 void test_HYDROGUI_BathymetryPrs::test_selection()
98 TestViewer::eraseAll( true );
99 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
101 importTestBath( aDoc );
102 TestViewer::showColorScale( false );
107 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
108 CPPUNIT_ASSERT( !bprs.IsNull() );
110 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
111 CPPUNIT_ASSERT_IMAGES;
113 select( 150, 5, 350, 140 );
114 TestViewer::setKey( "bathy_selection" );
115 CPPUNIT_ASSERT_IMAGES
117 select( 5, 5, 6, 6 );
118 TestViewer::setKey( "bathy_prs" );
119 CPPUNIT_ASSERT_IMAGES
121 //QTest::qWait( 50000 );
124 TestViewer::eraseAll( true );
127 void test_HYDROGUI_BathymetryPrs::test_rescale_by_selection()
129 TestViewer::eraseAll( true );
130 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
132 importTestBath( aDoc );
133 TestViewer::showColorScale( false );
138 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
139 CPPUNIT_ASSERT( !bprs.IsNull() );
141 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
142 CPPUNIT_ASSERT_IMAGES;
144 // 1. Rescale by selection
145 select( 150, 100, 350, 125 );
146 myBathPrs->RescaleBySelection();
147 updateColors(); // In HYDRO GUI it should be done by displayer
149 //QTest::qWait( 50000 );
152 myBathPrs->GetRange( min, max );
153 CPPUNIT_ASSERT_DOUBLES_EQUAL( 177.78, min, EPS );
154 CPPUNIT_ASSERT_DOUBLES_EQUAL( 182.70, max, EPS );
156 TestViewer::colorScale()->GetRange( min, max );
157 CPPUNIT_ASSERT_DOUBLES_EQUAL( 177.78, min, EPS );
158 CPPUNIT_ASSERT_DOUBLES_EQUAL( 182.70, max, EPS );
160 TestViewer::setKey( "bathy_rescaled_selection" );
161 CPPUNIT_ASSERT_IMAGES;
163 //QTest::qWait( 50000 );
166 myBathPrs->Rescale( 180, 181 );
167 updateColors(); // In HYDRO GUI it should be done by displayer
169 myBathPrs->GetRange( min, max );
170 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
171 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
173 TestViewer::colorScale()->GetRange( min, max );
174 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
175 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
177 TestViewer::setKey( "bathy_rescaled_user" );
178 CPPUNIT_ASSERT_IMAGES;
180 //QTest::qWait( 50000 );
183 TestViewer::eraseAll( true );
186 void test_HYDROGUI_BathymetryPrs::test_rescale_by_visible()
188 TestViewer::eraseAll( true );
189 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
191 importTestBath( aDoc );
192 TestViewer::showColorScale( false );
197 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
198 CPPUNIT_ASSERT( !bprs.IsNull() );
200 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
201 CPPUNIT_ASSERT_IMAGES;
203 // Change aspect to see a part of bathymetry
204 OCCViewer_ViewPort3d* vp = TestViewer::viewWindow()->getViewPort();
205 Handle(V3d_View) v = vp->getView();
206 v->SetProj( 1, 1, 1 );
207 vp->fitRect( QRect( 500, 380, 100, 70 ) );
208 qApp->processEvents();
210 // Rescale to the visible part of bathymetry
211 myBathPrs->RescaleByVisible( TestViewer::viewWindow() );
212 updateColors(); // In HYDRO GUI it should be done by displayer
213 vp->fitAll(); // Necessary to see the whole presentation
217 myBathPrs->GetRange( min, max );
218 CPPUNIT_ASSERT_DOUBLES_EQUAL( 176.18, min, EPS );
219 CPPUNIT_ASSERT_DOUBLES_EQUAL( 179.55, max, EPS );
221 TestViewer::colorScale()->GetRange( min, max );
222 CPPUNIT_ASSERT_DOUBLES_EQUAL( 176.18, min, EPS );
223 CPPUNIT_ASSERT_DOUBLES_EQUAL( 179.55, max, EPS );
225 TestViewer::setKey( "bathy_rescaled_visible" );
226 CPPUNIT_ASSERT_IMAGES;
228 //QTest::qWait( 50000 );
230 TestViewer::eraseAll( true );
233 void test_HYDROGUI_BathymetryPrs::test_text_presentation()
235 TestViewer::eraseAll( true );
236 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
238 importTestBath( aDoc );
239 TestViewer::showColorScale( false );
244 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
245 CPPUNIT_ASSERT( !bprs.IsNull() );
247 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
248 CPPUNIT_ASSERT_IMAGES;
250 // Assign text labels
251 int x1 = 150, y1 = 100, x2 = 200, y2 = 150;
252 select( x1, y1, x2, y2 );
253 myBathPrs->TextLabels( true );
254 OCCViewer_ViewPort3d* vp = TestViewer::viewWindow()->getViewPort();
255 vp->fitRect( QRect( x1, y1, x2-x1, y2-y1 ) );
257 qApp->processEvents();
259 TestViewer::setKey( "bathy_text_labels" );
260 CPPUNIT_ASSERT_IMAGES;
262 // Disable text labels
263 myBathPrs->TextLabels( false );
265 qApp->processEvents();
266 TestViewer::setKey( "bathy_prs" );
267 CPPUNIT_ASSERT_IMAGES;
269 // Special case: flag=false + non-empty selection
270 select( x1, y1, x2, y2 );
271 myBathPrs->TextLabels( false );
273 qApp->processEvents();
274 TestViewer::setKey( "bathy_prs" );
275 CPPUNIT_ASSERT_IMAGES;
278 //QTest::qWait( 50000 );
281 TestViewer::eraseAll( true );
284 void test_HYDROGUI_BathymetryPrs::test_rescale_default()
286 TestViewer::eraseAll( true );
287 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
289 importTestBath( aDoc );
290 TestViewer::showColorScale( false );
295 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
296 CPPUNIT_ASSERT( !bprs.IsNull() );
298 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
299 CPPUNIT_ASSERT_IMAGES;
304 myBathPrs->Rescale( 180, 181 );
305 updateColors(); // In HYDRO GUI it should be done by displayer
307 myBathPrs->GetRange( min, max );
308 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
309 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
311 TestViewer::colorScale()->GetRange( min, max );
312 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
313 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
315 TestViewer::setKey( "bathy_rescaled_user" );
316 CPPUNIT_ASSERT_IMAGES;
318 //QTest::qWait( 50000 );
320 // 2. Default rescale
321 myBathPrs->RescaleDefault();
322 updateColors(); // In HYDRO GUI it should be done by displayer
324 myBathPrs->GetRange( min, max );
325 CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
326 CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
328 TestViewer::colorScale()->GetRange( min, max );
329 CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
330 CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
332 TestViewer::setKey( "bathy_prs" );
333 CPPUNIT_ASSERT_IMAGES;
335 //QTest::qWait( 50000 );
338 TestViewer::eraseAll( true );
341 void test_HYDROGUI_BathymetryPrs::test_fit_on_selected()
343 TestViewer::eraseAll( true );
344 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
346 importTestBath( aDoc );
347 TestViewer::showColorScale( false );
352 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
353 CPPUNIT_ASSERT( !bprs.IsNull() );
355 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
356 CPPUNIT_ASSERT_IMAGES;
358 // Fit selected points on bathymetry
359 int x1 = 100, y1 = 50, x2 = 250, y2 = 200;
360 select( x1, y1, x2, y2 );
361 TestViewer::viewWindow()->onFitSelection();
362 TestViewer::setKey( "bathy_prs_fit_selected" );
363 CPPUNIT_ASSERT_IMAGES;
365 //QTest::qWait( 50000 );
368 TestViewer::eraseAll( true );