Salome HOME
656b312b06dc683e84287132a4f45c5f5e196588
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Curve.hxx
1 // Copyright (C) 2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:        CurveCreator_Curve.hxx
21 // Author:      Sergey KHROMOV
22
23 #ifndef _CurveCreator_Curve_HeaderFile
24 #define _CurveCreator_Curve_HeaderFile
25
26 #include "CurveCreator_ICurve.hxx"
27
28 #include "CurveCreator_Macro.hxx"
29 #include "CurveCreator.hxx"
30 #include "CurveCreator_Diff.hxx"
31
32 #include <list>
33
34 struct CurveCreator_Section;
35 class CurveCreator_Listener;
36
37 /**
38  *  The CurveCreator_Curve object is represented as one or more sets of
39  *  connected points; thus CurveCreator_Curve object can contain several
40  *  not connected curves (polylines or b-splines), each such curve has two
41  *  only ends � start and end points � in other words non-manifold curves
42  *  are not supported.
43  */
44 class CURVECREATOR_EXPORT CurveCreator_Curve : public CurveCreator_ICurve
45 {
46 private:
47   typedef std::list<CurveCreator_Diff> ListDiff;
48
49 public:
50   //! Constructor of the curve.
51   /** The dimension is explicitly specified in the constructor
52    *  and cannot be changed later.
53    */
54   CurveCreator_Curve(const CurveCreator::Dimension theDimension);
55
56   //! Destructor.
57   virtual ~CurveCreator_Curve();
58
59   //! Get the dimension.
60   virtual CurveCreator::Dimension getDimension() const;
61
62   //! Return unique section name
63   virtual std::string getUniqSectionName() const;
64
65   //! Set curve creator listener object
66   virtual void setListener( CurveCreator_Listener* theWatcher );
67
68   //! Remove curve creator listener object
69   virtual void removeListener();
70
71   /** Set depth of undo operations (unlimited if \a theDepth is -1
72    *  or disabled if \a theDepth is 0)
73    */
74   virtual void setUndoDepth(const int theDepth = -1);
75
76   //! Get depth of undo operations.
77   virtual int getUndoDepth() const;
78
79   virtual void startOperation();
80   virtual void finishOperation();
81
82   /**
83    * This method converts the point index to the index in
84    * an array of coordinates.
85    */
86   virtual int toICoord(const int theIPnt) const;
87
88 protected:
89   /** This method updates all undo/redo information required to be updated
90    *  after curve modification operation. It returns false if undo/redo
91    *  is disabled and true otherwise.
92    */
93   virtual bool addEmptyDiff();
94
95
96 public:
97   /************   Implementation of INTERFACE methods   ************/
98
99   /***********************************************/
100   /***          Undo/Redo methods              ***/
101   /***********************************************/
102
103   //! Get number of available undo operations
104   virtual int getNbUndo() const;
105
106   //! Undo previous operation
107   virtual bool undo();
108
109   //! Get number of available redo operations
110   virtual int getNbRedo() const;
111
112   //! Redo last previously "undone" operation
113   virtual bool redo();
114
115
116   /***********************************************/
117   /***           Section methods               ***/
118   /***********************************************/
119
120   //! Clear the polyline (remove all sections)
121   virtual bool clear();
122
123   //! Join range of sections to one section (join all sections if -1 is passed in one of arguments)
124   virtual bool join( const int theISectionTo = -1, 
125                      const int theISectionFrom = -1 );
126
127   //! Get number of sections
128   virtual int getNbSections() const;
129
130   //! Add a new section.
131   virtual int addSection( const std::string &theName, 
132                            const CurveCreator::SectionType theType,
133                            const bool theIsClosed );
134
135   //! Add a new section.
136   virtual int addSection( const std::string &theName, 
137                            const CurveCreator::SectionType theType,
138                            const bool theIsClosed,
139                            const CurveCreator::Coordinates &thePoints);
140
141   //! Removes the given sections.
142   virtual bool removeSection( const int theISection );
143
144   //! Get "closed" flag of the specified section
145   virtual bool isClosed( const int theISection ) const;
146
147   /**
148    *  Set "closed" flag of the specified section (all sections if
149    *  \a theISection is -1).
150    */
151   virtual bool setClosed( const int theISection, 
152                           const bool theIsClosed );
153
154   //! Returns specifyed section name
155   virtual std::string getSectionName( const int theISection ) const;
156
157   /** Set name of the specified section */
158   virtual bool setSectionName( const int theISection, 
159                                const std::string& theName );
160
161   //! Get type of the specified section
162   virtual CurveCreator::SectionType getSectionType( const int theISection ) const;
163
164   /**
165    *  Set type of the specified section (or all sections
166    *  if \a theISection is -1).
167    */
168   virtual bool setSectionType( const int theISection, 
169                                const CurveCreator::SectionType theType );
170
171
172   /***********************************************/
173   /***           Point methods                 ***/
174   /***********************************************/
175
176   /**
177    *  Add one point to the specified section starting from the given theIPnt index
178    *  (or at the end of points if \a theIPnt is -1).
179    */
180   virtual bool addPoints( const CurveCreator::Coordinates &theCoords,
181                           const int theISection,
182                           const int theIPnt = -1 );
183
184    //! Set coordinates of specified point
185   virtual bool setPoint( const int theISection,
186                          const int theIPnt,
187                          const CurveCreator::Coordinates& theNewCoords );
188
189   /** Remove point with given id */
190   virtual bool removePoint( const int theISection, const int theIPnt = -1 );
191
192   //! Get coordinates of specified point
193   virtual CurveCreator::Coordinates getPoint( const int theISection, 
194                                               const int theIPnt ) const;
195
196   /**
197    * Get points of a section (the total points in Curve if theISection is equal to -1)..
198    */
199   virtual CurveCreator::Coordinates getPoints( const int theISection = -1 ) const;
200
201
202   /**
203    *  Get number of points in specified section or (the total number of points
204    *  in Curve if theISection is equal to -1).
205    */
206   virtual int getNbPoints( const int theISection ) const;
207
208
209   /***********************************************/
210   /***       Presentation methods              ***/
211   /***********************************************/
212 //  virtual TopoDS_Wire constructWire() const;
213
214 public:
215
216   bool                            myIsLocked;
217   CurveCreator::Sections          mySections;   //!< curve data
218   CurveCreator::Dimension         myDimension;  //!< curve dimension
219   CurveCreator_Listener*          myListener;   //!< listener
220
221 private:
222
223   int                             myNbUndos;
224   int                             myNbRedos;
225   ListDiff::iterator              myCurrenPos;
226   ListDiff                        myListDiffs;
227   int                             myUndoDepth;
228   int                             myOpLevel;
229 };
230
231 #endif