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