Salome HOME
Update copyright
[modules/geom.git] / src / GEOM_I / GEOM_ICurvesOperations_i.cc
1 // Copyright (C) 2007-2011  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                                      CORBA::Boolean        theIsClosed)
339 {
340   GEOM::GEOM_Object_var aGEOMObject;
341
342   //Set a not done flag
343   GetOperations()->SetNotDone();
344
345   //Get the reference point
346   int ind = 0;
347   int aLen = thePoints.length();
348   std::list<Handle(GEOM_Object)> aPoints;
349   for (; ind < aLen; ind++) {
350     Handle(GEOM_Object) aPnt = GetObjectImpl(thePoints[ind]);
351     if (aPnt.IsNull()) return aGEOMObject._retn();
352     aPoints.push_back(aPnt);
353   }
354
355   // Make Polyline
356   Handle(GEOM_Object) anObject =
357     GetOperations()->MakePolyline(aPoints, theIsClosed);
358   if (!GetOperations()->IsDone() || anObject.IsNull())
359     return aGEOMObject._retn();
360
361   return GetObject(anObject);
362 }
363
364 //=============================================================================
365 /*!
366  *  MakeSplineBezier
367  */
368 //=============================================================================
369 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineBezier
370                                               (const GEOM::ListOfGO& thePoints,
371                                                CORBA::Boolean        theIsClosed)
372 {
373   GEOM::GEOM_Object_var aGEOMObject;
374
375   //Set a not done flag
376   GetOperations()->SetNotDone();
377
378   //Get the reference point
379   int ind = 0;
380   int aLen = thePoints.length();
381   std::list<Handle(GEOM_Object)> aPoints;
382   for (; ind < aLen; ind++) {
383     Handle(GEOM_Object) aPnt = GetObjectImpl(thePoints[ind]);
384     if (aPnt.IsNull()) return aGEOMObject._retn();
385     aPoints.push_back(aPnt);
386   }
387
388   // Make Bezier curve
389   Handle(GEOM_Object) anObject =
390       GetOperations()->MakeSplineBezier(aPoints, theIsClosed);
391   if (!GetOperations()->IsDone() || anObject.IsNull())
392     return aGEOMObject._retn();
393
394   return GetObject(anObject);
395 }
396
397 //=============================================================================
398 /*!
399  *  MakeSplineInterpolation
400  */
401 //=============================================================================
402 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineInterpolation
403                                               (const GEOM::ListOfGO& thePoints,
404                                                CORBA::Boolean        theIsClosed,
405                                                CORBA::Boolean        theDoReordering)
406 {
407   GEOM::GEOM_Object_var aGEOMObject;
408
409   //Set a not done flag
410   GetOperations()->SetNotDone();
411
412   //Get the reference point
413   int ind = 0;
414   int aLen = thePoints.length();
415   std::list<Handle(GEOM_Object)> aPoints;
416   for (; ind < aLen; ind++) {
417     Handle(GEOM_Object) aPnt = GetObjectImpl(thePoints[ind]);
418     if (aPnt.IsNull()) return aGEOMObject._retn();
419     aPoints.push_back(aPnt);
420   }
421
422   // Make Polyline
423   Handle(GEOM_Object) anObject =
424     GetOperations()->MakeSplineInterpolation(aPoints, theIsClosed, theDoReordering);
425   if (!GetOperations()->IsDone() || anObject.IsNull())
426     return aGEOMObject._retn();
427
428   return GetObject(anObject);
429 }
430
431 //=============================================================================
432 /*!
433  *  MakeCurveParametric
434  */
435 //=============================================================================
436 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr, 
437                                                                     double theParamMin, double theParamMax, double theParamStep, 
438                                                                     GEOM::curve_type theCurveType) {
439   GEOM::GEOM_Object_var aGEOMObject;
440   //Set a not done flag
441   GetOperations()->SetNotDone();
442   
443   GEOMImpl_ICurvesOperations::CurveType aType;
444   switch(theCurveType) {
445   case GEOM::Polyline:
446     aType = GEOMImpl_ICurvesOperations::Polyline;
447     break;
448   case GEOM::Bezier:
449     aType = GEOMImpl_ICurvesOperations::Bezier;
450     break;
451   case GEOM::Interpolation:
452     aType = GEOMImpl_ICurvesOperations::Interpolation;
453     break;
454   default:
455     break;
456   }  
457   
458
459   // Make Polyline
460   Handle(GEOM_Object) anObject =
461     GetOperations()->MakeCurveParametric(thexExpr, theyExpr, thezExpr, 
462                                            theParamMin, theParamMax, 
463                                            theParamStep, aType);
464   
465   if (!GetOperations()->IsDone() || anObject.IsNull())
466     return aGEOMObject._retn();  
467   
468   return GetObject(anObject);
469 }
470
471 //=============================================================================
472 /*!
473  *  MakeSketcher
474  */
475 //=============================================================================
476 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcher
477             (const char* theCommand, const GEOM::ListOfDouble& theWorkingPlane)
478 {
479   //Set a not done flag
480   GetOperations()->SetNotDone();
481
482   int ind = 0;
483   int aLen = theWorkingPlane.length();
484   std::list<double> aWorkingPlane;
485   for (; ind < aLen; ind++)
486     aWorkingPlane.push_back(theWorkingPlane[ind]);
487
488   // Make Sketcher
489   Handle(GEOM_Object) anObject =
490     GetOperations()->MakeSketcher(theCommand, aWorkingPlane);
491   if (!GetOperations()->IsDone() || anObject.IsNull())
492     return GEOM::GEOM_Object::_nil();
493
494   return GetObject(anObject);
495 }
496
497 //=============================================================================
498 /*!
499  *  Make3DSketcher
500  */
501 //=============================================================================
502 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::Make3DSketcher
503             (const GEOM::ListOfDouble& theCoordinates)
504 {
505   //Set a not done flag
506   GetOperations()->SetNotDone();
507
508   int ind = 0;
509   int aLen = theCoordinates.length();
510   std::list<double> aCoords;
511   for (; ind < aLen; ind++)
512     aCoords.push_back(theCoordinates[ind]);
513
514   // Make Sketcher
515   Handle(GEOM_Object) anObject =
516     GetOperations()->Make3DSketcher(aCoords);
517   if (!GetOperations()->IsDone() || anObject.IsNull())
518     return GEOM::GEOM_Object::_nil();
519
520   return GetObject(anObject);
521 }
522
523 //=============================================================================
524 /*!
525  *  MakeSketcherOnPlane
526  */
527 //=============================================================================
528 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcherOnPlane
529                 (const char* theCommand, GEOM::GEOM_Object_ptr theWorkingPlane)
530 {
531   //Set a not done flag
532   GetOperations()->SetNotDone();
533
534   Handle(GEOM_Object) aWorkingPlane = GetObjectImpl(theWorkingPlane);
535
536   // Make Sketcher
537   Handle(GEOM_Object) anObject =
538       GetOperations()->MakeSketcherOnPlane(theCommand, aWorkingPlane);
539   if (!GetOperations()->IsDone() || anObject.IsNull())
540     return GEOM::GEOM_Object::_nil();
541
542   return GetObject(anObject);
543 }