1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: CurveCreator_Operation.cxx
24 // Created: Wed Jun 26 13:06:56 2013
25 // Author: Sergey KHROMOV
29 #include <CurveCreator_Operation.hxx>
30 #include <CurveCreator_Curve.hxx>
34 //=======================================================================
35 // function: Constructor
37 //=======================================================================
38 CurveCreator_Operation::CurveCreator_Operation()
39 : myType (CurveCreator_Operation::Unknown),
44 //=======================================================================
45 // function: Destructor
47 //=======================================================================
48 CurveCreator_Operation::~CurveCreator_Operation()
53 //=======================================================================
54 // function: Constructor
56 //=======================================================================
57 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType)
61 if (theType == CurveCreator_Operation::Clear ||
62 theType == CurveCreator_Operation::Join) {
71 //=======================================================================
72 // function: Constructor
74 //=======================================================================
75 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
76 const int theIntParam)
80 if (theType == CurveCreator_Operation::RemoveSection) {
81 int *pData = (int *)allocate(sizeof(int));
83 pData[0] = theIntParam;
91 //=======================================================================
92 // function: Constructor
94 //=======================================================================
95 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
96 const int theIntParam1,
97 const int theIntParam2)
101 if (theType == CurveCreator_Operation::SetType ||
102 theType == CurveCreator_Operation::SetClosed ||
103 theType == CurveCreator_Operation::MoveSection ||
104 theType == CurveCreator_Operation::Join) {
105 int *pData = (int *)allocate(2*sizeof(int));
107 pData[0] = theIntParam1;
108 pData[1] = theIntParam2;
116 //=======================================================================
117 // function: Constructor
119 //=======================================================================
120 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
121 const int theIntParam1,
122 const int theIntParam2,
123 const int theIntParam3)
127 if (theType == CurveCreator_Operation::RemovePoints) {
128 int *pData = (int *)allocate(3*sizeof(int));
130 pData[0] = theIntParam1;
131 pData[1] = theIntParam2;
132 pData[2] = theIntParam3;
140 //=======================================================================
141 // function: Constructor
143 //=======================================================================
144 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
145 const CurveCreator::Coordinates &theCoords,
146 const int theIntParam)
150 if (theType == CurveCreator_Operation::AddPoints) {
151 const int aNbCoords = theCoords.size();
153 2*sizeof(theIntParam) + aNbCoords*sizeof(CurveCreator::TypeCoord);
154 int *pIntData = (int *)allocate(aSize);
156 *pIntData++ = theIntParam;
157 *pIntData++ = aNbCoords;
159 CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData;
162 for (; i < aNbCoords; i++) {
163 *pRealData++ = theCoords[i];
173 //=======================================================================
174 // function: Constructor
176 //=======================================================================
177 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
178 const CurveCreator::Coordinates &theCoords,
179 const int theIntParam1,
180 const int theIntParam2)
184 if (theType == CurveCreator_Operation::AddSection ||
185 theType == CurveCreator_Operation::InsertPoints ||
186 theType == CurveCreator_Operation::SetCoordinates) {
187 const int aNbCoords = theCoords.size();
189 3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord);
190 int *pIntData = (int *)allocate(aSize);
192 *pIntData++ = theIntParam1;
193 *pIntData++ = theIntParam2;
194 *pIntData++ = aNbCoords;
196 CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData;
199 for (; i < aNbCoords; i++) {
200 *pRealData++ = theCoords[i];
210 //=======================================================================
213 //=======================================================================
214 void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve)
216 if (theCurve != NULL) {
217 int *pInt = (int *)myPData;
220 case CurveCreator_Operation::AddPoints:
222 CurveCreator::Coordinates aCoords;
224 getCoords(&pInt[1], aCoords);
225 theCurve->addPoints(aCoords, pInt[0]);
228 case CurveCreator_Operation::RemovePoints:
229 theCurve->removePoints(pInt[0], pInt[1], pInt[2]);
231 case CurveCreator_Operation::InsertPoints:
233 CurveCreator::Coordinates aCoords;
235 getCoords(&pInt[2], aCoords);
236 theCurve->insertPoints(aCoords, pInt[0], pInt[1]);
239 case CurveCreator_Operation::SetType:
241 const CurveCreator::Type aType = (CurveCreator::Type) pInt[0];
243 theCurve->setType(aType, pInt[1]);
246 case CurveCreator_Operation::Clear:
249 case CurveCreator_Operation::SetCoordinates:
251 CurveCreator::Coordinates aCoords;
253 getCoords(&pInt[2], aCoords);
254 theCurve->setCoordinates(aCoords, pInt[0], pInt[1]);
257 case CurveCreator_Operation::SetClosed:
258 theCurve->setClosed((pInt[0] != 0), pInt[1]);
260 case CurveCreator_Operation::MoveSection:
261 theCurve->moveSection(pInt[0], pInt[1]);
263 case CurveCreator_Operation::Join:
264 if (myPData == NULL) {
267 theCurve->join(pInt[0], pInt[1]);
270 case CurveCreator_Operation::AddSection:
272 const CurveCreator::Type aType = (CurveCreator::Type) pInt[0];
273 CurveCreator::Coordinates aCoords;
275 getCoords(&pInt[2], aCoords);
276 theCurve->addSection(aType, (pInt[1] != 0), aCoords);
279 case CurveCreator_Operation::RemoveSection:
280 theCurve->removeSection(pInt[0]);
288 //=======================================================================
289 // function: allocate
291 //=======================================================================
292 void *CurveCreator_Operation::allocate(const size_t theSize)
294 if (myPData != NULL) {
298 myPData = malloc(theSize);
303 //=======================================================================
306 //=======================================================================
307 void CurveCreator_Operation::clear()
309 myType = CurveCreator_Operation::Unknown;
311 if (myPData != NULL) {
317 //=======================================================================
318 // function: getCoords
320 //=======================================================================
321 void CurveCreator_Operation::getCoords
322 (int *thePInt, CurveCreator::Coordinates &theCoords) const
324 const int aNbPnts = *thePInt;
325 CurveCreator::TypeCoord *pCoord = (CurveCreator::TypeCoord *)&thePInt[1];
327 for (int i = 0; i < aNbPnts; i++) {
328 theCoords.push_back(pCoord[i]);