Salome HOME
07098c561bc9c9fa4c82428afa96af026b50f66e
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ITransformOperations.cxx
1 // Copyright (C) 2007-2012  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 <GEOMImpl_TranslateDriver.hxx>
28 #include <GEOMImpl_MirrorDriver.hxx>
29 #include <GEOMImpl_ProjectionDriver.hxx>
30 #include <GEOMImpl_OffsetDriver.hxx>
31 #include <GEOMImpl_ScaleDriver.hxx>
32 #include <GEOMImpl_RotateDriver.hxx>
33 #include <GEOMImpl_PositionDriver.hxx>
34
35 #include <GEOMImpl_ITranslate.hxx>
36 #include <GEOMImpl_IMirror.hxx>
37 #include <GEOMImpl_IOffset.hxx>
38 #include <GEOMImpl_IScale.hxx>
39 #include <GEOMImpl_IRotate.hxx>
40 #include <GEOMImpl_IPosition.hxx>
41
42 #include <GEOMImpl_Types.hxx>
43
44 #include <GEOM_Function.hxx>
45 #include <GEOM_PythonDump.hxx>
46
47 #include <Basics_OCCTVersion.hxx>
48
49 #include "utilities.h"
50 #include <OpUtil.hxx>
51 #include <Utils_ExceptHandlers.hxx>
52
53 #include <TFunction_DriverTable.hxx>
54 #include <TFunction_Driver.hxx>
55 #include <TFunction_Logbook.hxx>
56 #include <TDF_Tool.hxx>
57
58 #include <BRep_Tool.hxx>
59 #include <BRep_Builder.hxx>
60 #include <TopExp.hxx>
61 #include <TopoDS.hxx>
62 #include <TopoDS_Edge.hxx>
63 #include <TopoDS_Vertex.hxx>
64 #include <TopoDS_Compound.hxx>
65 #include <gp_Pnt.hxx>
66 #include <gp_Vec.hxx>
67 #include <gp_Trsf.hxx>
68
69 #include <StdFail_NotDone.hxx>
70 #include <Standard_Failure.hxx>
71 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
72
73 //=============================================================================
74 /*!
75  *   constructor:
76  */
77 //=============================================================================
78
79 GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations (GEOM_Engine* theEngine, int theDocID)
80 : GEOM_IOperations(theEngine, theDocID)
81 {
82   MESSAGE("GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations");
83 }
84
85 //=============================================================================
86 /*!
87  *  destructor
88  */
89 //=============================================================================
90
91 GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations()
92 {
93   MESSAGE("GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations");
94 }
95
96
97 //=============================================================================
98 /*!
99  *  TranslateTwoPoints
100  */
101 //=============================================================================
102 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPoints
103        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
104 {
105   SetErrorCode(KO);
106
107   if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
108
109   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
110   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
111
112   // Get last functions of the arguments
113   Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
114   Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
115
116   //Add a translate function
117   aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS);
118
119   if (aFunction.IsNull()) return NULL;
120
121   //Check if the function is set correctly
122   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
123
124   GEOMImpl_ITranslate aTI (aFunction);
125   aTI.SetPoint1(aP1F);
126   aTI.SetPoint2(aP2F);
127   aTI.SetOriginal(aLastFunction);
128
129   //Compute the translation
130   try {
131 #if OCC_VERSION_LARGE > 0x06010000
132     OCC_CATCH_SIGNALS;
133 #endif
134     if (!GetSolver()->ComputeFunction(aFunction)) {
135       SetErrorCode("Translation driver failed");
136       return NULL;
137     }
138   }
139   catch (Standard_Failure) {
140     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
141     SetErrorCode(aFail->GetMessageString());
142     return NULL;
143   }
144
145   //Make a Python command
146   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateTwoPoints("
147     << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
148
149   SetErrorCode(OK);
150   return theObject;
151 }
152
153 //=============================================================================
154 /*!
155  *  TranslateDXDYDZ
156  */
157 //=============================================================================
158 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZ
159        (Handle(GEOM_Object) theObject, double theX, double theY,  double theZ)
160 {
161   SetErrorCode(KO);
162
163   if (theObject.IsNull()) return NULL;
164
165   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
166   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
167
168   //Add a translate function
169   aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ);
170
171   if (aFunction.IsNull()) return NULL;
172
173   //Check if the function is set correctly
174   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
175
176   GEOMImpl_ITranslate aTI(aFunction);
177   aTI.SetDX(theX);
178   aTI.SetDY(theY);
179   aTI.SetDZ(theZ);
180   aTI.SetOriginal(aLastFunction);
181
182   //Compute the translation
183   try {
184 #if OCC_VERSION_LARGE > 0x06010000
185     OCC_CATCH_SIGNALS;
186 #endif
187     if (!GetSolver()->ComputeFunction(aFunction)) {
188       SetErrorCode("Translation driver failed");
189       return NULL;
190     }
191   }
192   catch (Standard_Failure) {
193     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
194     SetErrorCode(aFail->GetMessageString());
195     return NULL;
196   }
197
198   //Make a Python command
199   GEOM::TPythonDump(aFunction) << "geompy.TranslateDXDYDZ("
200     << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
201
202   SetErrorCode(OK);
203   return theObject;
204 }
205
206
207 //=============================================================================
208 /*!
209  *  TranslateTwoPointsCopy
210  */
211 //=============================================================================
212 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPointsCopy
213        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
214 {
215   SetErrorCode(KO);
216
217   if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
218
219   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
220   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
221
222   //Add a new Copy object
223   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
224
225   //Add a translate function
226   Handle(GEOM_Function) aFunction =
227     aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS_COPY);
228
229   //Check if the function is set correctly
230   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
231
232   GEOMImpl_ITranslate aTI(aFunction);
233   aTI.SetPoint1(thePoint1->GetLastFunction());
234   aTI.SetPoint2(thePoint2->GetLastFunction());
235   //aTI.SetShape(theObject->GetValue());
236   aTI.SetOriginal(aLastFunction);
237
238   //Compute the translation
239   try {
240 #if OCC_VERSION_LARGE > 0x06010000
241     OCC_CATCH_SIGNALS;
242 #endif
243     if (!GetSolver()->ComputeFunction(aFunction)) {
244       SetErrorCode("Translation driver failed");
245       return NULL;
246     }
247   }
248   catch (Standard_Failure) {
249     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
250     SetErrorCode(aFail->GetMessageString());
251     return NULL;
252   }
253
254   //Make a Python command
255   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationTwoPoints("
256     << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
257
258   SetErrorCode(OK);
259   return aCopy;
260 }
261
262 //=============================================================================
263 /*!
264  *  TranslateDXDYDZCopy
265  */
266 //=============================================================================
267 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZCopy
268        (Handle(GEOM_Object) theObject, double theX, double theY,  double theZ)
269 {
270   SetErrorCode(KO);
271
272   if (theObject.IsNull()) return NULL;
273
274   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
275   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
276
277   //Add a new Copy object
278   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
279
280   //Add a translate function
281   Handle(GEOM_Function) aFunction =
282     aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ_COPY);
283
284   //Check if the function is set correctly
285   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
286
287   GEOMImpl_ITranslate aTI(aFunction);
288   aTI.SetDX(theX);
289   aTI.SetDY(theY);
290   aTI.SetDZ(theZ);
291   aTI.SetOriginal(aLastFunction);
292
293   //Compute the translation
294   try {
295 #if OCC_VERSION_LARGE > 0x06010000
296     OCC_CATCH_SIGNALS;
297 #endif
298     if (!GetSolver()->ComputeFunction(aFunction)) {
299       SetErrorCode("Translation driver failed");
300       return NULL;
301     }
302   }
303   catch (Standard_Failure) {
304     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
305     SetErrorCode(aFail->GetMessageString());
306     return NULL;
307   }
308
309   //Make a Python command
310   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslation("
311     << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
312
313   SetErrorCode(OK);
314   return aCopy;
315 }
316
317
318 //=============================================================================
319 /*!
320  *  TranslateVector
321  */
322 //=============================================================================
323 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVector
324        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
325 {
326   SetErrorCode(KO);
327
328   if (theObject.IsNull() || theVector.IsNull()) return NULL;
329
330   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
331   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
332
333   // Get last functions of the arguments
334   Handle(GEOM_Function) aVF = theVector->GetLastFunction();
335
336   //Add a translate function
337   aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR);
338
339   if (aFunction.IsNull()) return NULL;
340
341   //Check if the function is set correctly
342   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
343
344   GEOMImpl_ITranslate aTI (aFunction);
345   aTI.SetVector(aVF);
346   aTI.SetOriginal(aLastFunction);
347
348   //Compute the translation
349   try {
350 #if OCC_VERSION_LARGE > 0x06010000
351     OCC_CATCH_SIGNALS;
352 #endif
353     if (!GetSolver()->ComputeFunction(aFunction)) {
354       SetErrorCode("Translation driver failed");
355       return NULL;
356     }
357   }
358   catch (Standard_Failure) {
359     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
360     SetErrorCode(aFail->GetMessageString());
361     return NULL;
362   }
363
364   //Make a Python command
365   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateVector("
366                                << theObject << ", " << theVector << ")";
367
368   SetErrorCode(OK);
369   return theObject;
370 }
371 //=============================================================================
372 /*!
373  *  TranslateVectorCopy
374  */
375 //=============================================================================
376 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorCopy
377        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
378 {
379   SetErrorCode(KO);
380
381   if (theObject.IsNull() || theVector.IsNull()) return NULL;
382
383   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
384   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
385
386   //Add a new Copy object
387   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
388
389   //Add a translate function
390   Handle(GEOM_Function) aFunction =
391     aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_COPY);
392
393   //Check if the function is set correctly
394   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
395
396   GEOMImpl_ITranslate aTI(aFunction);
397   aTI.SetVector(theVector->GetLastFunction());
398 //  aTI.SetShape(theObject->GetValue());
399   aTI.SetOriginal(aLastFunction);
400
401   //Compute the translation
402   try {
403 #if OCC_VERSION_LARGE > 0x06010000
404     OCC_CATCH_SIGNALS;
405 #endif
406     if (!GetSolver()->ComputeFunction(aFunction)) {
407       SetErrorCode("Translation driver failed");
408       return NULL;
409     }
410   }
411   catch (Standard_Failure) {
412     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
413     SetErrorCode(aFail->GetMessageString());
414     return NULL;
415   }
416
417   //Make a Python command
418   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVector("
419                                << theObject << ", " << theVector << ")";
420
421   SetErrorCode(OK);
422   return aCopy;
423 }
424
425 //=============================================================================
426 /*!
427  *  TranslateVectorDistance
428  */
429 //=============================================================================
430 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorDistance
431        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector, double theDistance, bool theCopy)
432 {
433   SetErrorCode(KO);
434
435   if (theObject.IsNull() || theVector.IsNull()) return NULL;
436
437   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
438   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
439
440   Handle(GEOM_Object) aCopy;   //Add a new Copy object
441   Handle(GEOM_Function) aFunction;
442
443   //Add a translate function
444   if (theCopy) {
445     aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
446     aFunction = aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
447   }
448   else {
449     aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
450   }
451   if (aFunction.IsNull()) return NULL;
452
453   //Check if the function is set correctly
454   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
455
456   GEOMImpl_ITranslate aTI(aFunction);
457   aTI.SetVector(theVector->GetLastFunction());
458   aTI.SetDistance(theDistance);
459 //  aTI.SetShape(theObject->GetValue());
460   aTI.SetOriginal(aLastFunction);
461
462   //Compute the translation
463   try {
464 #if OCC_VERSION_LARGE > 0x06010000
465     OCC_CATCH_SIGNALS;
466 #endif
467     if (!GetSolver()->ComputeFunction(aFunction)) {
468       SetErrorCode("Translation driver failed");
469       return NULL;
470     }
471   }
472   catch (Standard_Failure) {
473     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
474     SetErrorCode(aFail->GetMessageString());
475     return NULL;
476   }
477
478   //Make a Python command
479   if (theCopy) {
480     GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVectorDistance("
481                                  << theObject << ", " << theVector << ", " << theDistance << ")";
482     SetErrorCode(OK);
483     return aCopy;
484   }
485
486   GEOM::TPythonDump(aFunction) << "geompy.TranslateVectorDistance("
487                                << theObject << ", " << theVector << ", " << theDistance << ", " << theCopy << ")";
488   SetErrorCode(OK);
489   return theObject;
490 }
491
492 //=============================================================================
493 /*!
494  *  Translate1D
495  */
496 //=============================================================================
497 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate1D
498        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector,
499         double theStep, Standard_Integer theNbTimes)
500 {
501   SetErrorCode(KO);
502
503   if (theObject.IsNull() || theVector.IsNull()) return NULL;
504
505   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
506   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
507
508   //Add a new Copy object
509   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
510
511   //Add a translate function
512   Handle(GEOM_Function) aFunction =
513     aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_1D);
514
515   //Check if the function is set correctly
516   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
517
518   GEOMImpl_ITranslate aTI(aFunction);
519   aTI.SetVector(theVector->GetLastFunction());
520   aTI.SetOriginal(aLastFunction);
521   aTI.SetStep1(theStep);
522   aTI.SetNbIter1(theNbTimes);
523
524   //Compute the translation
525   try {
526 #if OCC_VERSION_LARGE > 0x06010000
527     OCC_CATCH_SIGNALS;
528 #endif
529     if (!GetSolver()->ComputeFunction(aFunction)) {
530       SetErrorCode("Translation driver failed");
531       return NULL;
532     }
533   }
534   catch (Standard_Failure) {
535     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
536     SetErrorCode(aFail->GetMessageString());
537     return NULL;
538   }
539
540   //Make a Python command
541   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation1D("
542     << theObject << ", " << theVector << ", " << theStep << ", " << theNbTimes << ")";
543
544   SetErrorCode(OK);
545   return aCopy;
546 }
547
548 //=============================================================================
549 /*!
550  *  Translate2D
551  */
552 //=============================================================================
553 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate2D (Handle(GEOM_Object) theObject,
554                                                                 Handle(GEOM_Object) theVector,
555                                                                 double theStep1,
556                                                                 Standard_Integer theNbTimes1,
557                                                                 Handle(GEOM_Object) theVector2,
558                                                                 double theStep2,
559                                                                 Standard_Integer theNbTimes2)
560 {
561   SetErrorCode(KO);
562
563   if (theObject.IsNull() || theVector.IsNull() || theVector2.IsNull()) return NULL;
564
565   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
566   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
567
568   //Add a new Copy object
569   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
570
571   //Add a translate function
572   Handle(GEOM_Function) aFunction =
573     aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_2D);
574
575   //Check if the function is set correctly
576   if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
577
578   GEOMImpl_ITranslate aTI (aFunction);
579   aTI.SetVector(theVector->GetLastFunction());
580   aTI.SetVector2(theVector2->GetLastFunction());
581   aTI.SetOriginal(aLastFunction);
582   aTI.SetStep1(theStep1);
583   aTI.SetNbIter1(theNbTimes1);
584   aTI.SetStep2(theStep2);
585   aTI.SetNbIter2(theNbTimes2);
586
587   //Compute the translation
588   try {
589 #if OCC_VERSION_LARGE > 0x06010000
590     OCC_CATCH_SIGNALS;
591 #endif
592     if (!GetSolver()->ComputeFunction(aFunction)) {
593       SetErrorCode("Translation driver failed");
594       return NULL;
595     }
596   }
597   catch (Standard_Failure) {
598     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
599     SetErrorCode(aFail->GetMessageString());
600     return NULL;
601   }
602
603   //Make a Python command
604   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation2D("
605     << theObject << ", " << theVector  << ", " << theStep1 << ", " << theNbTimes1
606       << ", " << theVector2 << ", " << theStep2 << ", " << theNbTimes2 << ")";
607
608   SetErrorCode(OK);
609   return aCopy;
610 }
611
612 //=============================================================================
613 /*!
614  *  TranslateShape1D
615  */
616 //=============================================================================
617 /*
618 TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape1D (const TopoDS_Shape&  theShape,
619                                                               GEOMImpl_ITranslate* theTI)
620 {
621   TopoDS_Shape aRes;
622
623   // Vector
624   Handle(GEOM_Function) aVector = theTI->GetVector();
625   if (aVector.IsNull()) {
626     StdFail_NotDone::Raise("Invalid object is given for vector argument");
627   }
628   TopoDS_Shape aV = aVector->GetValue();
629   if (aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) {
630     StdFail_NotDone::Raise("Invalid object is given for vector argument");
631   }
632   TopoDS_Edge anEdge = TopoDS::Edge(aV);
633
634   gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
635   gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
636   if (aP1.Distance(aP2) < gp::Resolution()) {
637     StdFail_NotDone::Raise("Invalid object is given for vector argument");
638   }
639
640   // Step and Nb.times
641   Standard_Real step = theTI->GetStep1();
642   Standard_Integer nbtimes = theTI->GetNbIter1();
643
644   // Make multi-translation
645   gp_Trsf aTrsf;
646   gp_Vec aVec;
647   TopoDS_Compound aCompound;
648   BRep_Builder B;
649   B.MakeCompound(aCompound);
650
651   gp_Vec Vec (aP1, aP2);
652   Vec.Normalize();
653
654   TopLoc_Location aLocOrig = theShape.Location();
655   gp_Trsf aTrsfOrig = aLocOrig.Transformation();
656
657   for (int i = 0; i < nbtimes; i++) {
658     aVec = Vec * (i * step);
659     aTrsf.SetTranslation(aVec);
660     //NPAL18620: performance problem: multiple locations are accumulated
661     //           in shape and need a great time to process
662     //BRepBuilderAPI_Transform aTransformation(theShape, aTrsf, Standard_False);
663     //B.Add(aCompound, aTransformation.Shape());
664     TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
665     B.Add(aCompound, theShape.Located(aLocRes));
666   }
667   aRes = aCompound;
668
669   return aRes;
670 }
671 */
672
673 //=============================================================================
674 /*!
675  *  TranslateShape2D
676  */
677 //=============================================================================
678 /*
679 TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape2D (const TopoDS_Shape&  theShape,
680                                                               GEOMImpl_ITranslate* theTI)
681 {
682   TopoDS_Shape aRes;
683
684   // Vectors
685   Handle(GEOM_Function) aVector1 = theTI->GetVector();
686   Handle(GEOM_Function) aVector2 = theTI->GetVector2();
687
688   if (aVector1.IsNull() || aVector2.IsNull()) {
689     StdFail_NotDone::Raise("Invalid object is given for vector argument");
690   }
691
692   TopoDS_Shape aV1 = aVector1->GetValue();
693   TopoDS_Shape aV2 = aVector2->GetValue();
694
695   if (aV1.IsNull() || aV1.ShapeType() != TopAbs_EDGE ||
696       aV2.IsNull() || aV2.ShapeType() != TopAbs_EDGE) {
697     StdFail_NotDone::Raise("Invalid object is given for vector argument");
698   }
699
700   TopoDS_Edge anEdge1 = TopoDS::Edge(aV1);
701   TopoDS_Edge anEdge2 = TopoDS::Edge(aV2);
702
703   gp_Pnt aP11 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge1));
704   gp_Pnt aP12 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge1));
705   gp_Pnt aP21 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge2));
706   gp_Pnt aP22 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge2));
707
708   if (aP11.Distance(aP12) < gp::Resolution() ||
709       aP21.Distance(aP22) < gp::Resolution()) {
710     StdFail_NotDone::Raise("Invalid object is given for vector argument");
711   }
712
713   gp_Vec Vec1 (aP11, aP12);
714   gp_Vec Vec2 (aP21, aP22);
715
716   Vec1.Normalize();
717   Vec2.Normalize();
718
719   // Step and Nb.times
720   Standard_Real step1 = theTI->GetStep1(), step2 = theTI->GetStep2();
721   Standard_Integer nbtimes1 = theTI->GetNbIter1(), nbtimes2 = theTI->GetNbIter2();
722
723   // Make multi-translation
724   gp_Trsf aTrsf;
725   gp_Vec aVec;
726   Standard_Real DX, DY, DZ;
727   TopoDS_Compound aCompound;
728   BRep_Builder B;
729   B.MakeCompound(aCompound);
730
731   TopLoc_Location aLocOrig = theShape.Location();
732   gp_Trsf aTrsfOrig = aLocOrig.Transformation();
733
734   for (int i = 0; i < nbtimes1; i++) {
735     for (int j = 0; j < nbtimes2; j++) {
736       DX = i * step1 * Vec1.X() + j * step2 * Vec2.X();
737       DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y();
738       DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z();
739       aVec.SetCoord(DX, DY, DZ);
740       aTrsf.SetTranslation(aVec);
741       //NPAL18620: performance problem: multiple locations are accumulated
742       //           in shape and need a great time to process
743       //BRepBuilderAPI_Transform aBRepTransformation(theShape, aTrsf, Standard_False);
744       //B.Add(aCompound, aBRepTransformation.Shape());
745       TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
746       B.Add(aCompound, theShape.Located(aLocRes));
747     }
748   }
749   aRes = aCompound;
750
751   return aRes;
752 }
753 */
754
755 //=============================================================================
756 /*!
757  *  MirrorPlane
758  */
759 //=============================================================================
760 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlane
761        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
762 {
763   SetErrorCode(KO);
764
765   if (theObject.IsNull() || thePlane.IsNull()) return NULL;
766
767   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
768   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be mirrored
769
770   // Get last functions of the arguments
771   Handle(GEOM_Function) aPF = thePlane->GetLastFunction();
772
773   //Add a mirror function
774   Handle(GEOM_Function) aFunction =
775     theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE);
776   if (aFunction.IsNull()) return NULL;
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.SetPlane(aPF);
783   aTI.SetOriginal(aLastFunction);
784
785   //Compute the mirror
786   try {
787 #if OCC_VERSION_LARGE > 0x06010000
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) << "geompy.TrsfOp.MirrorPlane("
803                                << theObject << ", " << thePlane << ")";
804
805   SetErrorCode(OK);
806   return theObject;
807 }
808
809 //=============================================================================
810 /*!
811  *  MirrorPlaneCopy
812  */
813 //=============================================================================
814 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlaneCopy
815        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
816 {
817   SetErrorCode(KO);
818
819   if (theObject.IsNull() || thePlane.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   //Add a new Copy object
825   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
826
827   //Add a mirror function
828   Handle(GEOM_Function) aFunction =
829     aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE_COPY);
830
831   //Check if the function is set correctly
832   if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
833
834   GEOMImpl_IMirror aTI (aFunction);
835   aTI.SetPlane(thePlane->GetLastFunction());
836   aTI.SetOriginal(aLastFunction);
837
838   //Compute the mirror
839   try {
840 #if OCC_VERSION_LARGE > 0x06010000
841     OCC_CATCH_SIGNALS;
842 #endif
843     if (!GetSolver()->ComputeFunction(aFunction)) {
844       SetErrorCode("Mirror driver failed");
845       return NULL;
846     }
847   }
848   catch (Standard_Failure) {
849     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
850     SetErrorCode(aFail->GetMessageString());
851     return NULL;
852   }
853
854   //Make a Python command
855   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPlane("
856                                << theObject << ", " << thePlane << ")";
857
858   SetErrorCode(OK);
859   return aCopy;
860 }
861
862 //=============================================================================
863 /*!
864  *  MirrorPoint
865  */
866 //=============================================================================
867 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPoint
868        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
869 {
870   SetErrorCode(KO);
871
872   if (theObject.IsNull() || thePoint.IsNull()) return NULL;
873
874   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
875   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be mirrored
876
877   // Get last functions of the arguments
878   Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
879
880   //Add a mirror function
881   Handle(GEOM_Function) aFunction =
882     theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT);
883   if (aFunction.IsNull()) return NULL;
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.SetPoint(aPF);
890   aTI.SetOriginal(aLastFunction);
891
892   //Compute the mirror
893   try {
894 #if OCC_VERSION_LARGE > 0x06010000
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) << "geompy.TrsfOp.MirrorPoint("
910                                << theObject << ", " << thePoint << ")";
911
912   SetErrorCode(OK);
913   return NULL;
914 }
915
916 //=============================================================================
917 /*!
918  *  MirrorPointCopy
919  */
920 //=============================================================================
921 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPointCopy
922        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
923 {
924   SetErrorCode(KO);
925
926   if (theObject.IsNull() || thePoint.IsNull()) return NULL;
927
928   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
929   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
930
931   //Add a new Copy object
932   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
933
934   //Add a mirror function
935   Handle(GEOM_Function) aFunction =
936     aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT_COPY);
937
938   //Check if the function is set correctly
939   if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
940
941   GEOMImpl_IMirror aTI (aFunction);
942   aTI.SetPoint(thePoint->GetLastFunction());
943   aTI.SetOriginal(aLastFunction);
944
945   //Compute the mirror
946   try {
947 #if OCC_VERSION_LARGE > 0x06010000
948     OCC_CATCH_SIGNALS;
949 #endif
950     if (!GetSolver()->ComputeFunction(aFunction)) {
951       SetErrorCode("Mirror driver failed");
952       return NULL;
953     }
954   }
955   catch (Standard_Failure) {
956     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
957     SetErrorCode(aFail->GetMessageString());
958     return NULL;
959   }
960
961   //Make a Python command
962   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPoint("
963                                << theObject << ", " << thePoint << ")";
964
965   SetErrorCode(OK);
966   return aCopy;
967 }
968
969 //=============================================================================
970 /*!
971  *  MirrorAxis
972  */
973 //=============================================================================
974 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxis
975        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
976 {
977   SetErrorCode(KO);
978
979   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
980
981   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
982   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be mirrored
983
984   // Get last functions of the arguments
985   Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
986
987   //Add a mirror function
988   Handle(GEOM_Function) aFunction =
989     theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS);
990   if (aFunction.IsNull()) return NULL;
991
992   //Check if the function is set correctly
993   if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
994
995   GEOMImpl_IMirror aTI (aFunction);
996   aTI.SetAxis(anAF);
997   aTI.SetOriginal(aLastFunction);
998
999   //Compute the mirror
1000   try {
1001 #if OCC_VERSION_LARGE > 0x06010000
1002     OCC_CATCH_SIGNALS;
1003 #endif
1004     if (!GetSolver()->ComputeFunction(aFunction)) {
1005       SetErrorCode("Mirror driver failed");
1006       return NULL;
1007     }
1008   }
1009   catch (Standard_Failure) {
1010     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1011     SetErrorCode(aFail->GetMessageString());
1012     return NULL;
1013   }
1014
1015   //Make a Python command
1016   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorAxis("
1017                                << theObject << ", " << theAxis << ")";
1018
1019   SetErrorCode(OK);
1020   return NULL;
1021 }
1022
1023 //=============================================================================
1024 /*!
1025  *  MirrorAxisCopy
1026  */
1027 //=============================================================================
1028 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxisCopy
1029        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
1030 {
1031   SetErrorCode(KO);
1032
1033   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1034
1035   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
1036   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
1037
1038   //Add a new Copy object
1039   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1040
1041   //Add a mirror function
1042   Handle(GEOM_Function) aFunction =
1043     aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS_COPY);
1044
1045   //Check if the function is set correctly
1046   if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
1047
1048   GEOMImpl_IMirror aTI (aFunction);
1049   aTI.SetAxis(theAxis->GetLastFunction());
1050   aTI.SetOriginal(aLastFunction);
1051
1052   //Compute the mirror
1053   try {
1054 #if OCC_VERSION_LARGE > 0x06010000
1055     OCC_CATCH_SIGNALS;
1056 #endif
1057     if (!GetSolver()->ComputeFunction(aFunction)) {
1058       SetErrorCode("Mirror driver failed");
1059       return NULL;
1060     }
1061   }
1062   catch (Standard_Failure) {
1063     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1064     SetErrorCode(aFail->GetMessageString());
1065     return NULL;
1066   }
1067
1068   //Make a Python command
1069   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByAxis("
1070                                << theObject << ", " << theAxis << ")";
1071
1072   SetErrorCode(OK);
1073   return aCopy;
1074 }
1075
1076
1077 //=============================================================================
1078 /*!
1079  *  OffsetShape
1080  */
1081 //=============================================================================
1082 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShape
1083                               (Handle(GEOM_Object) theObject, double theOffset)
1084 {
1085   SetErrorCode(KO);
1086
1087   if (theObject.IsNull()) return NULL;
1088
1089   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1090   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
1091
1092   //Add a new Offset function
1093   Handle(GEOM_Function) aFunction =
1094     theObject->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE);
1095   if (aFunction.IsNull()) return NULL;
1096
1097   //Check if the function is set correctly
1098   if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
1099
1100   GEOMImpl_IOffset aTI (aFunction);
1101   aTI.SetShape(anOriginal);
1102   aTI.SetValue(theOffset);
1103
1104   //Compute the offset
1105   try {
1106 #if OCC_VERSION_LARGE > 0x06010000
1107     OCC_CATCH_SIGNALS;
1108 #endif
1109     if (!GetSolver()->ComputeFunction(aFunction)) {
1110       SetErrorCode("Offset driver failed");
1111       return NULL;
1112     }
1113   }
1114   catch (Standard_Failure) {
1115     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1116     SetErrorCode(aFail->GetMessageString());
1117     return NULL;
1118   }
1119
1120   //Make a Python command
1121   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.OffsetShape("
1122                                << theObject << ", " << theOffset << ")";
1123
1124   SetErrorCode(OK);
1125   return theObject;
1126 }
1127
1128 //=============================================================================
1129 /*!
1130  *  OffsetShapeCopy
1131  */
1132 //=============================================================================
1133 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShapeCopy
1134                               (Handle(GEOM_Object) theObject, double theOffset)
1135 {
1136   SetErrorCode(KO);
1137
1138   if (theObject.IsNull()) return NULL;
1139
1140   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1141   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
1142
1143   //Add a new Copy object
1144   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1145
1146   //Add a new Offset function
1147   Handle(GEOM_Function) aFunction =
1148     aCopy->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE_COPY);
1149   if (aFunction.IsNull()) return NULL;
1150
1151   //Check if the function is set correctly
1152   if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
1153
1154   GEOMImpl_IOffset aTI (aFunction);
1155   aTI.SetShape(anOriginal);
1156   aTI.SetValue(theOffset);
1157
1158   //Compute the offset
1159   try {
1160 #if OCC_VERSION_LARGE > 0x06010000
1161     OCC_CATCH_SIGNALS;
1162 #endif
1163     if (!GetSolver()->ComputeFunction(aFunction)) {
1164       SetErrorCode("Offset driver failed");
1165       return NULL;
1166     }
1167   }
1168   catch (Standard_Failure) {
1169     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1170     SetErrorCode(aFail->GetMessageString());
1171     return NULL;
1172   }
1173
1174   //Make a Python command
1175   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeOffset("
1176                                << theObject << ", " << theOffset << ")";
1177
1178   SetErrorCode(OK);
1179   return aCopy;
1180 }
1181
1182
1183 //=============================================================================
1184 /*!
1185  *  ProjectShapeCopy
1186  */
1187 //=============================================================================
1188 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ProjectShapeCopy
1189        (Handle(GEOM_Object) theSource, Handle(GEOM_Object) theTarget)
1190 {
1191   SetErrorCode(KO);
1192
1193   if (theSource.IsNull() || theTarget.IsNull()) return NULL;
1194
1195   Handle(GEOM_Function) aLastFunction = theSource->GetLastFunction();
1196   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be projected
1197
1198   //Add a new Projection object
1199   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), GEOM_PROJECTION);
1200
1201   //Add a Projection function
1202   Handle(GEOM_Function) aFunction =
1203     aCopy->AddFunction(GEOMImpl_ProjectionDriver::GetID(), PROJECTION_COPY);
1204
1205   //Check if the function is set correctly
1206   if (aFunction->GetDriverGUID() != GEOMImpl_ProjectionDriver::GetID()) return NULL;
1207
1208   GEOMImpl_IMirror aTI (aFunction);
1209   aTI.SetPlane(theTarget->GetLastFunction());
1210   aTI.SetOriginal(aLastFunction);
1211
1212   //Compute the Projection
1213   try {
1214 #if OCC_VERSION_LARGE > 0x06010000
1215     OCC_CATCH_SIGNALS;
1216 #endif
1217     if (!GetSolver()->ComputeFunction(aFunction)) {
1218       SetErrorCode("Projection driver failed");
1219       return NULL;
1220     }
1221   }
1222   catch (Standard_Failure) {
1223     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1224     SetErrorCode(aFail->GetMessageString());
1225     return NULL;
1226   }
1227
1228   //Make a Python command
1229   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeProjection("
1230                                << theSource << ", " << theTarget << ")";
1231
1232   SetErrorCode(OK);
1233   return aCopy;
1234 }
1235
1236
1237 //=============================================================================
1238 /*!
1239  *  ScaleShape
1240  */
1241 //=============================================================================
1242 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape
1243        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1244 {
1245   SetErrorCode(KO);
1246
1247   if (theObject.IsNull()) return NULL;
1248
1249   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1250   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1251
1252   //Add a scale function
1253   Handle(GEOM_Function) aFunction =
1254     theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE);
1255   if (aFunction.IsNull()) return NULL;
1256
1257   //Check if the function is set correctly
1258   if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1259
1260   // Set arguments
1261   GEOMImpl_IScale aTI (aFunction);
1262   aTI.SetShape(anOriginal);
1263   aTI.SetFactor(theFactor);
1264
1265   // Set point argument
1266   if (!thePoint.IsNull()) {
1267     Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1268     aTI.SetPoint(aPF);
1269   }
1270
1271   //Compute the scale
1272   try {
1273 #if OCC_VERSION_LARGE > 0x06010000
1274     OCC_CATCH_SIGNALS;
1275 #endif
1276     if (!GetSolver()->ComputeFunction(aFunction)) {
1277       SetErrorCode("Scale driver failed");
1278       return NULL;
1279     }
1280   }
1281   catch (Standard_Failure) {
1282     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1283     SetErrorCode(aFail->GetMessageString());
1284     return NULL;
1285   }
1286
1287   //Make a Python command
1288   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShape("
1289     << theObject << ", " << thePoint << ", " << theFactor << ")";
1290
1291   SetErrorCode(OK);
1292   return theObject;
1293 }
1294
1295 //=============================================================================
1296 /*!
1297  *  ScaleShapeCopy
1298  */
1299 //=============================================================================
1300 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy
1301        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1302 {
1303   SetErrorCode(KO);
1304
1305   if (theObject.IsNull()) return NULL;
1306
1307   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1308   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1309
1310   //Add a new Copy object
1311   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1312
1313   //Add a scale function
1314   Handle(GEOM_Function) aFunction =
1315     aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_COPY);
1316   if (aFunction.IsNull()) return NULL;
1317
1318   //Check if the function is set correctly
1319   if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1320
1321   // Set arguments
1322   GEOMImpl_IScale aTI (aFunction);
1323   aTI.SetShape(anOriginal);
1324   aTI.SetFactor(theFactor);
1325
1326   // Set point argument
1327   if (!thePoint.IsNull()) {
1328     Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1329     aTI.SetPoint(aPF);
1330   }
1331
1332   //Compute the scale
1333   try {
1334 #if OCC_VERSION_LARGE > 0x06010000
1335     OCC_CATCH_SIGNALS;
1336 #endif
1337     if (!GetSolver()->ComputeFunction(aFunction)) {
1338       SetErrorCode("Scale driver failed");
1339       return NULL;
1340     }
1341   }
1342   catch (Standard_Failure) {
1343     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1344     SetErrorCode(aFail->GetMessageString());
1345     return NULL;
1346   }
1347
1348   //Make a Python command
1349   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleTransform("
1350     << theObject << ", " << thePoint << ", " << theFactor << ")";
1351
1352   SetErrorCode(OK);
1353   return aCopy;
1354 }
1355
1356 //=============================================================================
1357 /*!
1358  *  ScaleShapeAlongAxes
1359  */
1360 //=============================================================================
1361 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeAlongAxes (Handle(GEOM_Object) theObject,
1362                                                                         Handle(GEOM_Object) thePoint,
1363                                                                         double theFactorX,
1364                                                                         double theFactorY,
1365                                                                         double theFactorZ,
1366                                                                         bool   doCopy)
1367 {
1368   SetErrorCode(KO);
1369
1370   if (theObject.IsNull()) return NULL;
1371
1372   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1373   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1374
1375   //Add a scale function
1376   Handle(GEOM_Object) aCopy;   //Add a new Copy object
1377   Handle(GEOM_Function) aFunction;
1378   if (doCopy) {
1379     aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1380     aFunction = aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES_COPY);
1381   }
1382   else {
1383     aFunction = theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES);
1384   }
1385   if (aFunction.IsNull()) return NULL;
1386
1387   //Check if the function is set correctly
1388   if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1389
1390   // Set arguments
1391   GEOMImpl_IScale aTI (aFunction);
1392   aTI.SetShape(anOriginal);
1393   aTI.SetFactorX(theFactorX);
1394   aTI.SetFactorY(theFactorY);
1395   aTI.SetFactorZ(theFactorZ);
1396
1397   // Set point (optional argument)
1398   if (!thePoint.IsNull()) {
1399     Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1400     aTI.SetPoint(aPF);
1401   }
1402
1403   //Compute the scale
1404   try {
1405 #if OCC_VERSION_LARGE > 0x06010000
1406     OCC_CATCH_SIGNALS;
1407 #endif
1408     if (!GetSolver()->ComputeFunction(aFunction)) {
1409       SetErrorCode("Scale driver failed");
1410       return NULL;
1411     }
1412   }
1413   catch (Standard_Failure) {
1414     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1415     SetErrorCode(aFail->GetMessageString());
1416     return NULL;
1417   }
1418
1419   SetErrorCode(OK);
1420
1421   //Make a Python command
1422   if (doCopy) {
1423     GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleAlongAxes("
1424                                  << theObject << ", " << thePoint << ", "
1425                                  << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1426     return aCopy;
1427   }
1428
1429   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShapeAlongAxes("
1430                                << theObject << ", " << thePoint << ", "
1431                                << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1432   return theObject;
1433 }
1434
1435 //=============================================================================
1436 /*!
1437  *  PositionShape
1438  */
1439 //=============================================================================
1440 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShape
1441         (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1442 {
1443   SetErrorCode(KO);
1444
1445   if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1446
1447   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1448   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1449
1450   //Add a Position function
1451   Standard_Integer aType = POSITION_SHAPE;
1452   if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL;
1453
1454   Handle(GEOM_Function) aFunction =
1455     theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1456   if (aFunction.IsNull()) return NULL;
1457
1458   //Check if the function is set correctly
1459   if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1460
1461   //Set operation arguments
1462   GEOMImpl_IPosition aTI (aFunction);
1463   aTI.SetShape(anOriginal);
1464   aTI.SetEndLCS(theEndLCS->GetLastFunction());
1465   if (!theStartLCS.IsNull())
1466     aTI.SetStartLCS(theObject == theStartLCS ? anOriginal : theStartLCS->GetLastFunction());
1467
1468   //Compute the Position
1469   try {
1470 #if OCC_VERSION_LARGE > 0x06010000
1471     OCC_CATCH_SIGNALS;
1472 #endif
1473     if (!GetSolver()->ComputeFunction(aFunction)) {
1474       SetErrorCode("Position driver failed");
1475       return NULL;
1476     }
1477   }
1478   catch (Standard_Failure) {
1479     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1480     SetErrorCode(aFail->GetMessageString());
1481     return NULL;
1482   }
1483
1484   //Make a Python command
1485   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionShape("
1486     << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1487
1488   SetErrorCode(OK);
1489   return theObject;
1490 }
1491
1492 //=============================================================================
1493 /*!
1494  *  PositionShapeCopy
1495  */
1496 //=============================================================================
1497 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShapeCopy
1498        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1499 {
1500   SetErrorCode(KO);
1501
1502   if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1503
1504   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1505   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1506
1507   //Add a new Copy object
1508   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1509
1510   //Add a position function
1511   Standard_Integer aType = POSITION_SHAPE_COPY;
1512   if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL_COPY;
1513
1514   Handle(GEOM_Function) aFunction =
1515     aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1516   if (aFunction.IsNull()) return NULL;
1517
1518   //Check if the function is set correctly
1519   if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1520
1521   GEOMImpl_IPosition aTI (aFunction);
1522   aTI.SetShape(anOriginal);
1523   aTI.SetEndLCS(theEndLCS->GetLastFunction());
1524   if (!theStartLCS.IsNull())
1525     aTI.SetStartLCS(theStartLCS->GetLastFunction());
1526
1527   //Compute the position
1528   try {
1529 #if OCC_VERSION_LARGE > 0x06010000
1530     OCC_CATCH_SIGNALS;
1531 #endif
1532     if (!GetSolver()->ComputeFunction(aFunction)) {
1533       SetErrorCode("Position driver failed");
1534       return NULL;
1535     }
1536   }
1537   catch (Standard_Failure) {
1538     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1539     SetErrorCode(aFail->GetMessageString());
1540     return NULL;
1541   }
1542
1543   //Make a Python command
1544   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakePosition("
1545     << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1546
1547   SetErrorCode(OK);
1548   return aCopy;
1549 }
1550
1551 //=============================================================================
1552 /*!
1553  *  PositionAlongPath
1554  */
1555 //=============================================================================
1556 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionAlongPath
1557        (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePath,
1558         double theDistance, bool theCopy, bool theReverse)
1559 {
1560   SetErrorCode(KO);
1561
1562   if (theObject.IsNull() || thePath.IsNull()) return NULL;
1563
1564   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1565   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1566
1567   //Add a position function
1568   Handle(GEOM_Function) aFunction;
1569   Handle(GEOM_Object) aCopy;
1570
1571   if (theCopy) {
1572     aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1573     aFunction = aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1574   }
1575   else
1576     aFunction = theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1577
1578   if (aFunction.IsNull()) return NULL;
1579
1580   //Check if the function is set correctly
1581   if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1582
1583   GEOMImpl_IPosition aTI (aFunction);
1584   aTI.SetShape(anOriginal);
1585   aTI.SetPath(thePath->GetLastFunction());
1586   aTI.SetDistance(theDistance);
1587   aTI.SetReverse(theReverse);
1588
1589   //Compute the position
1590   try {
1591 #if OCC_VERSION_LARGE > 0x06010000
1592     OCC_CATCH_SIGNALS;
1593 #endif
1594     if (!GetSolver()->ComputeFunction(aFunction)) {
1595       SetErrorCode("Position driver failed");
1596       return NULL;
1597     }
1598   }
1599   catch (Standard_Failure) {
1600     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1601     SetErrorCode(aFail->GetMessageString());
1602     return NULL;
1603   }
1604
1605   //Make a Python command
1606   if (theCopy) {
1607     GEOM::TPythonDump(aFunction) << aCopy << " = geompy.PositionAlongPath("
1608                                  << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1609     SetErrorCode(OK);
1610     return aCopy;
1611   }
1612
1613   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionAlongPath("
1614     << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1615
1616   SetErrorCode(OK);
1617   return theObject;
1618 }
1619
1620 //=============================================================================
1621 /*!
1622  *  Rotate
1623  */
1624 //=============================================================================
1625 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) theObject,
1626                                                            Handle(GEOM_Object) theAxis,
1627                                                            double theAngle)
1628 {
1629   SetErrorCode(KO);
1630
1631   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1632
1633   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1634   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1635
1636   // Get last functions of the arguments
1637   Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
1638
1639   //Add a rotate function
1640   aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE);
1641
1642   if (aFunction.IsNull()) return NULL;
1643
1644   //Check if the function is set correctly
1645   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1646
1647   GEOMImpl_IRotate aRI(aFunction);
1648   aRI.SetAxis(anAF);
1649   aRI.SetOriginal(aLastFunction);
1650   aRI.SetAngle(theAngle);
1651
1652   //Compute the translation
1653   try {
1654 #if OCC_VERSION_LARGE > 0x06010000
1655     OCC_CATCH_SIGNALS;
1656 #endif
1657     if (!GetSolver()->ComputeFunction(aFunction)) {
1658       SetErrorCode("Rotate driver failed");
1659       return NULL;
1660     }
1661   }
1662   catch (Standard_Failure) {
1663     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1664     SetErrorCode(aFail->GetMessageString());
1665     return NULL;
1666   }
1667
1668   //Make a Python command
1669   GEOM::TPythonDump(aFunction) << "geompy.Rotate(" << theObject
1670     << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
1671
1672   SetErrorCode(OK);
1673   return theObject;
1674 }
1675
1676 //=============================================================================
1677 /*!
1678  *  Rotate
1679  */
1680 //=============================================================================
1681 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, double theAngle)
1682 {
1683   SetErrorCode(KO);
1684
1685   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1686
1687   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1688   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1689
1690   //Add a new Copy object
1691   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1692
1693   //Add a rotate function
1694   aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_COPY);
1695   if (aFunction.IsNull()) return NULL;
1696
1697     //Check if the function is set correctly
1698   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1699
1700   GEOMImpl_IRotate aRI(aFunction);
1701   aRI.SetAxis(theAxis->GetLastFunction());
1702   aRI.SetOriginal(aLastFunction);
1703   aRI.SetAngle(theAngle);
1704
1705   //Compute the translation
1706   try {
1707 #if OCC_VERSION_LARGE > 0x06010000
1708     OCC_CATCH_SIGNALS;
1709 #endif
1710     if (!GetSolver()->ComputeFunction(aFunction)) {
1711       SetErrorCode("Rotate driver failed");
1712       return NULL;
1713     }
1714   }
1715   catch (Standard_Failure) {
1716     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1717     SetErrorCode(aFail->GetMessageString());
1718     return NULL;
1719   }
1720
1721   //Make a Python command
1722   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotation(" << theObject
1723     << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
1724
1725   SetErrorCode(OK);
1726   return aCopy;
1727 }
1728
1729 //=============================================================================
1730 /*!
1731  *  Rotate1D
1732  */
1733 //=============================================================================
1734 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) theObject,
1735                                                              Handle(GEOM_Object) theAxis,
1736                                                              Standard_Integer theNbTimes)
1737 {
1738   SetErrorCode(KO);
1739
1740   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1741
1742   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1743   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1744
1745   //Add a new Copy object
1746   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1747
1748   //Add a rotate function
1749   aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_1D);
1750   if (aFunction.IsNull()) return NULL;
1751
1752   //Check if the function is set correctly
1753   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1754
1755   GEOMImpl_IRotate aRI(aFunction);
1756   aRI.SetOriginal(aLastFunction);
1757   aRI.SetAxis(theAxis->GetLastFunction());
1758   aRI.SetNbIter1(theNbTimes);
1759
1760   //Compute the translation
1761   try {
1762 #if OCC_VERSION_LARGE > 0x06010000
1763     OCC_CATCH_SIGNALS;
1764 #endif
1765     if (!GetSolver()->ComputeFunction(aFunction)) {
1766       SetErrorCode("Rotate driver failed");
1767       return NULL;
1768     }
1769   }
1770   catch (Standard_Failure) {
1771     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1772     SetErrorCode(aFail->GetMessageString());
1773     return NULL;
1774   }
1775
1776   //Make a Python command
1777   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate1D("
1778     << theObject << ", " << theAxis << ", " << theNbTimes << ")";
1779
1780   SetErrorCode(OK);
1781   return aCopy;
1782 }
1783
1784 //=============================================================================
1785 /*!
1786  *  Rotate2D
1787  */
1788 //=============================================================================
1789 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) theObject,
1790                                                              Handle(GEOM_Object) theAxis,
1791                                                              double theAngle,
1792                                                              Standard_Integer theNbTimes1,
1793                                                              double theStep,
1794                                                              Standard_Integer theNbTimes2)
1795 {
1796   SetErrorCode(KO);
1797
1798   if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1799
1800   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1801   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1802
1803   //Add a new Copy object
1804   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1805
1806   //Add a rotate function
1807   aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_2D);
1808   if (aFunction.IsNull()) return NULL;
1809
1810     //Check if the function is set correctly
1811   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1812
1813   GEOMImpl_IRotate aRI(aFunction);
1814   aRI.SetAxis(theAxis->GetLastFunction());
1815   aRI.SetOriginal(aLastFunction);
1816   aRI.SetNbIter1(theNbTimes1);
1817   aRI.SetNbIter2(theNbTimes2);
1818   aRI.SetAngle(theAngle);
1819   aRI.SetStep(theStep);
1820
1821   //Compute the translation
1822   try {
1823 #if OCC_VERSION_LARGE > 0x06010000
1824     OCC_CATCH_SIGNALS;
1825 #endif
1826     if (!GetSolver()->ComputeFunction(aFunction)) {
1827       SetErrorCode("Rotate driver failed");
1828       return NULL;
1829     }
1830   }
1831   catch (Standard_Failure) {
1832     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1833     SetErrorCode(aFail->GetMessageString());
1834     return NULL;
1835   }
1836
1837   //Make a Python command
1838   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate2D("
1839     << theObject << ", " << theAxis << ", " << theAngle << ", "
1840       << theNbTimes1 << ", " << theStep << ", " << theNbTimes2 << ")";
1841
1842   SetErrorCode(OK);
1843   return aCopy;
1844 }
1845
1846 //=============================================================================
1847 /*!
1848  *  RotateThreePoints
1849  */
1850 //=============================================================================
1851 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEOM_Object) theObject,
1852                                                                       Handle(GEOM_Object) theCentPoint,
1853                                                                       Handle(GEOM_Object) thePoint1,
1854                                                                       Handle(GEOM_Object) thePoint2)
1855 {
1856   SetErrorCode(KO);
1857
1858   if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1859
1860   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1861   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1862
1863   // Get last functions of the arguments
1864   Handle(GEOM_Function) aCPF = theCentPoint->GetLastFunction();
1865   Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
1866   Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
1867
1868
1869   //Add a rotate function
1870   aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS);
1871
1872   if (aFunction.IsNull()) return NULL;
1873
1874   //Check if the function is set correctly
1875   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1876
1877   GEOMImpl_IRotate aRI(aFunction);
1878   aRI.SetCentPoint(aCPF);
1879   aRI.SetPoint1(aP1F);
1880   aRI.SetPoint2(aP2F);
1881   aRI.SetOriginal(aLastFunction);
1882
1883   //Compute the translation
1884   try {
1885 #if OCC_VERSION_LARGE > 0x06010000
1886     OCC_CATCH_SIGNALS;
1887 #endif
1888     if (!GetSolver()->ComputeFunction(aFunction)) {
1889       SetErrorCode("Rotate driver failed");
1890       return NULL;
1891     }
1892   }
1893   catch (Standard_Failure) {
1894     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1895     SetErrorCode(aFail->GetMessageString());
1896     return NULL;
1897   }
1898
1899   //Make a Python command
1900   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.RotateThreePoints(" << theObject
1901                                << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1902
1903   SetErrorCode(OK);
1904   return theObject;
1905 }
1906
1907 //=============================================================================
1908 /*!
1909  *  RotateThreePointsCopy
1910  */
1911 //=============================================================================
1912 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle(GEOM_Object) theObject,
1913                                                          Handle(GEOM_Object) theCentPoint,
1914                                                          Handle(GEOM_Object) thePoint1,
1915                                                          Handle(GEOM_Object) thePoint2)
1916 {
1917   SetErrorCode(KO);
1918
1919   if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1920
1921   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1922   if (aLastFunction.IsNull()) return NULL;  //There is no function which creates an object to be rotated
1923
1924   //Add a new Copy object
1925   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1926
1927   //Add a rotate function
1928   aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS_COPY);
1929   if (aFunction.IsNull()) return NULL;
1930
1931     //Check if the function is set correctly
1932   if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1933
1934   GEOMImpl_IRotate aRI(aFunction);
1935   aRI.SetCentPoint(theCentPoint->GetLastFunction());
1936   aRI.SetPoint1(thePoint1->GetLastFunction());
1937   aRI.SetPoint2(thePoint2->GetLastFunction());
1938   aRI.SetOriginal(aLastFunction);
1939
1940   //Compute the translation
1941   try {
1942 #if OCC_VERSION_LARGE > 0x06010000
1943     OCC_CATCH_SIGNALS;
1944 #endif
1945     if (!GetSolver()->ComputeFunction(aFunction)) {
1946       SetErrorCode("Rotate driver failed");
1947       return NULL;
1948     }
1949   }
1950   catch (Standard_Failure) {
1951     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1952     SetErrorCode(aFail->GetMessageString());
1953     return NULL;
1954   }
1955
1956   //Make a Python command
1957   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotationThreePoints(" << theObject
1958                                << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1959
1960   SetErrorCode(OK);
1961   return aCopy;
1962 }
1963
1964 //=============================================================================
1965 /*!
1966  *  TransformLikeOtherCopy
1967  */
1968 //=============================================================================
1969 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TransformLikeOtherCopy
1970                                                 (Handle(GEOM_Object) theObject,
1971                                                  Handle(GEOM_Object) theSample)
1972 {
1973   SetErrorCode(KO);
1974
1975   if (theObject.IsNull() || theSample.IsNull()) return NULL;
1976
1977   Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
1978   if (aLastFunction.IsNull()) return NULL; // There is no function which creates an object to be transformed
1979
1980   Handle(GEOM_Function) aSampleFunc = theSample->GetLastFunction();
1981   if (aSampleFunc.IsNull()) return NULL; // There is no function which creates a sample object
1982
1983   // Add a new Copy object
1984   Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1985
1986   // Add a transform function (depends on theSample function)
1987   Handle(GEOM_Function) aFunction =
1988     aCopy->AddFunction(aSampleFunc->GetDriverGUID(), aSampleFunc->GetType());
1989   if (aFunction.IsNull()) return NULL;
1990
1991   // Check if the function is set correctly
1992   if (aFunction->GetDriverGUID() != aSampleFunc->GetDriverGUID()) return NULL;
1993
1994   if (aSampleFunc->GetDriverGUID() == GEOMImpl_TranslateDriver::GetID()) {
1995     switch (aSampleFunc->GetType()) {
1996     case TRANSLATE_1D:
1997       {
1998         GEOMImpl_ITranslate aRI_sample (aSampleFunc);
1999         GEOMImpl_ITranslate aRI_target (aFunction);
2000
2001         aRI_target.SetVector(aRI_sample.GetVector());
2002         aRI_target.SetStep1(aRI_sample.GetStep1());
2003         aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2004
2005         aRI_target.SetOriginal(aLastFunction);
2006       }
2007       break;
2008     case TRANSLATE_2D:
2009       {
2010         GEOMImpl_ITranslate aRI_sample (aSampleFunc);
2011         GEOMImpl_ITranslate aRI_target (aFunction);
2012
2013         aRI_target.SetVector(aRI_sample.GetVector());
2014         aRI_target.SetStep1(aRI_sample.GetStep1());
2015         aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2016
2017         aRI_target.SetVector2(aRI_sample.GetVector2());
2018         aRI_target.SetStep2(aRI_sample.GetStep2());
2019         aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
2020
2021         aRI_target.SetOriginal(aLastFunction);
2022       }
2023       break;
2024     default:
2025       {
2026         SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2027         return NULL;
2028       }
2029     }
2030   }
2031   else if (aSampleFunc->GetDriverGUID() == GEOMImpl_RotateDriver::GetID()) {
2032     switch (aSampleFunc->GetType()) {
2033     case ROTATE_1D:
2034       {
2035         GEOMImpl_IRotate aRI_sample (aSampleFunc);
2036         GEOMImpl_IRotate aRI_target (aFunction);
2037
2038         aRI_target.SetAxis(aRI_sample.GetAxis());
2039         aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2040
2041         aRI_target.SetOriginal(aLastFunction);
2042       }
2043       break;
2044     case ROTATE_2D:
2045       {
2046         GEOMImpl_IRotate aRI_sample (aSampleFunc);
2047         GEOMImpl_IRotate aRI_target (aFunction);
2048
2049         aRI_target.SetAxis(aRI_sample.GetAxis());
2050
2051         aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2052         aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
2053
2054         aRI_target.SetAngle(aRI_sample.GetAngle());
2055         aRI_target.SetStep(aRI_sample.GetStep());
2056
2057         aRI_target.SetDir2(aRI_sample.GetDir2());
2058
2059         aRI_target.SetOriginal(aLastFunction);
2060       }
2061       break;
2062     case ROTATE_THREE_POINTS_COPY:
2063       {
2064         GEOMImpl_IRotate aRI_sample (aSampleFunc);
2065         GEOMImpl_IRotate aRI_target (aFunction);
2066
2067         aRI_target.SetCentPoint(aRI_sample.GetCentPoint());
2068         aRI_target.SetPoint1(aRI_sample.GetPoint1());
2069         aRI_target.SetPoint2(aRI_sample.GetPoint2());
2070
2071         aRI_target.SetOriginal(aLastFunction);
2072       }
2073       break;
2074     default:
2075       {
2076         SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2077         return NULL;
2078       }
2079     }
2080   }
2081   else {
2082     SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2083     return NULL;
2084   }
2085
2086   // Compute the transformation
2087   try {
2088 #if OCC_VERSION_LARGE > 0x06010000
2089     OCC_CATCH_SIGNALS;
2090 #endif
2091     if (!GetSolver()->ComputeFunction(aFunction)) {
2092       SetErrorCode("Driver failed");
2093       return NULL;
2094     }
2095   }
2096   catch (Standard_Failure) {
2097     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2098     SetErrorCode(aFail->GetMessageString());
2099     return NULL;
2100   }
2101
2102   //Make a Python command
2103   //GEOM::TPythonDump(aFunction) << aCopy << " = geompy.TransformLikeOtherCopy("
2104   //                             << theObject << ", " << theSample << ")";
2105
2106   SetErrorCode(OK);
2107   return aCopy;
2108 }