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