Salome HOME
patch for problems on SALOME 8.2.0
[modules/hydro.git] / src / HYDROData / HYDROData_Stream.h
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 #ifndef HYDROData_Stream_HeaderFile
20 #define HYDROData_Stream_HeaderFile
21
22 #include "HYDROData_NaturalObject.h"
23
24 #include <TopoDS_Face.hxx>
25 #include <TopoDS_Edge.hxx>
26 #include <TopoDS_Wire.hxx>
27
28 #include <Geom_BSplineCurve.hxx>
29 #include <vector>
30
31 class HYDROData_DTM;
32 class HYDROData_PolylineXY;
33 class HYDROData_Polyline3D;
34 class HYDROData_Profile;
35 class HYDROData_IProfilesInterpolator;
36 class TopTools_HArray1OfShape;
37
38
39 /**\class HYDROData_Stream
40  * \brief 
41  *
42  */
43 class HYDROData_Stream : public HYDROData_NaturalObject
44 {
45 public:
46
47   struct PrsDefinition
48   {
49     TopoDS_Shape myPrs3D;
50     TopoDS_Shape myPrs2D;
51     TopoDS_Wire  myLeftBank;   // 3d curve of the left bank
52     TopoDS_Wire  myRightBank;  // 3d curve of the right bank
53     TopoDS_Wire  myInlet;      // first (inlet) 2d profile 
54     TopoDS_Wire  myOutlet;     // last (inlet) 2d profile 
55   };
56
57 protected:
58   /**
59    * Enumeration of tags corresponding to the persistent object parameters.
60    */
61   enum DataTag
62   {
63     DataTag_First = HYDROData_NaturalObject::DataTag_First + 100, ///< first tag, to reserve
64     DataTag_HydraulicAxis,     ///< reference hydraulic axis
65     DataTag_Profile,           ///< reference profiles
66     DataTag_ParamsArray,       ///< parameters array
67     DataTag_BottomPolyline     ///< reference bottom polyline
68   };
69
70 public:
71   DEFINE_STANDARD_RTTIEXT(HYDROData_Stream, HYDROData_NaturalObject);
72
73 public:
74
75   /**
76    * Creates the presentations(2D and 3D) by given hydraulic axis and profiles.
77    */
78   HYDRODATA_EXPORT static bool CreatePresentations( const Handle(HYDROData_DTM)& theDTM,
79                                                     PrsDefinition&               thePrs );
80
81   HYDRODATA_EXPORT static void CreatePresentations( const Handle(TColgp_HArray1OfPnt)     theArrayOfFPnt,
82                                                     const Handle(TColgp_HArray1OfPnt)     theArrayOfLPnt,
83                                                     const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
84                                                     PrsDefinition&                        thePrs );
85
86 public:
87
88   /**
89    * Returns the kind of this object. Must be redefined in all objects of known type.
90    */
91   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_STREAM;}
92
93   /**
94    * Dump object to Python script representation.
95    */
96   HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath,
97                                                      MapOfTreatedObjects& theTreatedObjects ) const;
98
99   /**
100    * Returns the list of all reference objects of this object.
101    */
102   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
103
104   /**
105    * Update the profiles order and shape presentations of stream.
106    * Call this method whenever you made changes for stream data.
107    */
108   HYDRODATA_EXPORT virtual void Update();
109
110   /**
111    * Checks that object has 2D presentation. Reimlemented to retun true.
112    */
113   HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
114
115   /**
116    * Update the shape presentations of stream.
117    */
118   HYDRODATA_EXPORT void UpdatePrs( const Handle(HYDROData_DTM)& );
119
120   /**
121    *
122    */
123   HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination,
124                                         bool isGenerateNewName ) const;
125
126
127   /**
128    * Returns default filling color for new stream.
129    */
130   HYDRODATA_EXPORT virtual QColor DefaultFillingColor() const;
131
132   /**
133    * Returns default border color for new stream.
134    */
135   HYDRODATA_EXPORT virtual QColor DefaultBorderColor() const;
136
137   /**
138    * Returns true if given polyline can be used as stream axis.
139    */
140   HYDRODATA_EXPORT static bool IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theAxis );
141
142 public:      
143   // Public methods to work with Stream presentation
144   
145   /**
146    * Returns the left edge of the stream.
147    */
148   HYDRODATA_EXPORT virtual TopoDS_Shape GetLeftShape() const;
149
150   /**
151    * Returns the right edge of the stream.
152    */
153   HYDRODATA_EXPORT virtual TopoDS_Shape GetRightShape() const;
154
155   /**
156    * Returns the inlet edge of the stream.
157    */
158   HYDRODATA_EXPORT virtual TopoDS_Shape GetInletShape() const;
159
160   /**
161    * Returns the outlet edge of the stream.
162    */
163   HYDRODATA_EXPORT virtual TopoDS_Shape GetOutletShape() const;
164
165
166 public:      
167   // Public methods to work with Stream data fields
168
169   /**
170    * Sets reference hydraulic axis object for stream.
171    */
172   HYDRODATA_EXPORT virtual bool SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis );
173
174   /**
175    * Returns reference hydraulic axis object of stream.
176    */
177   HYDRODATA_EXPORT virtual Handle(HYDROData_PolylineXY) GetHydraulicAxis() const;
178
179   /**
180    * Remove reference hydraulic axis object from stream.
181    */
182   HYDRODATA_EXPORT virtual void RemoveHydraulicAxis();
183
184   /**
185    * Returns true if profile has the intersection with the given hydraulic axis.
186    * Returns the parameter of inresection point on axis if axis is presented by one curve,
187    * if axis presented by set of edges the <outPar> returns a common length of segments till the intersection point. 
188    */
189   HYDRODATA_EXPORT static bool HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis, 
190                                                 const Handle(HYDROData_Profile)&    theProfile,
191                                                 const TopoDS_Face&                  thePlane,
192                                                 Standard_Real&                      theOutPar );
193
194   /**
195    * Returns true if profile has the intersection with reference hydraulic axis.
196    * Returns the parameter of inresection point on axis if axis is presented by one curve,
197    * if axis presented by set of edges the <outPar> returns a common length of segments till the intersection point. 
198    */
199   HYDRODATA_EXPORT virtual bool HasIntersection( const Handle(HYDROData_Profile)& theProfile,
200                                                  const TopoDS_Face&               thePlane,
201                                                  Standard_Real&                   theOutPar ) const;
202
203   /**
204   * Builds a planar face
205   */
206   HYDRODATA_EXPORT static void BuildRefFace( TopoDS_Face& thePlane );
207
208   /**
209    * Add new one reference profile object for stream.
210    */
211   HYDRODATA_EXPORT virtual bool AddProfile( const Handle(HYDROData_Profile)& theProfile );
212
213   /**
214    * Add new one reference profile object for stream.
215    */
216   HYDRODATA_EXPORT virtual bool SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
217                                              const bool&                        theIsToOrder = true );
218
219   /**
220    * Returns all reference profile objects of stream.
221    */
222   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetProfiles() const;
223
224   /**
225    * Removes reference profile object from stream.
226    */
227   HYDRODATA_EXPORT virtual bool RemoveProfile( const Handle(HYDROData_Profile)& theProfile );
228
229   /**
230    * Removes all reference profile objects from stream.
231    */
232   HYDRODATA_EXPORT virtual void RemoveProfiles();
233
234   /**
235    * Generates bottom polyline for stream or update the existing bottom polyline.
236    * \return true in case of success
237    */
238   HYDRODATA_EXPORT virtual bool GenerateBottomPolyline();
239
240   /**
241    * Returns reference bottom polyline object of stream.
242    */
243   HYDRODATA_EXPORT virtual Handle(HYDROData_Polyline3D) GetBottomPolyline() const;
244   
245   /**
246    * Sets reference bottom polyline object for stream.
247    * \param theBottom the polyline 3D
248    * \return true in case of success
249    */
250   HYDRODATA_EXPORT virtual bool SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom );
251
252   /**
253    * Add interpolated profiles into the stream.
254    * \param theInterpolator the interpolator
255    * \return true in case of success
256    */
257   HYDRODATA_EXPORT virtual bool Interpolate( HYDROData_IProfilesInterpolator* theInterpolator );
258   
259
260   HYDRODATA_EXPORT double GetDDZ() const;
261   HYDRODATA_EXPORT void   SetDDZ( double theDDZ );
262   
263   HYDRODATA_EXPORT double GetSpatialStep() const;
264   HYDRODATA_EXPORT void   SetSpatialStep( double theSpatialStep );
265   
266 protected:
267
268   /**
269    * Insert one profile in to the stream profiles order.
270    */
271   void insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
272                                const int                        theBeforeIndex = -1 );
273
274   /**
275    * Fully recompute the order of all profiles in accordance with reference hydraulic axis.
276    * If hydraulic axis is not set all profiles will be removed from order.
277    */
278   void updateProfilesOrder();
279   
280   /**
281    * Returns the type of child altitude object.
282    * Reimplemented to create stream altitude object.
283    */
284   HYDRODATA_EXPORT virtual ObjectKind getAltitudeObjectType() const;
285
286   /**
287    * Builds b-spline using interpolation algorithm.
288    */
289   static Handle(Geom_BSplineCurve) buildInterpolationCurve(
290     const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt );
291
292 private:
293   
294   void setParametersArray( const QVector<double>& theArray );
295
296   TColStd_Array1OfReal* getParametersArray() const;
297
298   void removeParametersArray();
299
300   int insertParameter( const Standard_Real& theParam );
301
302   void removeParameter( const int& theIndex );
303
304   Handle(HYDROData_DTM) DTM() const;
305
306
307 protected:
308   friend class HYDROData_Iterator;
309   friend class test_HYDROData_Stream;
310
311   /**
312    * Creates new object in the internal data structure. Use higher level objects 
313    * to create objects with real content.
314    */
315   HYDRODATA_EXPORT HYDROData_Stream();
316
317   /**
318    * Destructs properties of the object and object itself, removes it from the document.
319    */
320   virtual HYDRODATA_EXPORT ~HYDROData_Stream();
321 };
322
323 #endif
324
325