Salome HOME
Merge from V5_1_4_BR 07/05/2010
[modules/geom.git] / src / GEOM_I / GEOM_ICurvesOperations_i.cc
1 //  Copyright (C) 2007-2010  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 "GEOM_ICurvesOperations_i.hh"
26
27 #include "utilities.h"
28 #include "OpUtil.hxx"
29
30 #include "GEOM_Engine.hxx"
31 #include "GEOM_Object.hxx"
32
33 //=============================================================================
34 /*!
35  *   constructor:
36  */
37 //=============================================================================
38 GEOM_ICurvesOperations_i::GEOM_ICurvesOperations_i (PortableServer::POA_ptr thePOA,
39                                                     GEOM::GEOM_Gen_ptr theEngine,
40                                                     ::GEOMImpl_ICurvesOperations* theImpl)
41 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
42 {
43   MESSAGE("GEOM_ICurvesOperations_i::GEOM_ICurvesOperations_i");
44 }
45
46 //=============================================================================
47 /*!
48  *  destructor
49  */
50 //=============================================================================
51 GEOM_ICurvesOperations_i::~GEOM_ICurvesOperations_i()
52 {
53   MESSAGE("GEOM_ICurvesOperations_i::~GEOM_ICurvesOperations_i");
54 }
55
56
57 //=============================================================================
58 /*!
59  *  MakeCirclePntVecR
60  */
61 //=============================================================================
62 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCirclePntVecR
63                       (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
64                        CORBA::Double theR)
65 {
66   GEOM::GEOM_Object_var aGEOMObject;
67
68   //Set a not done flag
69   GetOperations()->SetNotDone();
70
71   // Not set thePnt means origin of global CS,
72   // Not set theVec means Z axis of global CS
73   //if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
74
75   //Get the arguments
76   Handle(GEOM_Object) aPnt, aVec;
77   if (!CORBA::is_nil(thePnt)) {
78     aPnt = GetObjectImpl(thePnt);
79     if (aPnt.IsNull()) return aGEOMObject._retn();
80   }
81   if (!CORBA::is_nil(theVec)) {
82     aVec = GetObjectImpl(theVec);
83     if (aVec.IsNull()) return aGEOMObject._retn();
84   }
85
86   // Make Circle
87   Handle(GEOM_Object) anObject =
88     GetOperations()->MakeCirclePntVecR(aPnt, aVec, theR);
89   if (!GetOperations()->IsDone() || anObject.IsNull())
90     return aGEOMObject._retn();
91
92   return GetObject(anObject);
93 }
94
95 //=============================================================================
96 /*!
97  *  MakeCircleThreePnt
98  */
99 //=============================================================================
100 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCircleThreePnt
101                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2,
102                        GEOM::GEOM_Object_ptr thePnt3)
103 {
104   GEOM::GEOM_Object_var aGEOMObject;
105
106   //Set a not done flag
107   GetOperations()->SetNotDone();
108
109   //Get the reference points
110   Handle(GEOM_Object) aPnt1 = GetObjectImpl(thePnt1);
111   Handle(GEOM_Object) aPnt2 = GetObjectImpl(thePnt2);
112   Handle(GEOM_Object) aPnt3 = GetObjectImpl(thePnt3);
113
114   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
115
116   // Make Circle
117   Handle(GEOM_Object) anObject =
118       GetOperations()->MakeCircleThreePnt(aPnt1, aPnt2, aPnt3);
119   if (!GetOperations()->IsDone() || anObject.IsNull())
120     return aGEOMObject._retn();
121
122   return GetObject(anObject);
123 }
124
125 //=============================================================================
126 /*!
127  *  MakeCircleCenter2Pnt
128  */
129 //=============================================================================
130 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCircleCenter2Pnt
131                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2,
132                        GEOM::GEOM_Object_ptr thePnt3)
133 {
134   GEOM::GEOM_Object_var aGEOMObject;
135
136   //Set a not done flag
137   GetOperations()->SetNotDone();
138
139   //Get the reference points
140   Handle(GEOM_Object) aPnt1 = GetObjectImpl(thePnt1);
141   Handle(GEOM_Object) aPnt2 = GetObjectImpl(thePnt2);
142   Handle(GEOM_Object) aPnt3 = GetObjectImpl(thePnt3);
143
144   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
145
146   // Make Circle
147   Handle(GEOM_Object) anObject = GetOperations()->MakeCircleCenter2Pnt(aPnt1, aPnt2, aPnt3);
148   if (!GetOperations()->IsDone() || anObject.IsNull())
149     return aGEOMObject._retn();
150
151   return GetObject(anObject);
152 }
153
154 //=============================================================================
155 /*!
156  *  MakeEllipse
157  */
158 //=============================================================================
159 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeEllipse
160                       (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
161                        CORBA::Double theRMajor, double theRMinor)
162 {
163   GEOM::GEOM_Object_var aGEOMObject;
164
165   //Set a not done flag
166   GetOperations()->SetNotDone();
167
168   // Not set thePnt means origin of global CS,
169   // Not set theVec means Z axis of global CS
170   //if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
171
172   //Get the arguments
173   Handle(GEOM_Object) aPnt, aVec, aVecMaj;
174   if (!CORBA::is_nil(thePnt)) {
175     aPnt = GetObjectImpl(thePnt);
176     if (aPnt.IsNull()) return aGEOMObject._retn();
177   }
178   if (!CORBA::is_nil(theVec)) {
179     aVec = GetObjectImpl(theVec);
180     if (aVec.IsNull()) return aGEOMObject._retn();
181   }
182
183   // Make Ellipse
184   Handle(GEOM_Object) anObject =
185     GetOperations()->MakeEllipse(aPnt, aVec, theRMajor, theRMinor, aVecMaj);
186   if (!GetOperations()->IsDone() || anObject.IsNull())
187     return aGEOMObject._retn();
188
189   return GetObject(anObject);
190 }
191
192 //=============================================================================
193 /*!
194  *  MakeEllipseVec
195  */
196 //=============================================================================
197 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeEllipseVec
198                       (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
199                        CORBA::Double theRMajor, double theRMinor,
200                        GEOM::GEOM_Object_ptr theVecMaj)
201 {
202   GEOM::GEOM_Object_var aGEOMObject;
203
204   //Set a not done flag
205   GetOperations()->SetNotDone();
206
207   // Not set thePnt means origin of global CS,
208   // Not set theVec means Z axis of global CS
209   // Not set theVecMaj means X axis of global CS
210   //if (thePnt == NULL || theVec == NULL || theVecMaj == NULL) return aGEOMObject._retn();
211
212   //Get the arguments
213   Handle(GEOM_Object) aPnt, aVec, aVecMaj;
214   if (!CORBA::is_nil(thePnt)) {
215     aPnt = GetObjectImpl(thePnt);
216     if (aPnt.IsNull()) return aGEOMObject._retn();
217   }
218   if (!CORBA::is_nil(theVec)) {
219     aVec = GetObjectImpl(theVec);
220     if (aVec.IsNull()) return aGEOMObject._retn();
221   }
222   if (!CORBA::is_nil(theVecMaj)) {
223     aVecMaj = GetObjectImpl(theVecMaj);
224     if (aVecMaj.IsNull()) return aGEOMObject._retn();
225   }
226
227   // Make Ellipse
228   Handle(GEOM_Object) anObject =
229     GetOperations()->MakeEllipse(aPnt, aVec, theRMajor, theRMinor, aVecMaj);
230   if (!GetOperations()->IsDone() || anObject.IsNull())
231     return aGEOMObject._retn();
232
233   return GetObject(anObject);
234 }
235
236 //=============================================================================
237 /*!
238  *  MakeArc
239  */
240 //=============================================================================
241 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArc
242                                                 (GEOM::GEOM_Object_ptr thePnt1,
243                                                  GEOM::GEOM_Object_ptr thePnt2,
244                                                  GEOM::GEOM_Object_ptr thePnt3)
245 {
246   GEOM::GEOM_Object_var aGEOMObject;
247
248   //Set a not done flag
249   GetOperations()->SetNotDone();
250
251   //Get the reference points
252   Handle(GEOM_Object) aPnt1 = GetObjectImpl(thePnt1);
253   Handle(GEOM_Object) aPnt2 = GetObjectImpl(thePnt2);
254   Handle(GEOM_Object) aPnt3 = GetObjectImpl(thePnt3);
255
256   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
257
258   // Make Arc
259   Handle(GEOM_Object) anObject =
260     GetOperations()->MakeArc(aPnt1, aPnt2, aPnt3);
261   if (!GetOperations()->IsDone() || anObject.IsNull())
262     return aGEOMObject._retn();
263
264   return GetObject(anObject);
265 }
266
267
268 //=============================================================================
269 /*!
270  *  MakeArcCenter
271  */
272 //=============================================================================
273 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArcCenter
274     (GEOM::GEOM_Object_ptr thePnt1,
275      GEOM::GEOM_Object_ptr thePnt2,
276      GEOM::GEOM_Object_ptr thePnt3,
277      CORBA::Boolean theSense)
278
279 {
280   GEOM::GEOM_Object_var aGEOMObject;
281   //Set a not done flag
282   GetOperations()->SetNotDone();
283
284   //Get the reference points
285   Handle(GEOM_Object) aPnt1 = GetObjectImpl(thePnt1);
286   Handle(GEOM_Object) aPnt2 = GetObjectImpl(thePnt2);
287   Handle(GEOM_Object) aPnt3 = GetObjectImpl(thePnt3);
288
289   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
290
291   // Make ArcCenter
292   Handle(GEOM_Object) anObject =
293       GetOperations()->MakeArcCenter(aPnt1, aPnt2, aPnt3,theSense);
294   if (!GetOperations()->IsDone() || anObject.IsNull())
295     return aGEOMObject._retn();
296
297   return GetObject(anObject);
298 }
299
300 //=============================================================================
301 /*!
302  *  MakeArc
303  */
304 //=============================================================================
305 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArcOfEllipse
306                                                 (GEOM::GEOM_Object_ptr thePnt1,
307                                                  GEOM::GEOM_Object_ptr thePnt2,
308                                                  GEOM::GEOM_Object_ptr thePnt3)
309 {
310   GEOM::GEOM_Object_var aGEOMObject;
311
312   //Set a not done flag
313   GetOperations()->SetNotDone();
314
315   //Get the reference points
316   Handle(GEOM_Object) aPnt1 = GetObjectImpl(thePnt1);
317   Handle(GEOM_Object) aPnt2 = GetObjectImpl(thePnt2);
318   Handle(GEOM_Object) aPnt3 = GetObjectImpl(thePnt3);
319
320   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
321
322   // Make Arc
323   Handle(GEOM_Object) anObject =
324     GetOperations()->MakeArcOfEllipse(aPnt1, aPnt2, aPnt3);
325   if (!GetOperations()->IsDone() || anObject.IsNull())
326     return aGEOMObject._retn();
327
328   return GetObject(anObject);
329 }
330
331 //=============================================================================
332 /*!
333  *  MakePolyline
334  */
335 //=============================================================================
336 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakePolyline
337                                     (const GEOM::ListOfGO& thePoints)
338 {
339   GEOM::GEOM_Object_var aGEOMObject;
340
341   //Set a not done flag
342   GetOperations()->SetNotDone();
343
344   //Get the reference point
345   int ind = 0;
346   int aLen = thePoints.length();
347   std::list<Handle(GEOM_Object)> aPoints;
348   for (; ind < aLen; ind++) {
349     Handle(GEOM_Object) aPnt = GetObjectImpl(thePoints[ind]);
350     if (aPnt.IsNull()) return aGEOMObject._retn();
351     aPoints.push_back(aPnt);
352   }
353
354   // Make Polyline
355   Handle(GEOM_Object) anObject =
356     GetOperations()->MakePolyline(aPoints);
357   if (!GetOperations()->IsDone() || anObject.IsNull())
358     return aGEOMObject._retn();
359
360   return GetObject(anObject);
361 }
362
363 //=============================================================================
364 /*!
365  *  MakeSplineBezier
366  */
367 //=============================================================================
368 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineBezier
369                                               (const GEOM::ListOfGO& thePoints)
370 {
371   GEOM::GEOM_Object_var aGEOMObject;
372
373   //Set a not done flag
374   GetOperations()->SetNotDone();
375
376   //Get the reference point
377   int ind = 0;
378   int aLen = thePoints.length();
379   std::list<Handle(GEOM_Object)> aPoints;
380   for (; ind < aLen; ind++) {
381     Handle(GEOM_Object) aPnt = GetObjectImpl(thePoints[ind]);
382     if (aPnt.IsNull()) return aGEOMObject._retn();
383     aPoints.push_back(aPnt);
384   }
385
386   // Make Bezier curve
387   Handle(GEOM_Object) anObject =
388       GetOperations()->MakeSplineBezier(aPoints);
389   if (!GetOperations()->IsDone() || anObject.IsNull())
390     return aGEOMObject._retn();
391
392   return GetObject(anObject);
393 }
394
395 //=============================================================================
396 /*!
397  *  MakeSplineInterpolation
398  */
399 //=============================================================================
400 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineInterpolation
401                                               (const GEOM::ListOfGO& thePoints,
402                                                CORBA::Boolean        theIsClosed)
403 {
404   GEOM::GEOM_Object_var aGEOMObject;
405
406   //Set a not done flag
407   GetOperations()->SetNotDone();
408
409   //Get the reference point
410   int ind = 0;
411   int aLen = thePoints.length();
412   std::list<Handle(GEOM_Object)> aPoints;
413   for (; ind < aLen; ind++) {
414     Handle(GEOM_Object) aPnt = GetObjectImpl(thePoints[ind]);
415     if (aPnt.IsNull()) return aGEOMObject._retn();
416     aPoints.push_back(aPnt);
417   }
418
419   // Make Polyline
420   Handle(GEOM_Object) anObject =
421     GetOperations()->MakeSplineInterpolation(aPoints, theIsClosed);
422   if (!GetOperations()->IsDone() || anObject.IsNull())
423     return aGEOMObject._retn();
424
425   return GetObject(anObject);
426 }
427
428 //=============================================================================
429 /*!
430  *  MakeSketcher
431  */
432 //=============================================================================
433 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcher
434             (const char* theCommand, const GEOM::ListOfDouble& theWorkingPlane)
435 {
436   //Set a not done flag
437   GetOperations()->SetNotDone();
438
439   int ind = 0;
440   int aLen = theWorkingPlane.length();
441   std::list<double> aWorkingPlane;
442   for (; ind < aLen; ind++)
443     aWorkingPlane.push_back(theWorkingPlane[ind]);
444
445   // Make Sketcher
446   Handle(GEOM_Object) anObject =
447     GetOperations()->MakeSketcher(theCommand, aWorkingPlane);
448   if (!GetOperations()->IsDone() || anObject.IsNull())
449     return GEOM::GEOM_Object::_nil();
450
451   return GetObject(anObject);
452 }
453
454 //=============================================================================
455 /*!
456  *  Make3DSketcher
457  */
458 //=============================================================================
459 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::Make3DSketcher
460             (const GEOM::ListOfDouble& theCoordinates)
461 {
462   //Set a not done flag
463   GetOperations()->SetNotDone();
464
465   int ind = 0;
466   int aLen = theCoordinates.length();
467   std::list<double> aCoords;
468   for (; ind < aLen; ind++)
469     aCoords.push_back(theCoordinates[ind]);
470
471   // Make Sketcher
472   Handle(GEOM_Object) anObject =
473     GetOperations()->Make3DSketcher(aCoords);
474   if (!GetOperations()->IsDone() || anObject.IsNull())
475     return GEOM::GEOM_Object::_nil();
476
477   return GetObject(anObject);
478 }
479
480 //=============================================================================
481 /*!
482  *  MakeSketcherOnPlane
483  */
484 //=============================================================================
485 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcherOnPlane
486                 (const char* theCommand, GEOM::GEOM_Object_ptr theWorkingPlane)
487 {
488   //Set a not done flag
489   GetOperations()->SetNotDone();
490
491   Handle(GEOM_Object) aWorkingPlane = GetObjectImpl(theWorkingPlane);
492
493   // Make Sketcher
494   Handle(GEOM_Object) anObject =
495       GetOperations()->MakeSketcherOnPlane(theCommand, aWorkingPlane);
496   if (!GetOperations()->IsDone() || anObject.IsNull())
497     return GEOM::GEOM_Object::_nil();
498
499   return GetObject(anObject);
500 }