Salome HOME
debug of DTM/Stream presentations
[modules/hydro.git] / src / HYDROData / HYDROData_PolylineXY.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_PolylineXY_HeaderFile
20 #define HYDROData_PolylineXY_HeaderFile
21
22 #include "HYDROData_IPolyline.h"
23 #include <TopTools_HSequenceOfShape.hxx>
24
25 DEFINE_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline)
26
27 class QPainterPath;
28 class QTransform;
29 class TopoDS_Wire;
30 class gp_XYZ;
31 class gp_Pnt;
32
33 /**\class HYDROData_PolylineXY
34  * \brief Class that stores/retrieves information about the
35  *        parametric profile points.
36  */
37 class HYDROData_PolylineXY : public HYDROData_IPolyline
38 {
39 protected:
40   /**
41    * Enumeration of tags corresponding to the persistent object parameters.
42    */
43   enum DataTag
44   {
45     DataTag_First = HYDROData_IPolyline::DataTag_First + 100, ///< first tag, to reserve
46     DataTag_GeomObjectEntry,  ///< study entry of the imported GEOM object
47   };
48
49 public:
50   DEFINE_STANDARD_RTTI(HYDROData_PolylineXY);
51
52
53   /**
54    * Returns the kind of this object. Must be redefined in all objects of known type.
55    */
56   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_POLYLINEXY;}
57
58   /**
59    * Dump object to Python script representation.
60    */
61   HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath,
62                                                      MapOfTreatedObjects& theTreatedObjects ) const;
63
64   /**
65    * Update the wire contour on the basis of the polyline data.
66    * Call this method whenever you made changes for polyline data.
67    */
68   HYDRODATA_EXPORT virtual void Update();
69
70   HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy );
71
72   /**
73    * Checks that object has 2D presentation. Re-implemented to return true.
74    */
75   HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
76
77   /**
78    * Returns data of object wrapped to QVariant.
79    * Re-implemented to wrap and return saved path.
80    */
81   HYDRODATA_EXPORT virtual QVariant GetDataVariant();
82
83   /**
84    * Returns default wire color for new polyline.
85    */
86   HYDRODATA_EXPORT static QColor DefaultWireColor();
87
88   HYDRODATA_EXPORT bool IsCustom() const;
89   HYDRODATA_EXPORT bool GetIsInCustomFlag() const;
90   HYDRODATA_EXPORT void SetIsInCustomFlag( bool theValue );
91
92 public:
93
94   /**
95    * Returns the presentation of polyline section in CAS manner.
96    */
97   HYDRODATA_EXPORT static TopoDS_Wire BuildWire( const SectionType&                  theType,
98                                                  const bool&                         theIsClosed,
99                                                  const NCollection_Sequence<gp_XYZ>& thePoints );
100
101   /**
102    * Returns the presentation of polyline section in Qt manner.
103    */
104   HYDRODATA_EXPORT static void BuildPainterPath( QPainterPath&                       thePath,
105                                                  const SectionType&                  theType,
106                                                  const bool&                         theIsClosed,
107                                                  const NCollection_Sequence<gp_XYZ>& thePoints );
108
109 public:
110
111   /**
112    * Imports shape from IOR.
113    * \param theIOR the IOR of Geom object
114    * \return \c true if shape has been successfully imported
115    */
116   HYDRODATA_EXPORT virtual bool ImportFromGeomIOR( const TCollection_AsciiString& theIOR );
117
118   /**
119    * Stores the study entry of the imported GEOM object.
120    * \param theEntry GEOM object entry
121    */
122   HYDRODATA_EXPORT void SetGeomObjectEntry( const TCollection_AsciiString& theEntry );
123
124   /**
125    * Returns the imported GEOM object entry.
126    */
127   HYDRODATA_EXPORT TCollection_AsciiString GetGeomObjectEntry() const;
128
129 public:
130
131   /**
132    * Returns the 3D presentation of all points.
133    */
134   HYDRODATA_EXPORT virtual bool ImportShape( const TopoDS_Shape& theShape,
135                                              bool IsInterpolationAllowed,
136                                              const Handle( HYDROData_PolylineXY )& theOldPolyline,
137                                              bool IsClosureAllowed = true,
138                                              double theDeviation = 1.);
139
140   /**
141    * Returns flag indicating that polyline can be edited or not.
142    */
143   HYDRODATA_EXPORT virtual bool IsEditable() const;
144
145   
146   /**
147    * Returns true if polyline is closed
148    * \param theIsSimpleCheck flag indicating the type of checking
149    *        - if true then all wires checked on closures
150    *        - if false then for positive result polyline should consist of
151    *          only one wire and which must be closed
152    */
153   HYDRODATA_EXPORT bool IsClosed( const bool theIsSimpleCheck = true ) const;
154
155   /**
156    * Returns connected wires and their number, by rebuild of the wires from the edges, looking for connections
157    */
158   HYDRODATA_EXPORT int GetNbConnectedWires(Handle(TopTools_HSequenceOfShape)& aConnectedWires) const;
159
160    /**
161    * Returns the distance between first and point with index thePointIndex
162    * at the section with index theSectionIndex. -1 is returned if error is occurred.
163    */
164   HYDRODATA_EXPORT double GetDistance( const int theSectionIndex,
165                                        const int thePointIndex ) const;
166
167   /**
168    * Returns number of sections.
169    */
170   HYDRODATA_EXPORT virtual int NbSections() const;
171
172   /**
173    * Adds new one section.
174    * \param theSectName name of the section
175    * \param theSectionType type of section
176    * \param theIsClosed flag indicates closures of section
177    */
178   HYDRODATA_EXPORT virtual void AddSection( const TCollection_AsciiString& theSectName,
179                                             const SectionType              theSectionType,
180                                             const bool                     theIsClosed );
181
182   /**
183    * Returns name of section with given index.
184    * \param theSectionIndex index of section
185    */
186   HYDRODATA_EXPORT virtual TCollection_AsciiString GetSectionName( const int theSectionIndex ) const;
187
188   /**
189    * Set name for section with given index.
190    * \param theSectionIndex index of section
191    * \param theSectionName new section name
192    */
193   HYDRODATA_EXPORT virtual void SetSectionName( const int                      theSectionIndex, 
194                                                 const TCollection_AsciiString& theSectionName );
195
196   /**
197    * Returns type of section with given index.
198    * \param theSectionIndex index of section
199    */
200   HYDRODATA_EXPORT virtual SectionType GetSectionType( const int theSectionIndex ) const;
201
202   /**
203    * Set type for section with given index.
204    * \param theSectionIndex index of section
205    * \param theSectionType new section type
206    */
207   HYDRODATA_EXPORT virtual void SetSectionType( const int         theSectionIndex, 
208                                                 const SectionType theSectionType );
209
210   /**
211    * Returns true if section with given index is closed.
212    * \param theSectionIndex index of section
213    */
214   HYDRODATA_EXPORT virtual bool IsClosedSection( const int theSectionIndex ) const;
215
216   /**
217    * Set closed flag for section with given index.
218    * \param theSectionIndex index of section
219    * \param theIsClosed new closures state
220    */
221   HYDRODATA_EXPORT virtual void SetSectionClosed( const int  theSectionIndex, 
222                                                   const bool theIsClosed );
223
224   /**
225    * Adds new one section.
226    * \param theSectName name of the section
227    * \param theSectionType type of section
228    * \param theIsClosed flag indicates closures of section
229    */
230   HYDRODATA_EXPORT virtual void GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
231                                              NCollection_Sequence<SectionType>&             theSectTypes,
232                                              NCollection_Sequence<bool>&                    theSectClosures ) const;
233
234   /**
235    * Removes section with given index.
236    * \param theSectionIndex index of section
237    */
238   HYDRODATA_EXPORT virtual void RemoveSection( const int theSectionIndex );
239
240   /**
241    * Removes all sections.
242    */
243   HYDRODATA_EXPORT virtual void RemoveSections();
244
245
246   /**
247    * Adds new point for section with index "theSectionIndex".
248    * \param theSectionIndex index of section
249    * \param thePoint point to add
250    * \param theBeforeIndex if not equal -1 then insert point in this pos
251    */
252   HYDRODATA_EXPORT virtual void AddPoint( const int    theSectionIndex,
253                                           const Point& thePoint,
254                                           const int    thePointIndex = -1 );
255
256   /**
257    * Replaces point for section with index "theSectionIndex".
258    * \param theSectionIndex index of section
259    * \param thePoint new point
260    * \param thePointIndex index of point to replace
261    */
262   HYDRODATA_EXPORT virtual void SetPoint( const int    theSectionIndex,
263                                           const Point& thePoint,
264                                           const int    thePointIndex );
265
266   /**
267    * Replaces point for section with index "theSectionIndex".
268    * \param theSectionIndex index of section
269    * \param thePoints new points
270    */
271   HYDRODATA_EXPORT virtual void SetPoints( const int         theSectionIndex,
272                                            const PointsList& thePoints );
273
274   /**
275    * Removes point from section with index "theSectionIndex".
276    * \param theSectionIndex index of section
277    * \param thePointIndex index of point
278    */
279   HYDRODATA_EXPORT virtual void RemovePoint( const int theSectionIndex,
280                                              const int thePointIndex );
281
282
283   /**
284    * Returns list of points.
285    * \param theSectionIndex if not equal -1 then list of points returned
286    *                        only for section with this index
287    * \return list of points
288    */
289   HYDRODATA_EXPORT virtual PointsList GetPoints( const int theSectionIndex = -1, bool IsConvertToGlobal = false ) const;
290
291
292   /**
293    * Returns the painter path.
294    * Note: currently only the first section of the polyline data is taken into account.
295    * \return polyline painter path.
296    */
297   HYDRODATA_EXPORT virtual QPainterPath GetPainterPath() const;
298
299   /**
300    * Transform the polyline points.
301    * @param theTrsf the transformation
302    */
303   HYDRODATA_EXPORT void Transform( const QTransform& theTrsf );
304
305 protected:
306
307   /**
308    * Sets the flag indicating that polyline can be edited or not.
309    */
310   HYDRODATA_EXPORT virtual void setEditable( const bool theIsEditable );
311
312   HYDRODATA_EXPORT void Interpolate();
313
314 protected:
315
316   friend class HYDROData_Profile;
317   friend class HYDROData_Iterator;
318
319   /**
320    * Creates new object in the internal data structure. Use higher level objects 
321    * to create objects with real content.
322    */
323   HYDRODATA_EXPORT HYDROData_PolylineXY();
324
325   /**
326    * Destructs properties of the object and object itself, removes it from the document.
327    */
328   HYDRODATA_EXPORT ~HYDROData_PolylineXY();
329
330 private:
331   bool myIsInCustomFlag;
332 };
333
334 #endif