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