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