1 // Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: CurveCreator_Operation.cxx
21 // Author: Sergey KHROMOV
23 #include "CurveCreator_Operation.hxx"
24 #include "CurveCreator_Curve.hxx"
30 //=======================================================================
31 // function: Constructor
33 //=======================================================================
34 CurveCreator_Operation::CurveCreator_Operation()
35 : myType (CurveCreator_Operation::Unknown),
40 //=======================================================================
41 // function: Destructor
43 //=======================================================================
44 CurveCreator_Operation::~CurveCreator_Operation()
49 //=======================================================================
50 // function: Constructor
52 //=======================================================================
53 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType)
57 if (theType == CurveCreator_Operation::Clear ||
58 theType == CurveCreator_Operation::Join) {
67 //=======================================================================
68 // function: Constructor
70 //=======================================================================
71 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
72 const int theIntParam)
76 if (theType == CurveCreator_Operation::RemoveSection) {
77 int *pData = (int *)allocate(sizeof(int));
79 pData[0] = theIntParam;
87 //=======================================================================
88 // function: Constructor
90 //=======================================================================
91 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
92 const int theIntParam1,
93 const int theIntParam2)
97 if (theType == CurveCreator_Operation::SetType ||
98 theType == CurveCreator_Operation::SetClosed ||
99 theType == CurveCreator_Operation::MoveSection ||
100 theType == CurveCreator_Operation::RemovePoints ||
101 theType == CurveCreator_Operation::Join) {
102 int *pData = (int *)allocate(2*sizeof(int));
104 pData[0] = theIntParam1;
105 pData[1] = theIntParam2;
113 //=======================================================================
114 // function: Constructor
116 //=======================================================================
117 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
118 const int theIntParam1,
119 const int theIntParam2,
120 const int theIntParam3)
124 if (theType == CurveCreator_Operation::RemovePoints) {
125 int *pData = (int *)allocate(3*sizeof(int));
127 pData[0] = theIntParam1;
128 pData[1] = theIntParam2;
129 pData[2] = theIntParam3;
137 //=======================================================================
138 // function: Constructor
140 //=======================================================================
141 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
142 const CurveCreator::Coordinates &theCoords,
143 const int theIntParam)
147 if (theType == CurveCreator_Operation::AddPoints) {
148 const int aNbCoords = theCoords.size();
150 2*sizeof(theIntParam) + aNbCoords*sizeof(CurveCreator::TypeCoord);
151 int *pIntData = (int *)allocate(aSize);
153 *pIntData++ = theIntParam;
154 *pIntData++ = aNbCoords;
156 CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData;
159 for (; i < aNbCoords; i++) {
160 *pRealData++ = theCoords[i];
170 //=======================================================================
171 // function: Constructor
173 //=======================================================================
174 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
175 const CurveCreator::Coordinates &theCoords,
176 const int theIntParam1,
177 const int theIntParam2)
181 if (theType == CurveCreator_Operation::AddSection ||
182 theType == CurveCreator_Operation::InsertPoints ||
183 theType == CurveCreator_Operation::SetCoordinates) {
184 const int aNbCoords = theCoords.size();
186 3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord);
187 int *pIntData = (int *)allocate(aSize);
189 *pIntData++ = theIntParam1;
190 *pIntData++ = theIntParam2;
191 *pIntData++ = aNbCoords;
193 CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData;
196 for (; i < aNbCoords; i++) {
197 *pRealData++ = theCoords[i];
207 //=======================================================================
208 // function: Constructor
210 //=======================================================================
211 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
212 const std::string& theName,
213 const CurveCreator::Coordinates &theCoords,
214 const int theIntParam1,
215 const int theIntParam2)
218 if (theType == CurveCreator_Operation::AddSection ) {
219 const int aNbCoords = theCoords.size();
221 3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord) + theName.length() + 1;
222 int *pIntData = (int *)allocate(aSize);
224 *pIntData++ = theIntParam1;
225 *pIntData++ = theIntParam2;
226 char* aStrPtr = (char*)pIntData;
227 if( !theName.empty() ){
228 strcpy( aStrPtr, theName.c_str() );
229 aStrPtr += theName.length();
235 pIntData = (int*)aStrPtr;
236 *pIntData++ = aNbCoords;
238 CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)aStrPtr;
241 for (; i < aNbCoords; i++) {
242 *pRealData++ = theCoords[i];
252 bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
253 const std::string &theName,
254 const int theIntParam1 )
256 if (theType == CurveCreator_Operation::RenameSection ) {
257 size_t aSize = sizeof(theIntParam1) + theName.length() + 1;
258 int *pIntData = (int *)allocate(aSize);
259 *pIntData = theIntParam1;
261 if( !theName.empty() ){
262 strcpy( (char*)pIntData, theName.c_str() );
265 *((char*)pIntData) = 0;
273 //=======================================================================
276 //=======================================================================
277 void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve)
279 if (theCurve != NULL) {
280 int *pInt = (int *)myPData;
283 case CurveCreator_Operation::AddPoints:
284 case CurveCreator_Operation::InsertPoints:
286 CurveCreator::Coordinates aCoords;
288 getCoords(&pInt[2], aCoords);
289 std::vector<int> anISections, anIPnts;
290 anISections.push_back( pInt[0] );
291 anIPnts.push_back( pInt[1] );
292 theCurve->addPointsInternal(aCoords, anISections, anIPnts);
295 case CurveCreator_Operation::RemovePoints:
297 std::vector<int> anISections, anIPnts;
298 anISections.push_back( pInt[0] );
299 anIPnts.push_back( pInt[1] );
300 theCurve->removePointsInternal(anISections, anIPnts);
303 case CurveCreator_Operation::SetType:
305 const CurveCreator::SectionType aType = (CurveCreator::SectionType) pInt[0];
307 theCurve->setSectionTypeInternal( pInt[1], aType );
310 case CurveCreator_Operation::Clear:
311 theCurve->clearInternal();
313 case CurveCreator_Operation::SetCoordinates:
315 CurveCreator::Coordinates aCoords;
317 getCoords(&pInt[2], aCoords);
318 theCurve->setPointInternal(pInt[0], pInt[1], aCoords);
321 case CurveCreator_Operation::SetClosed:
322 theCurve->setClosedInternal((pInt[0] != 0), pInt[1]);
324 case CurveCreator_Operation::MoveSection:
325 theCurve->moveSectionInternal(pInt[0], pInt[1]);
327 case CurveCreator_Operation::Join:
328 if (myPData == NULL) {
329 theCurve->joinInternal();
331 theCurve->joinInternal(pInt[0], pInt[1]);
334 case CurveCreator_Operation::AddSection:
336 const CurveCreator::SectionType aType = (CurveCreator::SectionType) pInt[0];
338 std::string aName = std::string((char*)&pInt[2]);
340 CurveCreator::Coordinates aCoords;
342 char* aPtr = ((char*)&pInt[2]);
343 aPtr += (aName.length()) + 1;
344 getCoords((int*)aPtr, aCoords);
345 theCurve->addSectionInternal(aName, aType, (pInt[1] != 0), aCoords);
348 case CurveCreator_Operation::RemoveSection:
349 theCurve->removeSectionInternal(pInt[0]);
351 case CurveCreator_Operation::RenameSection:
353 std::string aName = std::string((char*)&pInt[1]);
354 theCurve->setSectionNameInternal(pInt[0], aName);
363 //=======================================================================
364 // function: allocate
366 //=======================================================================
367 void *CurveCreator_Operation::allocate(const size_t theSize)
369 if (myPData != NULL) {
373 myPData = malloc(theSize);
378 //=======================================================================
381 //=======================================================================
382 void CurveCreator_Operation::clear()
384 myType = CurveCreator_Operation::Unknown;
386 if (myPData != NULL) {
392 //=======================================================================
393 // function: getCoords
395 //=======================================================================
396 void CurveCreator_Operation::getCoords
397 (int *thePInt, CurveCreator::Coordinates &theCoords) const
399 const int aNbPnts = *thePInt;
400 CurveCreator::TypeCoord *pCoord = (CurveCreator::TypeCoord *)&thePInt[1];
402 for (int i = 0; i < aNbPnts; i++) {
403 theCoords.push_back(pCoord[i]);