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