Salome HOME
17f7fac8c4429cd3fd287efcc7f87408e48f0812
[modules/geom.git] / src / CurveCreator / CurveCreator_Diff.hxx
1 // Copyright (C) 2013-2023  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, or (at your option) any later version.
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    * </UL>
60    */
61   bool init(const CurveCreator_Curve *theCurve);
62
63   /**
64    * This method initializes the difference with an operation with one integer
65    * parameter. It is applicable to the following operations:
66    * <UL>
67    *   <LI>RemoveSection</LI>
68    * </UL>
69    */
70   bool init(const CurveCreator_Curve *theCurve,
71             const CurveCreator_Operation::Type theType,
72             const int theIntParam);
73
74   /**
75    * This method initializes the difference with an operation with two integer
76    * parameters. It is applicable to the following operations:
77    * <UL>
78    *   <LI>SetType</LI>
79    *   <LI>SetClosed</LI>
80    *   <LI>MoveSection</LI>
81    * </UL>
82    */
83   bool init(const CurveCreator_Curve *theCurve,
84             const CurveCreator_Operation::Type theType,
85             const int theIntParam1,
86             const int theIntParam2);
87
88     /**
89    * This method initializes the difference with an operation with two integer
90    * parameters. It is applicable to the following operations:
91    * <UL>
92    *   <LI>Join (with a list of int arguments)</LI>
93    * </UL>
94    */
95   bool init(const CurveCreator_Curve *theCurve,
96             const CurveCreator_Operation::Type theType,
97             const std::list<int>& theParams);
98
99   /**
100    * This method initializes the difference with an operation with one
101    * Name, one CurveCreator::Coordinates parameter and two integer parameters.
102    * It is applicable to the following operations:
103    * <UL>
104    *   <LI>AddSection</LI>
105    * </UL>
106    */
107   bool init(const CurveCreator_Curve *theCurve,
108             const CurveCreator_Operation::Type theType,
109             const std::string& theName,
110             const CurveCreator::Coordinates &theCoords,
111             const int theIntParam1,
112             const int theIntParam2);
113
114   /**
115    * This method initializes the difference with an operation with one
116    * string and one integer parameters.
117    * It is applicable to the following operations:
118    * <UL>
119    *   <LI>RenameSection</LI>
120    * </UL>
121    */
122   bool init(const CurveCreator_Curve *theCurve,
123             const CurveCreator_Operation::Type theType,
124             const std::string &theName,
125             const int theIntParam1 );
126
127   /**
128    * This method initializes the difference with an operation with
129    * list of pairs of integer parameters.
130    * It is applicable to the following operations:
131    * <UL>
132    *   <LI>RemovePoints</LI>
133    * </UL>
134    */
135   bool init(const CurveCreator_Curve *theCurve,
136             const CurveCreator_Operation::Type theType,
137             const CurveCreator_ICurve::SectionToPointList &theParamList);
138
139   /**
140    * This method initializes the difference with an operation with
141    * list of pairs of integer parameters with point coordinates.
142    * It is applicable to the following operations:
143    * <UL>
144    *   <LI>RemovePoints</LI>
145    * </UL>
146    */
147   bool init(const CurveCreator_Curve *theCurve,
148             const CurveCreator_Operation::Type theType,
149             const CurveCreator_ICurve::SectionToPointCoordsList &theParamList);
150
151   /**
152    * This method initializes the difference with an operation with
153    * list of pairs of integer parameters with point coordinates.
154    * \param theCurve the modified curve
155    * \param theOldParamList the old parameters (to be saved for undo)
156    */
157   bool init(const CurveCreator_Curve *theCurve,
158             const CurveCreator_ICurve::SectionToPointCoordsList &theOldParamList);
159
160
161   /**
162    * This method initializes the difference with an operation with one
163    * integer and one array of integer[3] parameters.
164    * It is applicable to the following operations:
165    * <UL>
166    *   <LI>ColorSection</LI>
167    * </UL>
168    */
169   bool init(const CurveCreator_Curve *theCurve,
170             const CurveCreator_Operation::Type theType,
171             const int theIntParam1,
172             const int theIntParam2[3]);
173
174   /**
175    * This method applies undo operation to theCurve.
176    */
177   void applyUndo(CurveCreator_Curve *theCurve);
178
179   /**
180    * This method applies redo operation to theCurve.
181    */
182   void applyRedo(CurveCreator_Curve *theCurve);
183
184 private:
185
186   /**
187    * This method clears initialized data pointers.
188    */
189   void clear();
190
191   /**
192    * This method sets the number of undos and allocates the required
193    * space for myPUndo.
194    */
195   void setNbUndos(const int theNbUndos);
196
197   /**
198    * This method returns the section index. It returns theIndex if it is
199    * a real index and the last section's index if theIndex is equal to -1.
200    */
201   int getSectionIndex(const CurveCreator_Curve *theCurve,
202                       const int theIndex) const;
203
204   /**
205    * Convert theIndex'th section of theCurve into AddSection command
206    * and store it in theOperation. Returns true in case of success and
207    * false otherwise.
208    */
209   bool addSectionToUndo(const CurveCreator_Curve *theCurve,
210                         const int theIndex,
211                         CurveCreator_Operation &theOperation) const;
212
213   /**
214    * Construct undos for SetType and SetClosed operations. Note: the
215    * algorithm is optimized taking into account that there are only 2 types
216    * and 2 values of isClosed flag. If the number of types is increased,
217    * this algorithm should be re-implemented.
218    */
219   bool setTypeOrClosedToUndo(const CurveCreator_Curve *theCurve,
220                              const CurveCreator_Operation::Type theType,
221                              const int theIntParam1,
222                              const int theIntParam2);
223
224 private:
225
226   int                     myNbUndos;
227   CurveCreator_Operation *myPUndo;
228   CurveCreator_Operation *myPRedo;
229
230 };
231
232 #endif