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