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