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