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