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 );
193 CPPUNIT_ASSERT_EQUAL( 10, aScript1.size() );
194 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1 = hydro_doc.CreateObject( KIND_STREAM )" ), aScript1[0].toStdString() );
195 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetName( \"stream_1\" )" ), aScript1[1].toStdString() );
196 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[2].toStdString() );
197 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.AddProfile( p1 )" ), aScript1[3].toStdString() );
198 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.AddProfile( p2 )" ), aScript1[4].toStdString() );
199 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetDDZ( 0.200 )" ), aScript1[5].toStdString() );
200 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetSpatialStep( 3.000 )" ), aScript1[6].toStdString() );
201 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[7].toStdString() );
202 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.Update()" ), aScript1[8].toStdString() );
203 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[9].toStdString() );
205 // Case 2. With hydraulic axis
207 Handle(HYDROData_Stream) aStream2 =
208 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
209 aStream2->SetName( "stream_2" );
211 Handle(HYDROData_PolylineXY) anHAxis =
212 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
213 anHAxis->SetName( "axis" );
215 aStream2->SetProfiles( profiles, false );
216 aStream2->SetDDZ( 0.2 );
217 aStream2->SetSpatialStep( 3.0 );
218 aStream2->SetReferenceObject( anHAxis, HYDROData_Stream::DataTag_HydraulicAxis );
221 objs["p1"] = aProfile1;
222 objs["p2"] = aProfile2;
223 objs["axis"] = anHAxis;
225 QStringList aScript2 = aStream2->DumpToPython( "", objs );
226 CPPUNIT_ASSERT_EQUAL( 11, aScript2.size() );
227 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2 = hydro_doc.CreateObject( KIND_STREAM )" ), aScript2[0].toStdString() );
228 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetName( \"stream_2\" )" ), aScript2[1].toStdString() );
229 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript2[2].toStdString() );
230 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetHydraulicAxis( axis )" ), aScript2[3].toStdString() );
231 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.AddProfile( p1 )" ), aScript2[4].toStdString() );
232 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.AddProfile( p2 )" ), aScript2[5].toStdString() );
233 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetDDZ( 0.200 )" ), aScript2[6].toStdString() );
234 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetSpatialStep( 3.000 )" ), aScript2[7].toStdString() );
235 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript2[8].toStdString() );
236 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.Update()" ), aScript2[9].toStdString() );
237 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript2[10].toStdString() );
242 void test_HYDROData_Stream::test_presentation()
244 TestViewer::eraseAll( true, true );
246 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
248 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
249 fname += "/Profiles.xyz";
250 NCollection_Sequence<int> bad_ids;
252 int aSize = HYDROData_Profile::ImportFromFile( aDoc, fname, bad_ids, true );
254 CPPUNIT_ASSERT_EQUAL( 0, bad_ids.Size() );
255 CPPUNIT_ASSERT_EQUAL( 46, aSize );
257 HYDROData_SequenceOfObjects profiles;
258 HYDROData_Iterator it( aDoc, KIND_PROFILE );
259 for( int i=0; it.More(); it.Next(), i++ )
263 it.Current()->Update();
264 profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) );
268 Handle(HYDROData_Stream) aStream =
269 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
271 aStream->SetProfiles( profiles, false );
272 aStream->SetDDZ( 0.2 );
273 aStream->SetSpatialStep( 10 );
276 TopoDS_Shape aPrs3d = aStream->GetShape3D();
277 TopoDS_Shape aPrs2d = aStream->GetTopShape();
279 TestViewer::show( aPrs2d, 0, true, "stream_dtm_2d", 1, 1 );
280 CPPUNIT_ASSERT_IMAGES;
282 TestViewer::eraseAll( true );
283 TestViewer::show( aPrs3d, 0, true, "stream_dtm_3d" );
284 CPPUNIT_ASSERT_IMAGES
290 void test_HYDROData_Stream::test_lism_1()
292 TCollection_AsciiString ref_path = REF_DATA_PATH.toLatin1().data();
294 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
295 fname += "/study_lism_1.cbf";
296 CPPUNIT_ASSERT_EQUAL( (int)DocError_OK, (int)HYDROData_Document::Load( fname.ToCString() ) );
298 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
300 HYDROData_SequenceOfObjects profiles;
301 HYDROData_Iterator it( aDoc, KIND_PROFILE );
302 for( int i=0; it.More(); it.Next(), i++ )
305 profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) );
307 CPPUNIT_ASSERT_EQUAL( 28, (int)profiles.Size() );
310 Handle(HYDROData_PolylineXY) aPolyXY_AX = Handle(HYDROData_PolylineXY)::DownCast(aDoc->FindObjectByName("AX"));
311 Handle(HYDROData_PolylineXY) aPolyXY_LB = Handle(HYDROData_PolylineXY)::DownCast(aDoc->FindObjectByName("LB"));
312 Handle(HYDROData_PolylineXY) aPolyXY_RB = Handle(HYDROData_PolylineXY)::DownCast(aDoc->FindObjectByName("RB"));
314 aPolyXY_AX->Update();
315 aPolyXY_LB->Update();
316 aPolyXY_RB->Update();
318 Handle(HYDROData_LISM) aLISM = Handle(HYDROData_LISM)::DownCast( aDoc->CreateObject( KIND_LISM ) );
319 aLISM->SetProfiles( profiles );
320 aLISM->SetHaxStep(2.0);
321 aLISM->SetNbProfilePoints( 200 );
322 aLISM->SetHydraulicAxis(aPolyXY_AX);
323 aLISM->SetLeftBank(aPolyXY_LB);
324 aLISM->SetRightBank(aPolyXY_RB);
325 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.0, aLISM->GetHaxStep(), EPS );
326 CPPUNIT_ASSERT_EQUAL( 200, aLISM->GetNbProfilePoints() );
329 CPPUNIT_ASSERT_EQUAL( 99000, (int)aLISM->GetAltitudePoints().size() );
331 Handle(AIS_InteractiveContext) aContext = TestViewer::context();
332 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, aLISM );
334 aBathPrs->update( true, false );
335 aBathPrs->RescaleDefault();
337 aBathPrs->GetRange( min, max );
338 TestViewer::colorScale()->SetRange( min, max );
339 CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.98390276785714281, min, EPS );
340 CPPUNIT_ASSERT_DOUBLES_EQUAL( 25.991840625000002, max, EPS );
342 aBathPrs->UpdateWithColorScale( TestViewer::colorScale() );
344 Handle(AIS_InteractiveObject) lism_prs = aBathPrs->getAISObjects()[0];
345 CPPUNIT_ASSERT( !lism_prs.IsNull() );
347 TestViewer::show( lism_prs, 0, 0, true, "lism_prs" );
348 CPPUNIT_ASSERT_IMAGES