Salome HOME
352a6ed19d6bda52ab00bf264dcd9d2f3307c260
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IBasicOperations.cxx
1 // Copyright (C) 2007-2022  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, or (at your option) any later version.
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_IBasicOperations.hxx>
26
27 #include "utilities.h"
28 #include <Utils_ExceptHandlers.hxx>
29
30 #include <TFunction_DriverTable.hxx>
31 #include <TFunction_Driver.hxx>
32 #include <TDF_Tool.hxx>
33
34 #include <GEOM_Function.hxx>
35 #include <GEOM_PythonDump.hxx>
36
37 #include <GEOMImpl_PointDriver.hxx>
38 #include <GEOMImpl_VectorDriver.hxx>
39 #include <GEOMImpl_LineDriver.hxx>
40 #include <GEOMImpl_PlaneDriver.hxx>
41 #include <GEOMImpl_MarkerDriver.hxx>
42
43 #include <GEOMImpl_IPoint.hxx>
44 #include <GEOMImpl_IVector.hxx>
45 #include <GEOMImpl_ILine.hxx>
46 #include <GEOMImpl_IPlane.hxx>
47 #include <GEOMImpl_IMarker.hxx>
48
49 #include <GEOMImpl_Types.hxx>
50
51 #include <Standard_Failure.hxx>
52 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
53
54 //=============================================================================
55 /*!
56  *   constructor:
57  */
58 //=============================================================================
59 GEOMImpl_IBasicOperations::GEOMImpl_IBasicOperations(GEOM_Engine* theEngine)
60 : GEOM_IOperations(theEngine)
61 {
62   MESSAGE("GEOMImpl_IBasicOperations::GEOMImpl_IBasicOperations");
63 }
64
65 //=============================================================================
66 /*!
67  *  destructor
68  */
69 //=============================================================================
70 GEOMImpl_IBasicOperations::~GEOMImpl_IBasicOperations()
71 {
72   MESSAGE("GEOMImpl_IBasicOperations::~GEOMImpl_IBasicOperations");
73 }
74
75
76 //=============================================================================
77 /*!
78  *  MakePointXYZ
79  */
80 //=============================================================================
81 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointXYZ
82                                         (double theX, double theY, double theZ)
83 {
84   SetErrorCode(KO);
85
86   //Add a new Point object
87   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GEOM_POINT);
88
89   //Add a new Point function with XYZ parameters
90   Handle(GEOM_Function) aFunction =
91     aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_XYZ);
92   if (aFunction.IsNull()) return NULL;
93
94   //Check if the function is set correctly
95   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
96
97   GEOMImpl_IPoint aPI(aFunction);
98
99   aPI.SetX(theX);
100   aPI.SetY(theY);
101   aPI.SetZ(theZ);
102
103   //Compute the point value
104   try {
105     OCC_CATCH_SIGNALS;
106     if (!GetSolver()->ComputeFunction(aFunction)) {
107       SetErrorCode("Point driver failed");
108       return NULL;
109     }
110   }
111   catch (Standard_Failure& aFail) {
112     SetErrorCode(aFail.GetMessageString());
113     return NULL;
114   }
115
116   //Make a Python command
117   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertex("
118     << theX << ", " << theY << ", " << theZ << ")";
119
120   SetErrorCode(OK);
121   return aPoint;
122 }
123
124 //=============================================================================
125 /*!
126  *  MakePointWithReference
127  */
128 //=============================================================================
129 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointWithReference
130       (Handle(GEOM_Object) theReference, double theX, double theY, double theZ)
131 {
132   SetErrorCode(KO);
133
134   if (theReference.IsNull()) return NULL;
135
136   //Add a new Point object
137   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GEOM_POINT);
138
139   //Add a new Point function for creation a point relativley another point
140   Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_XYZ_REF);
141
142   //Check if the function is set correctly
143   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
144
145   GEOMImpl_IPoint aPI(aFunction);
146
147   Handle(GEOM_Function) aRefFunction = theReference->GetLastFunction();
148   if (aRefFunction.IsNull()) return NULL;
149
150   aPI.SetRef(aRefFunction);
151   aPI.SetX(theX);
152   aPI.SetY(theY);
153   aPI.SetZ(theZ);
154
155   //Compute the point value
156   try {
157     OCC_CATCH_SIGNALS;
158     if (!GetSolver()->ComputeFunction(aFunction)) {
159       SetErrorCode("Point driver failed");
160       return NULL;
161     }
162   }
163   catch (Standard_Failure& aFail) {
164     SetErrorCode(aFail.GetMessageString());
165     return NULL;
166   }
167
168   //Make a Python command
169   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexWithRef("
170     << theReference << ", " << theX << ", " << theY << ", " << theZ << ")";
171
172   SetErrorCode(OK);
173   return aPoint;
174 }
175
176 //=============================================================================
177 /*!
178  *  makePointOnGeom
179  */
180 //=============================================================================
181 Handle(GEOM_Object) GEOMImpl_IBasicOperations::makePointOnGeom
182                     (Handle(GEOM_Object) theGeomObj,
183                      double              theParam1,
184                      double              theParam2,
185                      double              theParam3,
186                      const PointLocation theLocation,
187                      const bool          takeOrientationIntoAccount,
188                      Handle(GEOM_Object) theRefPoint)
189 {
190   SetErrorCode(KO);
191
192   if (theGeomObj.IsNull()) return NULL;
193
194   //Add a new Point object
195   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GEOM_POINT);
196
197   //Add a new Point function for creation a point relativley another point
198   int fType = POINT_CURVE_PAR;
199   switch( theLocation )
200     {
201     case PointOn_CurveByParam:   fType = POINT_CURVE_PAR; break;
202     case PointOn_CurveByLength:  fType = POINT_CURVE_LENGTH; break;                              
203     case PointOn_CurveByCoord:   fType = POINT_CURVE_COORD; break;
204     case PointOn_SurfaceByParam: fType = POINT_SURFACE_PAR; break;
205     case PointOn_SurfaceByCoord: fType = POINT_SURFACE_COORD; break;
206     case PointOn_Face:           fType = POINT_FACE_ANY; break;
207     default: break;
208     }
209   Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), fType);
210
211   //Check if the function is set correctly
212   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
213
214   GEOMImpl_IPoint aPI (aFunction);
215
216   Handle(GEOM_Function) aRefFunction = theGeomObj->GetLastFunction();
217   if (aRefFunction.IsNull()) return NULL;
218
219   switch( theLocation )
220     {
221     case PointOn_CurveByParam:
222       aPI.SetCurve(aRefFunction);
223       aPI.SetParameter(theParam1);
224       aPI.SetTakeOrientationIntoAccount(takeOrientationIntoAccount);
225       break;
226     case PointOn_CurveByLength:
227       aPI.SetCurve(aRefFunction);
228       aPI.SetLength(theParam1);
229       if (!theRefPoint.IsNull()) {
230         Handle(GEOM_Function) aRefPoint = theRefPoint->GetLastFunction();
231         aPI.SetRef(aRefPoint);
232       }
233       break;
234     case PointOn_CurveByCoord:
235       aPI.SetCurve(aRefFunction);
236       aPI.SetX(theParam1);
237       aPI.SetY(theParam2);
238       aPI.SetZ(theParam3);
239       break;
240     case PointOn_SurfaceByParam:
241       aPI.SetSurface(aRefFunction);
242       aPI.SetParameter(theParam1);
243       aPI.SetParameter2(theParam2);
244       break;
245     case PointOn_SurfaceByCoord:
246       aPI.SetSurface(aRefFunction);
247       aPI.SetX(theParam1);
248       aPI.SetY(theParam2);
249       aPI.SetZ(theParam3);
250       break;
251     case PointOn_Face:
252       aPI.SetSurface(aRefFunction);
253       break;
254     default: break;
255     }
256   
257   //Compute the point value
258   try {
259     OCC_CATCH_SIGNALS;
260     if (!GetSolver()->ComputeFunction(aFunction)) {
261       SetErrorCode("Point driver failed");
262       return NULL;
263     }
264   }
265   catch (Standard_Failure& aFail) {
266     SetErrorCode(aFail.GetMessageString());
267     return NULL;
268   }
269
270   //Make a Python command
271   switch( theLocation )
272     {
273     case PointOn_CurveByParam:
274       GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurve("
275                                    << theGeomObj << ", " << theParam1 << ", "
276                                    << takeOrientationIntoAccount <<  ")";
277       break;
278     case PointOn_CurveByLength:
279       GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurveByLength("
280                                    << theGeomObj << ", " << theParam1 << ", " << theRefPoint <<  ")";
281       break;
282     case PointOn_CurveByCoord:
283       GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurveByCoord("
284                                    << theGeomObj << ", " << theParam1 
285                                    << ", " << theParam2 << ", " << theParam3 << ")";
286       break;
287     case PointOn_SurfaceByParam:
288       GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnSurface("
289                                    << theGeomObj << ", " << theParam1 
290                                    << ", " << theParam2 << ")";
291       break;
292     case PointOn_SurfaceByCoord:
293       GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnSurfaceByCoord("
294                                    << theGeomObj << ", " << theParam1 
295                                    << ", " << theParam2 << ", " << theParam3 << ")";
296       break;
297     case PointOn_Face:
298       GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexInsideFace("
299                                    << theGeomObj << ")";
300       break;
301     default: break;
302     }
303
304   SetErrorCode(OK);
305   return aPoint;
306 }
307
308 //=============================================================================
309 /*!
310  *  MakePointOnCurve
311  */
312 //=============================================================================
313 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnCurve
314                             (Handle(GEOM_Object) theCurve,
315                              double              theParameter,
316                              bool                takeOrientationIntoAccount)
317 {
318   return makePointOnGeom(theCurve, theParameter, 0.0, 0.0, PointOn_CurveByParam,
319                          takeOrientationIntoAccount);
320 }
321
322 //=============================================================================
323 /*!
324  *  MakePointOnCurveByCoord
325  */
326 //=============================================================================
327 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnCurveByCoord
328                     (Handle(GEOM_Object) theCurve,
329                      double theXParam,
330                      double theYParam,
331                      double theZParam)
332 {
333   return makePointOnGeom(theCurve, theXParam, theYParam, theZParam, PointOn_CurveByCoord);
334 }
335
336 //=============================================================================
337 /*!
338  *  MakePointOnCurveByLength 
339  */
340 //=============================================================================
341 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnCurveByLength
342                     (Handle(GEOM_Object) theCurve, 
343                      double              theLength, 
344                      Handle(GEOM_Object) theStartPoint)
345 {
346   return makePointOnGeom(theCurve, theLength, 0.0, 0.0, PointOn_CurveByLength,
347                          false, theStartPoint);
348 }
349
350 //=============================================================================
351 /*!
352  *  MakePointOnSurface
353  */
354 //=============================================================================
355 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnSurface
356                     (Handle(GEOM_Object) theSurface,
357                      double theUParameter,
358                      double theVParameter)
359 {
360   return makePointOnGeom(theSurface, theUParameter, theVParameter, 0., PointOn_SurfaceByParam);
361 }
362
363 //=============================================================================
364 /*!
365  *  MakePointOnSurfaceByCoord
366  */
367 //=============================================================================
368 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnSurfaceByCoord
369                     (Handle(GEOM_Object) theSurface,
370                      double theXParam,
371                      double theYParam,
372                      double theZParam)
373 {
374   return makePointOnGeom(theSurface, theXParam, theYParam, theZParam, PointOn_SurfaceByCoord);
375 }
376
377 //=============================================================================
378 /*!
379  *  MakePointOnFace
380  */
381 //=============================================================================
382 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnFace (Handle(GEOM_Object) theFace)
383 {
384   return makePointOnGeom(theFace, 0., 0., 0., PointOn_Face);
385 }
386
387 //=============================================================================
388 /*!
389  *  MakePointOnLinesIntersection
390  */
391 //=============================================================================
392 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnLinesIntersection
393                             (Handle(GEOM_Object) theLine1, Handle(GEOM_Object) theLine2)
394 {
395   SetErrorCode(KO);
396
397   if (theLine1.IsNull() || theLine2.IsNull()) return NULL;
398
399   //Add a new Point object
400   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GEOM_POINT);
401
402   //Add a new Point function for creation a point relativley another point
403   Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_LINES_INTERSECTION);
404
405   //Check if the function is set correctly
406   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
407
408   GEOMImpl_IPoint aPI (aFunction);
409
410   Handle(GEOM_Function) aRef1 = theLine1->GetLastFunction();
411   Handle(GEOM_Function) aRef2 = theLine2->GetLastFunction();
412   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
413
414   aPI.SetLine1(aRef1);
415   aPI.SetLine2(aRef2);
416
417   //Compute the point value
418   try {
419     OCC_CATCH_SIGNALS;
420     if (!GetSolver()->ComputeFunction(aFunction)) {
421       SetErrorCode("Point driver failed");
422       return NULL;
423     }
424   }
425   catch (Standard_Failure& aFail) {
426     SetErrorCode(aFail.GetMessageString());
427     return NULL;
428   }
429
430   //Make a Python command
431   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnLinesIntersection("
432                                << theLine1 << ", " << theLine2 << ")";
433
434   SetErrorCode(OK);
435   return aPoint;
436 }
437
438 //=============================================================================
439 /*!
440  *  MakeTangentOnCurve
441  */
442 //=============================================================================
443 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeTangentOnCurve
444                             (const Handle(GEOM_Object)& theCurve, double theParameter)
445 {
446   SetErrorCode(KO);
447
448   if (theCurve.IsNull()) return NULL;
449
450   //Add a new Vector object
451   Handle(GEOM_Object) aVec = GetEngine()->AddObject(GEOM_VECTOR);
452
453   //Add a new Point function for creation a point relativley another point
454   Handle(GEOM_Function) aFunction = aVec->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TANGENT_CURVE_PAR);
455
456   //Check if the function is set correctly
457   if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
458
459   GEOMImpl_IVector aVI (aFunction);
460
461   Handle(GEOM_Function) aRefFunction = theCurve->GetLastFunction();
462   if (aRefFunction.IsNull()) return NULL;
463
464   aVI.SetCurve(aRefFunction);
465   aVI.SetParameter(theParameter);
466
467   //Compute the vector value
468   try {
469     OCC_CATCH_SIGNALS;
470     if (!GetSolver()->ComputeFunction(aFunction)) {
471       SetErrorCode("Vector driver failed");
472       return NULL;
473     }
474   }
475   catch (Standard_Failure& aFail) {
476     SetErrorCode(aFail.GetMessageString());
477     return NULL;
478   }
479
480   //Make a Python command
481   GEOM::TPythonDump(aFunction) << aVec << " = geompy.MakeTangentOnCurve("
482                                << theCurve << ", " << theParameter << ")";
483
484   SetErrorCode(OK);
485   return aVec;
486 }
487
488 //=============================================================================
489 /*!
490  *  MakeVectorDXDYDZ
491  */
492 //=============================================================================
493 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorDXDYDZ
494                                      (double theDX, double theDY, double theDZ)
495 {
496   SetErrorCode(KO);
497
498   //Add a new Vector object
499   Handle(GEOM_Object) aVector = GetEngine()->AddObject(GEOM_VECTOR);
500
501   //Add a new Vector function with DXDYDZ parameters
502   Handle(GEOM_Function) aFunction =
503     aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_DX_DY_DZ);
504   if (aFunction.IsNull()) return NULL;
505
506   //Check if the function is set correctly
507   if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
508
509   GEOMImpl_IVector aPI (aFunction);
510
511   aPI.SetDX(theDX);
512   aPI.SetDY(theDY);
513   aPI.SetDZ(theDZ);
514
515   //Compute the Vector value
516   try {
517     OCC_CATCH_SIGNALS;
518     if (!GetSolver()->ComputeFunction(aFunction)) {
519       SetErrorCode("Vector driver failed");
520       return NULL;
521     }
522   }
523   catch (Standard_Failure& aFail) {
524     SetErrorCode(aFail.GetMessageString());
525     return NULL;
526   }
527
528   //Make a Python command
529   GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVectorDXDYDZ("
530     << theDX << ", " << theDY << ", " << theDZ << ")";
531
532   SetErrorCode(OK);
533   return aVector;
534 }
535
536 //=============================================================================
537 /*!
538  *  MakeVectorTwoPnt
539  */
540 //=============================================================================
541 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorTwoPnt
542                      (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
543 {
544   SetErrorCode(KO);
545
546   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
547
548   //Add a new Vector object
549   Handle(GEOM_Object) aVector = GetEngine()->AddObject(GEOM_VECTOR);
550
551   //Add a new Vector function
552   Handle(GEOM_Function) aFunction =
553     aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TWO_PNT);
554
555   //Check if the function is set correctly
556   if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
557
558   GEOMImpl_IVector aPI (aFunction);
559
560   Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
561   Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
562   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
563
564   aPI.SetPoint1(aRef1);
565   aPI.SetPoint2(aRef2);
566
567   //Compute the Vector value
568   try {
569     OCC_CATCH_SIGNALS;
570     if (!GetSolver()->ComputeFunction(aFunction)) {
571       SetErrorCode("Vector driver failed");
572       return NULL;
573     }
574   }
575   catch (Standard_Failure& aFail) {
576     SetErrorCode(aFail.GetMessageString());
577     return NULL;
578   }
579
580   //Make a Python command
581   GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVector("
582                                << thePnt1 << ", " << thePnt2 << ")";
583
584   SetErrorCode(OK);
585   return aVector;
586 }
587
588
589 //=============================================================================
590 /*!
591  *  MakeLine
592  */
593 //=============================================================================
594 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLine
595                      (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theDir)
596 {
597   SetErrorCode(KO);
598
599   if (thePnt.IsNull() || theDir.IsNull()) return NULL;
600
601   //Add a new Line object
602   Handle(GEOM_Object) aLine = GetEngine()->AddObject(GEOM_LINE);
603
604   //Add a new Line function
605   Handle(GEOM_Function) aFunction =
606     aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_PNT_DIR);
607
608   //Check if the function is set correctly
609   if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
610
611   GEOMImpl_ILine aPI (aFunction);
612
613   Handle(GEOM_Function) aRef1 = thePnt->GetLastFunction();
614   Handle(GEOM_Function) aRef2 = theDir->GetLastFunction();
615   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
616
617   aPI.SetPoint1(aRef1);
618   aPI.SetPoint2(aRef2);
619
620   //Compute the Line value
621   try {
622     OCC_CATCH_SIGNALS;
623     if (!GetSolver()->ComputeFunction(aFunction)) {
624       SetErrorCode("Line driver failed");
625       return NULL;
626     }
627   }
628   catch (Standard_Failure& aFail) {
629     SetErrorCode(aFail.GetMessageString());
630     return NULL;
631   }
632
633   //Make a Python command
634   GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLine("
635                                << thePnt << ", " << theDir << ")";
636
637   SetErrorCode(OK);
638   return aLine;
639 }
640
641 //=============================================================================
642 /*!
643  *  MakeLineTwoPnt
644  */
645 //=============================================================================
646 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLineTwoPnt
647                      (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
648 {
649   SetErrorCode(KO);
650
651   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
652
653   //Add a new Line object
654   Handle(GEOM_Object) aLine = GetEngine()->AddObject(GEOM_LINE);
655
656   //Add a new Line function
657   Handle(GEOM_Function) aFunction =
658     aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_TWO_PNT);
659
660   //Check if the function is set correctly
661   if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
662
663   GEOMImpl_ILine aPI (aFunction);
664
665   Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
666   Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
667   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
668
669   aPI.SetPoint1(aRef1);
670   aPI.SetPoint2(aRef2);
671
672   //Compute the Line value
673   try {
674     OCC_CATCH_SIGNALS;
675     if (!GetSolver()->ComputeFunction(aFunction)) {
676       SetErrorCode("Line driver failed");
677       return NULL;
678     }
679   }
680   catch (Standard_Failure& aFail) {
681     SetErrorCode(aFail.GetMessageString());
682     return NULL;
683   }
684
685   //Make a Python command
686   GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLineTwoPnt("
687                                << thePnt1 << ", " << thePnt2 << ")";
688
689   SetErrorCode(OK);
690   return aLine;
691 }
692
693 //=============================================================================
694 /*!
695  *  MakeLineTwoFaces
696  */
697 //=============================================================================
698 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLineTwoFaces
699                      (Handle(GEOM_Object) theFace1, Handle(GEOM_Object) theFace2)
700 {
701   SetErrorCode(KO);
702
703   if (theFace1.IsNull() || theFace2.IsNull()) return NULL;
704
705   //Add a new Line object
706   Handle(GEOM_Object) aLine = GetEngine()->AddObject(GEOM_LINE);
707
708   //Add a new Line function
709   Handle(GEOM_Function) aFunction =
710     aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_TWO_FACES);
711
712   //Check if the function is set correctly
713   if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
714
715   GEOMImpl_ILine aPI (aFunction);
716
717   Handle(GEOM_Function) aRef1 = theFace1->GetLastFunction();
718   Handle(GEOM_Function) aRef2 = theFace2->GetLastFunction();
719   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
720
721   aPI.SetFace1(aRef1);
722   aPI.SetFace2(aRef2);
723
724   //Compute the Line value
725   try {
726     OCC_CATCH_SIGNALS;
727     if (!GetSolver()->ComputeFunction(aFunction)) {
728       SetErrorCode("Line driver failed");
729       return NULL;
730     }
731   }
732   catch (Standard_Failure& aFail) {
733     SetErrorCode(aFail.GetMessageString());
734     return NULL;
735   }
736
737   //Make a Python command
738   GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLineTwoFaces("
739                                << theFace1 << ", " << theFace2 << ")";
740
741   SetErrorCode(OK);
742   return aLine;
743 }
744
745 //=============================================================================
746 /*!
747  *  MakePlaneThreePnt
748  */
749 //=============================================================================
750 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneThreePnt
751                      (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2,
752                       Handle(GEOM_Object) thePnt3, double theSize)
753 {
754   SetErrorCode(KO);
755
756   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
757
758   //Add a new Plane object
759   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GEOM_PLANE);
760
761   //Add a new Plane function
762   Handle(GEOM_Function) aFunction =
763     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_THREE_PNT);
764
765   //Check if the function is set correctly
766   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
767
768   GEOMImpl_IPlane aPI (aFunction);
769
770   Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
771   Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
772   Handle(GEOM_Function) aRef3 = thePnt3->GetLastFunction();
773   if (aRef1.IsNull() || aRef2.IsNull() || aRef3.IsNull()) return NULL;
774
775   aPI.SetPoint1(aRef1);
776   aPI.SetPoint2(aRef2);
777   aPI.SetPoint3(aRef3);
778   aPI.SetSize(theSize);
779
780   //Compute the Plane value
781   try {
782     OCC_CATCH_SIGNALS;
783     if (!GetSolver()->ComputeFunction(aFunction)) {
784       SetErrorCode("Plane driver failed");
785       return NULL;
786     }
787   }
788   catch (Standard_Failure& aFail) {
789     SetErrorCode(aFail.GetMessageString());
790     return NULL;
791   }
792
793   //Make a Python command
794   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneThreePnt("
795     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ", " << theSize << ")";
796
797   SetErrorCode(OK);
798   return aPlane;
799 }
800
801 //=============================================================================
802 /*!
803  *  MakePlanePntVec
804  */
805 //=============================================================================
806 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlanePntVec
807                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
808                         double theSize)
809 {
810   SetErrorCode(KO);
811
812   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
813
814   //Add a new Plane object
815   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GEOM_PLANE);
816
817   //Add a new Plane function
818   Handle(GEOM_Function) aFunction =
819     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_PNT_VEC);
820
821   //Check if the function is set correctly
822   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
823
824   GEOMImpl_IPlane aPI (aFunction);
825
826   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
827   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
828   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
829
830   aPI.SetPoint(aRefPnt);
831   aPI.SetVector(aRefVec);
832   aPI.SetSize(theSize);
833
834   //Compute the Plane value
835   try {
836     OCC_CATCH_SIGNALS;
837     if (!GetSolver()->ComputeFunction(aFunction)) {
838       SetErrorCode("Plane driver failed");
839       return NULL;
840     }
841   }
842   catch (Standard_Failure& aFail) {
843     SetErrorCode(aFail.GetMessageString());
844     return NULL;
845   }
846
847   //Make a Python command
848   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlane("
849     << thePnt << ", " << theVec << ", " << theSize << ")";
850
851   SetErrorCode(OK);
852   return aPlane;
853 }
854
855 //=============================================================================
856 /*!
857  *  MakePlaneFace
858  */
859 //=============================================================================
860 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneFace
861                        (Handle(GEOM_Object) theFace, double theSize)
862 {
863   SetErrorCode(KO);
864
865   if (theFace.IsNull()) return NULL;
866
867   //Add a new Plane object
868   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GEOM_PLANE);
869
870   //Add a new Plane function
871   Handle(GEOM_Function) aFunction =
872     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_FACE);
873
874   //Check if the function is set correctly
875   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
876
877   GEOMImpl_IPlane aPI (aFunction);
878
879   Handle(GEOM_Function) aRef = theFace->GetLastFunction();
880   if (aRef.IsNull()) return NULL;
881
882   aPI.SetFace(aRef);
883   aPI.SetSize(theSize);
884
885   //Compute the Plane value
886   try {
887     OCC_CATCH_SIGNALS;
888     if (!GetSolver()->ComputeFunction(aFunction)) {
889       SetErrorCode("Plane driver failed");
890       return NULL;
891     }
892   }
893   catch (Standard_Failure& aFail) {
894     SetErrorCode(aFail.GetMessageString());
895     return NULL;
896   }
897
898   //Make a Python command
899   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneFace("
900                                << theFace << ", " << theSize << ")";
901
902   SetErrorCode(OK);
903   return aPlane;
904 }
905
906 //=============================================================================
907 /*!
908  *  MakePlane2Vec
909  */
910 //=============================================================================
911 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlane2Vec
912                        (Handle(GEOM_Object) theVec1, Handle(GEOM_Object) theVec2,
913                         double theSize)
914 {
915   SetErrorCode(KO);
916
917   if (theVec1.IsNull() || theVec2.IsNull()) return NULL;
918
919   //Add a new Plane object
920   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GEOM_PLANE);
921
922   //Add a new Plane function
923   Handle(GEOM_Function) aFunction =
924     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_2_VEC);
925
926   //Check if the function is set correctly
927   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
928
929   GEOMImpl_IPlane aPI (aFunction);
930
931   Handle(GEOM_Function) aRefVec1 = theVec1->GetLastFunction();
932   Handle(GEOM_Function) aRefVec2 = theVec2->GetLastFunction();
933   if (aRefVec1.IsNull() || aRefVec2.IsNull()) return NULL;
934
935   aPI.SetVector1(aRefVec1);
936   aPI.SetVector2(aRefVec2);
937   aPI.SetSize(theSize);
938
939   //Compute the Plane value
940   try {
941     OCC_CATCH_SIGNALS;
942     if (!GetSolver()->ComputeFunction(aFunction)) {
943       SetErrorCode("Plane driver failed");
944       return NULL;
945     }
946   }
947   catch (Standard_Failure& aFail) {
948     SetErrorCode(aFail.GetMessageString());
949     return NULL;
950   }
951
952   //Make a Python command
953   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlane2Vec("
954     << theVec1 << ", " << theVec2 << ", " << theSize << ")";
955
956   SetErrorCode(OK);
957   return aPlane;
958 }
959
960 //=============================================================================
961 /*!
962  *  MakePlaneLCS
963  */
964 //=============================================================================
965 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneLCS
966                        (Handle(GEOM_Object) theLCS, double theSize, int theOrientation)
967 {
968   SetErrorCode(KO);
969
970   //Add a new Plane object
971   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GEOM_PLANE);
972
973   //Add a new Plane function
974   Handle(GEOM_Function) aFunction =
975     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_LCS);
976
977   //Check if the function is set correctly
978   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
979
980   GEOMImpl_IPlane aPI (aFunction);
981
982   if ( !theLCS.IsNull() ) {
983     Handle(GEOM_Function) aRef = theLCS->GetLastFunction();
984     aPI.SetLCS(aRef);
985   }
986
987   aPI.SetSize(theSize);
988   aPI.SetOrientation(theOrientation);
989
990   //Compute the Plane value
991   try {
992     OCC_CATCH_SIGNALS;
993     if (!GetSolver()->ComputeFunction(aFunction)) {
994       SetErrorCode("Plane driver failed");
995       return NULL;
996     }
997   }
998   catch (Standard_Failure& aFail) {
999     SetErrorCode(aFail.GetMessageString());
1000     return NULL;
1001   }
1002
1003   //Make a Python command
1004   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneLCS("
1005                                << theLCS << ", " << theSize << ", " << theOrientation << ")";
1006
1007   SetErrorCode(OK);
1008   return aPlane;
1009 }
1010
1011
1012 //=============================================================================
1013 /*!
1014  *  MakeMarker
1015  */
1016 //=============================================================================
1017 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeMarker
1018                                   (double theOX,  double theOY,  double theOZ,
1019                                    double theXDX, double theXDY, double theXDZ,
1020                                    double theYDX, double theYDY, double theYDZ)
1021 {
1022   SetErrorCode(KO);
1023
1024   //Add a new Marker object
1025   Handle(GEOM_Object) aMarker = GetEngine()->AddObject(GEOM_MARKER);
1026
1027   //Add a new Marker function
1028   Handle(GEOM_Function) aFunction =
1029     aMarker->AddFunction(GEOMImpl_MarkerDriver::GetID(), MARKER_CS);
1030   if (aFunction.IsNull()) return NULL;
1031
1032   //Check if the function is set correctly
1033   if (aFunction->GetDriverGUID() != GEOMImpl_MarkerDriver::GetID()) return NULL;
1034
1035   GEOMImpl_IMarker aPI(aFunction);
1036
1037   aPI.SetOrigin(theOX, theOY, theOZ);
1038   aPI.SetXDir(theXDX, theXDY, theXDZ);
1039   aPI.SetYDir(theYDX, theYDY, theYDZ);
1040
1041   //Compute the marker value
1042   try {
1043     OCC_CATCH_SIGNALS;
1044     if (!GetSolver()->ComputeFunction(aFunction)) {
1045       SetErrorCode("Marker driver failed");
1046       return NULL;
1047     }
1048   }
1049   catch (Standard_Failure& aFail) {
1050     SetErrorCode(aFail.GetMessageString());
1051     return NULL;
1052   }
1053
1054   //Make a Python command
1055   GEOM::TPythonDump(aFunction) << aMarker << " = geompy.MakeMarker("
1056     << theOX << ", " << theOY << ", " << theOZ << ", "
1057       << theXDX << ", " << theXDY << ", " << theXDZ << ", "
1058         << theYDX << ", " << theYDY << ", " << theYDZ << ")";
1059
1060   SetErrorCode(OK);
1061   return aMarker;
1062 }
1063
1064 //=============================================================================
1065 /*!
1066  *  MakeMarkerFromShape
1067  */
1068 //=============================================================================
1069 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeMarkerFromShape
1070                                   (const Handle(GEOM_Object)& theShape)
1071 {
1072   SetErrorCode(KO);
1073
1074   //Add a new Marker object
1075   Handle(GEOM_Object) aMarker = GetEngine()->AddObject(GEOM_MARKER);
1076
1077   //Add a new Marker function
1078   Handle(GEOM_Function) aFunction =
1079     aMarker->AddFunction(GEOMImpl_MarkerDriver::GetID(), MARKER_SHAPE);
1080   if (aFunction.IsNull()) return NULL;
1081
1082   //Check if the function is set correctly
1083   if (aFunction->GetDriverGUID() != GEOMImpl_MarkerDriver::GetID()) return NULL;
1084
1085   GEOMImpl_IMarker aPI(aFunction);
1086
1087   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1088   if (aRefShape.IsNull()) return NULL;
1089
1090   aPI.SetShape(aRefShape);
1091
1092   //Compute the marker value
1093   try {
1094     OCC_CATCH_SIGNALS;
1095     if (!GetSolver()->ComputeFunction(aFunction)) {
1096       SetErrorCode("Marker driver failed");
1097       return NULL;
1098     }
1099   }
1100   catch (Standard_Failure& aFail) {
1101     SetErrorCode(aFail.GetMessageString());
1102     return NULL;
1103   }
1104
1105   //Make a Python command
1106   GEOM::TPythonDump(aFunction) << aMarker << " = geompy.MakeMarkerFromShape(" << theShape << ")";
1107
1108   SetErrorCode(OK);
1109   return aMarker;
1110 }
1111
1112 //=============================================================================
1113 /*!
1114  *  MakeMarkerPntTwoVec
1115  */
1116 //=============================================================================
1117 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeMarkerPntTwoVec
1118                                               (const Handle(GEOM_Object)& theOrigin,
1119                                                const Handle(GEOM_Object)& theXVec,
1120                                                const Handle(GEOM_Object)& theYVec)
1121 {
1122   SetErrorCode(KO);
1123
1124   //Add a new Marker object
1125   Handle(GEOM_Object) aMarker = GetEngine()->AddObject(GEOM_MARKER);
1126
1127   //Add a new Marker function
1128   Handle(GEOM_Function) aFunction =
1129     aMarker->AddFunction(GEOMImpl_MarkerDriver::GetID(), MARKER_PNT2VEC);
1130   if (aFunction.IsNull()) return NULL;
1131
1132   //Check if the function is set correctly
1133   if (aFunction->GetDriverGUID() != GEOMImpl_MarkerDriver::GetID()) return NULL;
1134
1135   GEOMImpl_IMarker aPI(aFunction);
1136
1137   Handle(GEOM_Function) aRefOrigin = theOrigin->GetLastFunction();
1138   Handle(GEOM_Function) aRefXVec = theXVec->GetLastFunction();
1139   Handle(GEOM_Function) aRefYVec = theYVec->GetLastFunction();
1140   if (aRefOrigin.IsNull() || aRefXVec.IsNull() || aRefYVec.IsNull()) return NULL;
1141
1142   aPI.SetOrigin(aRefOrigin);
1143   aPI.SetXVec(aRefXVec);
1144   aPI.SetYVec(aRefYVec);
1145
1146   //Compute the marker value
1147   try {
1148     OCC_CATCH_SIGNALS;
1149     if (!GetSolver()->ComputeFunction(aFunction)) {
1150       SetErrorCode("Marker driver failed");
1151       return NULL;
1152     }
1153   }
1154   catch (Standard_Failure& aFail) {
1155     SetErrorCode(aFail.GetMessageString());
1156     return NULL;
1157   }
1158
1159   //Make a Python command
1160   GEOM::TPythonDump(aFunction) << aMarker << " = geompy.MakeMarkerPntTwoVec("
1161     << theOrigin << ", " << theXVec << ", " << theYVec << ")";
1162
1163   SetErrorCode(OK);
1164   return aMarker;
1165 }
1166
1167 //=============================================================================
1168 /*!
1169  *  MakeTangentPlaneOnFace
1170  */
1171 //=============================================================================
1172
1173 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeTangentPlaneOnFace(const Handle(GEOM_Object)& theFace,
1174                                                                       double theParamU,
1175                                                                       double theParamV,
1176                                                                       double theSize)
1177 {
1178    SetErrorCode(KO);
1179
1180   if (theFace.IsNull()) return NULL;
1181
1182   //Add a new Plane object
1183   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GEOM_PLANE);
1184
1185   //Add a new Plane function
1186   Handle(GEOM_Function) aFunction =
1187     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_TANGENT_FACE);
1188
1189   //Check if the function is set correctly
1190   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
1191
1192   GEOMImpl_IPlane aPI (aFunction);
1193
1194   Handle(GEOM_Function) aRef = theFace->GetLastFunction();
1195   if (aRef.IsNull()) return NULL;
1196
1197   aPI.SetFace(aRef);
1198   aPI.SetSize(theSize);
1199   aPI.SetParameterU(theParamU);
1200   aPI.SetParameterV(theParamV);
1201
1202   //Compute the Plane value
1203   try {
1204     OCC_CATCH_SIGNALS;
1205     if (!GetSolver()->ComputeFunction(aFunction)) {
1206       SetErrorCode("Plane driver failed");
1207       return NULL;
1208     }
1209   }
1210   catch (Standard_Failure& aFail) {
1211     SetErrorCode(aFail.GetMessageString());
1212     return NULL;
1213   }
1214
1215   //Make a Python command
1216   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakeTangentPlaneOnFace("
1217                                << theFace << ", " <<theParamU <<", "<<theParamV <<", "<< theSize << ")";
1218
1219   SetErrorCode(OK);
1220   return aPlane;
1221 }