Salome HOME
Merge from BR_hydro 30/10/2013
[modules/geom.git] / src / CurveCreator / CurveCreator_Diff.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_Diff.hxx
21 // Author:      Sergey KHROMOV
22
23 #ifndef _CurveCreator_Diff_HeaderFile
24 #define _CurveCreator_Diff_HeaderFile
25
26 #include "CurveCreator_Operation.hxx"
27
28 class CurveCreator_Curve;
29
30
31 /**
32  * This is the support class for store/retrieve differences of undo/redo
33  * operations. To fill the difference it is necessary to create it with
34  * an appropriate type and to call the method initialize with required
35  * parameters.
36  */
37 class CurveCreator_Diff
38 {
39
40 private:
41
42 public:
43
44   /**
45    * Constructor.
46    */
47   CurveCreator_Diff();
48
49   /**
50    * Destructor.
51    */
52   ~CurveCreator_Diff();
53
54   /**
55    * This method initializes the difference with an operation without
56    * parameters. It is applicable to the following operations:
57    * <UL>
58    *   <LI>Clear</LI>
59    *   <LI>Join (without arguments)</LI>
60    * </UL>
61    */
62   bool init(const CurveCreator_Curve *theCurve,
63             const CurveCreator_Operation::Type theType);
64
65   /**
66    * This method initializes the difference with an operation with one integer
67    * parameter. It is applicable to the following operations:
68    * <UL>
69    *   <LI>RemoveSection</LI>
70    * </UL>
71    */
72   bool init(const CurveCreator_Curve *theCurve,
73             const CurveCreator_Operation::Type theType,
74             const int theIntParam);
75
76   /**
77    * This method initializes the difference with an operation with two integer
78    * parameters. It is applicable to the following operations:
79    * <UL>
80    *   <LI>SetType</LI>
81    *   <LI>SetClosed</LI>
82    *   <LI>MoveSection</LI>
83    *   <LI>Join (with 2 int arguments)</LI>
84    * </UL>
85    */
86   bool init(const CurveCreator_Curve *theCurve,
87             const CurveCreator_Operation::Type theType,
88             const int theIntParam1,
89             const int theIntParam2);
90
91   /**
92    * This method initializes the difference with an operation with three
93    * integer parameters. It is applicable to the following operations:
94    * <UL>
95    *   <LI>RemovePoints</LI>
96    * </UL>
97    */
98   bool init(const CurveCreator_Curve *theCurve,
99             const CurveCreator_Operation::Type theType,
100             const int theIntParam1,
101             const int theIntParam2,
102             const int theIntParam3);
103
104   /**
105    * This method initializes the difference with an operation with one
106    * CurveCreator::Coordinates parameter and one integer parameter.
107    * It is applicable to the following operations:
108    * <UL>
109    *   <LI>AddPoints</LI>
110    * </UL>
111    */
112   bool init(const CurveCreator_Curve *theCurve,
113             const CurveCreator_Operation::Type theType,
114             const CurveCreator::Coordinates &theCoords,
115             const int theIntParam);
116
117   /**
118    * This method initializes the difference with an operation with one
119    * CurveCreator::Coordinates parameter and two integer parameters.
120    * It is applicable to the following operations:
121    * <UL>
122    *   <LI>InsertPoints</LI>
123    *   <LI>SetCoordinates</LI>
124    * </UL>
125    */
126   bool init(const CurveCreator_Curve *theCurve,
127             const CurveCreator_Operation::Type theType,
128             const CurveCreator::Coordinates &theCoords,
129             const int theIntParam1,
130             const int theIntParam2);
131
132   /**
133    * This method initializes the difference with an operation with one
134    * Name, one CurveCreator::Coordinates parameter and two integer parameters.
135    * It is applicable to the following operations:
136    * <UL>
137    *   <LI>AddSection</LI>
138    * </UL>
139    */
140   bool init(const CurveCreator_Curve *theCurve,
141             const CurveCreator_Operation::Type theType,
142             const std::string& theName,
143             const CurveCreator::Coordinates &theCoords,
144             const int theIntParam1,
145             const int theIntParam2);
146
147   /**
148    * This method initializes the difference with an operation with one
149    * string and one integer parameters.
150    * It is applicable to the following operations:
151    * <UL>
152    *   <LI>RenameSection</LI>
153    * </UL>
154    */
155   bool init(const CurveCreator_Curve *theCurve,
156             const CurveCreator_Operation::Type theType,
157             const std::string &theName,
158             const int theIntParam1 );
159
160   /**
161    * This method applies undo operation to theCurve.
162    */
163   void applyUndo(CurveCreator_Curve *theCurve);
164
165   /**
166    * This method applies redo operation to theCurve.
167    */
168   void applyRedo(CurveCreator_Curve *theCurve);
169
170 private:
171
172   /**
173    * This method clears initialized data pointers.
174    */
175   void clear();
176
177   /**
178    * This method sets the number of undos and allocates the required
179    * space for myPUndo.
180    */
181   void setNbUndos(const int theNbUndos);
182
183   /**
184    * This method returns the section index. It returns theIndex if it is
185    * a real index and the last section's index if theIndex is equal to -1.
186    */
187   int getSectionIndex(const CurveCreator_Curve *theCurve,
188                       const int theIndex) const;
189
190   /**
191    * Convert theIndex'th section of theCurve into AddSection command
192    * and store it in theOperation. Returns true in case of success and
193    * false otherwise.
194    */
195   bool addSectionToUndo(const CurveCreator_Curve *theCurve,
196                         const int theIndex,
197                         CurveCreator_Operation &theOperation) const;
198
199   /**
200    * Construct undos for SetType and SetClosed operations. Note: the
201    * algorithm is optimized taking into account that there are only 2 types
202    * and 2 values of isClosed flag. If the number of types is increased,
203    * this algorithm should be re-implemented.
204    */
205   bool setTypeOrClosedToUndo(const CurveCreator_Curve *theCurve,
206                              const CurveCreator_Operation::Type theType,
207                              const int theIntParam1,
208                              const int theIntParam2);
209
210 private:
211
212   int                     myNbUndos;
213   CurveCreator_Operation *myPUndo;
214   CurveCreator_Operation *myPRedo;
215
216 };
217
218 #endif