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_HYDROData_Stream.h>
20 #include <HYDROGUI_StreamDlg.h>
21 #include <HYDROData_Document.h>
22 #include <HYDROData_DTM.h>
23 #include <HYDROData_Stream.h>
24 #include <HYDROData_IPolyline.h>
25 #include <HYDROData_Profile.h>
26 #include <HYDROData_PolylineXY.h>
27 #include <HYDROData_Iterator.h>
28 #include <AIS_InteractiveContext.hxx>
29 #include <AIS_ColorScale.hxx>
30 #include <TestViewer.h>
31 #include <QApplication>
34 #include <HYDROData_LISM.h>
35 #include <HYDROData_SinusX.h>
36 #include <HYDROGUI_ShapeBathymetry.h>
38 extern QString REF_DATA_PATH;
39 NCollection_Sequence<HYDROData_IPolyline::Point> points2;
40 const double EPS = 1E-3;
42 void test_HYDROData_Stream::setUp()
45 points2.Append( gp_XY( 0.0, 5.0 ) );
46 points2.Append( gp_XY( 1.0, 1.0 ) );
47 points2.Append( gp_XY( 1.5, 0.0 ) );
48 points2.Append( gp_XY( 4.0, 4.0 ) );
51 void test_HYDROData_Stream::tearDown()
55 void test_HYDROData_Stream::test_dialog()
58 TestViewer::eraseAll( true, true );
60 HYDROGUI_StreamDlg* aDlg = new HYDROGUI_StreamDlg( 0, "stream" );
62 qApp->processEvents();
64 QImage aStreamDlgImage = QPixmap::grabWidget( aDlg ).toImage();
65 CPPUNIT_ASSERT_IMAGES2( &aStreamDlgImage, "StreamDlg" );
67 aDlg->setDDZ( 12.34 );
68 CPPUNIT_ASSERT_DOUBLES_EQUAL( 12.34, aDlg->getDDZ(), EPS );
70 aDlg->setSpatialStep( 56.78 );
71 CPPUNIT_ASSERT_DOUBLES_EQUAL( 56.78, aDlg->getSpatialStep(), EPS );
76 void test_HYDROData_Stream::test_alt_object()
78 TestViewer::eraseAll( true, true );
80 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
82 Handle(HYDROData_Stream) aStream =
83 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
85 CPPUNIT_ASSERT_EQUAL( false, (bool)aStream.IsNull() );
86 CPPUNIT_ASSERT_EQUAL( true, (bool)aStream->GetAltitudeObject().IsNull() );
87 CPPUNIT_ASSERT_EQUAL( false, (bool)aStream->DTM().IsNull() );
88 CPPUNIT_ASSERT_EQUAL( false, (bool)aStream->GetAltitudeObject().IsNull() );
89 CPPUNIT_ASSERT_EQUAL( KIND_DTM, aStream->getAltitudeObjectType() );
91 Handle(HYDROData_DTM) aDTM =
92 Handle(HYDROData_DTM)::DownCast( aStream->GetAltitudeObject() );
93 CPPUNIT_ASSERT_EQUAL( false, (bool)aDTM.IsNull() );
98 void test_HYDROData_Stream::test_params_sync()
100 TestViewer::eraseAll( true, true );
102 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
104 Handle(HYDROData_Stream) aStream =
105 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
106 Handle(HYDROData_DTM) aDTM = aStream->DTM();
107 CPPUNIT_ASSERT_EQUAL( false, (bool)aDTM.IsNull() );
109 Handle(HYDROData_Profile) aProfile1 =
110 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
112 Handle(HYDROData_Profile) aProfile2 =
113 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
115 aProfile1->SetParametricPoints( points2 );
116 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
117 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
118 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
120 aProfile2->SetParametricPoints( points2 );
121 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
122 aProfile2->SetLeftPoint( gp_XY( 50, 0 ) );
123 aProfile2->SetRightPoint( gp_XY( 60, 10 ) );
125 HYDROData_SequenceOfObjects profiles;
126 profiles.Append( aProfile1 );
127 profiles.Append( aProfile2 );
129 aStream->SetProfiles( profiles, false );
130 aStream->SetDDZ( 3.14 );
131 aStream->SetSpatialStep( 4.14 );
133 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.14, aStream->GetDDZ(), EPS );
134 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.14, aDTM->GetDDZ(), EPS );
135 CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.14, aStream->GetSpatialStep(), EPS );
136 CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.14, aDTM->GetSpatialStep(), EPS );
138 HYDROData_SequenceOfObjects profiles1 = aStream->GetProfiles();
139 CPPUNIT_ASSERT_EQUAL( 2, profiles1.Size() );
140 CPPUNIT_ASSERT( profiles.Value(1)->Label() == profiles1.Value(1)->Label() );
141 CPPUNIT_ASSERT( profiles.Value(2)->Label() == profiles1.Value(2)->Label() );
143 HYDROData_SequenceOfObjects profiles2 = aDTM->GetProfiles();
144 CPPUNIT_ASSERT_EQUAL( 2, profiles2.Size() );
145 CPPUNIT_ASSERT( profiles.Value(1)->Label() == profiles2.Value(1)->Label() );
146 CPPUNIT_ASSERT( profiles.Value(2)->Label() == profiles2.Value(2)->Label() );
151 void test_HYDROData_Stream::test_dump()
153 TestViewer::eraseAll( true, true );
155 // Case 1. Without hydraulic axis
156 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
158 Handle(HYDROData_Stream) aStream1 =
159 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
160 aStream1->SetName( "stream_1" );
162 Handle(HYDROData_Profile) aProfile1 =
163 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
164 aProfile1->SetName( "p1" );
166 Handle(HYDROData_Profile) aProfile2 =
167 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
168 aProfile2->SetName( "p2" );
170 aProfile1->SetParametricPoints( points2 );
171 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
172 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
173 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
175 aProfile2->SetParametricPoints( points2 );
176 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
177 aProfile2->SetLeftPoint( gp_XY( 50, 0 ) );
178 aProfile2->SetRightPoint( gp_XY( 60, 10 ) );
180 HYDROData_SequenceOfObjects profiles;
181 profiles.Append( aProfile1 );
182 profiles.Append( aProfile2 );
184 aStream1->SetProfiles( profiles, false );
185 aStream1->SetDDZ( 0.2 );
186 aStream1->SetSpatialStep( 3.0 );
188 MapOfTreatedObjects objs;
189 objs["p1"] = aProfile1;
190 objs["p2"] = aProfile2;
192 QStringList aScript1 = aStream1->DumpToPython( "", objs );
194 CPPUNIT_ASSERT_EQUAL( 11, aScript1.size() );
195 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1 = hydro_doc.CreateObject( KIND_STREAM )" ), aScript1[0].toStdString() );
196 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetName( \"stream_1\" )" ), aScript1[1].toStdString() );
197 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[2].toStdString() );
198 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetInterpolationMethod( 0 )" ), aScript1[3].toStdString() );
199 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.AddProfile( p1 )" ), aScript1[4].toStdString() );
200 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.AddProfile( p2 )" ), aScript1[5].toStdString() );
201 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetDDZ( 0.200 )" ), aScript1[6].toStdString() );
202 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetSpatialStep( 3.000 )" ), aScript1[7].toStdString() );
203 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[8].toStdString() );
204 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.Update()" ), aScript1[9].toStdString() );
205 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[10].toStdString() );
207 // Case 2. With hydraulic axis
209 Handle(HYDROData_Stream) aStream2 =
210 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
211 aStream2->SetName( "stream_2" );
213 Handle(HYDROData_PolylineXY) anHAxis =
214 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
215 anHAxis->SetName( "axis" );
217 aStream2->SetProfiles( profiles, false );
218 aStream2->SetDDZ( 0.2 );
219 aStream2->SetSpatialStep( 3.0 );
220 aStream2->SetReferenceObject( anHAxis, HYDROData_Stream::DataTag_HydraulicAxis );
223 objs["p1"] = aProfile1;
224 objs["p2"] = aProfile2;
225 objs["axis"] = anHAxis;
227 QStringList aScript2 = aStream2->DumpToPython( "", objs );
228 CPPUNIT_ASSERT_EQUAL( 12, aScript2.size() );
229 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2 = hydro_doc.CreateObject( KIND_STREAM )" ), aScript2[0].toStdString() );
230 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetName( \"stream_2\" )" ), aScript2[1].toStdString() );
231 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript2[2].toStdString() );
232 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetInterpolationMethod( 0 )" ), aScript2[3].toStdString() );
233 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetHydraulicAxis( axis )" ), aScript2[4].toStdString() );
234 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.AddProfile( p1 )" ), aScript2[5].toStdString() );
235 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.AddProfile( p2 )" ), aScript2[6].toStdString() );
236 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetDDZ( 0.200 )" ), aScript2[7].toStdString() );
237 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetSpatialStep( 3.000 )" ), aScript2[8].toStdString() );
238 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript2[9].toStdString() );
239 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.Update()" ), aScript2[10].toStdString() );
240 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript2[11].toStdString() );
245 void test_HYDROData_Stream::test_presentation()
247 TestViewer::eraseAll( true, true );
249 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
251 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
252 fname += "/Profiles.xyz";
253 NCollection_Sequence<int> bad_ids;
255 int aSize = HYDROData_Profile::ImportFromFile( aDoc, fname, bad_ids, true );
257 CPPUNIT_ASSERT_EQUAL( 0, bad_ids.Size() );
258 CPPUNIT_ASSERT_EQUAL( 46, aSize );
260 HYDROData_SequenceOfObjects profiles;
261 HYDROData_Iterator it( aDoc, KIND_PROFILE );
262 for( int i=0; it.More(); it.Next(), i++ )
266 it.Current()->Update();
267 profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) );
271 Handle(HYDROData_Stream) aStream =
272 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
274 aStream->SetProfiles( profiles, false );
275 aStream->SetDDZ( 0.2 );
276 aStream->SetSpatialStep( 10 );
279 TopoDS_Shape aPrs3d = aStream->GetShape3D();
280 TopoDS_Shape aPrs2d = aStream->GetTopShape();
282 TestViewer::show( aPrs2d, 0, true, "stream_dtm_2d", 1, 1 );
283 CPPUNIT_ASSERT_IMAGES;
285 TestViewer::eraseAll( true );
286 TestViewer::show( aPrs3d, 0, true, "stream_dtm_3d" );
287 CPPUNIT_ASSERT_IMAGES
293 void test_HYDROData_Stream::test_lism_1()
295 TCollection_AsciiString ref_path = REF_DATA_PATH.toLatin1().data();
297 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
298 fname += "/study_lism_1.cbf";
299 CPPUNIT_ASSERT_EQUAL( (int)DocError_OK, (int)HYDROData_Document::Load( fname.ToCString() ) );
301 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
303 HYDROData_SequenceOfObjects profiles;
304 HYDROData_Iterator it( aDoc, KIND_PROFILE );
305 for( int i=0; it.More(); it.Next(), i++ )
308 profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) );
310 CPPUNIT_ASSERT_EQUAL( 28, (int)profiles.Size() );
313 Handle(HYDROData_PolylineXY) aPolyXY_AX = Handle(HYDROData_PolylineXY)::DownCast(aDoc->FindObjectByName("AX"));
314 Handle(HYDROData_PolylineXY) aPolyXY_LB = Handle(HYDROData_PolylineXY)::DownCast(aDoc->FindObjectByName("LB"));
315 Handle(HYDROData_PolylineXY) aPolyXY_RB = Handle(HYDROData_PolylineXY)::DownCast(aDoc->FindObjectByName("RB"));
317 aPolyXY_AX->Update();
318 aPolyXY_LB->Update();
319 aPolyXY_RB->Update();
321 Handle(HYDROData_LISM) aLISM = Handle(HYDROData_LISM)::DownCast( aDoc->CreateObject( KIND_LISM ) );
322 aLISM->SetProfiles( profiles );
323 aLISM->SetHaxStep(2.0);
324 aLISM->SetNbProfilePoints( 200 );
325 aLISM->SetHydraulicAxis(aPolyXY_AX);
326 aLISM->SetLeftBank(aPolyXY_LB);
327 aLISM->SetRightBank(aPolyXY_RB);
328 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.0, aLISM->GetHaxStep(), EPS );
329 CPPUNIT_ASSERT_EQUAL( 200, aLISM->GetNbProfilePoints() );
332 CPPUNIT_ASSERT_EQUAL( 99000, (int)aLISM->GetAltitudePoints().size() );
334 Handle(AIS_InteractiveContext) aContext = TestViewer::context();
335 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, aLISM );
337 aBathPrs->update( true, false );
338 aBathPrs->RescaleDefault();
340 aBathPrs->GetRange( min, max );
341 TestViewer::colorScale()->SetRange( min, max );
342 CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.98390276785714281, min, EPS );
343 CPPUNIT_ASSERT_DOUBLES_EQUAL( 25.991840625000002, max, EPS );
345 aBathPrs->UpdateWithColorScale( TestViewer::colorScale() );
347 Handle(AIS_InteractiveObject) lism_prs = aBathPrs->getAISObjects()[0];
348 CPPUNIT_ASSERT( !lism_prs.IsNull() );
350 TestViewer::show( lism_prs, 0, 0, true, "lism_prs" );
351 CPPUNIT_ASSERT_IMAGES