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