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_ViewPort3d.h>
27 extern QString REF_DATA_PATH;
28 const double EPS = 1E-3;
30 void test_HYDROGUI_BathymetryPrs::importTestBath( const Handle(HYDROData_Document)& theDoc )
32 myBath = Handle(HYDROData_Bathymetry)::DownCast( theDoc->CreateObject( KIND_BATHYMETRY ) );
34 QString fname = (REF_DATA_PATH + "/bathy.xyz");
35 CPPUNIT_ASSERT( myBath->ImportFromFiles( QStringList() << fname ) );
37 HYDROData_Bathymetry::AltitudePoints anAltitudePoints = myBath->GetAltitudePoints();
38 CPPUNIT_ASSERT_EQUAL( 14781, (int)anAltitudePoints.size() );
41 void test_HYDROGUI_BathymetryPrs::createBathPrs()
43 myBathPrs = new HYDROGUI_ShapeBathymetry( 0, TestViewer::context(), myBath );
47 myBathPrs->GetRange( min, max );
48 CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
49 CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
52 void test_HYDROGUI_BathymetryPrs::updateColors()
55 myBathPrs->GetRange( min, max );
57 TestViewer::colorScale()->SetRange( min, max );
58 myBathPrs->UpdateWithColorScale( TestViewer::colorScale() );
62 void test_HYDROGUI_BathymetryPrs::test_presentation()
64 TestViewer::eraseAll( true );
65 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
67 importTestBath( aDoc );
68 TestViewer::showColorScale( false );
73 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
74 CPPUNIT_ASSERT( !bprs.IsNull() );
76 TestViewer::show( bprs, 0, 0, true, "bathy_prs" );
78 //QTest::qWait( 50000 );
81 TestViewer::eraseAll( true );
84 void select( int x1, int y1, int x2, int y2 )
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();
94 void test_HYDROGUI_BathymetryPrs::test_selection()
96 TestViewer::eraseAll( true );
97 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
99 importTestBath( aDoc );
100 TestViewer::showColorScale( false );
105 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
106 CPPUNIT_ASSERT( !bprs.IsNull() );
108 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
109 CPPUNIT_ASSERT_IMAGES;
111 select( 150, 5, 350, 140 );
112 TestViewer::setKey( "bathy_selection" );
113 CPPUNIT_ASSERT_IMAGES
115 //QTest::qWait( 50000 );
118 TestViewer::eraseAll( true );
121 void test_HYDROGUI_BathymetryPrs::test_rescale_by_selection()
123 TestViewer::eraseAll( true );
124 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
126 importTestBath( aDoc );
127 TestViewer::showColorScale( false );
132 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
133 CPPUNIT_ASSERT( !bprs.IsNull() );
135 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
136 CPPUNIT_ASSERT_IMAGES;
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
143 //QTest::qWait( 50000 );
146 myBathPrs->GetRange( min, max );
147 CPPUNIT_ASSERT_DOUBLES_EQUAL( 177.78, min, EPS );
148 CPPUNIT_ASSERT_DOUBLES_EQUAL( 182.70, max, EPS );
150 TestViewer::colorScale()->GetRange( min, max );
151 CPPUNIT_ASSERT_DOUBLES_EQUAL( 177.78, min, EPS );
152 CPPUNIT_ASSERT_DOUBLES_EQUAL( 182.70, max, EPS );
154 TestViewer::setKey( "bathy_rescaled_selection" );
155 CPPUNIT_ASSERT_IMAGES;
157 //QTest::qWait( 50000 );
160 myBathPrs->Rescale( 180, 181 );
161 updateColors(); // In HYDRO GUI it should be done by displayer
163 myBathPrs->GetRange( min, max );
164 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
165 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
167 TestViewer::colorScale()->GetRange( min, max );
168 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
169 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
171 TestViewer::setKey( "bathy_rescaled_user" );
172 CPPUNIT_ASSERT_IMAGES;
174 //QTest::qWait( 50000 );
177 TestViewer::eraseAll( true );
180 void test_HYDROGUI_BathymetryPrs::test_rescale_by_visible()
182 TestViewer::eraseAll( true );
183 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
185 importTestBath( aDoc );
186 TestViewer::showColorScale( false );
191 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
192 CPPUNIT_ASSERT( !bprs.IsNull() );
194 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
195 CPPUNIT_ASSERT_IMAGES;
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();
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
211 myBathPrs->GetRange( min, max );
212 CPPUNIT_ASSERT_DOUBLES_EQUAL( 176.18, min, EPS );
213 CPPUNIT_ASSERT_DOUBLES_EQUAL( 179.55, max, EPS );
215 TestViewer::colorScale()->GetRange( min, max );
216 CPPUNIT_ASSERT_DOUBLES_EQUAL( 176.18, min, EPS );
217 CPPUNIT_ASSERT_DOUBLES_EQUAL( 179.55, max, EPS );
219 TestViewer::setKey( "bathy_rescaled_visible" );
220 CPPUNIT_ASSERT_IMAGES;
222 //QTest::qWait( 50000 );
224 TestViewer::eraseAll( true );
227 void test_HYDROGUI_BathymetryPrs::test_text_presentation()
229 TestViewer::eraseAll( true );
230 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
232 importTestBath( aDoc );
233 TestViewer::showColorScale( false );
238 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
239 CPPUNIT_ASSERT( !bprs.IsNull() );
241 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
242 CPPUNIT_ASSERT_IMAGES;
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 ) );
251 qApp->processEvents();
253 TestViewer::setKey( "bathy_text_labels" );
254 CPPUNIT_ASSERT_IMAGES;
256 //QTest::qWait( 50000 );
259 TestViewer::eraseAll( true );
262 void test_HYDROGUI_BathymetryPrs::test_rescale_default()
264 TestViewer::eraseAll( true );
265 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
267 importTestBath( aDoc );
268 TestViewer::showColorScale( false );
273 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
274 CPPUNIT_ASSERT( !bprs.IsNull() );
276 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
277 CPPUNIT_ASSERT_IMAGES;
282 myBathPrs->Rescale( 180, 181 );
283 updateColors(); // In HYDRO GUI it should be done by displayer
285 myBathPrs->GetRange( min, max );
286 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
287 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
289 TestViewer::colorScale()->GetRange( min, max );
290 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
291 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
293 TestViewer::setKey( "bathy_rescaled_user" );
294 CPPUNIT_ASSERT_IMAGES;
296 //QTest::qWait( 50000 );
298 // 2. Default rescale
299 myBathPrs->RescaleDefault();
300 updateColors(); // In HYDRO GUI it should be done by displayer
302 myBathPrs->GetRange( min, max );
303 CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
304 CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
306 TestViewer::colorScale()->GetRange( min, max );
307 CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
308 CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
310 TestViewer::setKey( "bathy_prs" );
311 CPPUNIT_ASSERT_IMAGES;
313 //QTest::qWait( 50000 );
316 TestViewer::eraseAll( true );