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 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
98 importTestBath( aDoc );
99 TestViewer::showColorScale( false );
104 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
105 CPPUNIT_ASSERT( !bprs.IsNull() );
107 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
108 CPPUNIT_ASSERT_IMAGES;
110 select( 150, 5, 350, 140 );
111 TestViewer::setKey( "bathy_selection" );
112 CPPUNIT_ASSERT_IMAGES
114 //QTest::qWait( 50000 );
117 TestViewer::eraseAll( true );
120 void test_HYDROGUI_BathymetryPrs::test_rescale_by_selection()
122 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
124 importTestBath( aDoc );
125 TestViewer::showColorScale( false );
130 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
131 CPPUNIT_ASSERT( !bprs.IsNull() );
133 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
134 CPPUNIT_ASSERT_IMAGES;
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
142 myBathPrs->GetRange( min, max );
143 CPPUNIT_ASSERT_DOUBLES_EQUAL( 177.78, min, EPS );
144 CPPUNIT_ASSERT_DOUBLES_EQUAL( 182.70, max, EPS );
146 TestViewer::colorScale()->GetRange( min, max );
147 CPPUNIT_ASSERT_DOUBLES_EQUAL( 177.78, min, EPS );
148 CPPUNIT_ASSERT_DOUBLES_EQUAL( 182.70, max, EPS );
150 TestViewer::setKey( "bathy_rescaled_selection" );
151 CPPUNIT_ASSERT_IMAGES;
153 //QTest::qWait( 50000 );
156 myBathPrs->Rescale( 180, 181 );
157 updateColors(); // In HYDRO GUI it should be done by displayer
159 myBathPrs->GetRange( min, max );
160 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
161 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
163 TestViewer::colorScale()->GetRange( min, max );
164 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
165 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
167 TestViewer::setKey( "bathy_rescaled_user" );
168 CPPUNIT_ASSERT_IMAGES;
170 //QTest::qWait( 50000 );
173 TestViewer::eraseAll( true );
176 void test_HYDROGUI_BathymetryPrs::test_rescale_by_visible()
178 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
180 importTestBath( aDoc );
181 TestViewer::showColorScale( false );
186 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
187 CPPUNIT_ASSERT( !bprs.IsNull() );
189 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
190 CPPUNIT_ASSERT_IMAGES;
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();
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
206 myBathPrs->GetRange( min, max );
207 CPPUNIT_ASSERT_DOUBLES_EQUAL( 176.18, min, EPS );
208 CPPUNIT_ASSERT_DOUBLES_EQUAL( 179.55, max, EPS );
210 TestViewer::colorScale()->GetRange( min, max );
211 CPPUNIT_ASSERT_DOUBLES_EQUAL( 176.18, min, EPS );
212 CPPUNIT_ASSERT_DOUBLES_EQUAL( 179.55, max, EPS );
214 TestViewer::setKey( "bathy_rescaled_visible" );
215 CPPUNIT_ASSERT_IMAGES;
217 //QTest::qWait( 50000 );
220 void test_HYDROGUI_BathymetryPrs::test_text_presentation()
222 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
224 importTestBath( aDoc );
225 TestViewer::showColorScale( false );
230 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
231 CPPUNIT_ASSERT( !bprs.IsNull() );
233 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
234 CPPUNIT_ASSERT_IMAGES;
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 ) );
243 qApp->processEvents();
245 TestViewer::setKey( "bathy_text_labels" );
246 CPPUNIT_ASSERT_IMAGES;
248 //QTest::qWait( 50000 );
251 TestViewer::eraseAll( true );
254 void test_HYDROGUI_BathymetryPrs::test_rescale_default()
256 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
258 importTestBath( aDoc );
259 TestViewer::showColorScale( false );
264 Handle(AIS_InteractiveObject) bprs = myBathPrs->getAISObject();
265 CPPUNIT_ASSERT( !bprs.IsNull() );
267 TestViewer::show( bprs, 0, 1, true, "bathy_prs" );
268 CPPUNIT_ASSERT_IMAGES;
273 myBathPrs->Rescale( 180, 181 );
274 updateColors(); // In HYDRO GUI it should be done by displayer
276 myBathPrs->GetRange( min, max );
277 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
278 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
280 TestViewer::colorScale()->GetRange( min, max );
281 CPPUNIT_ASSERT_DOUBLES_EQUAL( 180.0, min, EPS );
282 CPPUNIT_ASSERT_DOUBLES_EQUAL( 181.0, max, EPS );
284 TestViewer::setKey( "bathy_rescaled_user" );
285 CPPUNIT_ASSERT_IMAGES;
287 //QTest::qWait( 50000 );
289 // 2. Default rescale
290 myBathPrs->RescaleDefault();
291 updateColors(); // In HYDRO GUI it should be done by displayer
293 myBathPrs->GetRange( min, max );
294 CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
295 CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
297 TestViewer::colorScale()->GetRange( min, max );
298 CPPUNIT_ASSERT_DOUBLES_EQUAL( 175.56, min, EPS );
299 CPPUNIT_ASSERT_DOUBLES_EQUAL( 185.65, max, EPS );
301 TestViewer::setKey( "bathy_prs" );
302 CPPUNIT_ASSERT_IMAGES;
304 //QTest::qWait( 50000 );
307 TestViewer::eraseAll( true );