Salome HOME
Merge branch 'master' of ssh://git.salome-platform.org/modules/hydro
[modules/hydro.git] / src / HYDROData / HYDROData_PolylineXY.h
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef HYDROData_PolylineXY_HeaderFile
24 #define HYDROData_PolylineXY_HeaderFile
25
26 #include "HYDROData_IPolyline.h"
27
28 DEFINE_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline)
29
30 class QPainterPath;
31 class TopoDS_Wire;
32 class gp_XYZ;
33
34 /**\class HYDROData_PolylineXY
35  * \brief Class that stores/retreives information about the 
36  *        parametric profile points.
37  */
38 class HYDROData_PolylineXY : public HYDROData_IPolyline
39 {
40 protected:
41   /**
42    * Enumeration of tags corresponding to the persistent object parameters.
43    */
44   enum DataTag
45   {
46     DataTag_First = HYDROData_IPolyline::DataTag_First + 100, ///< first tag, to reserve
47     DataTag_GeomObjectEntry,  ///< study entry of the imported GEOM object
48   };
49
50 public:
51   DEFINE_STANDARD_RTTI(HYDROData_PolylineXY);
52
53
54   /**
55    * Returns the kind of this object. Must be redefined in all objects of known type.
56    */
57   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_POLYLINEXY;}
58
59   /**
60    * Dump object to Python script representation.
61    */
62   HYDRODATA_EXPORT virtual QStringList DumpToPython( 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. Reimlemented to retun true.
74    */
75   HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
76
77   /**
78    * Returns data of object wrapped to QVariant.
79    * Reimplemented 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 public:
89
90   /**
91    * Returns the presentation of polyline section in CAS maner.
92    */
93   HYDRODATA_EXPORT static TopoDS_Wire BuildWire( const SectionType&                  theType,
94                                                  const bool&                         theIsClosed,
95                                                  const NCollection_Sequence<gp_XYZ>& thePoints );
96
97   /**
98    * Returns the presentation of polyline section in Qt maner.
99    */
100   HYDRODATA_EXPORT static void BuildPainterPath( QPainterPath&                       thePath,
101                                                  const SectionType&                  theType,
102                                                  const bool&                         theIsClosed,
103                                                  const NCollection_Sequence<gp_XYZ>& thePoints );
104
105 public:
106
107   /**
108    * Imports shape from IOR.
109    * \param theIOR the IOR of Geom object
110    * \return \c true if shape has been successfully imported
111    */
112   HYDRODATA_EXPORT virtual bool ImportFromGeomIOR( const TCollection_AsciiString& theIOR );
113
114   /**
115    * Stores the study entry of the imported GEOM object.
116    * \param theEntry GEOM object entry
117    */
118   HYDRODATA_EXPORT void SetGeomObjectEntry( const TCollection_AsciiString& theEntry );
119
120   /**
121    * Returns the imported GEOM object entry.
122    */
123   HYDRODATA_EXPORT TCollection_AsciiString GetGeomObjectEntry() const;
124
125 public:
126
127   /**
128    * Returns the 2D presentation of all points.
129    */
130   HYDRODATA_EXPORT virtual TopoDS_Shape GetShape() const;
131
132   /**
133    * Returns the 3D presentation of all points.
134    */
135   HYDRODATA_EXPORT virtual bool ImportShape( const TopoDS_Shape& theShape );
136
137
138   /**
139    * Returns flag indicating that polyline can be edited or not.
140    */
141   HYDRODATA_EXPORT virtual bool IsEditable() const;
142
143   
144   /**
145    * Returns true if polyline is closed
146    * \param theIsSimpleCheck flag indicating the type of checking
147    *        - if true then all wires checked on closures
148    *        - if false then for positive result polyline should consist of
149    *          only one wire and which must be closed
150    */
151   HYDRODATA_EXPORT bool IsClosed( const bool theIsSimpleCheck = true ) const;
152
153    /**
154    * Returns the distance beetwen first and point with index thePointIndex
155    * at the section with index theSectionIndex. -1 is returned if error is occurred.
156    */
157   HYDRODATA_EXPORT double GetDistance( const int theSectionIndex,
158                                        const int thePointIndex ) const;
159
160
161   /**
162    * Returns number of sections.
163    */
164   HYDRODATA_EXPORT virtual int NbSections() const;
165
166   /**
167    * Adds new one section.
168    * \param theSectName name of the section
169    * \param theSectionType type of section
170    * \param theIsClosed flag indicates closures of section
171    */
172   HYDRODATA_EXPORT virtual void AddSection( const TCollection_AsciiString& theSectName,
173                                             const SectionType              theSectionType,
174                                             const bool                     theIsClosed );
175
176   /**
177    * Returns name of section with given index.
178    * \param theSectionIndex index of section
179    */
180   HYDRODATA_EXPORT virtual TCollection_AsciiString GetSectionName( const int theSectionIndex ) const;
181
182   /**
183    * Set name for section with given index.
184    * \param theSectionIndex index of section
185    * \param theSectionName new section name
186    */
187   HYDRODATA_EXPORT virtual void SetSectionName( const int                      theSectionIndex, 
188                                                 const TCollection_AsciiString& theSectionName );
189
190   /**
191    * Returns type of section with given index.
192    * \param theSectionIndex index of section
193    */
194   HYDRODATA_EXPORT virtual SectionType GetSectionType( const int theSectionIndex ) const;
195
196   /**
197    * Set type for section with given index.
198    * \param theSectionIndex index of section
199    * \param theSectionType new section type
200    */
201   HYDRODATA_EXPORT virtual void SetSectionType( const int         theSectionIndex, 
202                                                 const SectionType theSectionType );
203
204   /**
205    * Returns true if section with given index is closed.
206    * \param theSectionIndex index of section
207    */
208   HYDRODATA_EXPORT virtual bool IsClosedSection( const int theSectionIndex ) const;
209
210   /**
211    * Set closed flag for section with given index.
212    * \param theSectionIndex index of section
213    * \param theIsClosed new closures state
214    */
215   HYDRODATA_EXPORT virtual void SetSectionClosed( const int  theSectionIndex, 
216                                                   const bool theIsClosed );
217
218   /**
219    * Adds new one section.
220    * \param theSectName name of the section
221    * \param theSectionType type of section
222    * \param theIsClosed flag indicates closures of section
223    */
224   HYDRODATA_EXPORT virtual void GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
225                                              NCollection_Sequence<SectionType>&             theSectTypes,
226                                              NCollection_Sequence<bool>&                    theSectClosures ) const;
227
228   /**
229    * Removes section with given index.
230    * \param theSectionIndex index of section
231    */
232   HYDRODATA_EXPORT virtual void RemoveSection( const int theSectionIndex );
233
234   /**
235    * Removes all sections.
236    */
237   HYDRODATA_EXPORT virtual void RemoveSections();
238
239
240   /**
241    * Adds new point for section with index "theSectionIndex".
242    * \param theSectionIndex index of section
243    * \param thePoint point to add
244    * \param theBeforeIndex if not equal -1 then insert point in this pos
245    */
246   HYDRODATA_EXPORT virtual void AddPoint( const int    theSectionIndex,
247                                           const Point& thePoint,
248                                           const int    thePointIndex = -1 );
249
250   /**
251    * Replaces point for section with index "theSectionIndex".
252    * \param theSectionIndex index of section
253    * \param thePoint new point
254    * \param thePointIndex index of point to replace
255    */
256   HYDRODATA_EXPORT virtual void SetPoint( const int    theSectionIndex,
257                                           const Point& thePoint,
258                                           const int    thePointIndex );
259
260   /**
261    * Replaces point for section with index "theSectionIndex".
262    * \param theSectionIndex index of section
263    * \param thePoints new points
264    */
265   HYDRODATA_EXPORT virtual void SetPoints( const int         theSectionIndex,
266                                            const PointsList& thePoints );
267
268   /**
269    * Removes point from section with index "theSectionIndex".
270    * \param theSectionIndex index of section
271    * \param thePointIndex index of point
272    */
273   HYDRODATA_EXPORT virtual void RemovePoint( const int theSectionIndex,
274                                              const int thePointIndex );
275
276
277   /**
278    * Returns list of points.
279    * \param theSectionIndex if not equal -1 then list of points returned
280    *                        only for section with this index
281    * \return list of points
282    */
283   HYDRODATA_EXPORT virtual PointsList GetPoints( const int theSectionIndex = -1 ) const;
284
285
286   /**
287    * Returns the painter path.
288    * Note: currently only the first section of the polyline data is taken into account.
289    * \return polyline painter path.
290    */
291   HYDRODATA_EXPORT virtual QPainterPath GetPainterPath() const;
292
293
294 protected:
295
296   /**
297    * Sets the flag indicating that polyline can be edited or not.
298    */
299   HYDRODATA_EXPORT virtual void setEditable( const bool theIsEditable );
300
301 protected:
302
303   friend class HYDROData_Profile;
304   friend class HYDROData_Iterator;
305
306   /**
307    * Creates new object in the internal data structure. Use higher level objects 
308    * to create objects with real content.
309    */
310   HYDRODATA_EXPORT HYDROData_PolylineXY();
311
312   /**
313    * Destructs properties of the object and object itself, removes it from the document.
314    */
315   HYDRODATA_EXPORT ~HYDROData_PolylineXY();
316 };
317
318 #endif