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