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