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