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