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