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