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 <TestViewer.h>
27 #include <QApplication>
29 NCollection_Sequence<HYDROData_IPolyline::Point> points2;
30 const double EPS = 1E-3;
32 void test_HYDROData_Stream::setUp()
35 points2.Append( gp_XY( 0.0, 5.0 ) );
36 points2.Append( gp_XY( 1.0, 1.0 ) );
37 points2.Append( gp_XY( 1.5, 0.0 ) );
38 points2.Append( gp_XY( 4.0, 4.0 ) );
41 void test_HYDROData_Stream::tearDown()
45 void test_HYDROData_Stream::test_dialog()
47 HYDROGUI_StreamDlg* aDlg = new HYDROGUI_StreamDlg( 0, "stream" );
49 qApp->processEvents();
51 QImage aStreamDlgImage = QPixmap::grabWidget( aDlg ).toImage();
52 CPPUNIT_ASSERT_IMAGES2( &aStreamDlgImage, "StreamDlg" );
54 aDlg->setDDZ( 12.34 );
55 CPPUNIT_ASSERT_DOUBLES_EQUAL( 12.34, aDlg->getDDZ(), EPS );
57 aDlg->setSpatialStep( 56.78 );
58 CPPUNIT_ASSERT_DOUBLES_EQUAL( 56.78, aDlg->getSpatialStep(), EPS );
63 void test_HYDROData_Stream::test_alt_object()
65 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
67 Handle(HYDROData_Stream) aStream =
68 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
70 CPPUNIT_ASSERT_EQUAL( false, (bool)aStream.IsNull() );
71 CPPUNIT_ASSERT_EQUAL( false, (bool)aStream->GetAltitudeObject().IsNull() );
72 CPPUNIT_ASSERT_EQUAL( KIND_DTM, aStream->getAltitudeObjectType() );
74 Handle(HYDROData_DTM) aDTM =
75 Handle(HYDROData_DTM)::DownCast( aStream->GetAltitudeObject() );
76 CPPUNIT_ASSERT_EQUAL( false, (bool)aDTM.IsNull() );
81 void test_HYDROData_Stream::test_params_sync()
83 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
85 Handle(HYDROData_Stream) aStream =
86 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
87 Handle(HYDROData_DTM) aDTM =
88 Handle(HYDROData_DTM)::DownCast( aStream->GetAltitudeObject() );
89 CPPUNIT_ASSERT_EQUAL( false, (bool)aDTM.IsNull() );
91 Handle(HYDROData_Profile) aProfile1 =
92 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
94 Handle(HYDROData_Profile) aProfile2 =
95 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
97 aProfile1->SetParametricPoints( points2 );
98 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
99 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
100 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
102 aProfile2->SetParametricPoints( points2 );
103 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
104 aProfile2->SetLeftPoint( gp_XY( 50, 0 ) );
105 aProfile2->SetRightPoint( gp_XY( 60, 10 ) );
107 HYDROData_SequenceOfObjects profiles;
108 profiles.Append( aProfile1 );
109 profiles.Append( aProfile2 );
111 aStream->SetProfiles( profiles, false );
112 aStream->SetDDZ( 3.14 );
113 aStream->SetSpatialStep( 4.14 );
115 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.14, aStream->GetDDZ(), EPS );
116 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.14, aDTM->GetDDZ(), EPS );
117 CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.14, aStream->GetSpatialStep(), EPS );
118 CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.14, aDTM->GetSpatialStep(), EPS );
120 HYDROData_SequenceOfObjects profiles1 = aStream->GetProfiles();
121 CPPUNIT_ASSERT_EQUAL( 2, profiles1.Size() );
122 CPPUNIT_ASSERT( profiles.Value(1)->Label() == profiles1.Value(1)->Label() );
123 CPPUNIT_ASSERT( profiles.Value(2)->Label() == profiles1.Value(2)->Label() );
125 HYDROData_SequenceOfObjects profiles2 = aDTM->GetProfiles();
126 CPPUNIT_ASSERT_EQUAL( 2, profiles2.Size() );
127 CPPUNIT_ASSERT( profiles.Value(1)->Label() == profiles2.Value(1)->Label() );
128 CPPUNIT_ASSERT( profiles.Value(2)->Label() == profiles2.Value(2)->Label() );
133 void test_HYDROData_Stream::test_dump()
135 // Case 1. Without hydraulic axis
136 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
138 Handle(HYDROData_Stream) aStream1 =
139 Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) );
140 aStream1->SetName( "stream_1" );
142 Handle(HYDROData_Profile) aProfile1 =
143 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
144 aProfile1->SetName( "p1" );
146 Handle(HYDROData_Profile) aProfile2 =
147 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
148 aProfile2->SetName( "p2" );
150 aProfile1->SetParametricPoints( points2 );
151 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
152 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
153 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
155 aProfile2->SetParametricPoints( points2 );
156 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
157 aProfile2->SetLeftPoint( gp_XY( 50, 0 ) );
158 aProfile2->SetRightPoint( gp_XY( 60, 10 ) );
160 HYDROData_SequenceOfObjects profiles;
161 profiles.Append( aProfile1 );
162 profiles.Append( aProfile2 );
164 aStream1->SetProfiles( profiles, false );
165 aStream1->SetDDZ( 0.2 );
166 aStream1->SetSpatialStep( 3.0 );
168 MapOfTreatedObjects objs;
169 objs["p1"] = aProfile1;
170 objs["p2"] = aProfile2;
172 QStringList aScript1 = aStream1->DumpToPython( "", objs );
173 CPPUNIT_ASSERT_EQUAL( 10, aScript1.size() );
174 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1 = hydro_doc.CreateObject( KIND_STREAM )" ), aScript1[0].toStdString() );
175 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetName( \"stream_1\" )" ), aScript1[1].toStdString() );
176 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[2].toStdString() );
177 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.AddProfile( p1 )" ), aScript1[3].toStdString() );
178 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.AddProfile( p2 )" ), aScript1[4].toStdString() );
179 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetDDZ( 0.200 )" ), aScript1[5].toStdString() );
180 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetSpatialStep( 3.000 )" ), aScript1[6].toStdString() );
181 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[7].toStdString() );
182 CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.Update()" ), aScript1[8].toStdString() );
183 CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[9].toStdString() );