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