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