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