Salome HOME
cb3a5592513fab887e5152978f2e3fc2bd86494c
[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_Document.h>
22 #include <HYDROData_PolylineXY.h>
23 #include <HYDROData_PolylineOperator.h>
24 #include <HYDROData_Iterator.h>
25 #include <HYDROData_ImmersibleZone.h>
26 #include <HYDROData_Tool.h>
27
28 #include <QColor>
29 #include <QList>
30 #include <QPointF>
31
32 #include <TestShape.h>
33 #include <TestViewer.h>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Vertex.hxx>
36 #include <TopoDS_Wire.hxx>
37
38 void test_HYDROData_PolylineXY::testPolyline()
39 {
40   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
41
42   Handle(HYDROData_PolylineXY) aPolyline = 
43     Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
44
45   aPolyline->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false );
46   aPolyline->AddSection( "Section_2", HYDROData_PolylineXY::SECTION_SPLINE, true );
47
48   int aNbSections = aPolyline->NbSections();
49   CPPUNIT_ASSERT( aNbSections == 2 );
50   
51   NCollection_Sequence<TCollection_AsciiString>           aSectNames;
52   NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
53   NCollection_Sequence<bool>                              aSectClosures;
54   aPolyline->GetSections( aSectNames, aSectTypes, aSectClosures );
55
56   CPPUNIT_ASSERT_EQUAL( 2, aSectNames.Size() );
57   CPPUNIT_ASSERT( aSectNames.Value( 1 ) == "Section_1" );
58   CPPUNIT_ASSERT( aSectTypes.Value( 1 ) == HYDROData_PolylineXY::SECTION_POLYLINE );
59   CPPUNIT_ASSERT( aSectClosures.Value( 1 ) == false );
60
61   CPPUNIT_ASSERT( aSectNames.Value( 2 ) == "Section_2" );
62   CPPUNIT_ASSERT( aSectTypes.Value( 2 ) == HYDROData_PolylineXY::SECTION_SPLINE );
63   CPPUNIT_ASSERT( aSectClosures.Value( 2 ) == true );
64
65   aDoc->Close();
66 }
67
68
69 void test_HYDROData_PolylineXY::testCopy()
70 {
71   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
72   Handle(HYDROData_PolylineXY) aPolyline1 = 
73     Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
74
75
76 //  aPolyline1->setPoints(aPoints);
77
78   Handle(HYDROData_PolylineXY) aPolyline2 = 
79     Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
80
81   aPolyline1->CopyTo(aPolyline2, true);
82
83
84   aDoc->Close();
85 }
86
87 void test_HYDROData_PolylineXY::testSplit_refs_624()
88 {
89   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
90
91   Handle(HYDROData_PolylineXY) aPolyline = 
92     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
93   aPolyline->SetName( "test" );
94
95   QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
96   TopoDS_Wire aWire = Wire( aCoords, true );
97   aPolyline->SetShape( aWire );
98
99   gp_Pnt2d aPnt( 20, 20 );
100
101   TestViewer::show( aPolyline->GetShape(), 0, true, "LandCoverMap_Split_Polyline" );
102   //TestViewer::show( BRepBuilderAPI_MakeVertex( aPnt ).Vertex(), 1, true, Qt::green );
103   CPPUNIT_ASSERT_IMAGES
104
105   HYDROData_PolylineOperator anOp;
106   CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline, aPnt, 1E-3 ) );
107
108   HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY );
109   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
110   CPPUNIT_ASSERT_EQUAL( QString( "test" ), anIt.Current()->GetName() );
111   anIt.Next();
112   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
113   CPPUNIT_ASSERT_EQUAL( QString( "test_1" ), anIt.Current()->GetName() );
114   anIt.Next();
115   CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
116
117   aDoc->Close();
118 }
119
120 void test_HYDROData_PolylineXY::test_extraction_immersible_zone()
121 {
122   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
123
124   Handle(HYDROData_PolylineXY) aPolyline = 
125     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
126   aPolyline->SetName( "test" );
127
128   QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
129   TopoDS_Wire aWire = Wire( aCoords, true );
130   aPolyline->SetShape( aWire );
131
132   Handle(HYDROData_ImmersibleZone) aZone = 
133     Handle(HYDROData_ImmersibleZone)::DownCast( aDoc->CreateObject( KIND_IMMERSIBLE_ZONE ) );
134   aZone->SetName( "zone" );
135   aZone->SetPolyline( aPolyline );
136   aZone->Update();
137
138   CPPUNIT_ASSERT_EQUAL( false, (bool)aZone->GetTopShape().IsNull() );
139
140   HYDROData_PolylineOperator anOp;
141   CPPUNIT_ASSERT_EQUAL( true, anOp.Extract( aDoc, aZone ) );
142
143   Handle(HYDROData_PolylineXY) anOuter = 
144     Handle(HYDROData_PolylineXY)::DownCast( aDoc->FindObjectByName( "zone_Outer_1", KIND_POLYLINEXY ) );
145   CPPUNIT_ASSERT_EQUAL( false, (bool)anOuter.IsNull() );
146
147   TestViewer::show( aZone->GetTopShape(), 1, true, "Extraction_ImmZone" );
148   TestViewer::show( anOuter->GetShape(), 0, true, Qt::red );
149   CPPUNIT_ASSERT_IMAGES
150
151   aDoc->Close();
152 }