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