Salome HOME
45a81943493c1a8cb4c07474f372e15bded0bc13
[modules/hydro.git] / src / HYDROData / HYDROData_Stream.h
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef HYDROData_Stream_HeaderFile
24 #define HYDROData_Stream_HeaderFile
25
26 #include "HYDROData_NaturalObject.h"
27
28 #include <TopoDS_Face.hxx>
29 #include <TopoDS_Edge.hxx>
30
31 #include <Geom_BSplineCurve.hxx>
32
33 DEFINE_STANDARD_HANDLE(HYDROData_Stream, HYDROData_NaturalObject)
34
35 class Handle(HYDROData_PolylineXY);
36 class Handle(HYDROData_Profile);
37 class TColStd_Array1OfReal;
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_Edge  myLeftBank;
52     TopoDS_Edge  myRightBank;
53     TopoDS_Edge  myInlet;
54     TopoDS_Edge  myOutlet;
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   };
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    * Returns default filling color for new stream.
127    */
128   HYDRODATA_EXPORT static QColor DefaultFillingColor();
129
130   /**
131    * Returns default border color for new stream.
132    */
133   HYDRODATA_EXPORT static QColor DefaultBorderColor();
134
135   /**
136    * Returns true if given polyline can be used as stream axis.
137    */
138   HYDRODATA_EXPORT static bool IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theAxis );
139
140 public:      
141   // Public methods to work with Stream presentation
142   
143   /**
144    * Returns the left edge of the stream.
145    */
146   HYDRODATA_EXPORT virtual TopoDS_Shape GetLeftShape() const;
147
148   /**
149    * Returns the right edge of the stream.
150    */
151   HYDRODATA_EXPORT virtual TopoDS_Shape GetRightShape() const;
152
153   /**
154    * Returns the inlet edge of the stream.
155    */
156   HYDRODATA_EXPORT virtual TopoDS_Shape GetInletShape() const;
157
158   /**
159    * Returns the outlet edge of the stream.
160    */
161   HYDRODATA_EXPORT virtual TopoDS_Shape GetOutletShape() const;
162
163
164 public:      
165   // Public methods to work with Stream data fields
166
167   /**
168    * Sets reference hydraulic axis object for stream.
169    */
170   HYDRODATA_EXPORT virtual bool SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis );
171
172   /**
173    * Returns reference hydraulic axis object of stream.
174    */
175   HYDRODATA_EXPORT virtual Handle(HYDROData_PolylineXY) GetHydraulicAxis() const;
176
177   /**
178    * Remove reference hydraulic axis object from stream.
179    */
180   HYDRODATA_EXPORT virtual void RemoveHydraulicAxis();
181
182   /**
183    * Returns true if profile has the intersection with the given hydraulic axis.
184    * Returns the parameter of inresection point on axis if axis is presented by one curve,
185    * if axis presented by set of edges the <outPar> returns a common length of segments till the intersection point. 
186    */
187   HYDRODATA_EXPORT static bool HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis, 
188                                                 const Handle(HYDROData_Profile)&    theProfile,
189                                                 const TopoDS_Face&                  thePlane,
190                                                 Standard_Real&                      theOutPar );
191
192   /**
193    * Returns true if profile has the intersection with reference 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 virtual bool HasIntersection( const Handle(HYDROData_Profile)& theProfile,
198                                                  const TopoDS_Face&               thePlane,
199                                                  Standard_Real&                   theOutPar ) const;
200
201   /**
202   * Builds a planar face
203   */
204   HYDRODATA_EXPORT static bool BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
205                                           TopoDS_Face&                        thePlane );
206
207   /**
208    * Add new one reference profile object for stream.
209    */
210   HYDRODATA_EXPORT virtual bool AddProfile( const Handle(HYDROData_Profile)& theProfile );
211
212   /**
213    * Add new one reference profile object for stream.
214    */
215   HYDRODATA_EXPORT virtual bool SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
216                                              const bool&                        theIsToOrder = true );
217
218   /**
219    * Returns all reference profile objects of stream.
220    */
221   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetProfiles() const;
222
223   /**
224    * Removes reference profile object from stream.
225    */
226   HYDRODATA_EXPORT virtual bool RemoveProfile( const Handle(HYDROData_Profile)& theProfile );
227
228   /**
229    * Removes all reference profile objects from stream.
230    */
231   HYDRODATA_EXPORT virtual void RemoveProfiles();
232   
233 protected:
234
235   /**
236    * Insert one profile in to the stream profiles order.
237    */
238   void insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
239                                const int                        theBeforeIndex = -1 );
240
241   /**
242    * Fully recompute the order of all profiles in accordance with reference hydraulic axis.
243    * If hydraulic axis is not set all profiles will be removed from order.
244    */
245   void updateProfilesOrder();
246   
247   /**
248    * Returns the type of child altitude object.
249    * Reimplemented to create stream altitude object.
250    */
251   HYDRODATA_EXPORT virtual ObjectKind getAltitudeObjectType() const;
252
253   /**
254    * Builds b-spline using interpolation algorithm.
255    */
256   static Handle(Geom_BSplineCurve) buildInterpolationCurve(
257     const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt );
258
259   /**
260    * Returns default filling color for new object.
261    */
262   HYDRODATA_EXPORT virtual QColor getDefaultFillingColor() const;
263
264   /**
265    * Returns default border color for new object.
266    */
267   HYDRODATA_EXPORT virtual QColor getDefaultBorderColor() const;
268
269 private:
270   
271   void setParametersArray( const TColStd_Array1OfReal& theArray );
272
273   TColStd_Array1OfReal* getParametersArray() const;
274
275   void removeParametersArray();
276
277   int insertParameter( const Standard_Real& theParam );
278
279   void removeParameter( const int& theIndex );
280
281 protected:
282
283   friend class HYDROData_Iterator;
284
285   /**
286    * Creates new object in the internal data structure. Use higher level objects 
287    * to create objects with real content.
288    */
289   HYDRODATA_EXPORT HYDROData_Stream();
290
291   /**
292    * Destructs properties of the object and object itself, removes it from the document.
293    */
294   virtual HYDRODATA_EXPORT ~HYDROData_Stream();
295 };
296
297 #endif
298
299