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