]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_ICurvesOperations_i.cc
Salome HOME
Dump Python extension
[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   // Not set thePnt means origin of global CS,
69   // Not set theVec means Z axis of global CS
70   //if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
71
72   //Get the arguments
73   Handle(GEOM_Object) aPnt, aVec;
74   if (!CORBA::is_nil(thePnt)) {
75     aPnt = GetOperations()->GetEngine()->GetObject
76       (thePnt->GetStudyID(), thePnt->GetEntry());
77     if (aPnt.IsNull()) return aGEOMObject._retn();
78   }
79   if (!CORBA::is_nil(theVec)) {
80     aVec = GetOperations()->GetEngine()->GetObject
81       (theVec->GetStudyID(), theVec->GetEntry());
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   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn();
109
110   //Get the reference points
111   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
112     (thePnt1->GetStudyID(), thePnt1->GetEntry());
113   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
114     (thePnt2->GetStudyID(), thePnt2->GetEntry());
115   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
116     (thePnt3->GetStudyID(), thePnt3->GetEntry());
117
118   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
119
120   // Make Circle
121   Handle(GEOM_Object) anObject =
122       GetOperations()->MakeCircleThreePnt(aPnt1, aPnt2, aPnt3);
123   if (!GetOperations()->IsDone() || anObject.IsNull())
124     return aGEOMObject._retn();
125
126   return GetObject(anObject);
127 }
128
129 //=============================================================================
130 /*!
131  *  MakeCircleCenter2Pnt
132  */
133 //=============================================================================
134 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCircleCenter2Pnt
135                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2,
136                        GEOM::GEOM_Object_ptr thePnt3)
137 {
138   GEOM::GEOM_Object_var aGEOMObject;
139
140   //Set a not done flag
141   GetOperations()->SetNotDone();
142
143   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn();
144
145   //Get the reference points
146   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
147     (thePnt1->GetStudyID(), thePnt1->GetEntry());
148   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
149     (thePnt2->GetStudyID(), thePnt2->GetEntry());
150   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
151     (thePnt3->GetStudyID(), thePnt3->GetEntry());
152
153   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
154
155   // Make Circle
156   Handle(GEOM_Object) anObject = GetOperations()->MakeCircleCenter2Pnt(aPnt1, aPnt2, aPnt3);
157   if (!GetOperations()->IsDone() || anObject.IsNull())
158     return aGEOMObject._retn();
159
160   return GetObject(anObject);
161 }
162
163 //=============================================================================
164 /*!
165  *  MakeEllipse
166  */
167 //=============================================================================
168 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeEllipse
169                       (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
170                        CORBA::Double theRMajor, double theRMinor)
171 {
172   GEOM::GEOM_Object_var aGEOMObject;
173
174   //Set a not done flag
175   GetOperations()->SetNotDone();
176
177   // Not set thePnt means origin of global CS,
178   // Not set theVec means Z axis of global CS
179   //if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
180
181   //Get the arguments
182   Handle(GEOM_Object) aPnt, aVec;
183   if (!CORBA::is_nil(thePnt)) {
184     aPnt = GetOperations()->GetEngine()->GetObject
185       (thePnt->GetStudyID(), thePnt->GetEntry());
186     if (aPnt.IsNull()) return aGEOMObject._retn();
187   }
188   if (!CORBA::is_nil(theVec)) {
189     aVec = GetOperations()->GetEngine()->GetObject
190       (theVec->GetStudyID(), theVec->GetEntry());
191     if (aVec.IsNull()) return aGEOMObject._retn();
192   }
193
194   // Make Ellipse
195   Handle(GEOM_Object) anObject =
196     GetOperations()->MakeEllipse(aPnt, aVec, theRMajor, theRMinor);
197   if (!GetOperations()->IsDone() || anObject.IsNull())
198     return aGEOMObject._retn();
199
200   return GetObject(anObject);
201 }
202
203 //=============================================================================
204 /*!
205  *  MakeArc
206  */
207 //=============================================================================
208 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArc
209                                                 (GEOM::GEOM_Object_ptr thePnt1,
210                                                  GEOM::GEOM_Object_ptr thePnt2,
211                                                  GEOM::GEOM_Object_ptr thePnt3)
212 {
213   GEOM::GEOM_Object_var aGEOMObject;
214
215   //Set a not done flag
216   GetOperations()->SetNotDone();
217
218   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn();
219
220   //Get the reference points
221   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
222     (thePnt1->GetStudyID(), thePnt1->GetEntry());
223   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
224     (thePnt2->GetStudyID(), thePnt2->GetEntry());
225   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
226     (thePnt3->GetStudyID(), thePnt3->GetEntry());
227
228   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
229
230   // Make Arc
231   Handle(GEOM_Object) anObject =
232     GetOperations()->MakeArc(aPnt1, aPnt2, aPnt3);
233   if (!GetOperations()->IsDone() || anObject.IsNull())
234     return aGEOMObject._retn();
235
236   return GetObject(anObject);
237 }
238
239
240 //=============================================================================
241 /*!
242  *  MakeArcCenter
243  */
244 //=============================================================================
245 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArcCenter
246     (GEOM::GEOM_Object_ptr thePnt1,
247      GEOM::GEOM_Object_ptr thePnt2,
248      GEOM::GEOM_Object_ptr thePnt3,
249      CORBA::Boolean theSense)
250
251 {
252   GEOM::GEOM_Object_var aGEOMObject;
253   //Set a not done flag
254   GetOperations()->SetNotDone();
255
256   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn();
257
258   //Get the reference points
259   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
260       (thePnt1->GetStudyID(), thePnt1->GetEntry());
261   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
262       (thePnt2->GetStudyID(), thePnt2->GetEntry());
263   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
264       (thePnt3->GetStudyID(), thePnt3->GetEntry());
265
266   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
267
268   // Make ArcCenter
269   Handle(GEOM_Object) anObject =
270       GetOperations()->MakeArcCenter(aPnt1, aPnt2, aPnt3,theSense);
271   if (!GetOperations()->IsDone() || anObject.IsNull())
272     return aGEOMObject._retn();
273
274   return GetObject(anObject);
275 }
276 //=============================================================================
277 /*!
278  *  MakePolyline
279  */
280 //=============================================================================
281 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakePolyline
282                                     (const GEOM::ListOfGO& thePoints)
283 {
284   GEOM::GEOM_Object_var aGEOMObject;
285
286   //Set a not done flag
287   GetOperations()->SetNotDone();
288
289   //Get the reference point
290   int ind = 0;
291   int aLen = thePoints.length();
292   list<Handle(GEOM_Object)> aPoints;
293   for (; ind < aLen; ind++) {
294     if (thePoints[ind] == NULL) return aGEOMObject._retn();
295
296     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
297       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
298
299     if (aPnt.IsNull()) return aGEOMObject._retn();
300     aPoints.push_back(aPnt);
301   }
302
303   // Make Polyline
304   Handle(GEOM_Object) anObject =
305     GetOperations()->MakePolyline(aPoints);
306   if (!GetOperations()->IsDone() || anObject.IsNull())
307     return aGEOMObject._retn();
308
309   return GetObject(anObject);
310 }
311
312 //=============================================================================
313 /*!
314  *  MakeSplineBezier
315  */
316 //=============================================================================
317 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineBezier
318                                               (const GEOM::ListOfGO& thePoints)
319 {
320   GEOM::GEOM_Object_var aGEOMObject;
321
322   //Set a not done flag
323   GetOperations()->SetNotDone();
324
325   //Get the reference point
326   int ind = 0;
327   int aLen = thePoints.length();
328   list<Handle(GEOM_Object)> aPoints;
329   for (; ind < aLen; ind++) {
330     if (thePoints[ind] == NULL) return aGEOMObject._retn();
331
332     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
333       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
334
335     if (aPnt.IsNull()) return aGEOMObject._retn();
336     aPoints.push_back(aPnt);
337   }
338
339   // Make Bezier curve
340   Handle(GEOM_Object) anObject =
341       GetOperations()->MakeSplineBezier(aPoints);
342   if (!GetOperations()->IsDone() || anObject.IsNull())
343     return aGEOMObject._retn();
344
345   return GetObject(anObject);
346 }
347
348 //=============================================================================
349 /*!
350  *  MakeSplineInterpolation
351  */
352 //=============================================================================
353 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineInterpolation
354                                               (const GEOM::ListOfGO& thePoints)
355 {
356   GEOM::GEOM_Object_var aGEOMObject;
357
358   //Set a not done flag
359   GetOperations()->SetNotDone();
360
361   //Get the reference point
362   int ind = 0;
363   int aLen = thePoints.length();
364   list<Handle(GEOM_Object)> aPoints;
365   for (; ind < aLen; ind++) {
366     if (thePoints[ind] == NULL) return aGEOMObject._retn();
367
368     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
369       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
370
371     if (aPnt.IsNull()) return aGEOMObject._retn();
372     aPoints.push_back(aPnt);
373   }
374
375   // Make Polyline
376   Handle(GEOM_Object) anObject =
377       GetOperations()->MakeSplineInterpolation(aPoints);
378   if (!GetOperations()->IsDone() || anObject.IsNull())
379     return aGEOMObject._retn();
380
381   return GetObject(anObject);
382 }
383
384 //=============================================================================
385 /*!
386  *  MakeSketcher
387  */
388 //=============================================================================
389 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcher
390             (const char* theCommand, const GEOM::ListOfDouble& theWorkingPlane)
391 {
392   //Set a not done flag
393   GetOperations()->SetNotDone();
394
395   int ind = 0;
396   int aLen = theWorkingPlane.length();
397   list<double> aWorkingPlane;
398   for (; ind < aLen; ind++)
399     aWorkingPlane.push_back(theWorkingPlane[ind]);
400
401   // Make Sketcher
402   Handle(GEOM_Object) anObject =
403     GetOperations()->MakeSketcher(theCommand, aWorkingPlane);
404   if (!GetOperations()->IsDone() || anObject.IsNull())
405     return GEOM::GEOM_Object::_nil();
406
407   return GetObject(anObject);
408 }
409
410
411 //=============================================================================
412 /*!
413  *  MakeSketcherOnPlane
414  */
415 //=============================================================================
416 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcherOnPlane
417                 (const char* theCommand, GEOM::GEOM_Object_ptr theWorkingPlane)
418 {
419   //Set a not done flag
420   GetOperations()->SetNotDone();
421
422   Handle(GEOM_Object) aWorkingPlane = GetOperations()->GetEngine()->GetObject
423     (theWorkingPlane->GetStudyID(), theWorkingPlane->GetEntry());
424
425   // Make Sketcher
426   Handle(GEOM_Object) anObject =
427       GetOperations()->MakeSketcherOnPlane(theCommand, aWorkingPlane);
428   if (!GetOperations()->IsDone() || anObject.IsNull())
429     return GEOM::GEOM_Object::_nil();
430
431   return GetObject(anObject);
432 }