Salome HOME
0020555: EDF GEOM: MakeSketcher and localisation
[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.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.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) << aCopy << " = 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  *  PositionAlongPath
1342  */
1343 //=============================================================================
1344 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionAlongPath
1345        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePath, 
1346         double theDistance, bool theCopy, bool theReverse)
1347 {
1348   SetErrorCode(KO);
1349
1350   if (theObject.IsNull() || thePath.IsNull()) return NULL;
1351
1352   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1353   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1354
1355   //Add a position function
1356   Handle(GEOM_Function) aFunction;
1357   Handle(GEOM_Object) aCopy;
1358
1359   if (theCopy) {
1360     aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1361     aFunction = aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1362   }
1363   else
1364     aFunction = theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1365
1366   if (aFunction.IsNull()) return NULL;
1367
1368   //Check if the function is set correctly
1369   if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1370
1371   GEOMImpl_IPosition aTI (aFunction);
1372   aTI.SetShape(anOriginal);
1373   aTI.SetPath(thePath->GetLastFunction());
1374   aTI.SetDistance(theDistance);
1375   aTI.SetReverse(theReverse);
1376
1377   //Compute the position
1378   try {
1379 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1380     OCC_CATCH_SIGNALS;
1381 #endif
1382     if (!GetSolver()->ComputeFunction(aFunction)) {
1383       SetErrorCode("Position driver failed");
1384       return NULL;
1385     }
1386   }
1387   catch (Standard_Failure) {
1388     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1389     SetErrorCode(aFail->GetMessageString());
1390     return NULL;
1391   }
1392
1393   //Make a Python command
1394   if (theCopy) {
1395     GEOM::TPythonDump(aFunction) << aCopy << " = geompy.PositionAlongPath("
1396                                  << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1397     SetErrorCode(OK);
1398     return aCopy;
1399   }
1400
1401   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionAlongPath("
1402     << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1403
1404   SetErrorCode(OK);
1405   return theObject;
1406 }
1407
1408 //=============================================================================
1409 /*!
1410  *  Rotate
1411  */
1412 //=============================================================================
1413 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) theObject,
1414                                                            Handle(GEOM_Object) theAxis,
1415                                                            double theAngle)
1416 {
1417   SetErrorCode(KO);
1418
1419   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1420
1421   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1422   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1423
1424   // Get last functions of the arguments
1425   Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
1426
1427   //Add a rotate function
1428   aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE);
1429
1430   if (aFunction.IsNull()) return NULL;
1431
1432   //Check if the function is set correctly
1433   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1434
1435   GEOMImpl_IRotate aRI(aFunction);
1436   aRI.SetAxis(anAF);
1437   aRI.SetOriginal(aLastFunction);
1438   aRI.SetAngle(theAngle);
1439
1440   //Compute the translation
1441   try {
1442 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1443     OCC_CATCH_SIGNALS;
1444 #endif
1445     if (!GetSolver()->ComputeFunction(aFunction)) {
1446       SetErrorCode("Rotate driver failed");
1447       return NULL;
1448     }
1449   }
1450   catch (Standard_Failure) {
1451     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1452     SetErrorCode(aFail->GetMessageString());
1453     return NULL;
1454   }
1455
1456   //Make a Python command
1457   GEOM::TPythonDump(aFunction) << "geompy.Rotate(" << theObject
1458     << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1459
1460   SetErrorCode(OK);
1461   return theObject;
1462 }
1463
1464 //=============================================================================
1465 /*!
1466  *  Rotate
1467  */
1468 //=============================================================================
1469 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, double theAngle)
1470 {
1471   SetErrorCode(KO);
1472
1473   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1474
1475   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1476   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1477
1478   //Add a new Copy object
1479   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1480
1481   //Add a rotate function
1482   aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_COPY);
1483   if (aFunction.IsNull()) return NULL;
1484
1485     //Check if the function is set correctly
1486   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1487
1488   GEOMImpl_IRotate aRI(aFunction);
1489   aRI.SetAxis(theAxis->GetLastFunction());
1490   aRI.SetOriginal(aLastFunction);
1491   aRI.SetAngle(theAngle);
1492
1493   //Compute the translation
1494   try {
1495 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1496     OCC_CATCH_SIGNALS;
1497 #endif
1498     if (!GetSolver()->ComputeFunction(aFunction)) {
1499       SetErrorCode("Rotate driver failed");
1500       return NULL;
1501     }
1502   }
1503   catch (Standard_Failure) {
1504     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1505     SetErrorCode(aFail->GetMessageString());
1506     return NULL;
1507   }
1508
1509   //Make a Python command
1510   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotation(" << theObject
1511     << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1512
1513   SetErrorCode(OK);
1514   return aCopy;
1515 }
1516
1517 //=============================================================================
1518 /*!
1519  *  Rotate1D
1520  */
1521 //=============================================================================
1522 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) theObject,
1523                                                              Handle(GEOM_Object) theAxis,
1524                                                              Standard_Integer theNbTimes)
1525 {
1526   SetErrorCode(KO);
1527
1528   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1529
1530   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1531   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1532
1533   //Add a new Copy object
1534   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1535
1536   //Add a rotate function
1537   aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_1D);
1538   if (aFunction.IsNull()) return NULL;
1539
1540     //Check if the function is set correctly
1541   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1542
1543   GEOMImpl_IRotate aRI(aFunction);
1544   aRI.SetOriginal(aLastFunction);
1545   aRI.SetAxis(theAxis->GetLastFunction());
1546   aRI.SetNbIter1(theNbTimes);
1547
1548   //Compute the translation
1549   try {
1550 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1551     OCC_CATCH_SIGNALS;
1552 #endif
1553     if (!GetSolver()->ComputeFunction(aFunction)) {
1554       SetErrorCode("Rotate driver failed");
1555       return NULL;
1556     }
1557   }
1558   catch (Standard_Failure) {
1559     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1560     SetErrorCode(aFail->GetMessageString());
1561     return NULL;
1562   }
1563
1564   //Make a Python command
1565   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate1D("
1566     << theObject << ", " << theAxis << ", " << theNbTimes << ")";
1567
1568   SetErrorCode(OK);
1569   return aCopy;
1570 }
1571
1572 //=============================================================================
1573 /*!
1574  *  Rotate2D
1575  */
1576 //=============================================================================
1577 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) theObject,
1578                                                              Handle(GEOM_Object) theAxis,
1579                                                              double theAngle,
1580                                                              Standard_Integer theNbTimes1,
1581                                                              double theStep,
1582                                                              Standard_Integer theNbTimes2)
1583 {
1584   SetErrorCode(KO);
1585
1586   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1587
1588   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1589   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1590
1591   //Add a new Copy object
1592   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1593
1594   //Add a rotate function
1595   aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_2D);
1596   if (aFunction.IsNull()) return NULL;
1597
1598     //Check if the function is set correctly
1599   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1600
1601   GEOMImpl_IRotate aRI(aFunction);
1602   aRI.SetAxis(theAxis->GetLastFunction());
1603   aRI.SetOriginal(aLastFunction);
1604   aRI.SetNbIter1(theNbTimes1);
1605   aRI.SetNbIter2(theNbTimes2);
1606   aRI.SetAngle(theAngle);
1607   aRI.SetStep(theStep);
1608
1609   //Compute the translation
1610   try {
1611 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1612     OCC_CATCH_SIGNALS;
1613 #endif
1614     if (!GetSolver()->ComputeFunction(aFunction)) {
1615       SetErrorCode("Rotate driver failed");
1616       return NULL;
1617     }
1618   }
1619   catch (Standard_Failure) {
1620     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1621     SetErrorCode(aFail->GetMessageString());
1622     return NULL;
1623   }
1624
1625   //Make a Python command
1626   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate2D("
1627     << theObject << ", " << theAxis << ", " << theAngle << ", "
1628       << theNbTimes1 << ", " << theStep << ", " << theNbTimes2 << ")";
1629
1630   SetErrorCode(OK);
1631   return aCopy;
1632 }
1633
1634 //=============================================================================
1635 /*!
1636  *  RotateThreePoints
1637  */
1638 //=============================================================================
1639 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEOM_Object) theObject,
1640                                                                       Handle(GEOM_Object) theCentPoint, 
1641                                                                       Handle(GEOM_Object) thePoint1,
1642                                                                       Handle(GEOM_Object) thePoint2)
1643 {
1644   SetErrorCode(KO);
1645
1646   if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1647
1648   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1649   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1650
1651   // Get last functions of the arguments
1652   Handle(GEOM_Function) aCPF = theCentPoint->GetLastFunction();
1653   Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
1654   Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
1655
1656
1657   //Add a rotate function
1658   aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS);
1659
1660   if (aFunction.IsNull()) return NULL;
1661
1662   //Check if the function is set correctly
1663   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1664
1665   GEOMImpl_IRotate aRI(aFunction);
1666   aRI.SetCentPoint(aCPF);
1667   aRI.SetPoint1(aP1F);
1668   aRI.SetPoint2(aP2F);
1669   aRI.SetOriginal(aLastFunction);
1670
1671   //Compute the translation
1672   try {
1673 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1674     OCC_CATCH_SIGNALS;
1675 #endif
1676     if (!GetSolver()->ComputeFunction(aFunction)) {
1677       SetErrorCode("Rotate driver failed");
1678       return NULL;
1679     }
1680   }
1681   catch (Standard_Failure) {
1682     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1683     SetErrorCode(aFail->GetMessageString());
1684     return NULL;
1685   }
1686
1687   //Make a Python command
1688   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.RotateThreePoints(" << theObject
1689                                << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1690
1691   SetErrorCode(OK);
1692   return theObject;
1693 }
1694
1695 //=============================================================================
1696 /*!
1697  *  RotateThreePointsCopy
1698  */
1699 //=============================================================================
1700 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle(GEOM_Object) theObject, 
1701                                                          Handle(GEOM_Object) theCentPoint, 
1702                                                          Handle(GEOM_Object) thePoint1,
1703                                                          Handle(GEOM_Object) thePoint2)
1704 {
1705   SetErrorCode(KO);
1706
1707   if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1708
1709   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1710   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1711
1712   //Add a new Copy object
1713   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1714
1715   //Add a rotate function
1716   aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS_COPY);
1717   if (aFunction.IsNull()) return NULL;
1718
1719     //Check if the function is set correctly
1720   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1721
1722   GEOMImpl_IRotate aRI(aFunction);
1723   aRI.SetCentPoint(theCentPoint->GetLastFunction());
1724   aRI.SetPoint1(thePoint1->GetLastFunction());
1725   aRI.SetPoint2(thePoint2->GetLastFunction());
1726   aRI.SetOriginal(aLastFunction);
1727
1728   //Compute the translation
1729   try {
1730 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1731     OCC_CATCH_SIGNALS;
1732 #endif
1733     if (!GetSolver()->ComputeFunction(aFunction)) {
1734       SetErrorCode("Rotate driver failed");
1735       return NULL;
1736     }
1737   }
1738   catch (Standard_Failure) {
1739     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1740     SetErrorCode(aFail->GetMessageString());
1741     return NULL;
1742   }
1743
1744   //Make a Python command
1745   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotationThreePoints(" << theObject
1746                                << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1747
1748   SetErrorCode(OK);
1749   return aCopy;
1750 }
1751