Salome HOME
4af7d1c6e73e18606c90c23bf3d2ad5a7caf0712
[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_Polyline3D);
37 class Handle(HYDROData_Profile);
38 class TColStd_Array1OfReal;
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 public:
85
86   /**
87    * Returns the kind of this object. Must be redefined in all objects of known type.
88    */
89   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_STREAM;}
90
91   /**
92    * Dump object to Python script representation.
93    */
94   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
95
96   /**
97    * Returns the list of all reference objects of this object.
98    */
99   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
100
101   /**
102    * Returns the top shape of the object.
103    */
104   HYDRODATA_EXPORT virtual TopoDS_Shape GetTopShape() const;
105
106   /**
107    * Returns the 3d shape of the object.
108    */
109   HYDRODATA_EXPORT virtual TopoDS_Shape GetShape3D() const;
110
111   /**
112    * Update the profiles order and shape presentations of stream.
113    * Call this method whenever you made changes for stream data.
114    */
115   HYDRODATA_EXPORT virtual void Update();
116
117   /**
118    * Checks that object has 2D presentation. Reimlemented to retun true.
119    */
120   HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
121
122   /**
123    * Update the shape presentations of stream.
124    */
125   HYDRODATA_EXPORT virtual void UpdatePrs();
126
127   /**
128    * Returns default filling color for new stream.
129    */
130   HYDRODATA_EXPORT static QColor DefaultFillingColor();
131
132   /**
133    * Returns default border color for new stream.
134    */
135   HYDRODATA_EXPORT static QColor DefaultBorderColor();
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 bool BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
207                                           TopoDS_Face&                        thePlane );
208
209   /**
210    * Add new one reference profile object for stream.
211    */
212   HYDRODATA_EXPORT virtual bool AddProfile( const Handle(HYDROData_Profile)& theProfile );
213
214   /**
215    * Add new one reference profile object for stream.
216    */
217   HYDRODATA_EXPORT virtual bool SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
218                                              const bool&                        theIsToOrder = true );
219
220   /**
221    * Returns all reference profile objects of stream.
222    */
223   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetProfiles() const;
224
225   /**
226    * Removes reference profile object from stream.
227    */
228   HYDRODATA_EXPORT virtual bool RemoveProfile( const Handle(HYDROData_Profile)& theProfile );
229
230   /**
231    * Removes all reference profile objects from stream.
232    */
233   HYDRODATA_EXPORT virtual void RemoveProfiles();
234
235   /**
236    * Generates bottom polyline for stream or update the existing bottom polyline.
237    * \return true in case of success
238    */
239   HYDRODATA_EXPORT virtual bool GenerateBottomPolyline();
240
241   /**
242    * Returns reference bottom polyline object of stream.
243    */
244   HYDRODATA_EXPORT virtual Handle(HYDROData_Polyline3D) GetBottomPolyline() const;
245   
246 protected:
247
248   /**
249    * Insert one profile in to the stream profiles order.
250    */
251   void insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
252                                const int                        theBeforeIndex = -1 );
253
254   /**
255    * Fully recompute the order of all profiles in accordance with reference hydraulic axis.
256    * If hydraulic axis is not set all profiles will be removed from order.
257    */
258   void updateProfilesOrder();
259   
260   /**
261    * Returns the type of child altitude object.
262    * Reimplemented to create stream altitude object.
263    */
264   HYDRODATA_EXPORT virtual ObjectKind getAltitudeObjectType() const;
265
266   /**
267    * Builds b-spline using interpolation algorithm.
268    */
269   static Handle(Geom_BSplineCurve) buildInterpolationCurve(
270     const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt );
271
272   /**
273    * Returns default filling color for new object.
274    */
275   HYDRODATA_EXPORT virtual QColor getDefaultFillingColor() const;
276
277   /**
278    * Returns default border color for new object.
279    */
280   HYDRODATA_EXPORT virtual QColor getDefaultBorderColor() const;
281
282 private:
283   
284   void setParametersArray( const TColStd_Array1OfReal& theArray );
285
286   TColStd_Array1OfReal* getParametersArray() const;
287
288   void removeParametersArray();
289
290   int insertParameter( const Standard_Real& theParam );
291
292   void removeParameter( const int& theIndex );
293
294 protected:
295
296   friend class HYDROData_Iterator;
297
298   /**
299    * Creates new object in the internal data structure. Use higher level objects 
300    * to create objects with real content.
301    */
302   HYDRODATA_EXPORT HYDROData_Stream();
303
304   /**
305    * Destructs properties of the object and object itself, removes it from the document.
306    */
307   virtual HYDRODATA_EXPORT ~HYDROData_Stream();
308 };
309
310 #endif
311
312