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