Salome HOME
0021031: EDF 1646 GEOM: Modify Location leads to Position driver failed
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ITransformOperations.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <Standard_Stream.hxx>
24
25 #include <GEOMImpl_ITransformOperations.hxx>
26
27 #include "utilities.h"
28 #include <OpUtil.hxx>
29 #include <Utils_ExceptHandlers.hxx>
30
31 #include <TFunction_DriverTable.hxx>
32 #include <TFunction_Driver.hxx>
33 #include <TFunction_Logbook.hxx>
34 #include <TDF_Tool.hxx>
35
36 #include <GEOM_Function.hxx>
37 #include <GEOM_PythonDump.hxx>
38
39 #include <GEOMImpl_TranslateDriver.hxx>
40 #include <GEOMImpl_MirrorDriver.hxx>
41 #include <GEOMImpl_OffsetDriver.hxx>
42 #include <GEOMImpl_ScaleDriver.hxx>
43 #include <GEOMImpl_RotateDriver.hxx>
44 #include <GEOMImpl_PositionDriver.hxx>
45
46 #include <GEOMImpl_ITranslate.hxx>
47 #include <GEOMImpl_IMirror.hxx>
48 #include <GEOMImpl_IOffset.hxx>
49 #include <GEOMImpl_IScale.hxx>
50 #include <GEOMImpl_IRotate.hxx>
51 #include <GEOMImpl_IPosition.hxx>
52
53 #include <GEOMImpl_Types.hxx>
54
55 #include <Standard_Failure.hxx>
56 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
57
58 //=============================================================================
59 /*!
60  *   constructor:
61  */
62 //=============================================================================
63
64 GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations (GEOM_Engine* theEngine, int theDocID)
65 : GEOM_IOperations(theEngine, theDocID)
66 {
67   MESSAGE("GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations");
68 }
69
70 //=============================================================================
71 /*!
72  *  destructor
73  */
74 //=============================================================================
75
76 GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations()
77 {
78   MESSAGE("GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations");
79 }
80
81
82 //=============================================================================
83 /*!
84  *  TranslateTwoPoints
85  */
86 //=============================================================================
87 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPoints
88        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
89 {
90   SetErrorCode(KO);
91
92   if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
93
94   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
95   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
96
97   // Get last functions of the arguments
98   Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
99   Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
100
101   //Add a translate function
102   aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS);
103
104   if (aFunction.IsNull()) return NULL;
105
106   //Check if the function is set correctly
107   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
108
109   GEOMImpl_ITranslate aTI (aFunction);
110   aTI.SetPoint1(aP1F);
111   aTI.SetPoint2(aP2F);
112   aTI.SetOriginal(aLastFunction);
113
114   //Compute the translation
115   try {
116 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
117     OCC_CATCH_SIGNALS;
118 #endif
119     if (!GetSolver()->ComputeFunction(aFunction)) {
120       SetErrorCode("Translation driver failed");
121       return NULL;
122     }
123   }
124   catch (Standard_Failure) {
125     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
126     SetErrorCode(aFail->GetMessageString());
127     return NULL;
128   }
129
130   //Make a Python command
131   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateTwoPoints("
132     << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
133
134   SetErrorCode(OK);
135   return theObject;
136 }
137
138 //=============================================================================
139 /*!
140  *  TranslateDXDYDZ
141  */
142 //=============================================================================
143 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZ
144        (Handle(GEOM_Object) theObject, double theX, double theY,  double theZ)
145 {
146   SetErrorCode(KO);
147
148   if (theObject.IsNull()) return NULL;
149
150   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
151   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
152
153   //Add a translate function
154   aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ);
155
156   if (aFunction.IsNull()) return NULL;
157
158   //Check if the function is set correctly
159   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
160
161   GEOMImpl_ITranslate aTI(aFunction);
162   aTI.SetDX(theX);
163   aTI.SetDY(theY);
164   aTI.SetDZ(theZ);
165   aTI.SetOriginal(aLastFunction);
166
167   //Compute the translation
168   try {
169 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
170     OCC_CATCH_SIGNALS;
171 #endif
172     if (!GetSolver()->ComputeFunction(aFunction)) {
173       SetErrorCode("Translation driver failed");
174       return NULL;
175     }
176   }
177   catch (Standard_Failure) {
178     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
179     SetErrorCode(aFail->GetMessageString());
180     return NULL;
181   }
182
183   //Make a Python command
184   GEOM::TPythonDump(aFunction) << "geompy.TranslateDXDYDZ("
185     << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
186
187   SetErrorCode(OK);
188   return theObject;
189 }
190
191
192 //=============================================================================
193 /*!
194  *  TranslateTwoPointsCopy
195  */
196 //=============================================================================
197 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPointsCopy
198        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
199 {
200   SetErrorCode(KO);
201
202   if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
203
204   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
205   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
206
207   //Add a new Copy object
208   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
209
210   //Add a translate function
211   Handle(GEOM_Function) aFunction =
212     aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS_COPY);
213
214   //Check if the function is set correctly
215   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
216
217   GEOMImpl_ITranslate aTI(aFunction);
218   aTI.SetPoint1(thePoint1->GetLastFunction());
219   aTI.SetPoint2(thePoint2->GetLastFunction());
220   //aTI.SetShape(theObject->GetValue());
221   aTI.SetOriginal(aLastFunction);
222
223   //Compute the translation
224   try {
225 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
226     OCC_CATCH_SIGNALS;
227 #endif
228     if (!GetSolver()->ComputeFunction(aFunction)) {
229       SetErrorCode("Translation driver failed");
230       return NULL;
231     }
232   }
233   catch (Standard_Failure) {
234     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
235     SetErrorCode(aFail->GetMessageString());
236     return NULL;
237   }
238
239   //Make a Python command
240   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationTwoPoints("
241     << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
242
243   SetErrorCode(OK);
244   return aCopy;
245 }
246
247 //=============================================================================
248 /*!
249  *  TranslateDXDYDZCopy
250  */
251 //=============================================================================
252 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZCopy
253        (Handle(GEOM_Object) theObject, double theX, double theY,  double theZ)
254 {
255   SetErrorCode(KO);
256
257   if (theObject.IsNull()) return NULL;
258
259   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
260   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
261
262   //Add a new Copy object
263   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
264
265   //Add a translate function
266   Handle(GEOM_Function) aFunction =
267     aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ_COPY);
268
269   //Check if the function is set correctly
270   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
271
272   GEOMImpl_ITranslate aTI(aFunction);
273   aTI.SetDX(theX);
274   aTI.SetDY(theY);
275   aTI.SetDZ(theZ);
276   aTI.SetOriginal(aLastFunction);
277
278   //Compute the translation
279   try {
280 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
281     OCC_CATCH_SIGNALS;
282 #endif
283     if (!GetSolver()->ComputeFunction(aFunction)) {
284       SetErrorCode("Translation driver failed");
285       return NULL;
286     }
287   }
288   catch (Standard_Failure) {
289     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
290     SetErrorCode(aFail->GetMessageString());
291     return NULL;
292   }
293
294   //Make a Python command
295   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslation("
296     << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
297
298   SetErrorCode(OK);
299   return aCopy;
300 }
301
302
303 //=============================================================================
304 /*!
305  *  TranslateVector
306  */
307 //=============================================================================
308 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVector
309        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
310 {
311   SetErrorCode(KO);
312
313   if (theObject.IsNull() || theVector.IsNull()) return NULL;
314
315   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
316   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
317
318   // Get last functions of the arguments
319   Handle(GEOM_Function) aVF = theVector->GetLastFunction();
320
321   //Add a translate function
322   aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR);
323
324   if (aFunction.IsNull()) return NULL;
325
326   //Check if the function is set correctly
327   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
328
329   GEOMImpl_ITranslate aTI (aFunction);
330   aTI.SetVector(aVF);
331   aTI.SetOriginal(aLastFunction);
332
333   //Compute the translation
334   try {
335 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
336     OCC_CATCH_SIGNALS;
337 #endif
338     if (!GetSolver()->ComputeFunction(aFunction)) {
339       SetErrorCode("Translation driver failed");
340       return NULL;
341     }
342   }
343   catch (Standard_Failure) {
344     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
345     SetErrorCode(aFail->GetMessageString());
346     return NULL;
347   }
348
349   //Make a Python command
350   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateVector("
351                                << theObject << ", " << theVector << ")";
352
353   SetErrorCode(OK);
354   return theObject;
355 }
356 //=============================================================================
357 /*!
358  *  TranslateVectorCopy
359  */
360 //=============================================================================
361 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorCopy
362        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
363 {
364   SetErrorCode(KO);
365
366   if (theObject.IsNull() || theVector.IsNull()) return NULL;
367
368   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
369   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
370
371   //Add a new Copy object
372   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
373
374   //Add a translate function
375   Handle(GEOM_Function) aFunction =
376     aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_COPY);
377
378   //Check if the function is set correctly
379   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
380
381   GEOMImpl_ITranslate aTI(aFunction);
382   aTI.SetVector(theVector->GetLastFunction());
383 //  aTI.SetShape(theObject->GetValue());
384   aTI.SetOriginal(aLastFunction);
385
386   //Compute the translation
387   try {
388 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
389     OCC_CATCH_SIGNALS;
390 #endif
391     if (!GetSolver()->ComputeFunction(aFunction)) {
392       SetErrorCode("Translation driver failed");
393       return NULL;
394     }
395   }
396   catch (Standard_Failure) {
397     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
398     SetErrorCode(aFail->GetMessageString());
399     return NULL;
400   }
401
402   //Make a Python command
403   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVector("
404                                << theObject << ", " << theVector << ")";
405
406   SetErrorCode(OK);
407   return aCopy;
408 }
409
410 //=============================================================================
411 /*!
412  *  TranslateVectorDistance
413  */
414 //=============================================================================
415 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorDistance
416        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector, double theDistance, bool theCopy)
417 {
418   SetErrorCode(KO);
419
420   if (theObject.IsNull() || theVector.IsNull()) return NULL;
421
422   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
423   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
424
425   Handle(GEOM_Object) aCopy;   //Add a new Copy object
426   Handle(GEOM_Function) aFunction;
427
428   //Add a translate function
429   if (theCopy) {
430     aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
431     aFunction = aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
432   }
433   else {
434     aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
435   }
436   if (aFunction.IsNull()) return NULL;
437
438   //Check if the function is set correctly
439   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
440
441   GEOMImpl_ITranslate aTI(aFunction);
442   aTI.SetVector(theVector->GetLastFunction());
443   aTI.SetDistance(theDistance);
444 //  aTI.SetShape(theObject->GetValue());
445   aTI.SetOriginal(aLastFunction);
446
447   //Compute the translation
448   try {
449 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
450     OCC_CATCH_SIGNALS;
451 #endif
452     if (!GetSolver()->ComputeFunction(aFunction)) {
453       SetErrorCode("Translation driver failed");
454       return NULL;
455     }
456   }
457   catch (Standard_Failure) {
458     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
459     SetErrorCode(aFail->GetMessageString());
460     return NULL;
461   }
462
463   //Make a Python command
464   if (theCopy) {
465     GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVectorDistance("
466                                  << theObject << ", " << theVector << ", " << theDistance << ")";
467     SetErrorCode(OK);
468     return aCopy;
469   }
470
471   GEOM::TPythonDump(aFunction) << "geompy.TranslateVectorDistance("
472                                << theObject << ", " << theVector << ", " << theDistance << ", " << theCopy << ")";
473   SetErrorCode(OK);
474   return theObject;
475 }
476
477 //=============================================================================
478 /*!
479  *  Translate1D
480  */
481 //=============================================================================
482 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate1D
483        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector,
484         double theStep, Standard_Integer theNbTimes)
485 {
486   SetErrorCode(KO);
487
488   if (theObject.IsNull() || theVector.IsNull()) return NULL;
489
490   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
491   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
492
493   //Add a new Copy object
494   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
495
496   //Add a translate function
497   Handle(GEOM_Function) aFunction =
498     aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_1D);
499
500   //Check if the function is set correctly
501   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
502
503   GEOMImpl_ITranslate aTI(aFunction);
504   aTI.SetVector(theVector->GetLastFunction());
505   aTI.SetOriginal(aLastFunction);
506   aTI.SetStep1(theStep);
507   aTI.SetNbIter1(theNbTimes);
508
509   //Compute the translation
510   try {
511 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
512     OCC_CATCH_SIGNALS;
513 #endif
514     if (!GetSolver()->ComputeFunction(aFunction)) {
515       SetErrorCode("Translation driver failed");
516       return NULL;
517     }
518   }
519   catch (Standard_Failure) {
520     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
521     SetErrorCode(aFail->GetMessageString());
522     return NULL;
523   }
524
525   //Make a Python command
526   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation1D("
527     << theObject << ", " << theVector << ", " << theStep << ", " << theNbTimes << ")";
528
529   SetErrorCode(OK);
530   return aCopy;
531 }
532
533 //=============================================================================
534 /*!
535  *  Translate2D
536  */
537 //=============================================================================
538 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate2D (Handle(GEOM_Object) theObject,
539                                                                 Handle(GEOM_Object) theVector,
540                                                                 double theStep1,
541                                                                 Standard_Integer theNbTimes1,
542                                                                 Handle(GEOM_Object) theVector2,
543                                                                 double theStep2,
544                                                                 Standard_Integer theNbTimes2)
545 {
546   SetErrorCode(KO);
547
548   if (theObject.IsNull() || theVector.IsNull() || theVector2.IsNull()) return NULL;
549
550   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
551   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
552
553   //Add a new Copy object
554   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
555
556   //Add a translate function
557   Handle(GEOM_Function) aFunction =
558     aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_2D);
559
560   //Check if the function is set correctly
561   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
562
563   GEOMImpl_ITranslate aTI(aFunction);
564   aTI.SetVector(theVector->GetLastFunction());
565   aTI.SetVector2(theVector2->GetLastFunction());
566   aTI.SetOriginal(aLastFunction);
567   aTI.SetStep1(theStep1);
568   aTI.SetNbIter1(theNbTimes1);
569   aTI.SetStep2(theStep2);
570   aTI.SetNbIter2(theNbTimes2);
571
572   //Compute the translation
573   try {
574 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
575     OCC_CATCH_SIGNALS;
576 #endif
577     if (!GetSolver()->ComputeFunction(aFunction)) {
578       SetErrorCode("Translation driver failed");
579       return NULL;
580     }
581   }
582   catch (Standard_Failure) {
583     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
584     SetErrorCode(aFail->GetMessageString());
585     return NULL;
586   }
587
588   //Make a Python command
589   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation2D("
590     << theObject << ", " << theVector  << ", " << theStep1 << ", " << theNbTimes1
591       << ", " << theVector2 << ", " << theStep2 << ", " << theNbTimes2 << ")";
592
593   SetErrorCode(OK);
594   return aCopy;
595 }
596
597
598 //=============================================================================
599 /*!
600  *  MirrorPlane
601  */
602 //=============================================================================
603 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlane
604        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
605 {
606   SetErrorCode(KO);
607
608   if (theObject.IsNull() || thePlane.IsNull()) return NULL;
609
610   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
611   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be mirrored
612
613   // Get last functions of the arguments
614   Handle(GEOM_Function) aPF = thePlane->GetLastFunction();
615
616   //Add a mirror function
617   Handle(GEOM_Function) aFunction =
618     theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE);
619   if (aFunction.IsNull()) return NULL;
620
621   //Check if the function is set correctly
622   if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
623
624   GEOMImpl_IMirror aTI (aFunction);
625   aTI.SetPlane(aPF);
626   aTI.SetOriginal(aLastFunction);
627
628   //Compute the mirror
629   try {
630 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
631     OCC_CATCH_SIGNALS;
632 #endif
633     if (!GetSolver()->ComputeFunction(aFunction)) {
634       SetErrorCode("Mirror driver failed");
635       return NULL;
636     }
637   }
638   catch (Standard_Failure) {
639     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
640     SetErrorCode(aFail->GetMessageString());
641     return NULL;
642   }
643
644   //Make a Python command
645   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorPlane("
646                                << theObject << ", " << thePlane << ")";
647
648   SetErrorCode(OK);
649   return theObject;
650 }
651
652 //=============================================================================
653 /*!
654  *  MirrorPlaneCopy
655  */
656 //=============================================================================
657 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlaneCopy
658        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
659 {
660   SetErrorCode(KO);
661
662   if (theObject.IsNull() || thePlane.IsNull()) return NULL;
663
664   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
665   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
666
667   //Add a new Copy object
668   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
669
670   //Add a mirror function
671   Handle(GEOM_Function) aFunction =
672     aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE_COPY);
673
674   //Check if the function is set correctly
675   if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
676
677   GEOMImpl_IMirror aTI (aFunction);
678   aTI.SetPlane(thePlane->GetLastFunction());
679   aTI.SetOriginal(aLastFunction);
680
681   //Compute the mirror
682   try {
683 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
684     OCC_CATCH_SIGNALS;
685 #endif
686     if (!GetSolver()->ComputeFunction(aFunction)) {
687       SetErrorCode("Mirror driver failed");
688       return NULL;
689     }
690   }
691   catch (Standard_Failure) {
692     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
693     SetErrorCode(aFail->GetMessageString());
694     return NULL;
695   }
696
697   //Make a Python command
698   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPlane("
699                                << theObject << ", " << thePlane << ")";
700
701   SetErrorCode(OK);
702   return aCopy;
703 }
704
705 //=============================================================================
706 /*!
707  *  MirrorPoint
708  */
709 //=============================================================================
710 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPoint
711        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
712 {
713   SetErrorCode(KO);
714
715   if (theObject.IsNull() || thePoint.IsNull()) return NULL;
716
717   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
718   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be mirrored
719
720   // Get last functions of the arguments
721   Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
722
723   //Add a mirror function
724   Handle(GEOM_Function) aFunction =
725     theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT);
726   if (aFunction.IsNull()) return NULL;
727
728   //Check if the function is set correctly
729   if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
730
731   GEOMImpl_IMirror aTI (aFunction);
732   aTI.SetPoint(aPF);
733   aTI.SetOriginal(aLastFunction);
734
735   //Compute the mirror
736   try {
737 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
738     OCC_CATCH_SIGNALS;
739 #endif
740     if (!GetSolver()->ComputeFunction(aFunction)) {
741       SetErrorCode("Mirror driver failed");
742       return NULL;
743     }
744   }
745   catch (Standard_Failure) {
746     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
747     SetErrorCode(aFail->GetMessageString());
748     return NULL;
749   }
750
751   //Make a Python command
752   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorPoint("
753                                << theObject << ", " << thePoint << ")";
754
755   SetErrorCode(OK);
756   return NULL;
757 }
758
759 //=============================================================================
760 /*!
761  *  MirrorPointCopy
762  */
763 //=============================================================================
764 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPointCopy
765        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
766 {
767   SetErrorCode(KO);
768
769   if (theObject.IsNull() || thePoint.IsNull()) return NULL;
770
771   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
772   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
773
774   //Add a new Copy object
775   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
776
777   //Add a mirror function
778   Handle(GEOM_Function) aFunction =
779     aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT_COPY);
780
781   //Check if the function is set correctly
782   if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
783
784   GEOMImpl_IMirror aTI (aFunction);
785   aTI.SetPoint(thePoint->GetLastFunction());
786   aTI.SetOriginal(aLastFunction);
787
788   //Compute the mirror
789   try {
790 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
791     OCC_CATCH_SIGNALS;
792 #endif
793     if (!GetSolver()->ComputeFunction(aFunction)) {
794       SetErrorCode("Mirror driver failed");
795       return NULL;
796     }
797   }
798   catch (Standard_Failure) {
799     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
800     SetErrorCode(aFail->GetMessageString());
801     return NULL;
802   }
803
804   //Make a Python command
805   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPoint("
806                                << theObject << ", " << thePoint << ")";
807
808   SetErrorCode(OK);
809   return aCopy;
810 }
811
812 //=============================================================================
813 /*!
814  *  MirrorAxis
815  */
816 //=============================================================================
817 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxis
818        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
819 {
820   SetErrorCode(KO);
821
822   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
823
824   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
825   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be mirrored
826
827   // Get last functions of the arguments
828   Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
829
830   //Add a mirror function
831   Handle(GEOM_Function) aFunction =
832     theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS);
833   if (aFunction.IsNull()) return NULL;
834
835   //Check if the function is set correctly
836   if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
837
838   GEOMImpl_IMirror aTI (aFunction);
839   aTI.SetAxis(anAF);
840   aTI.SetOriginal(aLastFunction);
841
842   //Compute the mirror
843   try {
844 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
845     OCC_CATCH_SIGNALS;
846 #endif
847     if (!GetSolver()->ComputeFunction(aFunction)) {
848       SetErrorCode("Mirror driver failed");
849       return NULL;
850     }
851   }
852   catch (Standard_Failure) {
853     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
854     SetErrorCode(aFail->GetMessageString());
855     return NULL;
856   }
857
858   //Make a Python command
859   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorAxis("
860                                << theObject << ", " << theAxis << ")";
861
862   SetErrorCode(OK);
863   return NULL;
864 }
865
866 //=============================================================================
867 /*!
868  *  MirrorAxisCopy
869  */
870 //=============================================================================
871 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxisCopy
872        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
873 {
874   SetErrorCode(KO);
875
876   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
877
878   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
879   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
880
881   //Add a new Copy object
882   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
883
884   //Add a mirror function
885   Handle(GEOM_Function) aFunction =
886     aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS_COPY);
887
888   //Check if the function is set correctly
889   if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
890
891   GEOMImpl_IMirror aTI (aFunction);
892   aTI.SetAxis(theAxis->GetLastFunction());
893   aTI.SetOriginal(aLastFunction);
894
895   //Compute the mirror
896   try {
897 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
898     OCC_CATCH_SIGNALS;
899 #endif
900     if (!GetSolver()->ComputeFunction(aFunction)) {
901       SetErrorCode("Mirror driver failed");
902       return NULL;
903     }
904   }
905   catch (Standard_Failure) {
906     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
907     SetErrorCode(aFail->GetMessageString());
908     return NULL;
909   }
910
911   //Make a Python command
912   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByAxis("
913                                << theObject << ", " << theAxis << ")";
914
915   SetErrorCode(OK);
916   return aCopy;
917 }
918
919
920 //=============================================================================
921 /*!
922  *  OffsetShape
923  */
924 //=============================================================================
925 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShape
926                               (Handle(GEOM_Object) theObject, double theOffset)
927 {
928   SetErrorCode(KO);
929
930   if (theObject.IsNull()) return NULL;
931
932   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
933   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
934
935   //Add a new Offset function
936   Handle(GEOM_Function) aFunction =
937     theObject->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE);
938   if (aFunction.IsNull()) return NULL;
939
940   //Check if the function is set correctly
941   if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
942
943   GEOMImpl_IOffset aTI (aFunction);
944   aTI.SetShape(anOriginal);
945   aTI.SetValue(theOffset);
946
947   //Compute the offset
948   try {
949 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
950     OCC_CATCH_SIGNALS;
951 #endif
952     if (!GetSolver()->ComputeFunction(aFunction)) {
953       SetErrorCode("Offset driver failed");
954       return NULL;
955     }
956   }
957   catch (Standard_Failure) {
958     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
959     SetErrorCode(aFail->GetMessageString());
960     return NULL;
961   }
962
963   //Make a Python command
964   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.OffsetShape("
965                                << theObject << ", " << theOffset << ")";
966
967   SetErrorCode(OK);
968   return theObject;
969 }
970
971 //=============================================================================
972 /*!
973  *  OffsetShapeCopy
974  */
975 //=============================================================================
976 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShapeCopy
977                               (Handle(GEOM_Object) theObject, double theOffset)
978 {
979   SetErrorCode(KO);
980
981   if (theObject.IsNull()) return NULL;
982
983   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
984   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
985
986   //Add a new Copy object
987   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
988
989   //Add a new Offset function
990   Handle(GEOM_Function) aFunction =
991     aCopy->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE_COPY);
992   if (aFunction.IsNull()) return NULL;
993
994   //Check if the function is set correctly
995   if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
996
997   GEOMImpl_IOffset aTI (aFunction);
998   aTI.SetShape(anOriginal);
999   aTI.SetValue(theOffset);
1000
1001   //Compute the offset
1002   try {
1003 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1004     OCC_CATCH_SIGNALS;
1005 #endif
1006     if (!GetSolver()->ComputeFunction(aFunction)) {
1007       SetErrorCode("Offset driver failed");
1008       return NULL;
1009     }
1010   }
1011   catch (Standard_Failure) {
1012     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1013     SetErrorCode(aFail->GetMessageString());
1014     return NULL;
1015   }
1016
1017   //Make a Python command
1018   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeOffset("
1019                                << theObject << ", " << theOffset << ")";
1020
1021   SetErrorCode(OK);
1022   return aCopy;
1023 }
1024
1025
1026 //=============================================================================
1027 /*!
1028  *  ScaleShape
1029  */
1030 //=============================================================================
1031 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape
1032        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1033 {
1034   SetErrorCode(KO);
1035
1036   if (theObject.IsNull()) return NULL;
1037
1038   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1039   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1040
1041   //Add a scale function
1042   Handle(GEOM_Function) aFunction =
1043     theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE);
1044   if (aFunction.IsNull()) return NULL;
1045
1046   //Check if the function is set correctly
1047   if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1048
1049   // Set arguments
1050   GEOMImpl_IScale aTI (aFunction);
1051   aTI.SetShape(anOriginal);
1052   aTI.SetFactor(theFactor);
1053
1054   // Set point argument
1055   if (!thePoint.IsNull()) {
1056     Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1057     aTI.SetPoint(aPF);
1058   }
1059
1060   //Compute the scale
1061   try {
1062 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1063     OCC_CATCH_SIGNALS;
1064 #endif
1065     if (!GetSolver()->ComputeFunction(aFunction)) {
1066       SetErrorCode("Scale driver failed");
1067       return NULL;
1068     }
1069   }
1070   catch (Standard_Failure) {
1071     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1072     SetErrorCode(aFail->GetMessageString());
1073     return NULL;
1074   }
1075
1076   //Make a Python command
1077   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShape("
1078     << theObject << ", " << thePoint << ", " << theFactor << ")";
1079
1080   SetErrorCode(OK);
1081   return theObject;
1082 }
1083
1084 //=============================================================================
1085 /*!
1086  *  ScaleShapeCopy
1087  */
1088 //=============================================================================
1089 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy
1090        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1091 {
1092   SetErrorCode(KO);
1093
1094   if (theObject.IsNull()) return NULL;
1095
1096   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1097   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1098
1099   //Add a new Copy object
1100   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1101
1102   //Add a scale function
1103   Handle(GEOM_Function) aFunction =
1104     aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_COPY);
1105   if (aFunction.IsNull()) return NULL;
1106
1107   //Check if the function is set correctly
1108   if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1109
1110   // Set arguments
1111   GEOMImpl_IScale aTI (aFunction);
1112   aTI.SetShape(anOriginal);
1113   aTI.SetFactor(theFactor);
1114
1115   // Set point argument
1116   if (!thePoint.IsNull()) {
1117     Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1118     aTI.SetPoint(aPF);
1119   }
1120
1121   //Compute the scale
1122   try {
1123 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1124     OCC_CATCH_SIGNALS;
1125 #endif
1126     if (!GetSolver()->ComputeFunction(aFunction)) {
1127       SetErrorCode("Scale driver failed");
1128       return NULL;
1129     }
1130   }
1131   catch (Standard_Failure) {
1132     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1133     SetErrorCode(aFail->GetMessageString());
1134     return NULL;
1135   }
1136
1137   //Make a Python command
1138   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleTransform("
1139     << theObject << ", " << thePoint << ", " << theFactor << ")";
1140
1141   SetErrorCode(OK);
1142   return aCopy;
1143 }
1144
1145 //=============================================================================
1146 /*!
1147  *  ScaleShapeAlongAxes
1148  */
1149 //=============================================================================
1150 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeAlongAxes (Handle(GEOM_Object) theObject,
1151                                                                         Handle(GEOM_Object) thePoint,
1152                                                                         double theFactorX,
1153                                                                         double theFactorY,
1154                                                                         double theFactorZ,
1155                                                                         bool   doCopy)
1156 {
1157   SetErrorCode(KO);
1158
1159   if (theObject.IsNull()) return NULL;
1160
1161   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1162   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1163
1164   //Add a scale function
1165   Handle(GEOM_Object) aCopy;   //Add a new Copy object
1166   Handle(GEOM_Function) aFunction;
1167   if (doCopy) {
1168     aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1169     aFunction = aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES_COPY);
1170   }
1171   else {
1172     aFunction = theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES);
1173   }
1174   if (aFunction.IsNull()) return NULL;
1175
1176   //Check if the function is set correctly
1177   if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1178
1179   // Set arguments
1180   GEOMImpl_IScale aTI (aFunction);
1181   aTI.SetShape(anOriginal);
1182   aTI.SetFactorX(theFactorX);
1183   aTI.SetFactorY(theFactorY);
1184   aTI.SetFactorZ(theFactorZ);
1185
1186   // Set point (optional argument)
1187   if (!thePoint.IsNull()) {
1188     Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1189     aTI.SetPoint(aPF);
1190   }
1191
1192   //Compute the scale
1193   try {
1194 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1195     OCC_CATCH_SIGNALS;
1196 #endif
1197     if (!GetSolver()->ComputeFunction(aFunction)) {
1198       SetErrorCode("Scale driver failed");
1199       return NULL;
1200     }
1201   }
1202   catch (Standard_Failure) {
1203     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1204     SetErrorCode(aFail->GetMessageString());
1205     return NULL;
1206   }
1207
1208   SetErrorCode(OK);
1209
1210   //Make a Python command
1211   if (doCopy) {
1212     GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleAlongAxes("
1213                                  << theObject << ", " << thePoint << ", "
1214                                  << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1215     return aCopy;
1216   }
1217
1218   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShapeAlongAxes("
1219                                << theObject << ", " << thePoint << ", "
1220                                << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1221   return theObject;
1222 }
1223
1224 //=============================================================================
1225 /*!
1226  *  PositionShape
1227  */
1228 //=============================================================================
1229 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShape
1230         (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1231 {
1232   SetErrorCode(KO);
1233
1234   if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1235
1236   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1237   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1238
1239   //Add a Position function
1240   Standard_Integer aType = POSITION_SHAPE;
1241   if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL;
1242
1243   Handle(GEOM_Function) aFunction =
1244     theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1245   if (aFunction.IsNull()) return NULL;
1246
1247   //Check if the function is set correctly
1248   if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1249
1250   //Set operation arguments
1251   GEOMImpl_IPosition aTI (aFunction);
1252   aTI.SetShape(anOriginal);
1253   aTI.SetEndLCS(theEndLCS->GetLastFunction());
1254   if (!theStartLCS.IsNull())
1255     aTI.SetStartLCS(theObject == theStartLCS ? anOriginal : theStartLCS->GetLastFunction());
1256
1257   //Compute the Position
1258   try {
1259 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1260     OCC_CATCH_SIGNALS;
1261 #endif
1262     if (!GetSolver()->ComputeFunction(aFunction)) {
1263       SetErrorCode("Position driver failed");
1264       return NULL;
1265     }
1266   }
1267   catch (Standard_Failure) {
1268     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1269     SetErrorCode(aFail->GetMessageString());
1270     return NULL;
1271   }
1272
1273   //Make a Python command
1274   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionShape("
1275     << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1276
1277   SetErrorCode(OK);
1278   return theObject;
1279 }
1280
1281 //=============================================================================
1282 /*!
1283  *  PositionShapeCopy
1284  */
1285 //=============================================================================
1286 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShapeCopy
1287        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1288 {
1289   SetErrorCode(KO);
1290
1291   if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1292
1293   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1294   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1295
1296   //Add a new Copy object
1297   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1298
1299   //Add a position function
1300   Standard_Integer aType = POSITION_SHAPE_COPY;
1301   if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL_COPY;
1302
1303   Handle(GEOM_Function) aFunction =
1304     aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1305   if (aFunction.IsNull()) return NULL;
1306
1307   //Check if the function is set correctly
1308   if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1309
1310   GEOMImpl_IPosition aTI (aFunction);
1311   aTI.SetShape(anOriginal);
1312   aTI.SetEndLCS(theEndLCS->GetLastFunction());
1313   if (!theStartLCS.IsNull())
1314     aTI.SetStartLCS(theStartLCS->GetLastFunction());
1315
1316   //Compute the position
1317   try {
1318 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1319     OCC_CATCH_SIGNALS;
1320 #endif
1321     if (!GetSolver()->ComputeFunction(aFunction)) {
1322       SetErrorCode("Position driver failed");
1323       return NULL;
1324     }
1325   }
1326   catch (Standard_Failure) {
1327     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1328     SetErrorCode(aFail->GetMessageString());
1329     return NULL;
1330   }
1331
1332   //Make a Python command
1333   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakePosition("
1334     << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1335
1336   SetErrorCode(OK);
1337   return aCopy;
1338 }
1339
1340 //=============================================================================
1341 /*!
1342  *  PositionAlongPath
1343  */
1344 //=============================================================================
1345 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionAlongPath
1346        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePath, 
1347         double theDistance, bool theCopy, bool theReverse)
1348 {
1349   SetErrorCode(KO);
1350
1351   if (theObject.IsNull() || thePath.IsNull()) return NULL;
1352
1353   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1354   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1355
1356   //Add a position function
1357   Handle(GEOM_Function) aFunction;
1358   Handle(GEOM_Object) aCopy;
1359
1360   if (theCopy) {
1361     aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1362     aFunction = aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1363   }
1364   else
1365     aFunction = theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1366
1367   if (aFunction.IsNull()) return NULL;
1368
1369   //Check if the function is set correctly
1370   if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1371
1372   GEOMImpl_IPosition aTI (aFunction);
1373   aTI.SetShape(anOriginal);
1374   aTI.SetPath(thePath->GetLastFunction());
1375   aTI.SetDistance(theDistance);
1376   aTI.SetReverse(theReverse);
1377
1378   //Compute the position
1379   try {
1380 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1381     OCC_CATCH_SIGNALS;
1382 #endif
1383     if (!GetSolver()->ComputeFunction(aFunction)) {
1384       SetErrorCode("Position driver failed");
1385       return NULL;
1386     }
1387   }
1388   catch (Standard_Failure) {
1389     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1390     SetErrorCode(aFail->GetMessageString());
1391     return NULL;
1392   }
1393
1394   //Make a Python command
1395   if (theCopy) {
1396     GEOM::TPythonDump(aFunction) << aCopy << " = geompy.PositionAlongPath("
1397                                  << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1398     SetErrorCode(OK);
1399     return aCopy;
1400   }
1401
1402   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionAlongPath("
1403     << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1404
1405   SetErrorCode(OK);
1406   return theObject;
1407 }
1408
1409 //=============================================================================
1410 /*!
1411  *  Rotate
1412  */
1413 //=============================================================================
1414 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) theObject,
1415                                                            Handle(GEOM_Object) theAxis,
1416                                                            double theAngle)
1417 {
1418   SetErrorCode(KO);
1419
1420   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1421
1422   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1423   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1424
1425   // Get last functions of the arguments
1426   Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
1427
1428   //Add a rotate function
1429   aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE);
1430
1431   if (aFunction.IsNull()) return NULL;
1432
1433   //Check if the function is set correctly
1434   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1435
1436   GEOMImpl_IRotate aRI(aFunction);
1437   aRI.SetAxis(anAF);
1438   aRI.SetOriginal(aLastFunction);
1439   aRI.SetAngle(theAngle);
1440
1441   //Compute the translation
1442   try {
1443 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1444     OCC_CATCH_SIGNALS;
1445 #endif
1446     if (!GetSolver()->ComputeFunction(aFunction)) {
1447       SetErrorCode("Rotate driver failed");
1448       return NULL;
1449     }
1450   }
1451   catch (Standard_Failure) {
1452     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1453     SetErrorCode(aFail->GetMessageString());
1454     return NULL;
1455   }
1456
1457   //Make a Python command
1458   GEOM::TPythonDump(aFunction) << "geompy.Rotate(" << theObject
1459     << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1460
1461   SetErrorCode(OK);
1462   return theObject;
1463 }
1464
1465 //=============================================================================
1466 /*!
1467  *  Rotate
1468  */
1469 //=============================================================================
1470 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, double theAngle)
1471 {
1472   SetErrorCode(KO);
1473
1474   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1475
1476   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1477   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1478
1479   //Add a new Copy object
1480   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1481
1482   //Add a rotate function
1483   aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_COPY);
1484   if (aFunction.IsNull()) return NULL;
1485
1486     //Check if the function is set correctly
1487   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1488
1489   GEOMImpl_IRotate aRI(aFunction);
1490   aRI.SetAxis(theAxis->GetLastFunction());
1491   aRI.SetOriginal(aLastFunction);
1492   aRI.SetAngle(theAngle);
1493
1494   //Compute the translation
1495   try {
1496 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1497     OCC_CATCH_SIGNALS;
1498 #endif
1499     if (!GetSolver()->ComputeFunction(aFunction)) {
1500       SetErrorCode("Rotate driver failed");
1501       return NULL;
1502     }
1503   }
1504   catch (Standard_Failure) {
1505     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1506     SetErrorCode(aFail->GetMessageString());
1507     return NULL;
1508   }
1509
1510   //Make a Python command
1511   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotation(" << theObject
1512     << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1513
1514   SetErrorCode(OK);
1515   return aCopy;
1516 }
1517
1518 //=============================================================================
1519 /*!
1520  *  Rotate1D
1521  */
1522 //=============================================================================
1523 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) theObject,
1524                                                              Handle(GEOM_Object) theAxis,
1525                                                              Standard_Integer theNbTimes)
1526 {
1527   SetErrorCode(KO);
1528
1529   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1530
1531   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1532   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1533
1534   //Add a new Copy object
1535   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1536
1537   //Add a rotate function
1538   aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_1D);
1539   if (aFunction.IsNull()) return NULL;
1540
1541     //Check if the function is set correctly
1542   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1543
1544   GEOMImpl_IRotate aRI(aFunction);
1545   aRI.SetOriginal(aLastFunction);
1546   aRI.SetAxis(theAxis->GetLastFunction());
1547   aRI.SetNbIter1(theNbTimes);
1548
1549   //Compute the translation
1550   try {
1551 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1552     OCC_CATCH_SIGNALS;
1553 #endif
1554     if (!GetSolver()->ComputeFunction(aFunction)) {
1555       SetErrorCode("Rotate driver failed");
1556       return NULL;
1557     }
1558   }
1559   catch (Standard_Failure) {
1560     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1561     SetErrorCode(aFail->GetMessageString());
1562     return NULL;
1563   }
1564
1565   //Make a Python command
1566   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate1D("
1567     << theObject << ", " << theAxis << ", " << theNbTimes << ")";
1568
1569   SetErrorCode(OK);
1570   return aCopy;
1571 }
1572
1573 //=============================================================================
1574 /*!
1575  *  Rotate2D
1576  */
1577 //=============================================================================
1578 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) theObject,
1579                                                              Handle(GEOM_Object) theAxis,
1580                                                              double theAngle,
1581                                                              Standard_Integer theNbTimes1,
1582                                                              double theStep,
1583                                                              Standard_Integer theNbTimes2)
1584 {
1585   SetErrorCode(KO);
1586
1587   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1588
1589   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1590   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1591
1592   //Add a new Copy object
1593   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1594
1595   //Add a rotate function
1596   aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_2D);
1597   if (aFunction.IsNull()) return NULL;
1598
1599     //Check if the function is set correctly
1600   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1601
1602   GEOMImpl_IRotate aRI(aFunction);
1603   aRI.SetAxis(theAxis->GetLastFunction());
1604   aRI.SetOriginal(aLastFunction);
1605   aRI.SetNbIter1(theNbTimes1);
1606   aRI.SetNbIter2(theNbTimes2);
1607   aRI.SetAngle(theAngle);
1608   aRI.SetStep(theStep);
1609
1610   //Compute the translation
1611   try {
1612 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1613     OCC_CATCH_SIGNALS;
1614 #endif
1615     if (!GetSolver()->ComputeFunction(aFunction)) {
1616       SetErrorCode("Rotate driver failed");
1617       return NULL;
1618     }
1619   }
1620   catch (Standard_Failure) {
1621     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1622     SetErrorCode(aFail->GetMessageString());
1623     return NULL;
1624   }
1625
1626   //Make a Python command
1627   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate2D("
1628     << theObject << ", " << theAxis << ", " << theAngle << ", "
1629       << theNbTimes1 << ", " << theStep << ", " << theNbTimes2 << ")";
1630
1631   SetErrorCode(OK);
1632   return aCopy;
1633 }
1634
1635 //=============================================================================
1636 /*!
1637  *  RotateThreePoints
1638  */
1639 //=============================================================================
1640 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEOM_Object) theObject,
1641                                                                       Handle(GEOM_Object) theCentPoint, 
1642                                                                       Handle(GEOM_Object) thePoint1,
1643                                                                       Handle(GEOM_Object) thePoint2)
1644 {
1645   SetErrorCode(KO);
1646
1647   if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1648
1649   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1650   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1651
1652   // Get last functions of the arguments
1653   Handle(GEOM_Function) aCPF = theCentPoint->GetLastFunction();
1654   Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
1655   Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
1656
1657
1658   //Add a rotate function
1659   aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS);
1660
1661   if (aFunction.IsNull()) return NULL;
1662
1663   //Check if the function is set correctly
1664   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1665
1666   GEOMImpl_IRotate aRI(aFunction);
1667   aRI.SetCentPoint(aCPF);
1668   aRI.SetPoint1(aP1F);
1669   aRI.SetPoint2(aP2F);
1670   aRI.SetOriginal(aLastFunction);
1671
1672   //Compute the translation
1673   try {
1674 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1675     OCC_CATCH_SIGNALS;
1676 #endif
1677     if (!GetSolver()->ComputeFunction(aFunction)) {
1678       SetErrorCode("Rotate driver failed");
1679       return NULL;
1680     }
1681   }
1682   catch (Standard_Failure) {
1683     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1684     SetErrorCode(aFail->GetMessageString());
1685     return NULL;
1686   }
1687
1688   //Make a Python command
1689   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.RotateThreePoints(" << theObject
1690                                << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1691
1692   SetErrorCode(OK);
1693   return theObject;
1694 }
1695
1696 //=============================================================================
1697 /*!
1698  *  RotateThreePointsCopy
1699  */
1700 //=============================================================================
1701 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle(GEOM_Object) theObject, 
1702                                                          Handle(GEOM_Object) theCentPoint, 
1703                                                          Handle(GEOM_Object) thePoint1,
1704                                                          Handle(GEOM_Object) thePoint2)
1705 {
1706   SetErrorCode(KO);
1707
1708   if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1709
1710   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1711   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1712
1713   //Add a new Copy object
1714   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1715
1716   //Add a rotate function
1717   aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS_COPY);
1718   if (aFunction.IsNull()) return NULL;
1719
1720     //Check if the function is set correctly
1721   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1722
1723   GEOMImpl_IRotate aRI(aFunction);
1724   aRI.SetCentPoint(theCentPoint->GetLastFunction());
1725   aRI.SetPoint1(thePoint1->GetLastFunction());
1726   aRI.SetPoint2(thePoint2->GetLastFunction());
1727   aRI.SetOriginal(aLastFunction);
1728
1729   //Compute the translation
1730   try {
1731 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1732     OCC_CATCH_SIGNALS;
1733 #endif
1734     if (!GetSolver()->ComputeFunction(aFunction)) {
1735       SetErrorCode("Rotate driver failed");
1736       return NULL;
1737     }
1738   }
1739   catch (Standard_Failure) {
1740     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1741     SetErrorCode(aFail->GetMessageString());
1742     return NULL;
1743   }
1744
1745   //Make a Python command
1746   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotationThreePoints(" << theObject
1747                                << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1748
1749   SetErrorCode(OK);
1750   return aCopy;
1751 }
1752