Salome HOME
CurveCreator was updated
[modules/geom.git] / src / CurveCreator / CurveCreator_Diff.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:        CurveCreator_Diff.hxx
24 // Created:     Wed Jun  26 10:58:46 2013
25 // Author:      Sergey KHROMOV
26 //
27
28 #ifndef _CurveCreator_Diff_HeaderFile
29 #define _CurveCreator_Diff_HeaderFile
30
31
32 #include <CurveCreator_Operation.hxx>
33
34 class CurveCreator_Curve;
35
36
37 /**
38  * This is the support class for store/retrieve differences of undo/redo
39  * operations. To fill the difference it is necessary to create it with
40  * an appropriate type and to call the method initialize with required
41  * parameters.
42  */
43 class CurveCreator_Diff
44 {
45
46 private:
47
48 public:
49
50   /**
51    * Constructor.
52    */
53   CurveCreator_Diff();
54
55   /**
56    * Destructor.
57    */
58   ~CurveCreator_Diff();
59
60   /**
61    * This method initializes the difference with an operation without
62    * parameters. It is applicable to the following operations:
63    * <UL>
64    *   <LI>Clear</LI>
65    *   <LI>Join (without arguments)</LI>
66    * </UL>
67    */
68   bool init(const CurveCreator_Curve *theCurve,
69             const CurveCreator_Operation::Type theType);
70
71   /**
72    * This method initializes the difference with an operation with one integer
73    * parameter. It is applicable to the following operations:
74    * <UL>
75    *   <LI>RemoveSection</LI>
76    * </UL>
77    */
78   bool init(const CurveCreator_Curve *theCurve,
79             const CurveCreator_Operation::Type theType,
80             const int theIntParam);
81
82   /**
83    * This method initializes the difference with an operation with two integer
84    * parameters. It is applicable to the following operations:
85    * <UL>
86    *   <LI>SetType</LI>
87    *   <LI>SetClosed</LI>
88    *   <LI>MoveSection</LI>
89    *   <LI>Join (with 2 int arguments)</LI>
90    * </UL>
91    */
92   bool init(const CurveCreator_Curve *theCurve,
93             const CurveCreator_Operation::Type theType,
94             const int theIntParam1,
95             const int theIntParam2);
96
97   /**
98    * This method initializes the difference with an operation with three
99    * integer parameters. It is applicable to the following operations:
100    * <UL>
101    *   <LI>RemovePoints</LI>
102    * </UL>
103    */
104   bool init(const CurveCreator_Curve *theCurve,
105             const CurveCreator_Operation::Type theType,
106             const int theIntParam1,
107             const int theIntParam2,
108             const int theIntParam3);
109
110   /**
111    * This method initializes the difference with an operation with one
112    * CurveCreator::Coordinates parameter and one integer parameter.
113    * It is applicable to the following operations:
114    * <UL>
115    *   <LI>AddPoints</LI>
116    * </UL>
117    */
118   bool init(const CurveCreator_Curve *theCurve,
119             const CurveCreator_Operation::Type theType,
120             const CurveCreator::Coordinates &theCoords,
121             const int theIntParam);
122
123   /**
124    * This method initializes the difference with an operation with one
125    * CurveCreator::Coordinates parameter and two integer parameters.
126    * It is applicable to the following operations:
127    * <UL>
128    *   <LI>AddSection</LI>
129    *   <LI>InsertPoints</LI>
130    *   <LI>SetCoordinates</LI>
131    * </UL>
132    */
133   bool init(const CurveCreator_Curve *theCurve,
134             const CurveCreator_Operation::Type theType,
135             const CurveCreator::Coordinates &theCoords,
136             const int theIntParam1,
137             const int theIntParam2);
138
139   /**
140    * This method applies undo operation to theCurve.
141    */
142   void applyUndo(CurveCreator_Curve *theCurve);
143
144   /**
145    * This method applies redo operation to theCurve.
146    */
147   void applyRedo(CurveCreator_Curve *theCurve);
148
149 private:
150
151   /**
152    * This method clears initialized data pointers.
153    */
154   void clear();
155
156   /**
157    * This method sets the number of undos and allocates the required
158    * space for myPUndo.
159    */
160   void setNbUndos(const int theNbUndos);
161
162   /**
163    * This method returns the section index. It returns theIndex if it is
164    * a real index and the last section's index if theIndex is equal to -1.
165    */
166   int getSectionIndex(const CurveCreator_Curve *theCurve,
167                       const int theIndex) const;
168
169   /**
170    * Convert theIndex'th section of theCurve into AddSection command
171    * and store it in theOperation. Returns true in case of success and
172    * false otherwise.
173    */
174   bool addSectionToUndo(const CurveCreator_Curve *theCurve,
175                         const int theIndex,
176                         CurveCreator_Operation &theOperation) const;
177
178   /**
179    * Construct undos for SetType and SetClosed operations. Note: the
180    * algorithm is optimized taking into account that there are only 2 types
181    * and 2 values of isClosed flag. If the number of types is increased,
182    * this algorithm should be re-implemented.
183    */
184   bool setTypeOrClosedToUndo(const CurveCreator_Curve *theCurve,
185                              const CurveCreator_Operation::Type theType,
186                              const int theIntParam1,
187                              const int theIntParam2);
188
189 private:
190
191   int                     myNbUndos;
192   CurveCreator_Operation *myPUndo;
193   CurveCreator_Operation *myPRedo;
194
195 };
196
197 #endif