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_PolylineXY.h>
21 #include <HYDROData_Channel.h>
22 #include <HYDROData_Document.h>
23 #include <HYDROData_PolylineXY.h>
24 #include <HYDROData_Polyline3D.h>
25 #include <HYDROData_PolylineOperator.h>
26 #include <HYDROData_Profile.h>
27 #include <HYDROData_Iterator.h>
28 #include <HYDROData_ImmersibleZone.h>
29 #include <HYDROData_Tool.h>
30 #include <HYDROGUI_Polyline.h>
32 #include <AIS_DisplayMode.hxx>
33 #include <AIS_PointCloud.hxx>
34 #include <Prs3d_LineAspect.hxx>
35 #include <Prs3d_PointAspect.hxx>
36 #include <TColgp_HArray1OfPnt.hxx>
41 #include <TestShape.h>
42 #include <TestViewer.h>
43 #include <TopoDS_Edge.hxx>
44 #include <TopoDS_Vertex.hxx>
45 #include <TopoDS_Wire.hxx>
47 void test_HYDROData_PolylineXY::testPolyline()
49 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
51 Handle(HYDROData_PolylineXY) aPolyline =
52 Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
54 aPolyline->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false );
55 aPolyline->AddSection( "Section_2", HYDROData_PolylineXY::SECTION_SPLINE, true );
57 int aNbSections = aPolyline->NbSections();
58 CPPUNIT_ASSERT( aNbSections == 2 );
60 NCollection_Sequence<TCollection_AsciiString> aSectNames;
61 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
62 NCollection_Sequence<bool> aSectClosures;
63 aPolyline->GetSections( aSectNames, aSectTypes, aSectClosures );
65 CPPUNIT_ASSERT_EQUAL( 2, aSectNames.Size() );
66 CPPUNIT_ASSERT( aSectNames.Value( 1 ) == "Section_1" );
67 CPPUNIT_ASSERT( aSectTypes.Value( 1 ) == HYDROData_PolylineXY::SECTION_POLYLINE );
68 CPPUNIT_ASSERT( aSectClosures.Value( 1 ) == false );
70 CPPUNIT_ASSERT( aSectNames.Value( 2 ) == "Section_2" );
71 CPPUNIT_ASSERT( aSectTypes.Value( 2 ) == HYDROData_PolylineXY::SECTION_SPLINE );
72 CPPUNIT_ASSERT( aSectClosures.Value( 2 ) == true );
78 void test_HYDROData_PolylineXY::testCopy()
80 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
81 Handle(HYDROData_PolylineXY) aPolyline1 =
82 Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
85 // aPolyline1->setPoints(aPoints);
87 Handle(HYDROData_PolylineXY) aPolyline2 =
88 Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
90 aPolyline1->CopyTo(aPolyline2, true);
96 void test_HYDROData_PolylineXY::testSplit_refs_624()
98 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
100 Handle(HYDROData_PolylineXY) aPolyline =
101 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
102 aPolyline->SetName( "test" );
104 QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
105 TopoDS_Wire aWire = Wire( aCoords, true );
106 aPolyline->SetShape( aWire );
108 gp_Pnt2d aPnt( 20, 20 );
110 TestViewer::show( aPolyline->GetShape(), 0, true, "LandCoverMap_Split_Polyline" );
111 //TestViewer::show( BRepBuilderAPI_MakeVertex( aPnt ).Vertex(), 1, true, Qt::green );
112 CPPUNIT_ASSERT_IMAGES
114 HYDROData_PolylineOperator anOp;
115 CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline, aPnt, 1E-3 ) );
117 HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY );
118 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
119 CPPUNIT_ASSERT_EQUAL( QString( "test" ), anIt.Current()->GetName() );
121 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
122 CPPUNIT_ASSERT_EQUAL( QString( "test_1" ), anIt.Current()->GetName() );
124 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
129 void test_HYDROData_PolylineXY::test_extraction_immersible_zone()
131 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
133 Handle(HYDROData_PolylineXY) aPolyline =
134 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
135 aPolyline->SetName( "test" );
137 QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
138 TopoDS_Wire aWire = Wire( aCoords, true );
139 aPolyline->SetShape( aWire );
141 Handle(HYDROData_ImmersibleZone) aZone =
142 Handle(HYDROData_ImmersibleZone)::DownCast( aDoc->CreateObject( KIND_IMMERSIBLE_ZONE ) );
143 aZone->SetName( "zone" );
144 aZone->SetPolyline( aPolyline );
147 CPPUNIT_ASSERT_EQUAL( false, (bool)aZone->GetTopShape().IsNull() );
149 HYDROData_PolylineOperator anOp;
150 CPPUNIT_ASSERT_EQUAL( true, anOp.Extract( aDoc, aZone ) );
152 Handle(HYDROData_PolylineXY) anOuter =
153 Handle(HYDROData_PolylineXY)::DownCast( aDoc->FindObjectByName( "zone_Outer_1", KIND_POLYLINEXY ) );
154 CPPUNIT_ASSERT_EQUAL( false, (bool)anOuter.IsNull() );
156 TestViewer::show( aZone->GetTopShape(), 1, true, "Extraction_ImmZone" );
157 TestViewer::show( anOuter->GetShape(), 0, true, Qt::red );
158 CPPUNIT_ASSERT_IMAGES
163 void test_HYDROData_PolylineXY::test_extraction_channel_refs_611()
165 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
167 Handle(HYDROData_PolylineXY) aPolyline2d =
168 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
169 aPolyline2d->SetName( "polyline2d_1" );
170 aPolyline2d->AddSection( "", HYDROData_IPolyline::SECTION_SPLINE, false );
172 Handle(HYDROData_Polyline3D) aPolyline3d =
173 Handle(HYDROData_Polyline3D)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) );
174 aPolyline3d->SetName( "polyline3d_1" );
175 aPolyline3d->SetPolylineXY( aPolyline2d );
177 QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
178 TopoDS_Wire aWire = Wire( aCoords, false );
179 aPolyline2d->SetShape( aWire );
180 aPolyline3d->SetTopShape( aWire );
181 aPolyline3d->SetShape3D( aWire );
183 Handle(HYDROData_Profile) aProfile =
184 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
185 aProfile->SetName( "profile_1" );
187 QList<double> aCoordsPr = QList<double>() << 0.0 << 0.1 << 0.5 << 0.0 << 1.0 << 0.1;
188 TopoDS_Wire aWirePr = Wire( aCoordsPr, false );
189 aProfile->SetTopShape( aWirePr );
190 aProfile->SetShape3D( aWirePr );
193 Handle(HYDROData_Channel) aChannel =
194 Handle(HYDROData_Channel)::DownCast( aDoc->CreateObject( KIND_CHANNEL ) );
195 aChannel->SetName( "channel_1" );
197 aChannel->SetGuideLine( aPolyline3d );
198 aChannel->SetProfile( aProfile );
200 CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetTopShape().IsNull() );
201 CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetShape3D().IsNull() );
203 HYDROData_PolylineOperator anOp;
204 CPPUNIT_ASSERT_EQUAL( true, anOp.Extract( aDoc, aChannel ) );
206 Handle(HYDROData_PolylineXY) aLeft =
207 Handle(HYDROData_PolylineXY)::DownCast( aDoc->FindObjectByName( "channel_1_Left_Bank_1", KIND_POLYLINEXY ) );
208 Handle(HYDROData_PolylineXY) aRight =
209 Handle(HYDROData_PolylineXY)::DownCast( aDoc->FindObjectByName( "channel_1_Right_Bank_1", KIND_POLYLINEXY ) );
210 CPPUNIT_ASSERT_EQUAL( false, (bool)aRight.IsNull() );
212 TestViewer::show( aChannel->GetTopShape(), 1, true, "Extraction_Channel" );
213 TestViewer::show( aLeft->GetShape(), 0, true, Qt::red );
214 TestViewer::show( aRight->GetShape(), 0, true, Qt::red );
215 CPPUNIT_ASSERT_IMAGES
220 void test_HYDROData_PolylineXY::test_presentation()
222 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
224 Handle(HYDROData_PolylineXY) aPolyline2d =
225 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
226 aPolyline2d->SetName( "polyline2d_1" );
227 aPolyline2d->AddSection( "", HYDROData_IPolyline::SECTION_SPLINE, false );
229 QList<gp_XY> aPoints = QList<gp_XY>() << gp_XY( 0, 0 )
239 Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt( 1, aPoints.size() );
241 foreach( gp_XY aPoint, aPoints )
243 aPolyline2d->AddPoint( 0, aPoint );
244 aPnts->SetValue( i, gp_Pnt( aPoint.X(), aPoint.Y(), 0 ) );
247 aPolyline2d->Update();
249 CPPUNIT_ASSERT_EQUAL( false, (bool)aPolyline2d->GetShape().IsNull() );
251 Handle(AIS_PointCloud) aPointsPrs = new AIS_PointCloud();
252 aPointsPrs->SetPoints( aPnts );
253 aPointsPrs->SetColor( Quantity_NOC_BLUE1 );
254 aPointsPrs->Attributes()->PointAspect()->SetTypeOfMarker( Aspect_TOM_O );
256 Handle(HYDROGUI_Polyline) aNewPolylinePrs = new HYDROGUI_Polyline( aPolyline2d->GetShape() );
257 aNewPolylinePrs->SetColor( Quantity_NOC_DARKGREEN );
259 TestViewer::show( aPointsPrs, AIS_PointCloud::DM_Points, 0, true, "Polyline_Presentation" );
260 TestViewer::show( aPolyline2d->GetShape(), 0, true, Qt::red );
261 TestViewer::show( aNewPolylinePrs, AIS_PointCloud::DM_Points, 0, true, "" );
262 CPPUNIT_ASSERT_IMAGES
267 void test_HYDROData_PolylineXY::testSplit_refs_627()
269 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
271 Handle(HYDROData_PolylineXY) aPolyline =
272 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
273 aPolyline->SetName( "test" );
275 QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
276 TopoDS_Wire aWire = Wire( aCoords, false );
277 aPolyline->SetShape( aWire );
278 aPolyline->SetWireColor( Qt::red );
280 gp_Pnt2d aPnt( 20, 20 );
282 HYDROData_PolylineOperator anOp;
283 CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline, aPnt, 1E-3 ) );
285 TestViewer::show( TopoDS_Shape(), 0, true, "Split_Polylines_Colors" );
286 HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY );
287 for( ; anIt.More(); anIt.Next() )
289 Handle(HYDROData_PolylineXY) anObj = Handle(HYDROData_PolylineXY)::DownCast( anIt.Current() );
290 if( aPolyline->Label() != anObj->Label() )
291 TestViewer::show( anObj->GetShape(), 0, true, anObj->GetWireColor() );
293 CPPUNIT_ASSERT_IMAGES
295 HYDROData_Iterator anIt2( aDoc, KIND_POLYLINEXY );
296 CPPUNIT_ASSERT_EQUAL( true, anIt2.More() );
297 CPPUNIT_ASSERT_EQUAL( QString( "test" ), anIt2.Current()->GetName() );
298 CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ),
299 Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetWireColor() );
301 CPPUNIT_ASSERT_EQUAL( true, anIt2.More() );
302 CPPUNIT_ASSERT_EQUAL( QString( "test_1" ), anIt2.Current()->GetName() );
303 CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ),
304 Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetWireColor() );
306 CPPUNIT_ASSERT_EQUAL( true, anIt2.More() );
307 CPPUNIT_ASSERT_EQUAL( QString( "test_2" ), anIt2.Current()->GetName() );
308 CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ),
309 Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetWireColor() );
311 CPPUNIT_ASSERT_EQUAL( false, anIt2.More() );