Salome HOME
Copyrights update
[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/
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  *  MakePolyline
194  */
195 //=============================================================================
196 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakePolyline
197                                     (const GEOM::ListOfGO& thePoints)
198 {
199   GEOM::GEOM_Object_var aGEOMObject;
200
201   //Set a not done flag
202   GetOperations()->SetNotDone();
203
204   //Get the reference point
205   int ind = 0;
206   int aLen = thePoints.length();
207   list<Handle(GEOM_Object)> aPoints;
208   for (; ind < aLen; ind++) {
209     if (thePoints[ind] == NULL) return aGEOMObject._retn();
210
211     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
212       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
213
214     if (aPnt.IsNull()) return aGEOMObject._retn();
215     aPoints.push_back(aPnt);
216   }
217
218   // Make Polyline
219   Handle(GEOM_Object) anObject =
220     GetOperations()->MakePolyline(aPoints);
221   if (!GetOperations()->IsDone() || anObject.IsNull())
222     return aGEOMObject._retn();
223
224   return GetObject(anObject);
225 }
226
227 //=============================================================================
228 /*!
229  *  MakeSplineBezier
230  */
231 //=============================================================================
232 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineBezier
233                                               (const GEOM::ListOfGO& thePoints)
234 {
235   GEOM::GEOM_Object_var aGEOMObject;
236
237   //Set a not done flag
238   GetOperations()->SetNotDone();
239
240   //Get the reference point
241   int ind = 0;
242   int aLen = thePoints.length();
243   list<Handle(GEOM_Object)> aPoints;
244   for (; ind < aLen; ind++) {
245     if (thePoints[ind] == NULL) return aGEOMObject._retn();
246
247     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
248       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
249
250     if (aPnt.IsNull()) return aGEOMObject._retn();
251     aPoints.push_back(aPnt);
252   }
253
254   // Make Bezier curve
255   Handle(GEOM_Object) anObject =
256       GetOperations()->MakeSplineBezier(aPoints);
257   if (!GetOperations()->IsDone() || anObject.IsNull())
258     return aGEOMObject._retn();
259
260   return GetObject(anObject);
261 }
262
263 //=============================================================================
264 /*!
265  *  MakeSplineInterpolation
266  */
267 //=============================================================================
268 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineInterpolation
269                                               (const GEOM::ListOfGO& thePoints)
270 {
271   GEOM::GEOM_Object_var aGEOMObject;
272
273   //Set a not done flag
274   GetOperations()->SetNotDone();
275
276   //Get the reference point
277   int ind = 0;
278   int aLen = thePoints.length();
279   list<Handle(GEOM_Object)> aPoints;
280   for (; ind < aLen; ind++) {
281     if (thePoints[ind] == NULL) return aGEOMObject._retn();
282
283     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
284       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
285
286     if (aPnt.IsNull()) return aGEOMObject._retn();
287     aPoints.push_back(aPnt);
288   }
289
290   // Make Polyline
291   Handle(GEOM_Object) anObject =
292       GetOperations()->MakeSplineInterpolation(aPoints);
293   if (!GetOperations()->IsDone() || anObject.IsNull())
294     return aGEOMObject._retn();
295
296   return GetObject(anObject);
297 }
298
299 //=============================================================================
300 /*!
301  *  MakeSketcher
302  */
303 //=============================================================================
304 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcher
305             (const char* theCommand, const GEOM::ListOfDouble& theWorkingPlane)
306 {
307   //Set a not done flag
308   GetOperations()->SetNotDone();
309
310   int ind = 0;
311   int aLen = theWorkingPlane.length();
312   list<double> aWorkingPlane;
313   for (; ind < aLen; ind++)
314     aWorkingPlane.push_back(theWorkingPlane[ind]);
315
316   // Make Sketcher
317   Handle(GEOM_Object) anObject =
318     GetOperations()->MakeSketcher((char*)theCommand, aWorkingPlane);
319   if (!GetOperations()->IsDone() || anObject.IsNull())
320     return GEOM::GEOM_Object::_nil();
321
322   return GetObject(anObject);
323 }
324
325
326 //=============================================================================
327 /*!
328  *  MakeSketcherOnPlane
329  */
330 //=============================================================================
331 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcherOnPlane
332                 (const char* theCommand, GEOM::GEOM_Object_ptr theWorkingPlane)
333 {
334   //Set a not done flag
335   GetOperations()->SetNotDone();
336
337   Handle(GEOM_Object) aWorkingPlane = GetOperations()->GetEngine()->GetObject
338     (theWorkingPlane->GetStudyID(), theWorkingPlane->GetEntry());
339
340   // Make Sketcher
341   Handle(GEOM_Object) anObject =
342       GetOperations()->MakeSketcherOnPlane((char*)theCommand, aWorkingPlane);
343   if (!GetOperations()->IsDone() || anObject.IsNull())
344     return GEOM::GEOM_Object::_nil();
345
346   return GetObject(anObject);
347 }