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