]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_IBasicOperations.cxx
Salome HOME
SMH: Merged GEOM (NEWGUI, HEAD, POLYWORK)
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IBasicOperations.cxx
1 using namespace std;
2
3 #include "GEOMImpl_IBasicOperations.hxx"
4
5 #include "utilities.h"
6 #include "OpUtil.hxx"
7 #include "Utils_ExceptHandlers.hxx"
8
9 #include <TFunction_DriverTable.hxx>
10 #include <TFunction_Driver.hxx>
11 #include <TFunction_Logbook.hxx>
12 #include <TDF_Tool.hxx>
13
14 #include "GEOM_Function.hxx"
15 #include "GEOM_PythonDump.hxx"
16
17 #include "GEOMImpl_PointDriver.hxx"
18 #include "GEOMImpl_VectorDriver.hxx"
19 #include "GEOMImpl_LineDriver.hxx"
20 #include "GEOMImpl_PlaneDriver.hxx"
21 #include "GEOMImpl_MarkerDriver.hxx"
22
23 #include "GEOMImpl_IPoint.hxx"
24 #include "GEOMImpl_IVector.hxx"
25 #include "GEOMImpl_ILine.hxx"
26 #include "GEOMImpl_IPlane.hxx"
27 #include "GEOMImpl_IMarker.hxx"
28
29 #include "GEOMImpl_Types.hxx"
30
31 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
32
33 //=============================================================================
34 /*!
35  *   constructor:
36  */
37 //=============================================================================
38 GEOMImpl_IBasicOperations::GEOMImpl_IBasicOperations(GEOM_Engine* theEngine, int theDocID)
39 : GEOM_IOperations(theEngine, theDocID)
40 {
41   MESSAGE("GEOMImpl_IBasicOperations::GEOMImpl_IBasicOperations");
42 }
43
44 //=============================================================================
45 /*!
46  *  destructor
47  */
48 //=============================================================================
49 GEOMImpl_IBasicOperations::~GEOMImpl_IBasicOperations()
50 {
51   MESSAGE("GEOMImpl_IBasicOperations::~GEOMImpl_IBasicOperations");
52 }
53
54
55 //=============================================================================
56 /*!
57  *  MakePointXYZ
58  */
59 //=============================================================================
60 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointXYZ
61                                         (double theX, double theY, double theZ)
62 {
63   SetErrorCode(KO);
64
65   //Add a new Point object
66   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
67
68   //Add a new Point function with XYZ parameters
69   Handle(GEOM_Function) aFunction =
70     aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_XYZ);
71   if (aFunction.IsNull()) return NULL;
72
73   //Check if the function is set correctly
74   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
75
76   GEOMImpl_IPoint aPI(aFunction);
77
78   aPI.SetX(theX);
79   aPI.SetY(theY);
80   aPI.SetZ(theZ);
81
82   //Compute the point value
83   try {
84     if (!GetSolver()->ComputeFunction(aFunction)) {
85       SetErrorCode("Point driver failed");
86       return NULL;
87     }
88   }
89   catch (Standard_Failure) {
90     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
91     SetErrorCode(aFail->GetMessageString());
92     return NULL;
93   }
94
95   //Make a Python command
96   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertex("
97     << theX << ", " << theY << ", " << theZ << ")";
98
99   SetErrorCode(OK);
100   return aPoint;
101 }
102
103 //=============================================================================
104 /*!
105  *  MakePointWithReference
106  */
107 //=============================================================================
108 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointWithReference
109       (Handle(GEOM_Object) theReference, double theX, double theY, double theZ)
110 {
111   SetErrorCode(KO);
112
113   if (theReference.IsNull()) return NULL;
114
115   //Add a new Point object
116   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
117
118   //Add a new Point function for creation a point relativley another point
119   Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_XYZ_REF);
120
121   //Check if the function is set correctly
122   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
123
124   GEOMImpl_IPoint aPI(aFunction);
125
126   Handle(GEOM_Function) aRefFunction = theReference->GetLastFunction();
127   if (aRefFunction.IsNull()) return NULL;
128
129   aPI.SetRef(aRefFunction);
130   aPI.SetX(theX);
131   aPI.SetY(theY);
132   aPI.SetZ(theZ);
133
134   //Compute the point value
135   try {
136     if (!GetSolver()->ComputeFunction(aFunction)) {
137       SetErrorCode("Point driver failed");
138       return NULL;
139     }
140   }
141   catch (Standard_Failure) {
142     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
143     SetErrorCode(aFail->GetMessageString());
144     return NULL;
145   }
146
147   //Make a Python command
148   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexWithRef("
149     << theReference << ", " << theX << ", " << theY << ", " << theZ << ")";
150
151   SetErrorCode(OK);
152   return aPoint;
153 }
154
155 //=============================================================================
156 /*!
157  *  MakePointOnCurve
158  */
159 //=============================================================================
160 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnCurve
161                             (Handle(GEOM_Object) theCurve, double theParameter)
162 {
163   SetErrorCode(KO);
164
165   if (theCurve.IsNull()) return NULL;
166
167   //Add a new Point object
168   Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
169
170   //Add a new Point function for creation a point relativley another point
171   Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_CURVE_PAR);
172
173   //Check if the function is set correctly
174   if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
175
176   GEOMImpl_IPoint aPI (aFunction);
177
178   Handle(GEOM_Function) aRefFunction = theCurve->GetLastFunction();
179   if (aRefFunction.IsNull()) return NULL;
180
181   aPI.SetCurve(aRefFunction);
182   aPI.SetParameter(theParameter);
183
184   //Compute the point value
185   try {
186     if (!GetSolver()->ComputeFunction(aFunction)) {
187       SetErrorCode("Point driver failed");
188       return NULL;
189     }
190   }
191   catch (Standard_Failure) {
192     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
193     SetErrorCode(aFail->GetMessageString());
194     return NULL;
195   }
196
197   //Make a Python command
198   GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurve("
199                                << theCurve << ", " << theParameter << ")";
200
201   SetErrorCode(OK);
202   return aPoint;
203 }
204
205
206 //=============================================================================
207 /*!
208  *  MakeVectorDXDYDZ
209  */
210 //=============================================================================
211 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorDXDYDZ
212                                      (double theDX, double theDY, double theDZ)
213 {
214   SetErrorCode(KO);
215
216   //Add a new Vector object
217   Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
218
219   //Add a new Vector function with DXDYDZ parameters
220   Handle(GEOM_Function) aFunction =
221     aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_DX_DY_DZ);
222   if (aFunction.IsNull()) return NULL;
223
224   //Check if the function is set correctly
225   if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
226
227   GEOMImpl_IVector aPI (aFunction);
228
229   aPI.SetDX(theDX);
230   aPI.SetDY(theDY);
231   aPI.SetDZ(theDZ);
232
233   //Compute the Vector value
234   try {
235     if (!GetSolver()->ComputeFunction(aFunction)) {
236       SetErrorCode("Vector driver failed");
237       return NULL;
238     }
239   }
240   catch (Standard_Failure) {
241     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
242     SetErrorCode(aFail->GetMessageString());
243     return NULL;
244   }
245
246   //Make a Python command
247   GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVectorDXDYDZ("
248     << theDX << ", " << theDY << ", " << theDZ << ")";
249
250   SetErrorCode(OK);
251   return aVector;
252 }
253
254 //=============================================================================
255 /*!
256  *  MakeVectorTwoPnt
257  */
258 //=============================================================================
259 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorTwoPnt
260                      (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
261 {
262   SetErrorCode(KO);
263
264   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
265
266   //Add a new Vector object
267   Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
268
269   //Add a new Vector function
270   Handle(GEOM_Function) aFunction =
271     aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TWO_PNT);
272
273   //Check if the function is set correctly
274   if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
275
276   GEOMImpl_IVector aPI (aFunction);
277
278   Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
279   Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
280   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
281
282   aPI.SetPoint1(aRef1);
283   aPI.SetPoint2(aRef2);
284
285   //Compute the Vector value
286   try {
287     if (!GetSolver()->ComputeFunction(aFunction)) {
288       SetErrorCode("Vector driver failed");
289       return NULL;
290     }
291   }
292   catch (Standard_Failure) {
293     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
294     SetErrorCode(aFail->GetMessageString());
295     return NULL;
296   }
297
298   //Make a Python command
299   GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVector("
300                                << thePnt1 << ", " << thePnt2 << ")";
301
302   SetErrorCode(OK);
303   return aVector;
304 }
305
306
307 //=============================================================================
308 /*!
309  *  MakeLine
310  */
311 //=============================================================================
312 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLine
313                      (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theDir)
314 {
315   SetErrorCode(KO);
316
317   if (thePnt.IsNull() || theDir.IsNull()) return NULL;
318
319   //Add a new Line object
320   Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
321
322   //Add a new Line function
323   Handle(GEOM_Function) aFunction =
324     aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_PNT_DIR);
325
326   //Check if the function is set correctly
327   if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
328
329   GEOMImpl_ILine aPI (aFunction);
330
331   Handle(GEOM_Function) aRef1 = thePnt->GetLastFunction();
332   Handle(GEOM_Function) aRef2 = theDir->GetLastFunction();
333   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
334
335   aPI.SetPoint1(aRef1);
336   aPI.SetPoint2(aRef2);
337
338   //Compute the Line value
339   try {
340     if (!GetSolver()->ComputeFunction(aFunction)) {
341       SetErrorCode("Line driver failed");
342       return NULL;
343     }
344   }
345   catch (Standard_Failure) {
346     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
347     SetErrorCode(aFail->GetMessageString());
348     return NULL;
349   }
350
351   //Make a Python command
352   GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLine("
353                                << thePnt << ", " << theDir << ")";
354
355   SetErrorCode(OK);
356   return aLine;
357 }
358
359 //=============================================================================
360 /*!
361  *  MakeLineTwoPnt
362  */
363 //=============================================================================
364 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLineTwoPnt
365                      (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
366 {
367   SetErrorCode(KO);
368
369   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
370
371   //Add a new Line object
372   Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
373
374   //Add a new Line function
375   Handle(GEOM_Function) aFunction =
376     aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_TWO_PNT);
377
378   //Check if the function is set correctly
379   if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
380
381   GEOMImpl_ILine aPI (aFunction);
382
383   Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
384   Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
385   if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
386
387   aPI.SetPoint1(aRef1);
388   aPI.SetPoint2(aRef2);
389
390   //Compute the Line value
391   try {
392     if (!GetSolver()->ComputeFunction(aFunction)) {
393       SetErrorCode("Line driver failed");
394       return NULL;
395     }
396   }
397   catch (Standard_Failure) {
398     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
399     SetErrorCode(aFail->GetMessageString());
400     return NULL;
401   }
402
403   //Make a Python command
404   GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLineTwoPnt("
405                                << thePnt1 << ", " << thePnt2 << ")";
406
407   SetErrorCode(OK);
408   return aLine;
409 }
410
411
412 //=============================================================================
413 /*!
414  *  MakePlaneThreePnt
415  */
416 //=============================================================================
417 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneThreePnt
418                      (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2,
419                       Handle(GEOM_Object) thePnt3, double theSize)
420 {
421   SetErrorCode(KO);
422
423   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
424
425   //Add a new Plane object
426   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
427
428   //Add a new Plane function
429   Handle(GEOM_Function) aFunction =
430     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_THREE_PNT);
431
432   //Check if the function is set correctly
433   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
434
435   GEOMImpl_IPlane aPI (aFunction);
436
437   Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
438   Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
439   Handle(GEOM_Function) aRef3 = thePnt3->GetLastFunction();
440   if (aRef1.IsNull() || aRef2.IsNull() || aRef3.IsNull()) return NULL;
441
442   aPI.SetPoint1(aRef1);
443   aPI.SetPoint2(aRef2);
444   aPI.SetPoint3(aRef3);
445   aPI.SetSize(theSize);
446
447   //Compute the Plane value
448   try {
449     if (!GetSolver()->ComputeFunction(aFunction)) {
450       SetErrorCode("Plane driver failed");
451       return NULL;
452     }
453   }
454   catch (Standard_Failure) {
455     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
456     SetErrorCode(aFail->GetMessageString());
457     return NULL;
458   }
459
460   //Make a Python command
461   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneThreePnt("
462     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ", " << theSize << ")";
463
464   SetErrorCode(OK);
465   return aPlane;
466 }
467
468 //=============================================================================
469 /*!
470  *  MakePlanePntVec
471  */
472 //=============================================================================
473 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlanePntVec
474                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
475                         double theSize)
476 {
477   SetErrorCode(KO);
478
479   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
480
481   //Add a new Plane object
482   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
483
484   //Add a new Plane function
485   Handle(GEOM_Function) aFunction =
486     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_PNT_VEC);
487
488   //Check if the function is set correctly
489   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
490
491   GEOMImpl_IPlane aPI (aFunction);
492
493   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
494   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
495   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
496
497   aPI.SetPoint(aRefPnt);
498   aPI.SetVector(aRefVec);
499   aPI.SetSize(theSize);
500
501   //Compute the Plane value
502   try {
503     if (!GetSolver()->ComputeFunction(aFunction)) {
504       SetErrorCode("Plane driver failed");
505       return NULL;
506     }
507   }
508   catch (Standard_Failure) {
509     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
510     SetErrorCode(aFail->GetMessageString());
511     return NULL;
512   }
513
514   //Make a Python command
515   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlane("
516     << thePnt << ", " << theVec << ", " << theSize << ")";
517
518   SetErrorCode(OK);
519   return aPlane;
520 }
521
522 //=============================================================================
523 /*!
524  *  MakePlaneFace
525  */
526 //=============================================================================
527 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneFace
528                        (Handle(GEOM_Object) theFace, double theSize)
529 {
530   SetErrorCode(KO);
531
532   if (theFace.IsNull()) return NULL;
533
534   //Add a new Plane object
535   Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
536
537   //Add a new Plane function
538   Handle(GEOM_Function) aFunction =
539     aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_FACE);
540
541   //Check if the function is set correctly
542   if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
543
544   GEOMImpl_IPlane aPI (aFunction);
545
546   Handle(GEOM_Function) aRef = theFace->GetLastFunction();
547   if (aRef.IsNull()) return NULL;
548
549   aPI.SetFace(aRef);
550   aPI.SetSize(theSize);
551
552   //Compute the Plane value
553   try {
554     if (!GetSolver()->ComputeFunction(aFunction)) {
555       SetErrorCode("Plane driver failed");
556       return NULL;
557     }
558   }
559   catch (Standard_Failure) {
560     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
561     SetErrorCode(aFail->GetMessageString());
562     return NULL;
563   }
564
565   //Make a Python command
566   GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneFace("
567                                << theFace << ", " << theSize << ")";
568
569   SetErrorCode(OK);
570   return aPlane;
571 }
572
573
574 //=============================================================================
575 /*!
576  *  MakeMarker
577  */
578 //=============================================================================
579 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeMarker
580                                   (double theOX,  double theOY,  double theOZ,
581                                    double theXDX, double theXDY, double theXDZ,
582                                    double theYDX, double theYDY, double theYDZ)
583 {
584   SetErrorCode(KO);
585
586   //Add a new Marker object
587   Handle(GEOM_Object) aMarker = GetEngine()->AddObject(GetDocID(), GEOM_MARKER);
588
589   //Add a new Marker function
590   Handle(GEOM_Function) aFunction =
591     aMarker->AddFunction(GEOMImpl_MarkerDriver::GetID(), MARKER_CS);
592   if (aFunction.IsNull()) return NULL;
593
594   //Check if the function is set correctly
595   if (aFunction->GetDriverGUID() != GEOMImpl_MarkerDriver::GetID()) return NULL;
596
597   GEOMImpl_IMarker aPI(aFunction);
598
599   aPI.SetOrigin(theOX, theOY, theOZ);
600   aPI.SetXDir(theXDX, theXDY, theXDZ);
601   aPI.SetYDir(theYDX, theYDY, theYDZ);
602
603   //Compute the marker value
604   try {
605     if (!GetSolver()->ComputeFunction(aFunction)) {
606       SetErrorCode("Marker driver failed");
607       return NULL;
608     }
609   }
610   catch (Standard_Failure) {
611     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
612     SetErrorCode(aFail->GetMessageString());
613     return NULL;
614   }
615
616   //Make a Python command
617   GEOM::TPythonDump(aFunction) << aMarker << " = geompy.MakeMarker("
618     << theOX << ", " << theOY << ", " << theOZ << ", "
619       << theXDX << ", " << theXDY << ", " << theXDZ << ", "
620         << theYDX << ", " << theYDY << ", " << theYDZ << ")";
621
622   SetErrorCode(OK);
623   return aMarker;
624 }