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