Salome HOME
[fix] After merge with BR_PY3
[modules/hydro.git] / src / HYDROData / HYDROData_LISM.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 <HYDROData_LISM.h>
20 #include <HYDROData_Profile.h>
21 #include <HYDROData_StreamLinearInterpolation.h>
22 #include <TopoDS_Face.hxx>
23
24 #include <QSet>
25 #include <QString>
26
27 IMPLEMENT_STANDARD_RTTIEXT( HYDROData_LISM, HYDROData_Bathymetry )
28
29 HYDROData_LISM::HYDROData_LISM()
30 {
31 }
32
33 HYDROData_LISM::~HYDROData_LISM()
34 {
35 }
36
37 //
38 HYDROData_SequenceOfObjects HYDROData_LISM::GetProfiles() const
39 {
40   return GetReferenceObjects( DataTag_Profiles );
41 }
42
43 void HYDROData_LISM::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles )
44 {
45   SetReferenceObjects( theProfiles, DataTag_Profiles );
46   Changed( Geom_3d );
47 }
48
49 //
50 bool HYDROData_LISM::SetLeftBank( const Handle(HYDROData_PolylineXY)& theBank )
51 {
52   if (theBank.IsNull())
53     return false;
54
55   if ( !HYDROData_Stream::IsValidAsAxis( theBank ) )
56     return false;
57
58   Handle(HYDROData_PolylineXY) aPrevBank = GetLeftBank();
59   if ( IsEqual( aPrevBank, theBank ) )
60     return true;
61
62   SetReferenceObject( theBank, DataTag_LeftBank );
63   Changed( Geom_3d );
64   return true;
65 }
66
67 Handle(HYDROData_PolylineXY) HYDROData_LISM::GetLeftBank() const
68 {
69   return Handle(HYDROData_PolylineXY)::DownCast(GetReferenceObject( DataTag_LeftBank ) );
70 }
71
72 bool HYDROData_LISM::SetRightBank( const Handle(HYDROData_PolylineXY)& theBank )
73 {
74   if (theBank.IsNull())
75     return false;
76
77   if ( !HYDROData_Stream::IsValidAsAxis( theBank ) )
78     return false;
79
80   Handle(HYDROData_PolylineXY) aPrevBank = GetRightBank();
81   if ( IsEqual( aPrevBank, theBank ) )
82     return true;
83
84   SetReferenceObject( theBank, DataTag_RightBank );
85   Changed( Geom_3d );
86   return true;
87 }
88
89 bool HYDROData_LISM::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
90 {
91   if ( !HYDROData_Stream::IsValidAsAxis( theAxis ) )
92     return false;
93
94   Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
95   if ( IsEqual( aPrevAxis, theAxis ) )
96     return true;
97
98   SetReferenceObject( theAxis, DataTag_HydraulicAxis );
99
100   Changed( Geom_3d );
101   return true;
102 }
103
104 Handle(HYDROData_PolylineXY) HYDROData_LISM::GetHydraulicAxis() const
105 {
106   return Handle(HYDROData_PolylineXY)::DownCast( GetReferenceObject( DataTag_HydraulicAxis ) );
107 }
108
109
110 Handle(HYDROData_PolylineXY) HYDROData_LISM::GetRightBank() const
111 {
112   return Handle(HYDROData_PolylineXY)::DownCast(GetReferenceObject( DataTag_RightBank ) );
113 }
114
115 int HYDROData_LISM::GetNbProfilePoints() const
116 {
117   return GetInteger( DataTag_NbProfilePoints );
118 }
119
120 void HYDROData_LISM::SetNbProfilePoints( int theNbProints )
121 {
122   SetInteger( DataTag_NbProfilePoints, theNbProints );
123   Changed( Geom_3d );
124 }
125
126 double HYDROData_LISM::GetHaxStep() const
127 {
128   return GetDouble( DataTag_HaxStep );
129 }
130
131 void HYDROData_LISM::SetHaxStep( double theHaxStep )
132 {
133   SetDouble( DataTag_HaxStep, theHaxStep );
134   Changed( Geom_3d );
135 }
136
137 void HYDROData_LISM::Update()
138 {
139   AltitudePoints anOutPoints;
140   HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();  
141   int nbprofilepoints = GetNbProfilePoints();
142   double step = GetHaxStep();
143   Handle(HYDROData_PolylineXY) aHAX = GetHydraulicAxis();
144   Handle(HYDROData_PolylineXY) aLB = GetLeftBank();
145   Handle(HYDROData_PolylineXY) aRB = GetRightBank();
146
147   std::vector<std::string> warnings;
148   HYDROData_Stream::PrsDefinition prsDef;
149   HYDROData_StreamLinearInterpolation::Perform(aRefProfiles, nbprofilepoints, step, aHAX, aLB, aRB, anOutPoints, true, false, prsDef, &warnings);
150
151   SetAltitudePoints( anOutPoints );  
152  
153   SetShape( DataTag_LeftBankShape, prsDef.myLeftBank);
154   SetShape( DataTag_RightBankShape, prsDef.myRightBank);
155   SetShape( DataTag_InletShape, prsDef.myInlet);
156   SetShape( DataTag_OutletShape, prsDef.myOutlet );
157   SetShape( DataTag_3DShape, prsDef.myPrs3D );
158   SetShape( DataTag_2DShape, prsDef.myPrs2D );
159
160   HYDROData_Bathymetry::Update();
161 }
162
163
164 void HYDROData_LISM::GetShapePresentations( HYDROData_Stream::PrsDefinition& prsDef)
165 {
166   prsDef.myLeftBank = GetShape( DataTag_LeftBankShape);
167   prsDef.myRightBank = GetShape( DataTag_RightBankShape);
168   prsDef.myInlet = GetShape( DataTag_InletShape);
169   prsDef.myOutlet = GetShape( DataTag_OutletShape );
170   prsDef.myPrs3D = GetShape( DataTag_3DShape );
171   prsDef.myPrs2D  = GetShape( DataTag_2DShape );
172 }
173
174
175 /*void HYDROData_LISM::GetWarnings(NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>>& warnings)
176 {
177   warnings = myWarnings;
178 }
179    */