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