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