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>
31 #include <AIS_DisplayMode.hxx>
36 #include <TestShape.h>
37 #include <TestViewer.h>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS_Vertex.hxx>
40 #include <TopoDS_Wire.hxx>
42 void test_HYDROData_PolylineXY::testPolyline()
44 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
46 Handle(HYDROData_PolylineXY) aPolyline =
47 Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
49 aPolyline->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false );
50 aPolyline->AddSection( "Section_2", HYDROData_PolylineXY::SECTION_SPLINE, true );
52 int aNbSections = aPolyline->NbSections();
53 CPPUNIT_ASSERT( aNbSections == 2 );
55 NCollection_Sequence<TCollection_AsciiString> aSectNames;
56 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
57 NCollection_Sequence<bool> aSectClosures;
58 aPolyline->GetSections( aSectNames, aSectTypes, aSectClosures );
60 CPPUNIT_ASSERT_EQUAL( 2, aSectNames.Size() );
61 CPPUNIT_ASSERT( aSectNames.Value( 1 ) == "Section_1" );
62 CPPUNIT_ASSERT( aSectTypes.Value( 1 ) == HYDROData_PolylineXY::SECTION_POLYLINE );
63 CPPUNIT_ASSERT( aSectClosures.Value( 1 ) == false );
65 CPPUNIT_ASSERT( aSectNames.Value( 2 ) == "Section_2" );
66 CPPUNIT_ASSERT( aSectTypes.Value( 2 ) == HYDROData_PolylineXY::SECTION_SPLINE );
67 CPPUNIT_ASSERT( aSectClosures.Value( 2 ) == true );
73 void test_HYDROData_PolylineXY::testCopy()
75 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
76 Handle(HYDROData_PolylineXY) aPolyline1 =
77 Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
80 // aPolyline1->setPoints(aPoints);
82 Handle(HYDROData_PolylineXY) aPolyline2 =
83 Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
85 aPolyline1->CopyTo(aPolyline2, true);
91 void test_HYDROData_PolylineXY::testSplit_refs_624()
93 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
95 Handle(HYDROData_PolylineXY) aPolyline =
96 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
97 aPolyline->SetName( "test" );
99 QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
100 TopoDS_Wire aWire = Wire( aCoords, true );
101 aPolyline->SetShape( aWire );
103 gp_Pnt2d aPnt( 20, 20 );
105 TestViewer::show( aPolyline->GetShape(), 0, true, "LandCoverMap_Split_Polyline" );
106 //TestViewer::show( BRepBuilderAPI_MakeVertex( aPnt ).Vertex(), 1, true, Qt::green );
107 CPPUNIT_ASSERT_IMAGES
109 HYDROData_PolylineOperator anOp;
110 CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline, aPnt, 1E-3 ) );
112 HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY );
113 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
114 CPPUNIT_ASSERT_EQUAL( QString( "test" ), anIt.Current()->GetName() );
116 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
117 CPPUNIT_ASSERT_EQUAL( QString( "test_1" ), anIt.Current()->GetName() );
119 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
124 void test_HYDROData_PolylineXY::test_extraction_immersible_zone()
126 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
128 Handle(HYDROData_PolylineXY) aPolyline =
129 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
130 aPolyline->SetName( "test" );
132 QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
133 TopoDS_Wire aWire = Wire( aCoords, true );
134 aPolyline->SetShape( aWire );
136 Handle(HYDROData_ImmersibleZone) aZone =
137 Handle(HYDROData_ImmersibleZone)::DownCast( aDoc->CreateObject( KIND_IMMERSIBLE_ZONE ) );
138 aZone->SetName( "zone" );
139 aZone->SetPolyline( aPolyline );
142 CPPUNIT_ASSERT_EQUAL( false, (bool)aZone->GetTopShape().IsNull() );
144 HYDROData_PolylineOperator anOp;
145 CPPUNIT_ASSERT_EQUAL( true, anOp.Extract( aDoc, aZone ) );
147 Handle(HYDROData_PolylineXY) anOuter =
148 Handle(HYDROData_PolylineXY)::DownCast( aDoc->FindObjectByName( "zone_Outer_1", KIND_POLYLINEXY ) );
149 CPPUNIT_ASSERT_EQUAL( false, (bool)anOuter.IsNull() );
151 TestViewer::show( aZone->GetTopShape(), 1, true, "Extraction_ImmZone" );
152 TestViewer::show( anOuter->GetShape(), 0, true, Qt::red );
153 CPPUNIT_ASSERT_IMAGES
158 void test_HYDROData_PolylineXY::test_extraction_channel_refs_611()
160 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
162 Handle(HYDROData_PolylineXY) aPolyline2d =
163 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
164 aPolyline2d->SetName( "polyline2d_1" );
165 aPolyline2d->AddSection( "", HYDROData_IPolyline::SECTION_SPLINE, false );
167 Handle(HYDROData_Polyline3D) aPolyline3d =
168 Handle(HYDROData_Polyline3D)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) );
169 aPolyline3d->SetName( "polyline3d_1" );
170 aPolyline3d->SetPolylineXY( aPolyline2d );
172 QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
173 TopoDS_Wire aWire = Wire( aCoords, false );
174 aPolyline2d->SetShape( aWire );
175 aPolyline3d->SetTopShape( aWire );
176 aPolyline3d->SetShape3D( aWire );
178 Handle(HYDROData_Profile) aProfile =
179 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
180 aProfile->SetName( "profile_1" );
182 QList<double> aCoordsPr = QList<double>() << 0.0 << 0.1 << 0.5 << 0.0 << 1.0 << 0.1;
183 TopoDS_Wire aWirePr = Wire( aCoordsPr, false );
184 aProfile->SetTopShape( aWirePr );
185 aProfile->SetShape3D( aWirePr );
188 Handle(HYDROData_Channel) aChannel =
189 Handle(HYDROData_Channel)::DownCast( aDoc->CreateObject( KIND_CHANNEL ) );
190 aChannel->SetName( "channel_1" );
192 aChannel->SetGuideLine( aPolyline3d );
193 aChannel->SetProfile( aProfile );
195 CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetTopShape().IsNull() );
196 CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetShape3D().IsNull() );
198 HYDROData_PolylineOperator anOp;
199 CPPUNIT_ASSERT_EQUAL( true, anOp.Extract( aDoc, aChannel ) );
201 Handle(HYDROData_PolylineXY) aLeft =
202 Handle(HYDROData_PolylineXY)::DownCast( aDoc->FindObjectByName( "channel_1_Left_Bank_1", KIND_POLYLINEXY ) );
203 Handle(HYDROData_PolylineXY) aRight =
204 Handle(HYDROData_PolylineXY)::DownCast( aDoc->FindObjectByName( "channel_1_Right_Bank_1", KIND_POLYLINEXY ) );
205 CPPUNIT_ASSERT_EQUAL( false, (bool)aRight.IsNull() );
207 TestViewer::show( aChannel->GetTopShape(), 1, true, "Extraction_Channel" );
208 TestViewer::show( aLeft->GetShape(), 0, true, Qt::red );
209 TestViewer::show( aRight->GetShape(), 0, true, Qt::red );
210 CPPUNIT_ASSERT_IMAGES