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