Salome HOME
Merge branch 'BR_LAND_COVER_MAP' into BR_quadtree
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_Channel.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_Channel.h>
20 #include <HYDROData_Document.h>
21 #include <HYDROData_Channel.h>
22 #include <HYDROData_PolylineXY.h>
23 #include <HYDROData_Polyline3D.h>
24 #include <HYDROData_Profile.h>
25
26 #include <TestShape.h>
27 #include <TestViewer.h>
28
29 #include <AIS_DisplayMode.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Wire.hxx>
32 #include <QColor>
33 #include <QString>
34
35 TopoDS_Edge Spline( const QList<double>& theXYList, bool isClosed = false );
36
37 void test_HYDROData_Channel::test_2d_prs()
38 {
39   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
40
41   Handle(HYDROData_PolylineXY) aPolyline2d = 
42     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
43   aPolyline2d->SetName( "polyline2d_1" );
44   aPolyline2d->AddSection( "", HYDROData_IPolyline::SECTION_SPLINE, false );
45
46   Handle(HYDROData_Polyline3D) aPolyline3d = 
47     Handle(HYDROData_Polyline3D)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) );
48   aPolyline3d->SetName( "polyline3d_1" );
49   aPolyline3d->SetPolylineXY( aPolyline2d );
50
51   QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
52   TopoDS_Wire aWire = Wire( aCoords, false );
53   aPolyline2d->SetShape( aWire );
54   aPolyline3d->SetTopShape( aWire );
55   aPolyline3d->SetShape3D( aWire );
56
57   Handle(HYDROData_Profile) aProfile = 
58     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
59   aProfile->SetName( "profile_1" );
60
61   QList<double> aCoordsPr = QList<double>() << 0.0 << 0.1 << 0.5 << 0.0 << 1.0 << 0.1;
62   TopoDS_Wire aWirePr = Wire( aCoordsPr, false );
63   aProfile->SetTopShape( aWirePr );
64   aProfile->SetShape3D( aWirePr );
65
66
67   Handle(HYDROData_Channel) aChannel = 
68     Handle(HYDROData_Channel)::DownCast( aDoc->CreateObject( KIND_CHANNEL ) );
69   aChannel->SetName( "channel_1" );
70   
71   aChannel->SetGuideLine( aPolyline3d );
72   aChannel->SetProfile( aProfile );
73   aChannel->Update();
74   CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetTopShape().IsNull() );
75   CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetShape3D().IsNull() );
76
77   TestViewer::show( aChannel->GetTopShape(), AIS_Shaded, true, "Channel" );
78   TestViewer::show( aChannel->GetLeftShape(), AIS_WireFrame, true, Qt::red );
79   TestViewer::show( aChannel->GetRightShape(), AIS_WireFrame, true, Qt::red );
80   //TestViewer::show( aWire, AIS_Shaded, true, "Channel" );
81   CPPUNIT_ASSERT_IMAGES
82
83   aDoc->Close();
84 }