Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IBasicOperations.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include <Standard_Stream.hxx>
23
24 #include <GEOMImpl_IBasicOperations.hxx>
25
26 #include "utilities.h"
27 #include <OpUtil.hxx>
28 #include <Utils_ExceptHandlers.hxx>
29
30 #include <TFunction_DriverTable.hxx>
31 #include <TFunction_Driver.hxx>
32 #include <TFunction_Logbook.hxx>
33 #include <TDF_Tool.hxx>
34
35 #include <GEOM_Function.hxx>
36 #include <GEOM_PythonDump.hxx>
37
38 #include <GEOMImpl_PointDriver.hxx>
39 #include <GEOMImpl_VectorDriver.hxx>
40 #include <GEOMImpl_LineDriver.hxx>
41 #include <GEOMImpl_PlaneDriver.hxx>
42 #include <GEOMImpl_MarkerDriver.hxx>
43
44 #include <GEOMImpl_IPoint.hxx>
45 #include <GEOMImpl_IVector.hxx>
46 #include <GEOMImpl_ILine.hxx>
47 #include <GEOMImpl_IPlane.hxx>
48 #include <GEOMImpl_IMarker.hxx>
49
50 #include <GEOMImpl_Types.hxx>
51
52 #include <Standard_Failure.hxx>
53 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
54
55 //=============================================================================
56 /*!
57  *   constructor:
58  */
59 //=============================================================================
60 GEOMImpl_IBasicOperations::GEOMImpl_IBasicOperations(GEOM_Engine* theEngine, int theDocID)
61 : GEOM_IOperations(theEngine, theDocID)
62 {
63   MESSAGE("GEOMImpl_IBasicOperations::GEOMImpl_IBasicOperations");
64 }
65
66 //=============================================================================
67 /*!
68  *  destructor
69  */
70 //=============================================================================
71 GEOMImpl_IBasicOperations::~GEOMImpl_IBasicOperations()
72 {
73   MESSAGE("GEOMImpl_IBasicOperations::~GEOMImpl_IBasicOperations");
74 }
75
76
77 //=============================================================================
78 /*!
79  *  MakePointXYZ
80  */
81 //=============================================================================
82 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointXYZ
83                                         (double theX, double theY, double theZ)
84 {
85   SetErrorCode(KO);
86
87   //Add a new Point object
88   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
89
90   //Add a new Point function with XYZ parameters
91   Handle(GEOM_Function) aFunction =
92     aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_XYZ);
93   if (aFunction.IsNull()) return NULL;
94
95   //Check if the function is set correctly
96   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
97
98   GEOMImpl_IPoint aPI(aFunction);
99
100   aPI.SetX(theX);
101   aPI.SetY(theY);
102   aPI.SetZ(theZ);
103
104   //Compute the point value
105   try {
106 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
107     OCC_CATCH_SIGNALS;
108 #endif
109     if (!GetSolver()->ComputeFunction(aFunction)) {
110       SetErrorCode("Point driver failed");
111       return NULL;
112     }
113   }
114   catch (Standard_Failure) {
115     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
116     SetErrorCode(aFail->GetMessageString());
117     return NULL;
118   }
119
120   //Make a Python command
121   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertex("
122     << theX << ", " << theY << ", " << theZ << ")";
123
124   SetErrorCode(OK);
125   return aPoint;
126 }
127
128 //=============================================================================
129 /*!
130  *  MakePointWithReference
131  */
132 //=============================================================================
133 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointWithReference
134       (Handle(GEOM_Object) theReference, double theX, double theY, double theZ)
135 {
136   SetErrorCode(KO);
137
138   if (theReference.IsNull()) return NULL;
139
140   //Add a new Point object
141   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
142
143   //Add a new Point function for creation a point relativley another point
144   Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_XYZ_REF);
145
146   //Check if the function is set correctly
147   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
148
149   GEOMImpl_IPoint aPI(aFunction);
150
151   Handle(GEOM_Function) aRefFunction = theReference->GetLastFunction();
152   if (aRefFunction.IsNull()) return NULL;
153
154   aPI.SetRef(aRefFunction);
155   aPI.SetX(theX);
156   aPI.SetY(theY);
157   aPI.SetZ(theZ);
158
159   //Compute the point value
160   try {
161 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
162     OCC_CATCH_SIGNALS;
163 #endif
164     if (!GetSolver()->ComputeFunction(aFunction)) {
165       SetErrorCode("Point driver failed");
166       return NULL;
167     }
168   }
169   catch (Standard_Failure) {
170     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
171     SetErrorCode(aFail->GetMessageString());
172     return NULL;
173   }
174
175   //Make a Python command
176   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexWithRef("
177     << theReference << ", " << theX << ", " << theY << ", " << theZ << ")";
178
179   SetErrorCode(OK);
180   return aPoint;
181 }
182
183 //=============================================================================
184 /*!
185  *  MakePointOnCurve
186  */
187 //=============================================================================
188 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnCurve
189                             (Handle(GEOM_Object) theCurve, double theParameter)
190 {
191   SetErrorCode(KO);
192
193   if (theCurve.IsNull()) return NULL;
194
195   //Add a new Point object
196   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
197
198   //Add a new Point function for creation a point relativley another point
199   Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_CURVE_PAR);
200
201   //Check if the function is set correctly
202   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
203
204   GEOMImpl_IPoint aPI (aFunction);
205
206   Handle(GEOM_Function) aRefFunction = theCurve->GetLastFunction();
207   if (aRefFunction.IsNull()) return NULL;
208
209   aPI.SetCurve(aRefFunction);
210   aPI.SetParameter(theParameter);
211
212   //Compute the point value
213   try {
214 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
215     OCC_CATCH_SIGNALS;
216 #endif
217     if (!GetSolver()->ComputeFunction(aFunction)) {
218       SetErrorCode("Point driver failed");
219       return NULL;
220     }
221   }
222   catch (Standard_Failure) {
223     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
224     SetErrorCode(aFail->GetMessageString());
225     return NULL;
226   }
227
228   //Make a Python command
229   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurve("
230                                << theCurve << ", " << theParameter << ")";
231
232   SetErrorCode(OK);
233   return aPoint;
234 }
235
236
237 //=============================================================================
238 /*!
239  *  MakePointOnSurface
240  */
241 //=============================================================================
242 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnSurface
243    (Handle(GEOM_Object) theSurface, double theUParameter, double theVParameter)
244 {
245   SetErrorCode(KO);
246
247   if (theSurface.IsNull()) return NULL;
248
249   //Add a new Point object
250   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
251
252   //Add a new Point function for creation a point relativley another point
253   Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(),
254                                                         POINT_SURFACE_PAR);
255
256   //Check if the function is set correctly
257   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
258
259   GEOMImpl_IPoint aPI (aFunction);
260
261   Handle(GEOM_Function) aRefFunction = theSurface->GetLastFunction();
262   if (aRefFunction.IsNull()) return NULL;
263
264   aPI.SetSurface(aRefFunction);
265   aPI.SetParameter(theUParameter);
266   aPI.SetParameter2(theVParameter);
267
268   //Compute the point value
269   try {
270 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
271     OCC_CATCH_SIGNALS;
272 #endif
273     if (!GetSolver()->ComputeFunction(aFunction)) {
274       SetErrorCode("Point driver failed");
275       return NULL;
276     }
277   }
278   catch (Standard_Failure) {
279     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
280     SetErrorCode(aFail->GetMessageString());
281     return NULL;
282   }
283
284   //Make a Python command
285   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnSurface("
286                                << theSurface << ", " << theUParameter 
287                                << ", " << theVParameter << ")";
288
289   SetErrorCode(OK);
290   return aPoint;
291 }
292
293
294 //=============================================================================
295 /*!
296  *  MakePointOnLinesIntersection
297  */
298 //=============================================================================
299 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnLinesIntersection
300                             (Handle(GEOM_Object) theLine1, Handle(GEOM_Object) theLine2)
301 {
302   SetErrorCode(KO);
303
304   if (theLine1.IsNull() || theLine2.IsNull()) return NULL;
305
306   //Add a new Point object
307   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
308
309   //Add a new Point function for creation a point relativley another point
310   Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_LINES_INTERSECTION);
311
312   //Check if the function is set correctly
313   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
314
315   GEOMImpl_IPoint aPI (aFunction);
316
317   Handle(GEOM_Function) aRef1 = theLine1->GetLastFunction();
318   Handle(GEOM_Function) aRef2 = theLine2->GetLastFunction();
319   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
320
321   aPI.SetLine1(aRef1);
322   aPI.SetLine2(aRef2);
323
324   //Compute the point value
325   try {
326 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
327     OCC_CATCH_SIGNALS;
328 #endif
329     if (!GetSolver()->ComputeFunction(aFunction)) {
330       SetErrorCode("Point driver failed");
331       return NULL;
332     }
333   }
334   catch (Standard_Failure) {
335     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
336     SetErrorCode(aFail->GetMessageString());
337     return NULL;
338   }
339
340   //Make a Python command
341   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnLinesIntersection("
342                                << theLine1 << ", " << theLine2 << ")";
343
344   SetErrorCode(OK);
345   return aPoint;
346 }
347
348 //=============================================================================
349 /*!
350  *  MakeTangentOnCurve
351  */
352 //=============================================================================
353 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeTangentOnCurve
354                             (const Handle(GEOM_Object)& theCurve, double theParameter)
355 {
356   SetErrorCode(KO);
357
358   if (theCurve.IsNull()) return NULL;
359
360   //Add a new Vector object
361   Handle(GEOM_Object) aVec = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
362
363   //Add a new Point function for creation a point relativley another point
364   Handle(GEOM_Function) aFunction = aVec->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TANGENT_CURVE_PAR);
365
366   //Check if the function is set correctly
367   if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
368
369   GEOMImpl_IVector aVI (aFunction);
370
371   Handle(GEOM_Function) aRefFunction = theCurve->GetLastFunction();
372   if (aRefFunction.IsNull()) return NULL;
373
374   aVI.SetCurve(aRefFunction);
375   aVI.SetParameter(theParameter);
376
377   //Compute the vector value
378   try {
379 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
380     OCC_CATCH_SIGNALS;
381 #endif
382     if (!GetSolver()->ComputeFunction(aFunction)) {
383       SetErrorCode("Vector driver failed");
384       return NULL;
385     }
386   }
387   catch (Standard_Failure) {
388     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
389     SetErrorCode(aFail->GetMessageString());
390     return NULL;
391   }
392
393   //Make a Python command
394   GEOM::TPythonDump(aFunction) << aVec << " = geompy.MakeTangentOnCurve("
395                                << theCurve << ", " << theParameter << ")";
396
397   SetErrorCode(OK);
398   return aVec;
399 }
400
401 //=============================================================================
402 /*!
403  *  MakeVectorDXDYDZ
404  */
405 //=============================================================================
406 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorDXDYDZ
407                                      (double theDX, double theDY, double theDZ)
408 {
409   SetErrorCode(KO);
410
411   //Add a new Vector object
412   Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
413
414   //Add a new Vector function with DXDYDZ parameters
415   Handle(GEOM_Function) aFunction =
416     aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_DX_DY_DZ);
417   if (aFunction.IsNull()) return NULL;
418
419   //Check if the function is set correctly
420   if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
421
422   GEOMImpl_IVector aPI (aFunction);
423
424   aPI.SetDX(theDX);
425   aPI.SetDY(theDY);
426   aPI.SetDZ(theDZ);
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) << aVector << " = geompy.MakeVectorDXDYDZ("
446     << theDX << ", " << theDY << ", " << theDZ << ")";
447
448   SetErrorCode(OK);
449   return aVector;
450 }
451
452 //=============================================================================
453 /*!
454  *  MakeVectorTwoPnt
455  */
456 //=============================================================================
457 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorTwoPnt
458                      (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
459 {
460   SetErrorCode(KO);
461
462   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
463
464   //Add a new Vector object
465   Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
466
467   //Add a new Vector function
468   Handle(GEOM_Function) aFunction =
469     aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TWO_PNT);
470
471   //Check if the function is set correctly
472   if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
473
474   GEOMImpl_IVector aPI (aFunction);
475
476   Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
477   Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
478   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
479
480   aPI.SetPoint1(aRef1);
481   aPI.SetPoint2(aRef2);
482
483   //Compute the Vector value
484   try {
485 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
486     OCC_CATCH_SIGNALS;
487 #endif
488     if (!GetSolver()->ComputeFunction(aFunction)) {
489       SetErrorCode("Vector driver failed");
490       return NULL;
491     }
492   }
493   catch (Standard_Failure) {
494     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
495     SetErrorCode(aFail->GetMessageString());
496     return NULL;
497   }
498
499   //Make a Python command
500   GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVector("
501                                << thePnt1 << ", " << thePnt2 << ")";
502
503   SetErrorCode(OK);
504   return aVector;
505 }
506
507
508 //=============================================================================
509 /*!
510  *  MakeLine
511  */
512 //=============================================================================
513 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLine
514                      (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theDir)
515 {
516   SetErrorCode(KO);
517
518   if (thePnt.IsNull() || theDir.IsNull()) return NULL;
519
520   //Add a new Line object
521   Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
522
523   //Add a new Line function
524   Handle(GEOM_Function) aFunction =
525     aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_PNT_DIR);
526
527   //Check if the function is set correctly
528   if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
529
530   GEOMImpl_ILine aPI (aFunction);
531
532   Handle(GEOM_Function) aRef1 = thePnt->GetLastFunction();
533   Handle(GEOM_Function) aRef2 = theDir->GetLastFunction();
534   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
535
536   aPI.SetPoint1(aRef1);
537   aPI.SetPoint2(aRef2);
538
539   //Compute the Line value
540   try {
541 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
542     OCC_CATCH_SIGNALS;
543 #endif
544     if (!GetSolver()->ComputeFunction(aFunction)) {
545       SetErrorCode("Line driver failed");
546       return NULL;
547     }
548   }
549   catch (Standard_Failure) {
550     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
551     SetErrorCode(aFail->GetMessageString());
552     return NULL;
553   }
554
555   //Make a Python command
556   GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLine("
557                                << thePnt << ", " << theDir << ")";
558
559   SetErrorCode(OK);
560   return aLine;
561 }
562
563 //=============================================================================
564 /*!
565  *  MakeLineTwoPnt
566  */
567 //=============================================================================
568 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLineTwoPnt
569                      (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
570 {
571   SetErrorCode(KO);
572
573   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
574
575   //Add a new Line object
576   Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
577
578   //Add a new Line function
579   Handle(GEOM_Function) aFunction =
580     aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_TWO_PNT);
581
582   //Check if the function is set correctly
583   if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
584
585   GEOMImpl_ILine aPI (aFunction);
586
587   Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
588   Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
589   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
590
591   aPI.SetPoint1(aRef1);
592   aPI.SetPoint2(aRef2);
593
594   //Compute the Line value
595   try {
596 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
597     OCC_CATCH_SIGNALS;
598 #endif
599     if (!GetSolver()->ComputeFunction(aFunction)) {
600       SetErrorCode("Line driver failed");
601       return NULL;
602     }
603   }
604   catch (Standard_Failure) {
605     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
606     SetErrorCode(aFail->GetMessageString());
607     return NULL;
608   }
609
610   //Make a Python command
611   GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLineTwoPnt("
612                                << thePnt1 << ", " << thePnt2 << ")";
613
614   SetErrorCode(OK);
615   return aLine;
616 }
617
618 //=============================================================================
619 /*!
620  *  MakeLineTwoFaces
621  */
622 //=============================================================================
623 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLineTwoFaces
624                      (Handle(GEOM_Object) theFace1, Handle(GEOM_Object) theFace2)
625 {
626   SetErrorCode(KO);
627
628   if (theFace1.IsNull() || theFace2.IsNull()) return NULL;
629
630   //Add a new Line object
631   Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
632
633   //Add a new Line function
634   Handle(GEOM_Function) aFunction =
635     aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_TWO_FACES);
636
637   //Check if the function is set correctly
638   if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
639
640   GEOMImpl_ILine aPI (aFunction);
641
642   Handle(GEOM_Function) aRef1 = theFace1->GetLastFunction();
643   Handle(GEOM_Function) aRef2 = theFace2->GetLastFunction();
644   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
645
646   aPI.SetFace1(aRef1);
647   aPI.SetFace2(aRef2);
648
649   //Compute the Line value
650   try {
651 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
652     OCC_CATCH_SIGNALS;
653 #endif
654     if (!GetSolver()->ComputeFunction(aFunction)) {
655       SetErrorCode("Line driver failed");
656       return NULL;
657     }
658   }
659   catch (Standard_Failure) {
660     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
661     SetErrorCode(aFail->GetMessageString());
662     return NULL;
663   }
664
665   //Make a Python command
666   GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLineTwoFaces("
667                                << theFace1 << ", " << theFace2 << ")";
668
669   SetErrorCode(OK);
670   return aLine;
671 }
672
673 //=============================================================================
674 /*!
675  *  MakePlaneThreePnt
676  */
677 //=============================================================================
678 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneThreePnt
679                      (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2,
680                       Handle(GEOM_Object) thePnt3, double theSize)
681 {
682   SetErrorCode(KO);
683
684   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
685
686   //Add a new Plane object
687   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
688
689   //Add a new Plane function
690   Handle(GEOM_Function) aFunction =
691     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_THREE_PNT);
692
693   //Check if the function is set correctly
694   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
695
696   GEOMImpl_IPlane aPI (aFunction);
697
698   Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
699   Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
700   Handle(GEOM_Function) aRef3 = thePnt3->GetLastFunction();
701   if (aRef1.IsNull() || aRef2.IsNull() || aRef3.IsNull()) return NULL;
702
703   aPI.SetPoint1(aRef1);
704   aPI.SetPoint2(aRef2);
705   aPI.SetPoint3(aRef3);
706   aPI.SetSize(theSize);
707
708   //Compute the Plane value
709   try {
710 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
711     OCC_CATCH_SIGNALS;
712 #endif
713     if (!GetSolver()->ComputeFunction(aFunction)) {
714       SetErrorCode("Plane driver failed");
715       return NULL;
716     }
717   }
718   catch (Standard_Failure) {
719     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
720     SetErrorCode(aFail->GetMessageString());
721     return NULL;
722   }
723
724   //Make a Python command
725   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneThreePnt("
726     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ", " << theSize << ")";
727
728   SetErrorCode(OK);
729   return aPlane;
730 }
731
732 //=============================================================================
733 /*!
734  *  MakePlanePntVec
735  */
736 //=============================================================================
737 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlanePntVec
738                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
739                         double theSize)
740 {
741   SetErrorCode(KO);
742
743   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
744
745   //Add a new Plane object
746   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
747
748   //Add a new Plane function
749   Handle(GEOM_Function) aFunction =
750     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_PNT_VEC);
751
752   //Check if the function is set correctly
753   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
754
755   GEOMImpl_IPlane aPI (aFunction);
756
757   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
758   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
759   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
760
761   aPI.SetPoint(aRefPnt);
762   aPI.SetVector(aRefVec);
763   aPI.SetSize(theSize);
764
765   //Compute the Plane value
766   try {
767 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
768     OCC_CATCH_SIGNALS;
769 #endif
770     if (!GetSolver()->ComputeFunction(aFunction)) {
771       SetErrorCode("Plane driver failed");
772       return NULL;
773     }
774   }
775   catch (Standard_Failure) {
776     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
777     SetErrorCode(aFail->GetMessageString());
778     return NULL;
779   }
780
781   //Make a Python command
782   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlane("
783     << thePnt << ", " << theVec << ", " << theSize << ")";
784
785   SetErrorCode(OK);
786   return aPlane;
787 }
788
789 //=============================================================================
790 /*!
791  *  MakePlaneFace
792  */
793 //=============================================================================
794 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneFace
795                        (Handle(GEOM_Object) theFace, double theSize)
796 {
797   SetErrorCode(KO);
798
799   if (theFace.IsNull()) return NULL;
800
801   //Add a new Plane object
802   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
803
804   //Add a new Plane function
805   Handle(GEOM_Function) aFunction =
806     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_FACE);
807
808   //Check if the function is set correctly
809   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
810
811   GEOMImpl_IPlane aPI (aFunction);
812
813   Handle(GEOM_Function) aRef = theFace->GetLastFunction();
814   if (aRef.IsNull()) return NULL;
815
816   aPI.SetFace(aRef);
817   aPI.SetSize(theSize);
818
819   //Compute the Plane value
820   try {
821 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
822     OCC_CATCH_SIGNALS;
823 #endif
824     if (!GetSolver()->ComputeFunction(aFunction)) {
825       SetErrorCode("Plane driver failed");
826       return NULL;
827     }
828   }
829   catch (Standard_Failure) {
830     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
831     SetErrorCode(aFail->GetMessageString());
832     return NULL;
833   }
834
835   //Make a Python command
836   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneFace("
837                                << theFace << ", " << theSize << ")";
838
839   SetErrorCode(OK);
840   return aPlane;
841 }
842
843
844 //=============================================================================
845 /*!
846  *  MakeMarker
847  */
848 //=============================================================================
849 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeMarker
850                                   (double theOX,  double theOY,  double theOZ,
851                                    double theXDX, double theXDY, double theXDZ,
852                                    double theYDX, double theYDY, double theYDZ)
853 {
854   SetErrorCode(KO);
855
856   //Add a new Marker object
857   Handle(GEOM_Object) aMarker = GetEngine()->AddObject(GetDocID(), GEOM_MARKER);
858
859   //Add a new Marker function
860   Handle(GEOM_Function) aFunction =
861     aMarker->AddFunction(GEOMImpl_MarkerDriver::GetID(), MARKER_CS);
862   if (aFunction.IsNull()) return NULL;
863
864   //Check if the function is set correctly
865   if (aFunction->GetDriverGUID() != GEOMImpl_MarkerDriver::GetID()) return NULL;
866
867   GEOMImpl_IMarker aPI(aFunction);
868
869   aPI.SetOrigin(theOX, theOY, theOZ);
870   aPI.SetXDir(theXDX, theXDY, theXDZ);
871   aPI.SetYDir(theYDX, theYDY, theYDZ);
872
873   //Compute the marker value
874   try {
875 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
876     OCC_CATCH_SIGNALS;
877 #endif
878     if (!GetSolver()->ComputeFunction(aFunction)) {
879       SetErrorCode("Marker driver failed");
880       return NULL;
881     }
882   }
883   catch (Standard_Failure) {
884     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
885     SetErrorCode(aFail->GetMessageString());
886     return NULL;
887   }
888
889   //Make a Python command
890   GEOM::TPythonDump(aFunction) << aMarker << " = geompy.MakeMarker("
891     << theOX << ", " << theOY << ", " << theOZ << ", "
892       << theXDX << ", " << theXDY << ", " << theXDZ << ", "
893         << theYDX << ", " << theYDY << ", " << theYDZ << ")";
894
895   SetErrorCode(OK);
896   return aMarker;
897 }
898
899 //=============================================================================
900 /*!
901  *  MakeTangentPlaneOnFace
902  */
903 //=============================================================================
904
905 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeTangentPlaneOnFace(const Handle(GEOM_Object)& theFace,
906                                                                       double theParamU,
907                                                                       double theParamV,
908                                                                       double theSize)
909 {
910    SetErrorCode(KO);
911
912   if (theFace.IsNull()) return NULL;
913
914   //Add a new Plane object
915   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
916
917   //Add a new Plane function
918   Handle(GEOM_Function) aFunction =
919     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_TANGENT_FACE);
920
921   //Check if the function is set correctly
922   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
923
924   GEOMImpl_IPlane aPI (aFunction);
925
926   Handle(GEOM_Function) aRef = theFace->GetLastFunction();
927   if (aRef.IsNull()) return NULL;
928
929   aPI.SetFace(aRef);
930   aPI.SetSize(theSize);
931   aPI.SetParameterU(theParamU);
932   aPI.SetParameterV(theParamV);
933
934   //Compute the Plane value
935   try {
936 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
937     OCC_CATCH_SIGNALS;
938 #endif
939     if (!GetSolver()->ComputeFunction(aFunction)) {
940       SetErrorCode("Plane driver failed");
941       return NULL;
942     }
943   }
944   catch (Standard_Failure) {
945     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
946     SetErrorCode(aFail->GetMessageString());
947     return NULL;
948   }
949
950   //Make a Python command
951   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakeTangentPlaneOnFace("
952                                << theFace << ", " <<theParamU <<", "<<theParamV <<", "<< theSize << ")";
953
954   SetErrorCode(OK);
955   return aPlane;
956 }
957
958