Salome HOME
Insert a point on a selected segment - debug
[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 <AIS_Point.hxx>
33 #include <AIS_Line.hxx>
34 #include <AIS_InteractiveObject.hxx>
35
36 #include <list>
37
38 struct CurveCreator_Section;
39 class CurveCreator_Displayer;
40
41 /**
42  *  The CurveCreator_Curve object is represented as one or more sets of
43  *  connected points; thus CurveCreator_Curve object can contain several
44  *  not connected curves (polylines or b-splines), each such curve has two
45  *  only ends � start and end points � in other words non-manifold curves
46  *  are not supported.
47  */
48 class CURVECREATOR_EXPORT CurveCreator_Curve : public CurveCreator_ICurve
49 {
50 protected:
51   typedef std::list<CurveCreator_Diff> ListDiff;
52
53 public:
54   //! Constructor of the curve.
55   /** The dimension is explicitly specified in the constructor
56    *  and cannot be changed later.
57    */
58   CurveCreator_Curve(const CurveCreator::Dimension theDimension);
59
60   //! Destructor.
61   virtual ~CurveCreator_Curve();
62
63   //! Get the dimension.
64   virtual CurveCreator::Dimension getDimension() const;
65
66   //! Return unique section name
67   virtual std::string getUniqSectionName() const;
68
69   //! Set curve creator Displayer object
70   virtual void setDisplayer( CurveCreator_Displayer* theDisplayer );
71
72   //! Remove curve creator Displayer object
73   virtual void removeDisplayer();
74
75   /** Set depth of undo operations (unlimited if \a theDepth is -1
76    *  or disabled if \a theDepth is 0)
77    */
78   virtual void setUndoDepth(const int theDepth = -1);
79
80   //! Get depth of undo operations.
81   virtual int getUndoDepth() const;
82
83   virtual void startOperation();
84   virtual void finishOperation();
85
86   /**
87    * This method converts the point index to the index in
88    * an array of coordinates.
89    */
90   virtual int toICoord(const int theIPnt) const;
91
92   ListAISObjects constructSection( int theISection ) const;
93
94 protected:
95   /** This method updates all undo/redo information required to be updated
96    *  after curve modification operation. It returns false if undo/redo
97    *  is disabled and true otherwise.
98    */
99   virtual bool addEmptyDiff();
100
101   Handle_AIS_Point getAISPoint( int theISection, int theIPoint ) const;
102   Handle_AIS_Line  getAISLine( int theISection, int theIPoint1, int theIPoint2 ) const;
103   void getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const;
104
105   void redisplayCurve();
106
107 public:
108   /************   Implementation of INTERFACE methods   ************/
109
110   /***********************************************/
111   /***          Undo/Redo methods              ***/
112   /***********************************************/
113
114   //! Get number of available undo operations
115   virtual int getNbUndo() const;
116
117   //! Undo previous operation
118   virtual bool undo();
119
120   //! Get number of available redo operations
121   virtual int getNbRedo() const;
122
123   //! Redo last previously "undone" operation
124   virtual bool redo();
125
126
127   /***********************************************/
128   /***           Section methods               ***/
129   /***********************************************/
130
131   //! Clear the polyline (remove all sections)
132   virtual bool clear();
133
134   //! Join range of sections to one section (join all sections if -1 is passed in one of arguments)
135   virtual bool join( const int theISectionTo = -1, 
136                      const int theISectionFrom = -1 );
137
138   //! Get number of sections
139   virtual int getNbSections() const;
140
141   //! Add a new section.
142   virtual int addSection( const std::string &theName, 
143                            const CurveCreator::SectionType theType,
144                            const bool theIsClosed );
145
146   //! Add a new section.
147   virtual int addSection( const std::string &theName, 
148                            const CurveCreator::SectionType theType,
149                            const bool theIsClosed,
150                            const CurveCreator::Coordinates &thePoints);
151
152   //! Removes the given sections.
153   virtual bool removeSection( const int theISection );
154
155   //! Get "closed" flag of the specified section
156   virtual bool isClosed( const int theISection ) const;
157
158   /**
159    *  Set "closed" flag of the specified section (all sections if
160    *  \a theISection is -1).
161    */
162   virtual bool setClosed( const int theISection, 
163                           const bool theIsClosed );
164
165   //! Returns specifyed section name
166   virtual std::string getSectionName( const int theISection ) const;
167
168   /** Set name of the specified section */
169   virtual bool setSectionName( const int theISection, 
170                                const std::string& theName );
171
172   //! Get type of the specified section
173   virtual CurveCreator::SectionType getSectionType( const int theISection ) const;
174
175   /**
176    *  Set type of the specified section (or all sections
177    *  if \a theISection is -1).
178    */
179   virtual bool setSectionType( const int theISection, 
180                                const CurveCreator::SectionType theType );
181
182
183   /***********************************************/
184   /***           Point methods                 ***/
185   /***********************************************/
186
187   /**
188    *  Add one point to the specified section starting from the given theIPnt index
189    *  (or at the end of points if \a theIPnt is -1).
190    */
191   virtual bool addPoints( const CurveCreator::Coordinates &theCoords,
192                           const int theISection,
193                           const int theIPnt = -1 );
194
195    //! Set coordinates of specified point
196   virtual bool setPoint( const int theISection,
197                          const int theIPnt,
198                          const CurveCreator::Coordinates& theNewCoords );
199
200   /** Remove point with given id */
201   virtual bool removePoint( const int theISection, const int theIPnt = -1 );
202
203   //! Get coordinates of specified point
204   virtual CurveCreator::Coordinates getPoint( const int theISection, 
205                                               const int theIPnt ) const;
206
207   /**
208    * Get points of a section (the total points in Curve if theISection is equal to -1)..
209    */
210   virtual CurveCreator::Coordinates getPoints( const int theISection = -1 ) const;
211
212
213   /**
214    *  Get number of points in specified section or (the total number of points
215    *  in Curve if theISection is equal to -1).
216    */
217   virtual int getNbPoints( const int theISection ) const;
218
219
220   /***********************************************/
221   /***       Presentation methods              ***/
222   /***********************************************/
223   virtual ListAISObjects constructWire() const;
224
225 public:
226
227   bool                            myIsLocked;
228   CurveCreator::Sections          mySections;   //!< curve data
229   CurveCreator::Dimension         myDimension;  //!< curve dimension
230   CurveCreator_Displayer*         myDisplayer;  //!< curve displayer
231
232 private:
233
234   int                             myNbUndos;
235   int                             myNbRedos;
236   ListDiff::iterator              myCurrenPos;
237   ListDiff                        myListDiffs;
238   int                             myUndoDepth;
239   int                             myOpLevel;
240 };
241
242 #endif