Salome HOME
NPAL: 16557, 16558, 16578, 16549, 16561
[modules/geom.git] / src / GEOM_I / GEOM_ICurvesOperations_i.cc
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/ or email : webmaster.salome@opencascade.com
19 //
20 #include <Standard_Stream.hxx>
21
22 #include "GEOM_ICurvesOperations_i.hh"
23
24 #include "utilities.h"
25 #include "OpUtil.hxx"
26
27 #include "GEOM_Engine.hxx"
28 #include "GEOM_Object.hxx"
29
30 //=============================================================================
31 /*!
32  *   constructor:
33  */
34 //=============================================================================
35 GEOM_ICurvesOperations_i::GEOM_ICurvesOperations_i (PortableServer::POA_ptr thePOA,
36                                                     GEOM::GEOM_Gen_ptr theEngine,
37                                                     ::GEOMImpl_ICurvesOperations* theImpl)
38 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
39 {
40   MESSAGE("GEOM_ICurvesOperations_i::GEOM_ICurvesOperations_i");
41 }
42
43 //=============================================================================
44 /*!
45  *  destructor
46  */
47 //=============================================================================
48 GEOM_ICurvesOperations_i::~GEOM_ICurvesOperations_i()
49 {
50   MESSAGE("GEOM_ICurvesOperations_i::~GEOM_ICurvesOperations_i");
51 }
52
53
54 //=============================================================================
55 /*!
56  *  MakeCirclePntVecR
57  */
58 //=============================================================================
59 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCirclePntVecR
60                       (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
61                        CORBA::Double theR)
62 {
63   GEOM::GEOM_Object_var aGEOMObject;
64
65   //Set a not done flag
66   GetOperations()->SetNotDone();
67
68   if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
69
70   //Get the reference points
71   Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
72     (thePnt->GetStudyID(), thePnt->GetEntry());
73   Handle(GEOM_Object) aVec = GetOperations()->GetEngine()->GetObject
74     (theVec->GetStudyID(), theVec->GetEntry());
75
76   if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
77
78   // Make Circle
79   Handle(GEOM_Object) anObject =
80     GetOperations()->MakeCirclePntVecR(aPnt, aVec, theR);
81   if (!GetOperations()->IsDone() || anObject.IsNull())
82     return aGEOMObject._retn();
83
84   return GetObject(anObject);
85 }
86
87 //=============================================================================
88 /*!
89  *  MakeCircleThreePnt
90  */
91 //=============================================================================
92 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCircleThreePnt
93                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2,
94                        GEOM::GEOM_Object_ptr thePnt3)
95 {
96   GEOM::GEOM_Object_var aGEOMObject;
97
98   //Set a not done flag
99   GetOperations()->SetNotDone();
100
101   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn();
102
103   //Get the reference points
104   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
105     (thePnt1->GetStudyID(), thePnt1->GetEntry());
106   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
107     (thePnt2->GetStudyID(), thePnt2->GetEntry());
108   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
109     (thePnt3->GetStudyID(), thePnt3->GetEntry());
110
111   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
112
113   // Make Circle
114   Handle(GEOM_Object) anObject =
115       GetOperations()->MakeCircleThreePnt(aPnt1, aPnt2, aPnt3);
116   if (!GetOperations()->IsDone() || anObject.IsNull())
117     return aGEOMObject._retn();
118
119   return GetObject(anObject);
120 }
121
122 //=============================================================================
123 /*!
124  *  MakeCircleCenter2Pnt
125  */
126 //=============================================================================
127 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCircleCenter2Pnt
128                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2,
129                        GEOM::GEOM_Object_ptr thePnt3)
130 {
131   GEOM::GEOM_Object_var aGEOMObject;
132
133   //Set a not done flag
134   GetOperations()->SetNotDone();
135
136   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn();
137
138   //Get the reference points
139   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
140     (thePnt1->GetStudyID(), thePnt1->GetEntry());
141   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
142     (thePnt2->GetStudyID(), thePnt2->GetEntry());
143   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
144     (thePnt3->GetStudyID(), thePnt3->GetEntry());
145
146   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
147
148   // Make Circle
149   Handle(GEOM_Object) anObject = GetOperations()->MakeCircleCenter2Pnt(aPnt1, aPnt2, aPnt3);
150   if (!GetOperations()->IsDone() || anObject.IsNull())
151     return aGEOMObject._retn();
152
153   return GetObject(anObject);
154 }
155
156 //=============================================================================
157 /*!
158  *  MakeEllipse
159  */
160 //=============================================================================
161 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeEllipse
162                       (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
163                        CORBA::Double theRMajor, double theRMinor)
164 {
165   GEOM::GEOM_Object_var aGEOMObject;
166
167   //Set a not done flag
168   GetOperations()->SetNotDone();
169
170   if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
171
172   //Get the reference points
173   Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
174     (thePnt->GetStudyID(), thePnt->GetEntry());
175   Handle(GEOM_Object) aVec = GetOperations()->GetEngine()->GetObject
176     (theVec->GetStudyID(), theVec->GetEntry());
177
178   if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
179
180   // Make Ellipse
181   Handle(GEOM_Object) anObject =
182     GetOperations()->MakeEllipse(aPnt, aVec, theRMajor, theRMinor);
183   if (!GetOperations()->IsDone() || anObject.IsNull())
184     return aGEOMObject._retn();
185
186   return GetObject(anObject);
187 }
188
189 //=============================================================================
190 /*!
191  *  MakeArc
192  */
193 //=============================================================================
194 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArc
195                                                 (GEOM::GEOM_Object_ptr thePnt1,
196                                                  GEOM::GEOM_Object_ptr thePnt2,
197                                                  GEOM::GEOM_Object_ptr thePnt3)
198 {
199   GEOM::GEOM_Object_var aGEOMObject;
200
201   //Set a not done flag
202   GetOperations()->SetNotDone();
203
204   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn();
205
206   //Get the reference points
207   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
208     (thePnt1->GetStudyID(), thePnt1->GetEntry());
209   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
210     (thePnt2->GetStudyID(), thePnt2->GetEntry());
211   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
212     (thePnt3->GetStudyID(), thePnt3->GetEntry());
213
214   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
215
216   // Make Arc
217   Handle(GEOM_Object) anObject =
218     GetOperations()->MakeArc(aPnt1, aPnt2, aPnt3);
219   if (!GetOperations()->IsDone() || anObject.IsNull())
220     return aGEOMObject._retn();
221
222   return GetObject(anObject);
223 }
224
225
226 //=============================================================================
227 /*!
228  *  MakeArcCenter
229  */
230 //=============================================================================
231 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArcCenter
232     (GEOM::GEOM_Object_ptr thePnt1,
233      GEOM::GEOM_Object_ptr thePnt2,
234      GEOM::GEOM_Object_ptr thePnt3,
235      CORBA::Boolean theSense)
236
237 {
238   GEOM::GEOM_Object_var aGEOMObject;
239   //Set a not done flag
240   GetOperations()->SetNotDone();
241
242   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn();
243
244   //Get the reference points
245   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
246       (thePnt1->GetStudyID(), thePnt1->GetEntry());
247   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
248       (thePnt2->GetStudyID(), thePnt2->GetEntry());
249   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
250       (thePnt3->GetStudyID(), thePnt3->GetEntry());
251
252   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
253
254   // Make ArcCenter
255   Handle(GEOM_Object) anObject =
256       GetOperations()->MakeArcCenter(aPnt1, aPnt2, aPnt3,theSense);
257   if (!GetOperations()->IsDone() || anObject.IsNull())
258     return aGEOMObject._retn();
259
260   return GetObject(anObject);
261 }
262 //=============================================================================
263 /*!
264  *  MakePolyline
265  */
266 //=============================================================================
267 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakePolyline
268                                     (const GEOM::ListOfGO& thePoints)
269 {
270   GEOM::GEOM_Object_var aGEOMObject;
271
272   //Set a not done flag
273   GetOperations()->SetNotDone();
274
275   //Get the reference point
276   int ind = 0;
277   int aLen = thePoints.length();
278   list<Handle(GEOM_Object)> aPoints;
279   for (; ind < aLen; ind++) {
280     if (thePoints[ind] == NULL) return aGEOMObject._retn();
281
282     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
283       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
284
285     if (aPnt.IsNull()) return aGEOMObject._retn();
286     aPoints.push_back(aPnt);
287   }
288
289   // Make Polyline
290   Handle(GEOM_Object) anObject =
291     GetOperations()->MakePolyline(aPoints);
292   if (!GetOperations()->IsDone() || anObject.IsNull())
293     return aGEOMObject._retn();
294
295   return GetObject(anObject);
296 }
297
298 //=============================================================================
299 /*!
300  *  MakeSplineBezier
301  */
302 //=============================================================================
303 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineBezier
304                                               (const GEOM::ListOfGO& thePoints)
305 {
306   GEOM::GEOM_Object_var aGEOMObject;
307
308   //Set a not done flag
309   GetOperations()->SetNotDone();
310
311   //Get the reference point
312   int ind = 0;
313   int aLen = thePoints.length();
314   list<Handle(GEOM_Object)> aPoints;
315   for (; ind < aLen; ind++) {
316     if (thePoints[ind] == NULL) return aGEOMObject._retn();
317
318     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
319       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
320
321     if (aPnt.IsNull()) return aGEOMObject._retn();
322     aPoints.push_back(aPnt);
323   }
324
325   // Make Bezier curve
326   Handle(GEOM_Object) anObject =
327       GetOperations()->MakeSplineBezier(aPoints);
328   if (!GetOperations()->IsDone() || anObject.IsNull())
329     return aGEOMObject._retn();
330
331   return GetObject(anObject);
332 }
333
334 //=============================================================================
335 /*!
336  *  MakeSplineInterpolation
337  */
338 //=============================================================================
339 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineInterpolation
340                                               (const GEOM::ListOfGO& thePoints)
341 {
342   GEOM::GEOM_Object_var aGEOMObject;
343
344   //Set a not done flag
345   GetOperations()->SetNotDone();
346
347   //Get the reference point
348   int ind = 0;
349   int aLen = thePoints.length();
350   list<Handle(GEOM_Object)> aPoints;
351   for (; ind < aLen; ind++) {
352     if (thePoints[ind] == NULL) return aGEOMObject._retn();
353
354     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
355       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
356
357     if (aPnt.IsNull()) return aGEOMObject._retn();
358     aPoints.push_back(aPnt);
359   }
360
361   // Make Polyline
362   Handle(GEOM_Object) anObject =
363       GetOperations()->MakeSplineInterpolation(aPoints);
364   if (!GetOperations()->IsDone() || anObject.IsNull())
365     return aGEOMObject._retn();
366
367   return GetObject(anObject);
368 }
369
370 //=============================================================================
371 /*!
372  *  MakeSketcher
373  */
374 //=============================================================================
375 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcher
376             (const char* theCommand, const GEOM::ListOfDouble& theWorkingPlane)
377 {
378   //Set a not done flag
379   GetOperations()->SetNotDone();
380
381   int ind = 0;
382   int aLen = theWorkingPlane.length();
383   list<double> aWorkingPlane;
384   for (; ind < aLen; ind++)
385     aWorkingPlane.push_back(theWorkingPlane[ind]);
386
387   // Make Sketcher
388   Handle(GEOM_Object) anObject =
389     GetOperations()->MakeSketcher((char*)theCommand, aWorkingPlane);
390   if (!GetOperations()->IsDone() || anObject.IsNull())
391     return GEOM::GEOM_Object::_nil();
392
393   return GetObject(anObject);
394 }
395
396
397 //=============================================================================
398 /*!
399  *  MakeSketcherOnPlane
400  */
401 //=============================================================================
402 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcherOnPlane
403                 (const char* theCommand, GEOM::GEOM_Object_ptr theWorkingPlane)
404 {
405   //Set a not done flag
406   GetOperations()->SetNotDone();
407
408   Handle(GEOM_Object) aWorkingPlane = GetOperations()->GetEngine()->GetObject
409     (theWorkingPlane->GetStudyID(), theWorkingPlane->GetEntry());
410
411   // Make Sketcher
412   Handle(GEOM_Object) anObject =
413       GetOperations()->MakeSketcherOnPlane((char*)theCommand, aWorkingPlane);
414   if (!GetOperations()->IsDone() || anObject.IsNull())
415     return GEOM::GEOM_Object::_nil();
416
417   return GetObject(anObject);
418 }