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