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