Salome HOME
refs #576: Artificial object that does not follow the polyline.
[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
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     DataTag_BottomPolyline     ///< reference bottom polyline
68   };
69
70 public:
71
72   DEFINE_STANDARD_RTTI(HYDROData_Stream);
73
74 public:
75
76   /**
77    * Creates the presentations(2D and 3D) by given hydraulic axis and profiles.
78    */
79   HYDRODATA_EXPORT static bool CreatePresentations( const Handle(HYDROData_PolylineXY)& theHydAxis,
80                                                     const HYDROData_SequenceOfObjects&  theProfiles,
81                                                     PrsDefinition&                      thePrs );
82
83   /**
84    * Creates the presentations(2D and 3D) by given first points, last points and profiles.
85    * If 2D profiles is null - they will not used in the presentation.
86    */
87   HYDRODATA_EXPORT static bool CreatePresentations( const Handle(TColgp_HArray1OfPnt)     theArrayOfFPnt,
88                                                     const Handle(TColgp_HArray1OfPnt)     theArrayOfLPnt,
89                                                     const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
90                                                     const Handle(TopTools_HArray1OfShape) theArrOf2DProfiles,
91                                                     PrsDefinition&                        thePrs );
92
93 public:
94
95   /**
96    * Returns the kind of this object. Must be redefined in all objects of known type.
97    */
98   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_STREAM;}
99
100   /**
101    * Dump object to Python script representation.
102    */
103   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
104
105   /**
106    * Returns the list of all reference objects of this object.
107    */
108   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
109
110   /**
111    * Returns the top shape of the object.
112    */
113   HYDRODATA_EXPORT virtual TopoDS_Shape GetTopShape() const;
114
115   /**
116    * Returns the 3d shape of the object.
117    */
118   HYDRODATA_EXPORT virtual TopoDS_Shape GetShape3D() const;
119
120   /**
121    * Update the profiles order and shape presentations of stream.
122    * Call this method whenever you made changes for stream data.
123    */
124   HYDRODATA_EXPORT virtual void Update();
125
126   /**
127    * Checks that object has 2D presentation. Reimlemented to retun true.
128    */
129   HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
130
131   /**
132    * Update the shape presentations of stream.
133    */
134   HYDRODATA_EXPORT virtual void UpdatePrs();
135
136   /**
137    *
138    */
139   HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination ) const;
140
141
142   /**
143    * Returns default filling color for new stream.
144    */
145   HYDRODATA_EXPORT static QColor DefaultFillingColor();
146
147   /**
148    * Returns default border color for new stream.
149    */
150   HYDRODATA_EXPORT static QColor DefaultBorderColor();
151
152   /**
153    * Returns true if given polyline can be used as stream axis.
154    */
155   HYDRODATA_EXPORT static bool IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theAxis );
156
157 public:      
158   // Public methods to work with Stream presentation
159   
160   /**
161    * Returns the left edge of the stream.
162    */
163   HYDRODATA_EXPORT virtual TopoDS_Shape GetLeftShape() const;
164
165   /**
166    * Returns the right edge of the stream.
167    */
168   HYDRODATA_EXPORT virtual TopoDS_Shape GetRightShape() const;
169
170   /**
171    * Returns the inlet edge of the stream.
172    */
173   HYDRODATA_EXPORT virtual TopoDS_Shape GetInletShape() const;
174
175   /**
176    * Returns the outlet edge of the stream.
177    */
178   HYDRODATA_EXPORT virtual TopoDS_Shape GetOutletShape() const;
179
180
181 public:      
182   // Public methods to work with Stream data fields
183
184   /**
185    * Sets reference hydraulic axis object for stream.
186    */
187   HYDRODATA_EXPORT virtual bool SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis );
188
189   /**
190    * Returns reference hydraulic axis object of stream.
191    */
192   HYDRODATA_EXPORT virtual Handle(HYDROData_PolylineXY) GetHydraulicAxis() const;
193
194   /**
195    * Remove reference hydraulic axis object from stream.
196    */
197   HYDRODATA_EXPORT virtual void RemoveHydraulicAxis();
198
199   /**
200    * Returns true if profile has the intersection with the given hydraulic axis.
201    * Returns the parameter of inresection point on axis if axis is presented by one curve,
202    * if axis presented by set of edges the <outPar> returns a common length of segments till the intersection point. 
203    */
204   HYDRODATA_EXPORT static bool HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis, 
205                                                 const Handle(HYDROData_Profile)&    theProfile,
206                                                 const TopoDS_Face&                  thePlane,
207                                                 Standard_Real&                      theOutPar );
208
209   /**
210    * Returns true if profile has the intersection with reference hydraulic axis.
211    * Returns the parameter of inresection point on axis if axis is presented by one curve,
212    * if axis presented by set of edges the <outPar> returns a common length of segments till the intersection point. 
213    */
214   HYDRODATA_EXPORT virtual bool HasIntersection( const Handle(HYDROData_Profile)& theProfile,
215                                                  const TopoDS_Face&               thePlane,
216                                                  Standard_Real&                   theOutPar ) const;
217
218   /**
219   * Builds a planar face
220   */
221   HYDRODATA_EXPORT static bool BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
222                                           TopoDS_Face&                        thePlane );
223
224   /**
225    * Add new one reference profile object for stream.
226    */
227   HYDRODATA_EXPORT virtual bool AddProfile( const Handle(HYDROData_Profile)& theProfile );
228
229   /**
230    * Add new one reference profile object for stream.
231    */
232   HYDRODATA_EXPORT virtual bool SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
233                                              const bool&                        theIsToOrder = true );
234
235   /**
236    * Returns all reference profile objects of stream.
237    */
238   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetProfiles() const;
239
240   /**
241    * Removes reference profile object from stream.
242    */
243   HYDRODATA_EXPORT virtual bool RemoveProfile( const Handle(HYDROData_Profile)& theProfile );
244
245   /**
246    * Removes all reference profile objects from stream.
247    */
248   HYDRODATA_EXPORT virtual void RemoveProfiles();
249
250   /**
251    * Generates bottom polyline for stream or update the existing bottom polyline.
252    * \return true in case of success
253    */
254   HYDRODATA_EXPORT virtual bool GenerateBottomPolyline();
255
256   /**
257    * Returns reference bottom polyline object of stream.
258    */
259   HYDRODATA_EXPORT virtual Handle(HYDROData_Polyline3D) GetBottomPolyline() const;
260   
261   /**
262    * Sets reference bottom polyline object for stream.
263    * \param theBottom the polyline 3D
264    * \return true in case of success
265    */
266   HYDRODATA_EXPORT virtual bool SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom );
267
268   /**
269    * Add interpolated profiles into the stream.
270    * \param theInterpolator the interpolator
271    * \return true in case of success
272    */
273   HYDRODATA_EXPORT virtual bool Interpolate( HYDROData_IProfilesInterpolator* theInterpolator );
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   /**
302    * Returns default filling color for new object.
303    */
304   HYDRODATA_EXPORT virtual QColor getDefaultFillingColor() const;
305
306   /**
307    * Returns default border color for new object.
308    */
309   HYDRODATA_EXPORT virtual QColor getDefaultBorderColor() const;
310
311 private:
312   
313   void setParametersArray( const TColStd_Array1OfReal& theArray );
314
315   TColStd_Array1OfReal* getParametersArray() const;
316
317   void removeParametersArray();
318
319   int insertParameter( const Standard_Real& theParam );
320
321   void removeParameter( const int& theIndex );
322
323 protected:
324
325   friend class HYDROData_Iterator;
326
327   /**
328    * Creates new object in the internal data structure. Use higher level objects 
329    * to create objects with real content.
330    */
331   HYDRODATA_EXPORT HYDROData_Stream();
332
333   /**
334    * Destructs properties of the object and object itself, removes it from the document.
335    */
336   virtual HYDRODATA_EXPORT ~HYDROData_Stream();
337 };
338
339 #endif
340
341