Salome HOME
Implementation of Undo/Redo of 'SetPoints', 'AddPoints', 'RemovePoints'.
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Operation.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_Operation.hxx
21 // Author:      Sergey KHROMOV
22
23 #ifndef _CurveCreator_Operation_HeaderFile
24 #define _CurveCreator_Operation_HeaderFile
25
26 #include "CurveCreator.hxx"
27 #include "CurveCreator_ICurve.hxx"
28 #include "CurveCreator_PosPoint.hxx"
29
30 #include <string>
31 #include <vector>
32
33 class CurveCreator_Curve;
34
35
36 /**
37  * This is the support class that describes a modification operation that
38  * can be applied to CurveCreator_Curve.
39  */
40 class CurveCreator_Operation
41 {
42
43 public:
44
45   /**
46    * This is a type of CurveCreator_Curve modification operation.
47    */
48   enum Type
49   {
50     Unknown = 0,    //!< Unknown method.
51     AddPoints,      //!< Method CurveCreator_Curve::addPoints
52     RemovePoints,   //!< Method CurveCreator_Curve::removePoints
53     InsertPoints,   //!< Method CurveCreator_Curve::insertPoints
54     SetType,        //!< Method CurveCreator_Curve::setType
55     Clear,          //!< Method CurveCreator_Curve::clear
56     SetCoordinates, //!< Method CurveCreator_Curve::setCoordinates
57     SetClosed,      //!< Method CurveCreator_Curve::setClosed
58     MoveSection,    //!< Method CurveCreator_Curve::moveSection
59     Join,           //!< Method CurveCreator_Curve::join
60     AddSection,     //!< Method CurveCreator_Curve::addSection
61     RemoveSection,   //!< Method CurveCreator_Curve::removeSection
62     RenameSection   //!< Method CurveCreator_Curve::renameSection
63   };
64
65   /**
66    * Empty constructor.
67    */
68   CurveCreator_Operation();
69
70   /**
71    * Destructor.
72    */
73   ~CurveCreator_Operation();
74
75   /**
76    * This method initializes the object with an operation without parameters.
77    * It is applicable to the following operations:
78    * <UL>
79    *   <LI>Clear</LI>
80    *   <LI>Join (without arguments)</LI>
81    * </UL>
82    * @return true in case of success; false otherwise.
83    */
84   bool init(const Type theType);
85
86   /**
87    * This method initializes the object with an operation with one integer
88    * parameter. It is applicable to the following operations:
89    * <UL>
90    *   <LI>RemoveSection</LI>
91    * </UL>
92    * @return true in case of success; false otherwise.
93    */
94   bool init(const Type theType, const int theIntParam);
95
96   /**
97    * This method initializes the object with an operation with two integer
98    * parameters. It is applicable to the following operations:
99    * <UL>
100    *   <LI>SetType</LI>
101    *   <LI>SetClosed</LI>
102    *   <LI>MoveSection</LI>
103    *   <LI>Join (with 2 int arguments)</LI>
104    * </UL>
105    * @return true in case of success; false otherwise.
106    */
107   bool init(const Type theType, const int theIntParam1,
108             const int theIntParam2);
109
110   /**
111    * This method initializes the object with an operation with 
112    * list of pairs of integer parameters. 
113    * It is applicable to the following operations:
114    * <UL>
115    *   <LI>RemovePoints</LI>
116    * </UL>
117    * @return true in case of success; false otherwise.
118    */
119   bool init(const Type theType, 
120     const CurveCreator_ICurve::SectionToPointList &theParamList1);
121
122   /**
123    * This method initializes the object with an operation with three integer
124    * parameters. It is applicable to the following operations:
125    * <UL>
126    *   <LI>RemovePoints</LI>
127    * </UL>
128    * @return true in case of success; false otherwise.
129    */
130   bool init(const Type theType, const int theIntParam1,
131             const int theIntParam2, const int theIntParam3);
132
133   /**
134    * This method initializes the object with an operation with one
135    * CurveCreator::Coordinates parameter and one integer parameter.
136    * It is applicable to the following operations:
137    * <UL>
138    *   <LI>AddPoints</LI>
139    * </UL>
140    * @return true in case of success; false otherwise.
141    */
142   bool init(const Type theType, const CurveCreator::Coordinates &theCoords,
143             const int theIntParam);
144
145   /**
146    * This method initializes the object with an operation with one
147    * CurveCreator::Coordinates parameter and two integer parameters.
148    * It is applicable to the following operations:
149    * <UL>
150    *   <LI>AddSection</LI>
151    *   <LI>InsertPoints</LI>
152    *   <LI>SetCoordinates</LI>
153    * </UL>
154    * @return true in case of success; false otherwise.
155    */
156   bool init(const Type theType, const CurveCreator::Coordinates &theCoords,
157             const int theIntParam1, const int theIntParam2);
158   /**
159    * This method initializes the object with an operation with
160    * list of pairs of integer parameters and CurveCreator::Coordinates parameters.
161    * It is applicable to the following operations:
162    * <UL>
163    *   <LI>InsertPoints</LI>
164    * </UL>
165    * @return true in case of success; false otherwise.
166    */
167   bool init(const Type theType, 
168             const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1);
169
170   /**
171    * This method initializes the object with an operation with one
172    * string, one CurveCreator::Coordinates parameter and two integer parameters.
173    * It is applicable to the following operations:
174    * <UL>
175    *   <LI>AddSection</LI>
176    *   <LI>InsertPoints</LI>
177    *   <LI>SetCoordinates</LI>
178    * </UL>
179    * @return true in case of success; false otherwise.
180    */
181   bool init(const CurveCreator_Operation::Type theType,
182             const std::string& theName,
183             const CurveCreator::Coordinates &theCoords,
184             const int theIntParam1,
185             const int theIntParam2);
186
187
188   /**
189    * This method initializes the object with an operation with one
190    * string parameter and one integer.
191    * It is applicable to the following operations:
192    * <UL>
193    *   <LI>RenameSection</LI>
194    * </UL>
195    * @return true in case of success; false otherwise.
196    */
197   bool init(const CurveCreator_Operation::Type theType,
198                                     const std::string &theName,
199                                     const int theIntParam1 );
200
201   /**
202    * This method applies the current operation to theCurve.
203    */
204   void apply(CurveCreator_Curve *theCurve);
205
206 private:
207
208   /**
209    * This method allocates required memory for the operation data.
210    * Returns myPData for convenience purpose.
211    */
212   void *allocate(const size_t theSize);
213
214   /**
215    * This method clears initialized data pointers.
216    */
217   void clear();
218
219   /**
220    * This method returns the coordinates read from thePInt.
221    */
222   void getCoords(int *thePInt, CurveCreator::Coordinates &theCoords) const;
223
224 private:
225
226   Type  myType;
227   void *myPData;
228
229 };
230
231 #endif