Salome HOME
*** empty log message ***
[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  *  MakeEllipse
125  */
126 //=============================================================================
127 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeEllipse
128                       (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
129                        CORBA::Double theRMajor, double theRMinor)
130 {
131   GEOM::GEOM_Object_var aGEOMObject;
132
133   //Set a not done flag
134   GetOperations()->SetNotDone();
135
136   if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
137
138   //Get the reference points
139   Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
140     (thePnt->GetStudyID(), thePnt->GetEntry());
141   Handle(GEOM_Object) aVec = GetOperations()->GetEngine()->GetObject
142     (theVec->GetStudyID(), theVec->GetEntry());
143
144   if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
145
146   // Make Ellipse
147   Handle(GEOM_Object) anObject =
148     GetOperations()->MakeEllipse(aPnt, aVec, theRMajor, theRMinor);
149   if (!GetOperations()->IsDone() || anObject.IsNull())
150     return aGEOMObject._retn();
151
152   return GetObject(anObject);
153 }
154
155 //=============================================================================
156 /*!
157  *  MakeArc
158  */
159 //=============================================================================
160 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArc
161                                                 (GEOM::GEOM_Object_ptr thePnt1,
162                                                  GEOM::GEOM_Object_ptr thePnt2,
163                                                  GEOM::GEOM_Object_ptr thePnt3)
164 {
165   GEOM::GEOM_Object_var aGEOMObject;
166
167   //Set a not done flag
168   GetOperations()->SetNotDone();
169
170   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn();
171
172   //Get the reference points
173   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
174     (thePnt1->GetStudyID(), thePnt1->GetEntry());
175   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
176     (thePnt2->GetStudyID(), thePnt2->GetEntry());
177   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
178     (thePnt3->GetStudyID(), thePnt3->GetEntry());
179
180   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
181
182   // Make Arc
183   Handle(GEOM_Object) anObject =
184     GetOperations()->MakeArc(aPnt1, aPnt2, aPnt3);
185   if (!GetOperations()->IsDone() || anObject.IsNull())
186     return aGEOMObject._retn();
187
188   return GetObject(anObject);
189 }
190
191
192 //=============================================================================
193 /*!
194  *  MakeArcCenter
195  */
196 //=============================================================================
197 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArcCenter
198     (GEOM::GEOM_Object_ptr thePnt1,
199      GEOM::GEOM_Object_ptr thePnt2,
200      GEOM::GEOM_Object_ptr thePnt3,
201      CORBA::Boolean theSense)
202
203 {
204   GEOM::GEOM_Object_var aGEOMObject;
205   //Set a not done flag
206   GetOperations()->SetNotDone();
207
208   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn();
209
210   //Get the reference points
211   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
212       (thePnt1->GetStudyID(), thePnt1->GetEntry());
213   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
214       (thePnt2->GetStudyID(), thePnt2->GetEntry());
215   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
216       (thePnt3->GetStudyID(), thePnt3->GetEntry());
217
218   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
219
220   // Make ArcCenter
221   Handle(GEOM_Object) anObject =
222       GetOperations()->MakeArcCenter(aPnt1, aPnt2, aPnt3,theSense);
223   if (!GetOperations()->IsDone() || anObject.IsNull())
224     return aGEOMObject._retn();
225
226   return GetObject(anObject);
227 }
228 //=============================================================================
229 /*!
230  *  MakePolyline
231  */
232 //=============================================================================
233 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakePolyline
234                                     (const GEOM::ListOfGO& thePoints)
235 {
236   GEOM::GEOM_Object_var aGEOMObject;
237
238   //Set a not done flag
239   GetOperations()->SetNotDone();
240
241   //Get the reference point
242   int ind = 0;
243   int aLen = thePoints.length();
244   list<Handle(GEOM_Object)> aPoints;
245   for (; ind < aLen; ind++) {
246     if (thePoints[ind] == NULL) return aGEOMObject._retn();
247
248     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
249       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
250
251     if (aPnt.IsNull()) return aGEOMObject._retn();
252     aPoints.push_back(aPnt);
253   }
254
255   // Make Polyline
256   Handle(GEOM_Object) anObject =
257     GetOperations()->MakePolyline(aPoints);
258   if (!GetOperations()->IsDone() || anObject.IsNull())
259     return aGEOMObject._retn();
260
261   return GetObject(anObject);
262 }
263
264 //=============================================================================
265 /*!
266  *  MakeSplineBezier
267  */
268 //=============================================================================
269 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineBezier
270                                               (const GEOM::ListOfGO& thePoints)
271 {
272   GEOM::GEOM_Object_var aGEOMObject;
273
274   //Set a not done flag
275   GetOperations()->SetNotDone();
276
277   //Get the reference point
278   int ind = 0;
279   int aLen = thePoints.length();
280   list<Handle(GEOM_Object)> aPoints;
281   for (; ind < aLen; ind++) {
282     if (thePoints[ind] == NULL) return aGEOMObject._retn();
283
284     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
285       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
286
287     if (aPnt.IsNull()) return aGEOMObject._retn();
288     aPoints.push_back(aPnt);
289   }
290
291   // Make Bezier curve
292   Handle(GEOM_Object) anObject =
293       GetOperations()->MakeSplineBezier(aPoints);
294   if (!GetOperations()->IsDone() || anObject.IsNull())
295     return aGEOMObject._retn();
296
297   return GetObject(anObject);
298 }
299
300 //=============================================================================
301 /*!
302  *  MakeSplineInterpolation
303  */
304 //=============================================================================
305 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineInterpolation
306                                               (const GEOM::ListOfGO& thePoints)
307 {
308   GEOM::GEOM_Object_var aGEOMObject;
309
310   //Set a not done flag
311   GetOperations()->SetNotDone();
312
313   //Get the reference point
314   int ind = 0;
315   int aLen = thePoints.length();
316   list<Handle(GEOM_Object)> aPoints;
317   for (; ind < aLen; ind++) {
318     if (thePoints[ind] == NULL) return aGEOMObject._retn();
319
320     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
321       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
322
323     if (aPnt.IsNull()) return aGEOMObject._retn();
324     aPoints.push_back(aPnt);
325   }
326
327   // Make Polyline
328   Handle(GEOM_Object) anObject =
329       GetOperations()->MakeSplineInterpolation(aPoints);
330   if (!GetOperations()->IsDone() || anObject.IsNull())
331     return aGEOMObject._retn();
332
333   return GetObject(anObject);
334 }
335
336 //=============================================================================
337 /*!
338  *  MakeSketcher
339  */
340 //=============================================================================
341 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcher
342             (const char* theCommand, const GEOM::ListOfDouble& theWorkingPlane)
343 {
344   //Set a not done flag
345   GetOperations()->SetNotDone();
346
347   int ind = 0;
348   int aLen = theWorkingPlane.length();
349   list<double> aWorkingPlane;
350   for (; ind < aLen; ind++)
351     aWorkingPlane.push_back(theWorkingPlane[ind]);
352
353   // Make Sketcher
354   Handle(GEOM_Object) anObject =
355     GetOperations()->MakeSketcher((char*)theCommand, aWorkingPlane);
356   if (!GetOperations()->IsDone() || anObject.IsNull())
357     return GEOM::GEOM_Object::_nil();
358
359   return GetObject(anObject);
360 }
361
362
363 //=============================================================================
364 /*!
365  *  MakeSketcherOnPlane
366  */
367 //=============================================================================
368 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcherOnPlane
369                 (const char* theCommand, GEOM::GEOM_Object_ptr theWorkingPlane)
370 {
371   //Set a not done flag
372   GetOperations()->SetNotDone();
373
374   Handle(GEOM_Object) aWorkingPlane = GetOperations()->GetEngine()->GetObject
375     (theWorkingPlane->GetStudyID(), theWorkingPlane->GetEntry());
376
377   // Make Sketcher
378   Handle(GEOM_Object) anObject =
379       GetOperations()->MakeSketcherOnPlane((char*)theCommand, aWorkingPlane);
380   if (!GetOperations()->IsDone() || anObject.IsNull())
381     return GEOM::GEOM_Object::_nil();
382
383   return GetObject(anObject);
384 }