Salome HOME
stream/channel/dtm presentation redisign + bug fixes for old brep proj, etc.. (draft)
[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   HYDRODATA_EXPORT static void CreatePresentations( const Handle(TColgp_HArray1OfPnt)     theArrayOfFPnt,
87                                                     const Handle(TColgp_HArray1OfPnt)     theArrayOfLPnt,
88                                                     const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
89                                                     PrsDefinition&                        thePrs );
90
91 public:
92
93   /**
94    * Returns the kind of this object. Must be redefined in all objects of known type.
95    */
96   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_STREAM;}
97
98   /**
99    * Dump object to Python script representation.
100    */
101   HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath,
102                                                      MapOfTreatedObjects& theTreatedObjects ) const;
103
104   /**
105    * Returns the list of all reference objects of this object.
106    */
107   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() 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 void UpdatePrs( const Handle_HYDROData_DTM& );
124
125   /**
126    *
127    */
128   HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination,
129                                         bool isGenerateNewName ) const;
130
131
132   /**
133    * Returns default filling color for new stream.
134    */
135   HYDRODATA_EXPORT virtual QColor DefaultFillingColor() const;
136
137   /**
138    * Returns default border color for new stream.
139    */
140   HYDRODATA_EXPORT virtual QColor DefaultBorderColor() const;
141
142   /**
143    * Returns true if given polyline can be used as stream axis.
144    */
145   HYDRODATA_EXPORT static bool IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theAxis );
146
147 public:      
148   // Public methods to work with Stream presentation
149   
150   /**
151    * Returns the left edge of the stream.
152    */
153   HYDRODATA_EXPORT virtual TopoDS_Shape GetLeftShape() const;
154
155   /**
156    * Returns the right edge of the stream.
157    */
158   HYDRODATA_EXPORT virtual TopoDS_Shape GetRightShape() const;
159
160   /**
161    * Returns the inlet edge of the stream.
162    */
163   HYDRODATA_EXPORT virtual TopoDS_Shape GetInletShape() const;
164
165   /**
166    * Returns the outlet edge of the stream.
167    */
168   HYDRODATA_EXPORT virtual TopoDS_Shape GetOutletShape() const;
169
170
171 public:      
172   // Public methods to work with Stream data fields
173
174   /**
175    * Sets reference hydraulic axis object for stream.
176    */
177   HYDRODATA_EXPORT virtual bool SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis );
178
179   /**
180    * Returns reference hydraulic axis object of stream.
181    */
182   HYDRODATA_EXPORT virtual Handle(HYDROData_PolylineXY) GetHydraulicAxis() const;
183
184   /**
185    * Remove reference hydraulic axis object from stream.
186    */
187   HYDRODATA_EXPORT virtual void RemoveHydraulicAxis();
188
189   /**
190    * Returns true if profile has the intersection with the given hydraulic axis.
191    * Returns the parameter of inresection point on axis if axis is presented by one curve,
192    * if axis presented by set of edges the <outPar> returns a common length of segments till the intersection point. 
193    */
194   HYDRODATA_EXPORT static bool HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis, 
195                                                 const Handle(HYDROData_Profile)&    theProfile,
196                                                 const TopoDS_Face&                  thePlane,
197                                                 Standard_Real&                      theOutPar );
198
199   /**
200    * Returns true if profile has the intersection with reference 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 virtual bool HasIntersection( const Handle(HYDROData_Profile)& theProfile,
205                                                  const TopoDS_Face&               thePlane,
206                                                  Standard_Real&                   theOutPar ) const;
207
208   /**
209   * Builds a planar face
210   */
211   HYDRODATA_EXPORT static bool BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
212                                           TopoDS_Face&                        thePlane );
213
214   /**
215    * Add new one reference profile object for stream.
216    */
217   HYDRODATA_EXPORT virtual bool AddProfile( const Handle(HYDROData_Profile)& theProfile );
218
219   /**
220    * Add new one reference profile object for stream.
221    */
222   HYDRODATA_EXPORT virtual bool SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
223                                              const bool&                        theIsToOrder = true );
224
225   /**
226    * Returns all reference profile objects of stream.
227    */
228   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetProfiles() const;
229
230   /**
231    * Removes reference profile object from stream.
232    */
233   HYDRODATA_EXPORT virtual bool RemoveProfile( const Handle(HYDROData_Profile)& theProfile );
234
235   /**
236    * Removes all reference profile objects from stream.
237    */
238   HYDRODATA_EXPORT virtual void RemoveProfiles();
239
240   /**
241    * Generates bottom polyline for stream or update the existing bottom polyline.
242    * \return true in case of success
243    */
244   HYDRODATA_EXPORT virtual bool GenerateBottomPolyline();
245
246   /**
247    * Returns reference bottom polyline object of stream.
248    */
249   HYDRODATA_EXPORT virtual Handle(HYDROData_Polyline3D) GetBottomPolyline() const;
250   
251   /**
252    * Sets reference bottom polyline object for stream.
253    * \param theBottom the polyline 3D
254    * \return true in case of success
255    */
256   HYDRODATA_EXPORT virtual bool SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom );
257
258   /**
259    * Add interpolated profiles into the stream.
260    * \param theInterpolator the interpolator
261    * \return true in case of success
262    */
263   HYDRODATA_EXPORT virtual bool Interpolate( HYDROData_IProfilesInterpolator* theInterpolator );
264   
265
266   HYDRODATA_EXPORT double GetDDZ() const;
267   HYDRODATA_EXPORT void   SetDDZ( double theDDZ );
268   
269   HYDRODATA_EXPORT double GetSpatialStep() const;
270   HYDRODATA_EXPORT void   SetSpatialStep( double theSpatialStep );
271   
272 protected:
273
274   /**
275    * Insert one profile in to the stream profiles order.
276    */
277   void insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
278                                const int                        theBeforeIndex = -1 );
279
280   /**
281    * Fully recompute the order of all profiles in accordance with reference hydraulic axis.
282    * If hydraulic axis is not set all profiles will be removed from order.
283    */
284   void updateProfilesOrder();
285   
286   /**
287    * Returns the type of child altitude object.
288    * Reimplemented to create stream altitude object.
289    */
290   HYDRODATA_EXPORT virtual ObjectKind getAltitudeObjectType() const;
291
292   /**
293    * Builds b-spline using interpolation algorithm.
294    */
295   static Handle(Geom_BSplineCurve) buildInterpolationCurve(
296     const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt );
297
298 private:
299   
300   void setParametersArray( const TColStd_Array1OfReal& theArray );
301
302   TColStd_Array1OfReal* getParametersArray() const;
303
304   void removeParametersArray();
305
306   int insertParameter( const Standard_Real& theParam );
307
308   void removeParameter( const int& theIndex );
309
310   Handle_HYDROData_DTM DTM() const;
311
312
313 protected:
314   friend class HYDROData_Iterator;
315   friend class test_HYDROData_Stream;
316
317   /**
318    * Creates new object in the internal data structure. Use higher level objects 
319    * to create objects with real content.
320    */
321   HYDRODATA_EXPORT HYDROData_Stream();
322
323   /**
324    * Destructs properties of the object and object itself, removes it from the document.
325    */
326   virtual HYDRODATA_EXPORT ~HYDROData_Stream();
327 };
328
329 #endif
330
331