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