Salome HOME
Merge branch 'BR_2017' of ssh://git.salome-platform.org/modules/hydro into BR_2017
[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 #include <HYDROGUI_Polyline.h>
26
27 #include <TestShape.h>
28 #include <TestViewer.h>
29
30 #include <AIS_DisplayMode.hxx>
31 #include <TopoDS_Edge.hxx>
32 #include <TopoDS_Wire.hxx>
33 #include <QColor>
34 #include <QString>
35
36 TopoDS_Edge Spline( const QList<double>& theXYList, bool isClosed = false );
37
38 void test_HYDROData_Channel::test_channel_prs_refs_751()
39 {
40   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
41
42   Handle(HYDROData_PolylineXY) Polyline_2 = 
43     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
44   Polyline_2->SetName( "polyline2d_1" );
45   Polyline_2->AddSection( "", HYDROData_IPolyline::SECTION_SPLINE, false );
46   Polyline_2->AddPoint( 0, gp_XY( -192.40, 397.86 ) );
47   Polyline_2->AddPoint( 0, gp_XY( -53.44, 293.35 ) );
48   Polyline_2->AddPoint( 0, gp_XY( 102.14, 225.65 ) );
49   Polyline_2->AddPoint( 0, gp_XY( 251.78, 108.08 ) );
50   Polyline_2->Update();
51
52   CPPUNIT_ASSERT_EQUAL( false, (bool)Polyline_2->GetShape().IsNull() );
53
54   Handle(HYDROData_Profile) aProfile0 = 
55     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
56   aProfile0->SetName( "profile_0" );
57
58   HYDROData_IPolyline::PointsList aPoints;
59   aPoints.Append( gp_XY( 0.0, 0.0 ) );
60   aPoints.Append( gp_XY( 1.0, 0.0 ) );
61   aProfile0->GetProfileUZ( true );
62   aProfile0->SetParametricPoints( aPoints );
63   aProfile0->Update();
64
65   Handle(HYDROData_Polyline3D) aPolyline3d = 
66     Handle(HYDROData_Polyline3D)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) );
67   aPolyline3d->SetName( "polyline3d_1" );
68   aPolyline3d->SetPolylineXY( Polyline_2 );
69   aPolyline3d->SetProfileUZ( aProfile0->GetProfileUZ() );
70   aPolyline3d->Update();
71
72   Handle(HYDROData_Profile) aProfile = 
73     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
74   aProfile->SetName( "profile_1" );
75
76   aPoints.Clear();
77   aPoints.Append( gp_XY( 0.0, 0.1 ) );
78   aPoints.Append( gp_XY( 12.5, 0.0 ) );
79   aPoints.Append( gp_XY( 25.0, 0.1 ) );
80   aProfile->GetProfileUZ( true );
81   aProfile->SetParametricPoints( aPoints );
82   aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
83   aProfile->Update();
84
85   CPPUNIT_ASSERT_EQUAL( false, (bool)aProfile->GetShape3D().IsNull() );
86   CPPUNIT_ASSERT_EQUAL( false, (bool)aPolyline3d->GetShape3D().IsNull() );
87
88   Handle(HYDROData_Channel) aChannel = 
89     Handle(HYDROData_Channel)::DownCast( aDoc->CreateObject( KIND_CHANNEL ) );
90   aChannel->SetName( "channel_1" );
91   
92   aChannel->SetGuideLine( aPolyline3d );
93   aChannel->SetProfile( aProfile );
94   aChannel->Update();
95   CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetTopShape().IsNull() );
96   CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetShape3D().IsNull() );
97
98   TestViewer::show( aChannel->GetTopShape(), AIS_Shaded, true, "Channel" );
99   TestViewer::show( aChannel->GetLeftShape(), AIS_WireFrame, true, Qt::red );
100   TestViewer::show( aChannel->GetRightShape(), AIS_WireFrame, true, Qt::red );
101   Handle(HYDROGUI_Polyline) Polyline_Prs = new HYDROGUI_Polyline( aPolyline3d->GetShape3D() );
102   Polyline_Prs->SetColor( Quantity_NOC_WHITE );
103   TestViewer::show( Polyline_Prs, AIS_WireFrame, 0, true, "" );
104   CPPUNIT_ASSERT_IMAGES
105  
106   aDoc->Close();
107 }