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