Salome HOME
326c19821dad2a103c137efd1641f9d7b4e073f1
[modules/geom.git] / src / CurveCreator / CurveCreator_CurveEditor.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_CurveEditor.hxx
21 // Author:      Sergey KHROMOV
22
23 #ifndef _CurveCreator_CurveEditor_HeaderFile
24 #define _CurveCreator_CurveEditor_HeaderFile
25
26 #include "CurveCreator_Diff.hxx"
27 #include "CurveCreator_Curve.hxx"
28
29 #include <list>
30
31 /**
32  *  The CurveCreator_CurveEditor is designed to manage of
33  *  editing operations of CurveCreator_Curve class.
34  */
35 class CURVECREATOR_EXPORT CurveCreator_CurveEditor
36 {
37
38 private:
39
40   typedef std::list<CurveCreator_Diff> ListDiff;
41
42 public:
43
44   //! Constuctor, initialized by the curve object
45   CurveCreator_CurveEditor(CurveCreator_Curve* thePCurve);
46
47   //! Destructor, detaches from the Curve
48   ~CurveCreator_CurveEditor();
49
50   //! Returns the curve.
51   CurveCreator_Curve *getCurve() const;
52
53   //! This method returns true if this editor is attached to a valid curve.
54   bool isAttached() const;
55
56   //! Undo previous operation
57   void undo();
58
59   //! Redo last previously �undoed� operation
60   void redo();
61
62   //! Get number of available undo operations
63   int getNbUndo() const;
64
65   //! Get number of available redo operations
66   int getNbRedo() const;
67
68   //! Set depth of undo operations (unlimited if \a theDepth is -1
69   //  or disabled if \a theDepth is 0)
70   void setUndoDepth(const int theDepth = -1);
71
72   //! Get depth of undo operations.
73   int getUndoDepth() const;
74
75   /** Set type of the specified section (or all sections
76    *  if \a theISection is -1).
77    */
78   void setType(const CurveCreator::Type theType, const int theISection = -1);
79
80   /** Set section closed (or all sections
81    *  if \a theISection is -1).
82    */
83   void setClosed(const bool theIsClosed, const int theISection);
84
85   /** Set section name (if theISection is invalid it is ignored).
86    */
87   void setName(const std::string& theName, const int theISection);
88
89   /** Add points to the specified section (or last section
90    *  if \a theISection is -1).
91    */
92   void addPoints(const CurveCreator::Coordinates &thePoints,
93                  const int theISection = -1);
94
95   //! Add a new section.
96   void addSection(const std::string &theName, const CurveCreator::Type theType,
97                   const bool theIsClosed,
98                   const CurveCreator::Coordinates &thePoints);
99
100   //! Removes the section. If theISection equals -1, removes the last section.
101   void removeSection(const int theISection = -1);
102
103   /** Insert points in the given position (add to the end of list
104    *  if \a theIPnt parameter is -1) of the specified section
105    *  (or last section if \a theISection parameter is -1).
106    */
107   void insertPoints(const CurveCreator::Coordinates &thePoints,
108                     const int theISection = -1,
109                     const int theIPnt = -1);
110
111   /** Remove \a nbPoints points from given \a theISection,
112    *  starting from given \a theIPnt (of all points up to the end of
113    *  section if \a theNbPoints is -1).
114    */
115   void removePoints(const int theISection,
116                     const int theIPnt,
117                     const int theNbPoints = -1);
118
119   /** Mobe point in \a theISection from given position \a theOrigIPnt
120    *  to new position \a theNewIPnt.
121    */
122   void movePoint(const int theISection,
123                   const int theOrigIPnt,
124                   const int theNewIPnt );
125
126   //! Remove all sections.
127   void clear();
128
129   //! Set coordinates of specified point
130   void setCoordinates(const CurveCreator::Coordinates &theCoords,
131                       const int theISection,
132                       const int theIPnt);
133
134   /** Move specified \a theISection to the specified position
135    *  in the sections list.
136    */
137   void moveSection(const int theISection, const int theNewIndex);
138
139   //! Join two sections to one section
140   void join(const int theISectionTo, const int theISectionFrom);
141
142   //! Join all sections to the single curve
143   void join();
144
145   void startOperation();
146   void finishOperation();
147 private:
148
149   /** This method updates all undo/redo information required to be updated
150    *  after curve modification operation. It returns false if undo/redo
151    *  is disabled and true otherwise.
152    */
153   bool addEmptyDiff();
154
155 private:
156
157   int myNbUndos;
158   int myNbRedos;
159   ListDiff::iterator myCurrenPos;
160   ListDiff myListDiffs;
161   CurveCreator_Curve* myPCurve;
162   int myUndoDepth;
163   int myOpLevel;
164 };
165
166 #endif