Salome HOME
a311e48d3761a2533297ce4317f6b5998617ab58
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_PolylineXY.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include<test_HYDROData_PolylineXY.h>
20
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
31 #include <AIS_DisplayMode.hxx>
32 #include <QColor>
33 #include <QList>
34 #include <QPointF>
35
36 #include <TestShape.h>
37 #include <TestViewer.h>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS_Vertex.hxx>
40 #include <TopoDS_Wire.hxx>
41
42 void test_HYDROData_PolylineXY::testPolyline()
43 {
44   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
45
46   Handle(HYDROData_PolylineXY) aPolyline = 
47     Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
48
49   aPolyline->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false );
50   aPolyline->AddSection( "Section_2", HYDROData_PolylineXY::SECTION_SPLINE, true );
51
52   int aNbSections = aPolyline->NbSections();
53   CPPUNIT_ASSERT( aNbSections == 2 );
54   
55   NCollection_Sequence<TCollection_AsciiString>           aSectNames;
56   NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
57   NCollection_Sequence<bool>                              aSectClosures;
58   aPolyline->GetSections( aSectNames, aSectTypes, aSectClosures );
59
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 );
64
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 );
68
69   aDoc->Close();
70 }
71
72
73 void test_HYDROData_PolylineXY::testCopy()
74 {
75   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
76   Handle(HYDROData_PolylineXY) aPolyline1 = 
77     Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
78
79
80 //  aPolyline1->setPoints(aPoints);
81
82   Handle(HYDROData_PolylineXY) aPolyline2 = 
83     Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
84
85   aPolyline1->CopyTo(aPolyline2, true);
86
87
88   aDoc->Close();
89 }
90
91 void test_HYDROData_PolylineXY::testSplit_refs_624()
92 {
93   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
94
95   Handle(HYDROData_PolylineXY) aPolyline = 
96     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
97   aPolyline->SetName( "test" );
98
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 );
102
103   gp_Pnt2d aPnt( 20, 20 );
104
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
108
109   HYDROData_PolylineOperator anOp;
110   CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline, aPnt, 1E-3 ) );
111
112   HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY );
113   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
114   CPPUNIT_ASSERT_EQUAL( QString( "test" ), anIt.Current()->GetName() );
115   anIt.Next();
116   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
117   CPPUNIT_ASSERT_EQUAL( QString( "test_1" ), anIt.Current()->GetName() );
118   anIt.Next();
119   CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
120
121   aDoc->Close();
122 }
123
124 void test_HYDROData_PolylineXY::test_extraction_immersible_zone()
125 {
126   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
127
128   Handle(HYDROData_PolylineXY) aPolyline = 
129     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
130   aPolyline->SetName( "test" );
131
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 );
135
136   Handle(HYDROData_ImmersibleZone) aZone = 
137     Handle(HYDROData_ImmersibleZone)::DownCast( aDoc->CreateObject( KIND_IMMERSIBLE_ZONE ) );
138   aZone->SetName( "zone" );
139   aZone->SetPolyline( aPolyline );
140   aZone->Update();
141
142   CPPUNIT_ASSERT_EQUAL( false, (bool)aZone->GetTopShape().IsNull() );
143
144   HYDROData_PolylineOperator anOp;
145   CPPUNIT_ASSERT_EQUAL( true, anOp.Extract( aDoc, aZone ) );
146
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() );
150
151   TestViewer::show( aZone->GetTopShape(), 1, true, "Extraction_ImmZone" );
152   TestViewer::show( anOuter->GetShape(), 0, true, Qt::red );
153   CPPUNIT_ASSERT_IMAGES
154
155   aDoc->Close();
156 }
157
158 void test_HYDROData_PolylineXY::test_extraction_channel_refs_611()
159 {
160 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
161
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 );
166
167   Handle(HYDROData_Polyline3D) aPolyline3d = 
168     Handle(HYDROData_Polyline3D)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) );
169   aPolyline3d->SetName( "polyline3d_1" );
170   aPolyline3d->SetPolylineXY( aPolyline2d );
171
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 );
177
178   Handle(HYDROData_Profile) aProfile = 
179     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
180   aProfile->SetName( "profile_1" );
181
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 );
186
187
188   Handle(HYDROData_Channel) aChannel = 
189     Handle(HYDROData_Channel)::DownCast( aDoc->CreateObject( KIND_CHANNEL ) );
190   aChannel->SetName( "channel_1" );
191   
192   aChannel->SetGuideLine( aPolyline3d );
193   aChannel->SetProfile( aProfile );
194   aChannel->Update();
195   CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetTopShape().IsNull() );
196   CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetShape3D().IsNull() );
197
198   HYDROData_PolylineOperator anOp;
199   CPPUNIT_ASSERT_EQUAL( true, anOp.Extract( aDoc, aChannel ) );
200
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() );
206
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
211
212   aDoc->Close();
213 }