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 <TestViewer.h>
30 #include <QApplication>
33 extern QString REF_DATA_PATH;
34 NCollection_Sequence<HYDROData_IPolyline::Point> points2;
35 const double EPS = 1E-3;
37 void test_HYDROData_Stream::setUp()
40 points2.Append( gp_XY( 0.0, 5.0 ) );
41 points2.Append( gp_XY( 1.0, 1.0 ) );
42 points2.Append( gp_XY( 1.5, 0.0 ) );
43 points2.Append( gp_XY( 4.0, 4.0 ) );
46 void test_HYDROData_Stream::tearDown()
50 void test_HYDROData_Stream::test_dialog()
53 TestViewer::eraseAll( true, true );
55 HYDROGUI_StreamDlg* aDlg = new HYDROGUI_StreamDlg( 0, "stream" );
57 qApp->processEvents();
59 QImage aStreamDlgImage = QPixmap::grabWidget( aDlg ).toImage();
60 CPPUNIT_ASSERT_IMAGES2( &aStreamDlgImage, "StreamDlg" );
62 aDlg->setDDZ( 12.34 );
63 CPPUNIT_ASSERT_DOUBLES_EQUAL( 12.34, aDlg->getDDZ(), EPS );
65 aDlg->setSpatialStep( 56.78 );
66 CPPUNIT_ASSERT_DOUBLES_EQUAL( 56.78, aDlg->getSpatialStep(), EPS );
71 void test_HYDROData_Stream::test_alt_object()
73 TestViewer::eraseAll( true, true );
75 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
77 Handle(HYDROData_Stream) aStream =
78 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
80 CPPUNIT_ASSERT_EQUAL( false, (bool)aStream.IsNull() );
81 CPPUNIT_ASSERT_EQUAL( true, (bool)aStream->GetAltitudeObject().IsNull() );
82 CPPUNIT_ASSERT_EQUAL( false, (bool)aStream->DTM().IsNull() );
83 CPPUNIT_ASSERT_EQUAL( false, (bool)aStream->GetAltitudeObject().IsNull() );
84 CPPUNIT_ASSERT_EQUAL( KIND_DTM, aStream->getAltitudeObjectType() );
86 Handle(HYDROData_DTM) aDTM =
87 Handle(HYDROData_DTM)::DownCast( aStream->GetAltitudeObject() );
88 CPPUNIT_ASSERT_EQUAL( false, (bool)aDTM.IsNull() );
93 void test_HYDROData_Stream::test_params_sync()
95 TestViewer::eraseAll( true, true );
97 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
99 Handle(HYDROData_Stream) aStream =
100 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
101 Handle(HYDROData_DTM) aDTM = aStream->DTM();
102 CPPUNIT_ASSERT_EQUAL( false, (bool)aDTM.IsNull() );
104 Handle(HYDROData_Profile) aProfile1 =
105 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
107 Handle(HYDROData_Profile) aProfile2 =
108 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
110 aProfile1->SetParametricPoints( points2 );
111 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
112 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
113 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
115 aProfile2->SetParametricPoints( points2 );
116 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
117 aProfile2->SetLeftPoint( gp_XY( 50, 0 ) );
118 aProfile2->SetRightPoint( gp_XY( 60, 10 ) );
120 HYDROData_SequenceOfObjects profiles;
121 profiles.Append( aProfile1 );
122 profiles.Append( aProfile2 );
124 aStream->SetProfiles( profiles, false );
125 aStream->SetDDZ( 3.14 );
126 aStream->SetSpatialStep( 4.14 );
128 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.14, aStream->GetDDZ(), EPS );
129 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.14, aDTM->GetDDZ(), EPS );
130 CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.14, aStream->GetSpatialStep(), EPS );
131 CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.14, aDTM->GetSpatialStep(), EPS );
133 HYDROData_SequenceOfObjects profiles1 = aStream->GetProfiles();
134 CPPUNIT_ASSERT_EQUAL( 2, profiles1.Size() );
135 CPPUNIT_ASSERT( profiles.Value(1)->Label() == profiles1.Value(1)->Label() );
136 CPPUNIT_ASSERT( profiles.Value(2)->Label() == profiles1.Value(2)->Label() );
138 HYDROData_SequenceOfObjects profiles2 = aDTM->GetProfiles();
139 CPPUNIT_ASSERT_EQUAL( 2, profiles2.Size() );
140 CPPUNIT_ASSERT( profiles.Value(1)->Label() == profiles2.Value(1)->Label() );
141 CPPUNIT_ASSERT( profiles.Value(2)->Label() == profiles2.Value(2)->Label() );
146 void test_HYDROData_Stream::test_dump()
148 TestViewer::eraseAll( true, true );
150 // Case 1. Without hydraulic axis
151 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
153 Handle(HYDROData_Stream) aStream1 =
154 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
155 aStream1->SetName( "stream_1" );
157 Handle(HYDROData_Profile) aProfile1 =
158 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
159 aProfile1->SetName( "p1" );
161 Handle(HYDROData_Profile) aProfile2 =
162 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
163 aProfile2->SetName( "p2" );
165 aProfile1->SetParametricPoints( points2 );
166 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
167 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
168 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
170 aProfile2->SetParametricPoints( points2 );
171 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
172 aProfile2->SetLeftPoint( gp_XY( 50, 0 ) );
173 aProfile2->SetRightPoint( gp_XY( 60, 10 ) );
175 HYDROData_SequenceOfObjects profiles;
176 profiles.Append( aProfile1 );
177 profiles.Append( aProfile2 );
179 aStream1->SetProfiles( profiles, false );
180 aStream1->SetDDZ( 0.2 );
181 aStream1->SetSpatialStep( 3.0 );
183 MapOfTreatedObjects objs;
184 objs["p1"] = aProfile1;
185 objs["p2"] = aProfile2;
187 QStringList aScript1 = aStream1->DumpToPython( "", objs );
188 CPPUNIT_ASSERT_EQUAL( 10, aScript1.size() );
189 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1 = hydro_doc.CreateObject( KIND_STREAM )" ), aScript1[0].toStdString() );
190 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetName( \"stream_1\" )" ), aScript1[1].toStdString() );
191 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[2].toStdString() );
192 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.AddProfile( p1 )" ), aScript1[3].toStdString() );
193 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.AddProfile( p2 )" ), aScript1[4].toStdString() );
194 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetDDZ( 0.200 )" ), aScript1[5].toStdString() );
195 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetSpatialStep( 3.000 )" ), aScript1[6].toStdString() );
196 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[7].toStdString() );
197 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.Update()" ), aScript1[8].toStdString() );
198 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[9].toStdString() );
200 // Case 2. With hydraulic axis
202 Handle(HYDROData_Stream) aStream2 =
203 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
204 aStream2->SetName( "stream_2" );
206 Handle(HYDROData_PolylineXY) anHAxis =
207 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
208 anHAxis->SetName( "axis" );
210 aStream2->SetProfiles( profiles, false );
211 aStream2->SetDDZ( 0.2 );
212 aStream2->SetSpatialStep( 3.0 );
213 aStream2->SetReferenceObject( anHAxis, HYDROData_Stream::DataTag_HydraulicAxis );
216 objs["p1"] = aProfile1;
217 objs["p2"] = aProfile2;
218 objs["axis"] = anHAxis;
220 QStringList aScript2 = aStream2->DumpToPython( "", objs );
221 CPPUNIT_ASSERT_EQUAL( 11, aScript2.size() );
222 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2 = hydro_doc.CreateObject( KIND_STREAM )" ), aScript2[0].toStdString() );
223 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetName( \"stream_2\" )" ), aScript2[1].toStdString() );
224 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript2[2].toStdString() );
225 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetHydraulicAxis( axis )" ), aScript2[3].toStdString() );
226 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.AddProfile( p1 )" ), aScript2[4].toStdString() );
227 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.AddProfile( p2 )" ), aScript2[5].toStdString() );
228 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetDDZ( 0.200 )" ), aScript2[6].toStdString() );
229 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetSpatialStep( 3.000 )" ), aScript2[7].toStdString() );
230 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript2[8].toStdString() );
231 CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.Update()" ), aScript2[9].toStdString() );
232 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript2[10].toStdString() );
237 void test_HYDROData_Stream::test_presentation()
239 TestViewer::eraseAll( true, true );
241 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
243 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
244 fname += "/Profiles.xyz";
245 NCollection_Sequence<int> bad_ids;
247 int aSize = HYDROData_Profile::ImportFromFile( aDoc, fname, bad_ids, true );
249 CPPUNIT_ASSERT_EQUAL( 0, bad_ids.Size() );
250 CPPUNIT_ASSERT_EQUAL( 46, aSize );
252 HYDROData_SequenceOfObjects profiles;
253 HYDROData_Iterator it( aDoc, KIND_PROFILE );
254 for( int i=0; it.More(); it.Next(), i++ )
258 it.Current()->Update();
259 profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) );
263 Handle(HYDROData_Stream) aStream =
264 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
266 aStream->SetProfiles( profiles, false );
267 aStream->SetDDZ( 0.2 );
268 aStream->SetSpatialStep( 10 );
271 TopoDS_Shape aPrs3d = aStream->GetShape3D();
272 TopoDS_Shape aPrs2d = aStream->GetTopShape();
274 TestViewer::show( aPrs2d, 0, true, "stream_dtm_2d", 1, 1 );
275 CPPUNIT_ASSERT_IMAGES;
277 TestViewer::eraseAll( true );
278 TestViewer::show( aPrs3d, 0, true, "stream_dtm_3d" );
279 CPPUNIT_ASSERT_IMAGES