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