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