Salome HOME
IMP 0016175: EDF455: Save GUIState don't redisplay the objects.
[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 /*!
237  *  MakePointOnSurface
238  */
239 //=============================================================================
240 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnSurface
241    (Handle(GEOM_Object) theSurface, double theUParameter, double theVParameter)
242 {
243   SetErrorCode(KO);
244
245   if (theSurface.IsNull()) return NULL;
246
247   //Add a new Point object
248   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
249
250   //Add a new Point function for creation a point relativley another point
251   Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(),
252                                                         POINT_SURFACE_PAR);
253
254   //Check if the function is set correctly
255   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
256
257   GEOMImpl_IPoint aPI (aFunction);
258
259   Handle(GEOM_Function) aRefFunction = theSurface->GetLastFunction();
260   if (aRefFunction.IsNull()) return NULL;
261
262   aPI.SetSurface(aRefFunction);
263   aPI.SetParameter(theUParameter);
264   aPI.SetParameter2(theVParameter);
265
266   //Compute the point value
267   try {
268 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
269     OCC_CATCH_SIGNALS;
270 #endif
271     if (!GetSolver()->ComputeFunction(aFunction)) {
272       SetErrorCode("Point driver failed");
273       return NULL;
274     }
275   }
276   catch (Standard_Failure) {
277     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
278     SetErrorCode(aFail->GetMessageString());
279     return NULL;
280   }
281
282   //Make a Python command
283   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnSurface("
284                                << theSurface << ", " << theUParameter 
285                                << ", " << theVParameter << ")";
286
287   SetErrorCode(OK);
288   return aPoint;
289 }
290
291
292 //=============================================================================
293 /*!
294  *  MakePointOnLinesIntersection
295  */
296 //=============================================================================
297 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnLinesIntersection
298                             (Handle(GEOM_Object) theLine1, Handle(GEOM_Object) theLine2)
299 {
300   SetErrorCode(KO);
301
302   if (theLine1.IsNull() || theLine2.IsNull()) return NULL;
303
304   //Add a new Point object
305   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
306
307   //Add a new Point function for creation a point relativley another point
308   Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_LINES_INTERSECTION);
309
310   //Check if the function is set correctly
311   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
312
313   GEOMImpl_IPoint aPI (aFunction);
314
315   Handle(GEOM_Function) aRef1 = theLine1->GetLastFunction();
316   Handle(GEOM_Function) aRef2 = theLine2->GetLastFunction();
317   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
318
319   aPI.SetLine1(aRef1);
320   aPI.SetLine2(aRef2);
321
322   //Compute the point value
323   try {
324 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
325     OCC_CATCH_SIGNALS;
326 #endif
327     if (!GetSolver()->ComputeFunction(aFunction)) {
328       SetErrorCode("Point driver failed");
329       return NULL;
330     }
331   }
332   catch (Standard_Failure) {
333     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
334     SetErrorCode(aFail->GetMessageString());
335     return NULL;
336   }
337
338   //Make a Python command
339   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnLinesIntersection("
340                                << theLine1 << ", " << theLine2 << ")";
341
342   SetErrorCode(OK);
343   return aPoint;
344 }
345
346 //=============================================================================
347 /*!
348  *  MakeTangentOnCurve
349  */
350 //=============================================================================
351 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeTangentOnCurve
352                             (const Handle(GEOM_Object)& theCurve, double theParameter)
353 {
354   SetErrorCode(KO);
355
356   if (theCurve.IsNull()) return NULL;
357
358   //Add a new Vector object
359   Handle(GEOM_Object) aVec = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
360
361   //Add a new Point function for creation a point relativley another point
362   Handle(GEOM_Function) aFunction = aVec->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TANGENT_CURVE_PAR);
363
364   //Check if the function is set correctly
365   if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
366
367   GEOMImpl_IVector aVI (aFunction);
368
369   Handle(GEOM_Function) aRefFunction = theCurve->GetLastFunction();
370   if (aRefFunction.IsNull()) return NULL;
371
372   aVI.SetCurve(aRefFunction);
373   aVI.SetParameter(theParameter);
374
375   //Compute the vector 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("Vector 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) << aVec << " = geompy.MakeTangentOnCurve("
393                                << theCurve << ", " << theParameter << ")";
394
395   SetErrorCode(OK);
396   return aVec;
397 }
398
399 //=============================================================================
400 /*!
401  *  MakeVectorDXDYDZ
402  */
403 //=============================================================================
404 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorDXDYDZ
405                                      (double theDX, double theDY, double theDZ)
406 {
407   SetErrorCode(KO);
408
409   //Add a new Vector object
410   Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
411
412   //Add a new Vector function with DXDYDZ parameters
413   Handle(GEOM_Function) aFunction =
414     aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_DX_DY_DZ);
415   if (aFunction.IsNull()) return NULL;
416
417   //Check if the function is set correctly
418   if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
419
420   GEOMImpl_IVector aPI (aFunction);
421
422   aPI.SetDX(theDX);
423   aPI.SetDY(theDY);
424   aPI.SetDZ(theDZ);
425
426   //Compute the Vector value
427   try {
428 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
429     OCC_CATCH_SIGNALS;
430 #endif
431     if (!GetSolver()->ComputeFunction(aFunction)) {
432       SetErrorCode("Vector driver failed");
433       return NULL;
434     }
435   }
436   catch (Standard_Failure) {
437     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
438     SetErrorCode(aFail->GetMessageString());
439     return NULL;
440   }
441
442   //Make a Python command
443   GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVectorDXDYDZ("
444     << theDX << ", " << theDY << ", " << theDZ << ")";
445
446   SetErrorCode(OK);
447   return aVector;
448 }
449
450 //=============================================================================
451 /*!
452  *  MakeVectorTwoPnt
453  */
454 //=============================================================================
455 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorTwoPnt
456                      (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
457 {
458   SetErrorCode(KO);
459
460   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
461
462   //Add a new Vector object
463   Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
464
465   //Add a new Vector function
466   Handle(GEOM_Function) aFunction =
467     aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TWO_PNT);
468
469   //Check if the function is set correctly
470   if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
471
472   GEOMImpl_IVector aPI (aFunction);
473
474   Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
475   Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
476   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
477
478   aPI.SetPoint1(aRef1);
479   aPI.SetPoint2(aRef2);
480
481   //Compute the Vector value
482   try {
483 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
484     OCC_CATCH_SIGNALS;
485 #endif
486     if (!GetSolver()->ComputeFunction(aFunction)) {
487       SetErrorCode("Vector driver failed");
488       return NULL;
489     }
490   }
491   catch (Standard_Failure) {
492     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
493     SetErrorCode(aFail->GetMessageString());
494     return NULL;
495   }
496
497   //Make a Python command
498   GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVector("
499                                << thePnt1 << ", " << thePnt2 << ")";
500
501   SetErrorCode(OK);
502   return aVector;
503 }
504
505
506 //=============================================================================
507 /*!
508  *  MakeLine
509  */
510 //=============================================================================
511 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLine
512                      (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theDir)
513 {
514   SetErrorCode(KO);
515
516   if (thePnt.IsNull() || theDir.IsNull()) return NULL;
517
518   //Add a new Line object
519   Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
520
521   //Add a new Line function
522   Handle(GEOM_Function) aFunction =
523     aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_PNT_DIR);
524
525   //Check if the function is set correctly
526   if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
527
528   GEOMImpl_ILine aPI (aFunction);
529
530   Handle(GEOM_Function) aRef1 = thePnt->GetLastFunction();
531   Handle(GEOM_Function) aRef2 = theDir->GetLastFunction();
532   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
533
534   aPI.SetPoint1(aRef1);
535   aPI.SetPoint2(aRef2);
536
537   //Compute the Line value
538   try {
539 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
540     OCC_CATCH_SIGNALS;
541 #endif
542     if (!GetSolver()->ComputeFunction(aFunction)) {
543       SetErrorCode("Line driver failed");
544       return NULL;
545     }
546   }
547   catch (Standard_Failure) {
548     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
549     SetErrorCode(aFail->GetMessageString());
550     return NULL;
551   }
552
553   //Make a Python command
554   GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLine("
555                                << thePnt << ", " << theDir << ")";
556
557   SetErrorCode(OK);
558   return aLine;
559 }
560
561 //=============================================================================
562 /*!
563  *  MakeLineTwoPnt
564  */
565 //=============================================================================
566 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLineTwoPnt
567                      (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
568 {
569   SetErrorCode(KO);
570
571   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
572
573   //Add a new Line object
574   Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
575
576   //Add a new Line function
577   Handle(GEOM_Function) aFunction =
578     aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_TWO_PNT);
579
580   //Check if the function is set correctly
581   if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
582
583   GEOMImpl_ILine aPI (aFunction);
584
585   Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
586   Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
587   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
588
589   aPI.SetPoint1(aRef1);
590   aPI.SetPoint2(aRef2);
591
592   //Compute the Line value
593   try {
594 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
595     OCC_CATCH_SIGNALS;
596 #endif
597     if (!GetSolver()->ComputeFunction(aFunction)) {
598       SetErrorCode("Line driver failed");
599       return NULL;
600     }
601   }
602   catch (Standard_Failure) {
603     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
604     SetErrorCode(aFail->GetMessageString());
605     return NULL;
606   }
607
608   //Make a Python command
609   GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLineTwoPnt("
610                                << thePnt1 << ", " << thePnt2 << ")";
611
612   SetErrorCode(OK);
613   return aLine;
614 }
615
616 //=============================================================================
617 /*!
618  *  MakeLineTwoFaces
619  */
620 //=============================================================================
621 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLineTwoFaces
622                      (Handle(GEOM_Object) theFace1, Handle(GEOM_Object) theFace2)
623 {
624   SetErrorCode(KO);
625
626   if (theFace1.IsNull() || theFace2.IsNull()) return NULL;
627
628   //Add a new Line object
629   Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
630
631   //Add a new Line function
632   Handle(GEOM_Function) aFunction =
633     aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_TWO_FACES);
634
635   //Check if the function is set correctly
636   if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
637
638   GEOMImpl_ILine aPI (aFunction);
639
640   Handle(GEOM_Function) aRef1 = theFace1->GetLastFunction();
641   Handle(GEOM_Function) aRef2 = theFace2->GetLastFunction();
642   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
643
644   aPI.SetFace1(aRef1);
645   aPI.SetFace2(aRef2);
646
647   //Compute the Line value
648   try {
649 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
650     OCC_CATCH_SIGNALS;
651 #endif
652     if (!GetSolver()->ComputeFunction(aFunction)) {
653       SetErrorCode("Line driver failed");
654       return NULL;
655     }
656   }
657   catch (Standard_Failure) {
658     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
659     SetErrorCode(aFail->GetMessageString());
660     return NULL;
661   }
662
663   //Make a Python command
664   GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLineTwoFaces("
665                                << theFace1 << ", " << theFace2 << ")";
666
667   SetErrorCode(OK);
668   return aLine;
669 }
670
671 //=============================================================================
672 /*!
673  *  MakePlaneThreePnt
674  */
675 //=============================================================================
676 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneThreePnt
677                      (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2,
678                       Handle(GEOM_Object) thePnt3, double theSize)
679 {
680   SetErrorCode(KO);
681
682   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
683
684   //Add a new Plane object
685   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
686
687   //Add a new Plane function
688   Handle(GEOM_Function) aFunction =
689     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_THREE_PNT);
690
691   //Check if the function is set correctly
692   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
693
694   GEOMImpl_IPlane aPI (aFunction);
695
696   Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
697   Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
698   Handle(GEOM_Function) aRef3 = thePnt3->GetLastFunction();
699   if (aRef1.IsNull() || aRef2.IsNull() || aRef3.IsNull()) return NULL;
700
701   aPI.SetPoint1(aRef1);
702   aPI.SetPoint2(aRef2);
703   aPI.SetPoint3(aRef3);
704   aPI.SetSize(theSize);
705
706   //Compute the Plane value
707   try {
708 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
709     OCC_CATCH_SIGNALS;
710 #endif
711     if (!GetSolver()->ComputeFunction(aFunction)) {
712       SetErrorCode("Plane driver failed");
713       return NULL;
714     }
715   }
716   catch (Standard_Failure) {
717     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
718     SetErrorCode(aFail->GetMessageString());
719     return NULL;
720   }
721
722   //Make a Python command
723   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneThreePnt("
724     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ", " << theSize << ")";
725
726   SetErrorCode(OK);
727   return aPlane;
728 }
729
730 //=============================================================================
731 /*!
732  *  MakePlanePntVec
733  */
734 //=============================================================================
735 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlanePntVec
736                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
737                         double theSize)
738 {
739   SetErrorCode(KO);
740
741   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
742
743   //Add a new Plane object
744   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
745
746   //Add a new Plane function
747   Handle(GEOM_Function) aFunction =
748     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_PNT_VEC);
749
750   //Check if the function is set correctly
751   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
752
753   GEOMImpl_IPlane aPI (aFunction);
754
755   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
756   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
757   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
758
759   aPI.SetPoint(aRefPnt);
760   aPI.SetVector(aRefVec);
761   aPI.SetSize(theSize);
762
763   //Compute the Plane value
764   try {
765 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
766     OCC_CATCH_SIGNALS;
767 #endif
768     if (!GetSolver()->ComputeFunction(aFunction)) {
769       SetErrorCode("Plane driver failed");
770       return NULL;
771     }
772   }
773   catch (Standard_Failure) {
774     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
775     SetErrorCode(aFail->GetMessageString());
776     return NULL;
777   }
778
779   //Make a Python command
780   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlane("
781     << thePnt << ", " << theVec << ", " << theSize << ")";
782
783   SetErrorCode(OK);
784   return aPlane;
785 }
786
787 //=============================================================================
788 /*!
789  *  MakePlaneFace
790  */
791 //=============================================================================
792 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneFace
793                        (Handle(GEOM_Object) theFace, double theSize)
794 {
795   SetErrorCode(KO);
796
797   if (theFace.IsNull()) return NULL;
798
799   //Add a new Plane object
800   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
801
802   //Add a new Plane function
803   Handle(GEOM_Function) aFunction =
804     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_FACE);
805
806   //Check if the function is set correctly
807   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
808
809   GEOMImpl_IPlane aPI (aFunction);
810
811   Handle(GEOM_Function) aRef = theFace->GetLastFunction();
812   if (aRef.IsNull()) return NULL;
813
814   aPI.SetFace(aRef);
815   aPI.SetSize(theSize);
816
817   //Compute the Plane value
818   try {
819 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
820     OCC_CATCH_SIGNALS;
821 #endif
822     if (!GetSolver()->ComputeFunction(aFunction)) {
823       SetErrorCode("Plane driver failed");
824       return NULL;
825     }
826   }
827   catch (Standard_Failure) {
828     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
829     SetErrorCode(aFail->GetMessageString());
830     return NULL;
831   }
832
833   //Make a Python command
834   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneFace("
835                                << theFace << ", " << theSize << ")";
836
837   SetErrorCode(OK);
838   return aPlane;
839 }
840
841
842 //=============================================================================
843 /*!
844  *  MakeMarker
845  */
846 //=============================================================================
847 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeMarker
848                                   (double theOX,  double theOY,  double theOZ,
849                                    double theXDX, double theXDY, double theXDZ,
850                                    double theYDX, double theYDY, double theYDZ)
851 {
852   SetErrorCode(KO);
853
854   //Add a new Marker object
855   Handle(GEOM_Object) aMarker = GetEngine()->AddObject(GetDocID(), GEOM_MARKER);
856
857   //Add a new Marker function
858   Handle(GEOM_Function) aFunction =
859     aMarker->AddFunction(GEOMImpl_MarkerDriver::GetID(), MARKER_CS);
860   if (aFunction.IsNull()) return NULL;
861
862   //Check if the function is set correctly
863   if (aFunction->GetDriverGUID() != GEOMImpl_MarkerDriver::GetID()) return NULL;
864
865   GEOMImpl_IMarker aPI(aFunction);
866
867   aPI.SetOrigin(theOX, theOY, theOZ);
868   aPI.SetXDir(theXDX, theXDY, theXDZ);
869   aPI.SetYDir(theYDX, theYDY, theYDZ);
870
871   //Compute the marker value
872   try {
873 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
874     OCC_CATCH_SIGNALS;
875 #endif
876     if (!GetSolver()->ComputeFunction(aFunction)) {
877       SetErrorCode("Marker driver failed");
878       return NULL;
879     }
880   }
881   catch (Standard_Failure) {
882     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
883     SetErrorCode(aFail->GetMessageString());
884     return NULL;
885   }
886
887   //Make a Python command
888   GEOM::TPythonDump(aFunction) << aMarker << " = geompy.MakeMarker("
889     << theOX << ", " << theOY << ", " << theOZ << ", "
890       << theXDX << ", " << theXDY << ", " << theXDZ << ", "
891         << theYDX << ", " << theYDY << ", " << theYDZ << ")";
892
893   SetErrorCode(OK);
894   return aMarker;
895 }
896
897 //=============================================================================
898 /*!
899  *  MakeTangentPlaneOnFace
900  */
901 //=============================================================================
902
903 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeTangentPlaneOnFace(const Handle(GEOM_Object)& theFace,
904                                                                       double theParamU,
905                                                                       double theParamV,
906                                                                       double theSize)
907 {
908    SetErrorCode(KO);
909
910   if (theFace.IsNull()) return NULL;
911
912   //Add a new Plane object
913   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
914
915   //Add a new Plane function
916   Handle(GEOM_Function) aFunction =
917     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_TANGENT_FACE);
918
919   //Check if the function is set correctly
920   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
921
922   GEOMImpl_IPlane aPI (aFunction);
923
924   Handle(GEOM_Function) aRef = theFace->GetLastFunction();
925   if (aRef.IsNull()) return NULL;
926
927   aPI.SetFace(aRef);
928   aPI.SetSize(theSize);
929   aPI.SetParameterU(theParamU);
930   aPI.SetParameterV(theParamV);
931
932   //Compute the Plane value
933   try {
934 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
935     OCC_CATCH_SIGNALS;
936 #endif
937     if (!GetSolver()->ComputeFunction(aFunction)) {
938       SetErrorCode("Plane driver failed");
939       return NULL;
940     }
941   }
942   catch (Standard_Failure) {
943     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
944     SetErrorCode(aFail->GetMessageString());
945     return NULL;
946   }
947
948   //Make a Python command
949   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakeTangentPlaneOnFace("
950                                << theFace << ", " <<theParamU <<", "<<theParamV <<", "<< theSize << ")";
951
952   SetErrorCode(OK);
953   return aPlane;
954 }
955
956