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() );
63 void test_HYDROGUI_BathymetryPrs::test_presentation()
65 TestViewer::eraseAll( true, true );
66 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
68 importTestBath( aDoc );
69 TestViewer::showColorScale( false );
74 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
75 CPPUNIT_ASSERT( !bprs.IsNull() );
77 TestViewer::show( bprs, 0, 0, true, "bathy_prs" );
79 //QTest::qWait( 50000 );
82 TestViewer::eraseAll( true, true );
85 void select( int x1, int y1, int x2, int y2 )
87 QPoint p1( x1, y1 ), p2( x2, y2 );
88 QWidget* w = TestViewer::viewWindow()->getViewPort();
89 QTest::mousePress( w, Qt::LeftButton, Qt::NoModifier, p1 );
90 QTest::mouseEvent( QTest::MouseMove, w, Qt::LeftButton, Qt::NoModifier, p2 );
91 QTest::mouseRelease( w, Qt::LeftButton, Qt::NoModifier, p2 );
92 qApp->processEvents();
95 void test_HYDROGUI_BathymetryPrs::test_selection()
97 TestViewer::eraseAll( true, true );
98 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
100 importTestBath( aDoc );
101 TestViewer::showColorScale( false );
106 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
107 CPPUNIT_ASSERT( !bprs.IsNull() );
109 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
110 CPPUNIT_ASSERT_IMAGES;
112 select( 150, 5, 350, 140 );
113 TestViewer::setKey( "bathy_selection" );
114 CPPUNIT_ASSERT_IMAGES
116 select( 5, 5, 6, 6 );
117 TestViewer::setKey( "bathy_prs" );
118 CPPUNIT_ASSERT_IMAGES
120 //QTest::qWait( 50000 );
123 TestViewer::eraseAll( true, true );
126 void test_HYDROGUI_BathymetryPrs::test_rescale_by_selection()
128 TestViewer::eraseAll( true, true );
129 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
131 importTestBath( aDoc );
132 TestViewer::showColorScale( false );
137 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
138 CPPUNIT_ASSERT( !bprs.IsNull() );
140 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
141 CPPUNIT_ASSERT_IMAGES;
143 // 1. Rescale by selection
144 select( 150, 100, 350, 125 );
145 myBathPrs->RescaleBySelection();
146 updateColors(); // In HYDRO GUI it should be done by displayer
148 //QTest::qWait( 50000 );
151 myBathPrs->GetRange( min, max );
152 CPPUNIT_ASSERT_DOUBLES_EQUAL( 177.78, min, EPS );
153 CPPUNIT_ASSERT_DOUBLES_EQUAL( 182.70, max, EPS );
155 TestViewer::colorScale()->GetRange( min, max );
156 CPPUNIT_ASSERT_DOUBLES_EQUAL( 177.78, min, EPS );
157 CPPUNIT_ASSERT_DOUBLES_EQUAL( 182.70, max, EPS );
159 TestViewer::setKey( "bathy_rescaled_selection" );
160 CPPUNIT_ASSERT_IMAGES;
162 //QTest::qWait( 50000 );
165 myBathPrs->Rescale( 180, 181 );
166 updateColors(); // In HYDRO GUI it should be done by displayer
168 myBathPrs->GetRange( min, max );
169 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
170 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
172 TestViewer::colorScale()->GetRange( min, max );
173 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
174 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
176 TestViewer::setKey( "bathy_rescaled_user" );
177 CPPUNIT_ASSERT_IMAGES;
179 //QTest::qWait( 50000 );
182 TestViewer::eraseAll( true, true );
185 void test_HYDROGUI_BathymetryPrs::test_rescale_by_visible()
187 TestViewer::eraseAll( true, true );
188 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
190 importTestBath( aDoc );
191 TestViewer::showColorScale( false );
196 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
197 CPPUNIT_ASSERT( !bprs.IsNull() );
199 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
200 CPPUNIT_ASSERT_IMAGES;
202 // Change aspect to see a part of bathymetry
203 OCCViewer_ViewPort3d* vp = TestViewer::viewWindow()->getViewPort();
204 Handle(V3d_View) v = vp->getView();
205 v->SetProj( 1, 1, 1 );
206 vp->fitRect( QRect( 500, 380, 100, 70 ) );
207 qApp->processEvents();
209 // Rescale to the visible part of bathymetry
210 myBathPrs->RescaleByVisible( TestViewer::viewWindow() );
211 updateColors(); // In HYDRO GUI it should be done by displayer
212 vp->fitAll(); // Necessary to see the whole presentation
216 myBathPrs->GetRange( min, max );
217 CPPUNIT_ASSERT_DOUBLES_EQUAL( 176.18, min, EPS );
218 CPPUNIT_ASSERT_DOUBLES_EQUAL( 179.55, max, EPS );
220 TestViewer::colorScale()->GetRange( min, max );
221 CPPUNIT_ASSERT_DOUBLES_EQUAL( 176.18, min, EPS );
222 CPPUNIT_ASSERT_DOUBLES_EQUAL( 179.55, max, EPS );
224 TestViewer::setKey( "bathy_rescaled_visible" );
225 CPPUNIT_ASSERT_IMAGES;
227 //QTest::qWait( 50000 );
229 TestViewer::eraseAll( true, true );
232 void test_HYDROGUI_BathymetryPrs::test_text_presentation()
234 TestViewer::eraseAll( true, true );
235 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
237 importTestBath( aDoc );
238 TestViewer::showColorScale( false );
243 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
244 CPPUNIT_ASSERT( !bprs.IsNull() );
246 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
247 CPPUNIT_ASSERT_IMAGES;
249 // Assign text labels
250 int x1 = 150, y1 = 100, x2 = 200, y2 = 150;
251 select( x1, y1, x2, y2 );
252 myBathPrs->TextLabels( true );
253 OCCViewer_ViewPort3d* vp = TestViewer::viewWindow()->getViewPort();
254 vp->fitRect( QRect( x1, y1, x2-x1, y2-y1 ) );
256 qApp->processEvents();
258 TestViewer::setKey( "bathy_text_labels" );
259 CPPUNIT_ASSERT_IMAGES;
261 // Disable text labels
262 myBathPrs->TextLabels( false );
264 qApp->processEvents();
265 TestViewer::setKey( "bathy_prs" );
266 CPPUNIT_ASSERT_IMAGES;
268 // Special case: flag=false + non-empty selection
269 select( x1, y1, x2, y2 );
270 myBathPrs->TextLabels( false );
272 qApp->processEvents();
273 TestViewer::setKey( "bathy_prs" );
274 CPPUNIT_ASSERT_IMAGES;
277 //QTest::qWait( 50000 );
280 TestViewer::eraseAll( true, true );
283 void test_HYDROGUI_BathymetryPrs::test_rescale_default()
285 TestViewer::eraseAll( true, true );
286 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
288 importTestBath( aDoc );
289 TestViewer::showColorScale( false );
294 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
295 CPPUNIT_ASSERT( !bprs.IsNull() );
297 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
298 CPPUNIT_ASSERT_IMAGES;
303 myBathPrs->Rescale( 180, 181 );
304 updateColors(); // In HYDRO GUI it should be done by displayer
306 myBathPrs->GetRange( min, max );
307 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
308 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
310 TestViewer::colorScale()->GetRange( min, max );
311 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
312 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
314 TestViewer::setKey( "bathy_rescaled_user" );
315 CPPUNIT_ASSERT_IMAGES;
317 //QTest::qWait( 50000 );
319 // 2. Default rescale
320 myBathPrs->RescaleDefault();
321 updateColors(); // In HYDRO GUI it should be done by displayer
323 myBathPrs->GetRange( min, max );
324 CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
325 CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
327 TestViewer::colorScale()->GetRange( min, max );
328 CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
329 CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
331 TestViewer::setKey( "bathy_prs" );
332 CPPUNIT_ASSERT_IMAGES;
334 //QTest::qWait( 50000 );
337 TestViewer::eraseAll( true, true );
340 void test_HYDROGUI_BathymetryPrs::test_fit_on_selected()
342 TestViewer::eraseAll( true, true );
343 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
345 importTestBath( aDoc );
346 TestViewer::showColorScale( false );
351 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObjects()[0];
352 CPPUNIT_ASSERT( !bprs.IsNull() );
354 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
355 CPPUNIT_ASSERT_IMAGES;
357 // Fit selected points on bathymetry
358 int x1 = 100, y1 = 50, x2 = 250, y2 = 200;
359 select( x1, y1, x2, y2 );
360 TestViewer::viewWindow()->onFitSelection();
361 TestViewer::setKey( "bathy_prs_fit_selected" );
362 CPPUNIT_ASSERT_IMAGES;
364 //QTest::qWait( 50000 );
367 TestViewer::eraseAll( true, true );