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