Salome HOME
Remove functionality by popup menu and the keyboard button "Delete".
[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   //! For internal use only! Undo/Redo are not used here.
95   virtual bool moveSectionInternal(const int theISection,
96                            const int theNewIndex);
97   //! Move section to new position in list
98   virtual bool moveSection(const int theISection,
99                    const int theNewIndex);
100
101 protected:
102   /** This method updates all undo/redo information required to be updated
103    *  after curve modification operation. It returns false if undo/redo
104    *  is disabled and true otherwise.
105    */
106   virtual bool addEmptyDiff();
107
108   Handle_AIS_Point getAISPoint( int theISection, int theIPoint ) const;
109   Handle_AIS_Line  getAISLine( int theISection, int theIPoint1, int theIPoint2 ) const;
110   void getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const;
111
112   void redisplayCurve();
113
114 public:
115   /************   Implementation of INTERFACE methods   ************/
116
117   /***********************************************/
118   /***          Undo/Redo methods              ***/
119   /***********************************************/
120
121   //! Get number of available undo operations
122   virtual int getNbUndo() const;
123
124   //! Undo previous operation
125   virtual bool undo();
126
127   //! Get number of available redo operations
128   virtual int getNbRedo() const;
129
130   //! Redo last previously "undone" operation
131   virtual bool redo();
132
133
134   /***********************************************/
135   /***           Section methods               ***/
136   /***********************************************/
137
138   //! For internal use only! Undo/Redo are not used here.
139   virtual bool clearInternal();
140   //! Clear the polyline (remove all sections)
141   virtual bool clear();
142
143   //! For internal use only! Undo/Redo are not used here.
144   virtual bool joinInternal( const int theISectionTo = -1, 
145                              const int theISectionFrom = -1 );
146   //! Join range of sections to one section (join all sections if -1 is passed in one of arguments)
147   virtual bool join( const int theISectionTo = -1, 
148                      const int theISectionFrom = -1 );
149
150   //! Get number of sections
151   virtual int getNbSections() const;
152
153   //! For internal use only! Undo/Redo are not used here.
154   virtual int addSectionInternal( const std::string &theName, 
155                                   const CurveCreator::SectionType theType,
156                                   const bool theIsClosed,
157                                   const CurveCreator::Coordinates &thePoints);
158   //! Add a new section.
159   virtual int addSection( const std::string &theName, 
160                            const CurveCreator::SectionType theType,
161                            const bool theIsClosed );
162   //! Add a new section.
163   virtual int addSection( const std::string &theName, 
164                            const CurveCreator::SectionType theType,
165                            const bool theIsClosed,
166                            const CurveCreator::Coordinates &thePoints);
167   
168   //! For internal use only! Undo/Redo are not used here.
169   virtual bool removeSectionInternal( const int theISection );
170   //! Removes the given sections.
171   virtual bool removeSection( const int theISection );
172
173   //! Get "closed" flag of the specified section
174   virtual bool isClosed( const int theISection ) const;
175
176   //! For internal use only! Undo/Redo are not used here.
177   virtual bool setClosedInternal( const int theISection, 
178                                   const bool theIsClosed );
179   /**
180    *  Set "closed" flag of the specified section (all sections if
181    *  \a theISection is -1).
182    */
183   virtual bool setClosed( const int theISection, 
184                           const bool theIsClosed );
185
186   //! Returns specifyed section name
187   virtual std::string getSectionName( const int theISection ) const;
188
189   //! For internal use only! Undo/Redo are not used here.
190   virtual bool setSectionNameInternal( const int theISection, 
191                                        const std::string& theName );
192   /** Set name of the specified section */
193   virtual bool setSectionName( const int theISection, 
194                                const std::string& theName );
195
196   //! Get type of the specified section
197   virtual CurveCreator::SectionType getSectionType( const int theISection ) const;
198
199   //! For internal use only! Undo/Redo are not used here.
200   virtual bool setSectionTypeInternal( const int theISection, 
201                                        const CurveCreator::SectionType theType );
202   /**
203    *  Set type of the specified section (or all sections
204    *  if \a theISection is -1).
205    */
206   virtual bool setSectionType( const int theISection, 
207                                const CurveCreator::SectionType theType );
208
209
210   /***********************************************/
211   /***           Point methods                 ***/
212   /***********************************************/
213
214   //! For internal use only! Undo/Redo are not used here.
215   virtual bool addPointsInternal( const CurveCreator::Coordinates &theCoords,
216                                   const std::vector<int> &theISections,
217                                   const std::vector<int> &theIPnts );
218   /**
219    *  Add one point to the specified section starting from the given theIPnt index
220    *  (or at the end of points if \a theIPnt is -1).
221    */
222   virtual bool addPoints( const CurveCreator::Coordinates &theCoords,
223                           const int theISection,
224                           const int theIPnt = -1 );
225
226   //! For internal use only! Undo/Redo are not used here.
227   virtual bool setPointInternal( const int theISection,
228                                  const int theIPnt,
229                                  const CurveCreator::Coordinates& theNewCoords );
230    //! Set coordinates of specified point
231   virtual bool setPoint( const int theISection,
232                          const int theIPnt,
233                          const CurveCreator::Coordinates& theNewCoords );
234
235   //! Set coordinates of specified points from different sections
236   virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords);
237
238   //! For internal use only! Undo/Redo are not used here.
239   virtual bool removePointsInternal( const std::vector<int> &theISections, 
240                                      const std::vector<int> &theIPnts );
241   /** Remove point with given id */
242   virtual bool removePoint( const int theISection, const int theIPnt = -1 );
243
244   //! Remove several points from different sections with given ids
245   virtual bool removeSeveralPoints( const SectionToPointList &theSectionToPntIDs);
246
247   //! Get coordinates of specified point
248   virtual CurveCreator::Coordinates getPoint( const int theISection, 
249                                               const int theIPnt ) const;
250
251   /**
252    * Get points of a section (the total points in Curve if theISection is equal to -1)..
253    */
254   virtual CurveCreator::Coordinates getPoints( const int theISection = -1 ) const;
255
256
257   /**
258    *  Get number of points in specified section or (the total number of points
259    *  in Curve if theISection is equal to -1).
260    */
261   virtual int getNbPoints( const int theISection ) const;
262
263
264   /***********************************************/
265   /***       Presentation methods              ***/
266   /***********************************************/
267   virtual ListAISObjects constructWire() const;
268
269 public:
270
271   bool                            myIsLocked;
272   CurveCreator::Sections          mySections;   //!< curve data
273   CurveCreator::Dimension         myDimension;  //!< curve dimension
274   CurveCreator_Displayer*         myDisplayer;  //!< curve displayer
275
276 private:
277
278   int                             myNbUndos;
279   int                             myNbRedos;
280   ListDiff::iterator              myCurrenPos;
281   ListDiff                        myListDiffs;
282   int                             myUndoDepth;
283   int                             myOpLevel;
284 };
285
286 #endif