Salome HOME
ff966ddcf3297bfd18cd3055af23334df5b8a714
[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_Tool.h>
26
27 #include <QColor>
28 #include <QList>
29 #include <QPointF>
30
31 #include <TestShape.h>
32 #include <TestViewer.h>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Vertex.hxx>
35 #include <TopoDS_Wire.hxx>
36
37 void test_HYDROData_PolylineXY::testPolyline()
38 {
39   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
40
41   Handle(HYDROData_PolylineXY) aPolyline = 
42     Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
43
44   aPolyline->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false );
45   aPolyline->AddSection( "Section_2", HYDROData_PolylineXY::SECTION_SPLINE, true );
46
47   int aNbSections = aPolyline->NbSections();
48   CPPUNIT_ASSERT( aNbSections == 2 );
49   
50   NCollection_Sequence<TCollection_AsciiString>           aSectNames;
51   NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
52   NCollection_Sequence<bool>                              aSectClosures;
53   aPolyline->GetSections( aSectNames, aSectTypes, aSectClosures );
54
55   CPPUNIT_ASSERT_EQUAL( 2, aSectNames.Size() );
56   CPPUNIT_ASSERT( aSectNames.Value( 1 ) == "Section_1" );
57   CPPUNIT_ASSERT( aSectTypes.Value( 1 ) == HYDROData_PolylineXY::SECTION_POLYLINE );
58   CPPUNIT_ASSERT( aSectClosures.Value( 1 ) == false );
59
60   CPPUNIT_ASSERT( aSectNames.Value( 2 ) == "Section_2" );
61   CPPUNIT_ASSERT( aSectTypes.Value( 2 ) == HYDROData_PolylineXY::SECTION_SPLINE );
62   CPPUNIT_ASSERT( aSectClosures.Value( 2 ) == true );
63
64   aDoc->Close();
65 }
66
67
68 void test_HYDROData_PolylineXY::testCopy()
69 {
70   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
71   Handle(HYDROData_PolylineXY) aPolyline1 = 
72     Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
73
74
75 //  aPolyline1->setPoints(aPoints);
76
77   Handle(HYDROData_PolylineXY) aPolyline2 = 
78     Handle(HYDROData_PolylineXY)::DownCast(aDoc->CreateObject(KIND_POLYLINEXY));
79
80   aPolyline1->CopyTo(aPolyline2, true);
81
82
83   aDoc->Close();
84 }
85
86 void test_HYDROData_PolylineXY::testSplit_refs_624()
87 {
88   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
89
90   Handle(HYDROData_PolylineXY) aPolyline = 
91     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
92   aPolyline->SetName( "test" );
93
94   QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
95   TopoDS_Wire aWire = Wire( aCoords, true );
96   aPolyline->SetShape( aWire );
97
98   gp_Pnt2d aPnt( 20, 20 );
99
100   TestViewer::show( aPolyline->GetShape(), 0, true, "LandCoverMap_Split_Polyline" );
101   //TestViewer::show( BRepBuilderAPI_MakeVertex( aPnt ).Vertex(), 1, true, Qt::green );
102   CPPUNIT_ASSERT_IMAGES
103
104   HYDROData_PolylineOperator anOp;
105   CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline, aPnt, 1E-3 ) );
106
107   HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY );
108   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
109   CPPUNIT_ASSERT_EQUAL( QString( "test" ), anIt.Current()->GetName() );
110   anIt.Next();
111   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
112   CPPUNIT_ASSERT_EQUAL( QString( "test_1" ), anIt.Current()->GetName() );
113   anIt.Next();
114   CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
115
116   aDoc->Close();
117 }
118