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