Salome HOME
Avoid including of SALOMEDS classes; fix pb with objects deletion
[modules/geom.git] / src / GEOM_I / GEOM_ICurvesOperations_i.cc
1 #include <Standard_Stream.hxx>
2
3 #include "GEOM_ICurvesOperations_i.hh"
4
5 #include "utilities.h"
6 #include "OpUtil.hxx"
7
8 #include "GEOM_Engine.hxx"
9 #include "GEOM_Object.hxx"
10
11 //=============================================================================
12 /*!
13  *   constructor:
14  */
15 //=============================================================================
16 GEOM_ICurvesOperations_i::GEOM_ICurvesOperations_i (PortableServer::POA_ptr thePOA,
17                                                     GEOM::GEOM_Gen_ptr theEngine,
18                                                     ::GEOMImpl_ICurvesOperations* theImpl)
19 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
20 {
21   MESSAGE("GEOM_ICurvesOperations_i::GEOM_ICurvesOperations_i");
22 }
23
24 //=============================================================================
25 /*!
26  *  destructor
27  */
28 //=============================================================================
29 GEOM_ICurvesOperations_i::~GEOM_ICurvesOperations_i()
30 {
31   MESSAGE("GEOM_ICurvesOperations_i::~GEOM_ICurvesOperations_i");
32 }
33
34
35 //=============================================================================
36 /*!
37  *  MakeCirclePntVecR
38  */
39 //=============================================================================
40 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCirclePntVecR
41                       (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
42                        CORBA::Double theR)
43 {
44   GEOM::GEOM_Object_var aGEOMObject;
45
46   //Set a not done flag
47   GetOperations()->SetNotDone();
48
49   if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
50
51   //Get the reference points
52   Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
53     (thePnt->GetStudyID(), thePnt->GetEntry());
54   Handle(GEOM_Object) aVec = GetOperations()->GetEngine()->GetObject
55     (theVec->GetStudyID(), theVec->GetEntry());
56
57   if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
58
59   // Make Circle
60   Handle(GEOM_Object) anObject =
61     GetOperations()->MakeCirclePntVecR(aPnt, aVec, theR);
62   if (!GetOperations()->IsDone() || anObject.IsNull())
63     return aGEOMObject._retn();
64
65   return GetObject(anObject);
66 }
67
68 //=============================================================================
69 /*!
70  *  MakeCircleThreePnt
71  */
72 //=============================================================================
73 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCircleThreePnt
74                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2,
75                        GEOM::GEOM_Object_ptr thePnt3)
76 {
77   GEOM::GEOM_Object_var aGEOMObject;
78
79   //Set a not done flag
80   GetOperations()->SetNotDone();
81
82   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn();
83
84   //Get the reference points
85   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
86     (thePnt1->GetStudyID(), thePnt1->GetEntry());
87   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
88     (thePnt2->GetStudyID(), thePnt2->GetEntry());
89   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
90     (thePnt3->GetStudyID(), thePnt3->GetEntry());
91
92   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
93
94   // Make Circle
95   Handle(GEOM_Object) anObject =
96       GetOperations()->MakeCircleThreePnt(aPnt1, aPnt2, aPnt3);
97   if (!GetOperations()->IsDone() || anObject.IsNull())
98     return aGEOMObject._retn();
99
100   return GetObject(anObject);
101 }
102
103 //=============================================================================
104 /*!
105  *  MakeEllipse
106  */
107 //=============================================================================
108 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeEllipse
109                       (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
110                        CORBA::Double theRMajor, double theRMinor)
111 {
112   GEOM::GEOM_Object_var aGEOMObject;
113
114   //Set a not done flag
115   GetOperations()->SetNotDone();
116
117   if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
118
119   //Get the reference points
120   Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
121     (thePnt->GetStudyID(), thePnt->GetEntry());
122   Handle(GEOM_Object) aVec = GetOperations()->GetEngine()->GetObject
123     (theVec->GetStudyID(), theVec->GetEntry());
124
125   if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
126
127   // Make Ellipse
128   Handle(GEOM_Object) anObject =
129     GetOperations()->MakeEllipse(aPnt, aVec, theRMajor, theRMinor);
130   if (!GetOperations()->IsDone() || anObject.IsNull())
131     return aGEOMObject._retn();
132
133   return GetObject(anObject);
134 }
135
136 //=============================================================================
137 /*!
138  *  MakeArc
139  */
140 //=============================================================================
141 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeArc
142                                                 (GEOM::GEOM_Object_ptr thePnt1,
143                                                  GEOM::GEOM_Object_ptr thePnt2,
144                                                  GEOM::GEOM_Object_ptr thePnt3)
145 {
146   GEOM::GEOM_Object_var aGEOMObject;
147
148   //Set a not done flag
149   GetOperations()->SetNotDone();
150
151   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL) return aGEOMObject._retn();
152
153   //Get the reference points
154   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
155     (thePnt1->GetStudyID(), thePnt1->GetEntry());
156   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
157     (thePnt2->GetStudyID(), thePnt2->GetEntry());
158   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
159     (thePnt3->GetStudyID(), thePnt3->GetEntry());
160
161   if (aPnt1.IsNull() || aPnt2.IsNull() || aPnt3.IsNull()) return aGEOMObject._retn();
162
163   // Make Arc
164   Handle(GEOM_Object) anObject =
165     GetOperations()->MakeArc(aPnt1, aPnt2, aPnt3);
166   if (!GetOperations()->IsDone() || anObject.IsNull())
167     return aGEOMObject._retn();
168
169   return GetObject(anObject);
170 }
171
172 //=============================================================================
173 /*!
174  *  MakePolyline
175  */
176 //=============================================================================
177 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakePolyline
178                                     (const GEOM::ListOfGO& thePoints)
179 {
180   GEOM::GEOM_Object_var aGEOMObject;
181
182   //Set a not done flag
183   GetOperations()->SetNotDone();
184
185   //Get the reference point
186   int ind = 0;
187   int aLen = thePoints.length();
188   list<Handle(GEOM_Object)> aPoints;
189   for (; ind < aLen; ind++) {
190     if (thePoints[ind] == NULL) return aGEOMObject._retn();
191
192     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
193       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
194
195     if (aPnt.IsNull()) return aGEOMObject._retn();
196     aPoints.push_back(aPnt);
197   }
198
199   // Make Polyline
200   Handle(GEOM_Object) anObject =
201     GetOperations()->MakePolyline(aPoints);
202   if (!GetOperations()->IsDone() || anObject.IsNull())
203     return aGEOMObject._retn();
204
205   return GetObject(anObject);
206 }
207
208 //=============================================================================
209 /*!
210  *  MakeSplineBezier
211  */
212 //=============================================================================
213 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineBezier
214                                               (const GEOM::ListOfGO& thePoints)
215 {
216   GEOM::GEOM_Object_var aGEOMObject;
217
218   //Set a not done flag
219   GetOperations()->SetNotDone();
220
221   //Get the reference point
222   int ind = 0;
223   int aLen = thePoints.length();
224   list<Handle(GEOM_Object)> aPoints;
225   for (; ind < aLen; ind++) {
226     if (thePoints[ind] == NULL) return aGEOMObject._retn();
227
228     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
229       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
230
231     if (aPnt.IsNull()) return aGEOMObject._retn();
232     aPoints.push_back(aPnt);
233   }
234
235   // Make Bezier curve
236   Handle(GEOM_Object) anObject =
237       GetOperations()->MakeSplineBezier(aPoints);
238   if (!GetOperations()->IsDone() || anObject.IsNull())
239     return aGEOMObject._retn();
240
241   return GetObject(anObject);
242 }
243
244 //=============================================================================
245 /*!
246  *  MakeSplineInterpolation
247  */
248 //=============================================================================
249 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineInterpolation
250                                               (const GEOM::ListOfGO& thePoints)
251 {
252   GEOM::GEOM_Object_var aGEOMObject;
253
254   //Set a not done flag
255   GetOperations()->SetNotDone();
256
257   //Get the reference point
258   int ind = 0;
259   int aLen = thePoints.length();
260   list<Handle(GEOM_Object)> aPoints;
261   for (; ind < aLen; ind++) {
262     if (thePoints[ind] == NULL) return aGEOMObject._retn();
263
264     Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
265       (thePoints[ind]->GetStudyID(), thePoints[ind]->GetEntry());
266
267     if (aPnt.IsNull()) return aGEOMObject._retn();
268     aPoints.push_back(aPnt);
269   }
270
271   // Make Polyline
272   Handle(GEOM_Object) anObject =
273       GetOperations()->MakeSplineInterpolation(aPoints);
274   if (!GetOperations()->IsDone() || anObject.IsNull())
275     return aGEOMObject._retn();
276
277   return GetObject(anObject);
278 }
279
280 //=============================================================================
281 /*!
282  *  MakeSketcher
283  */
284 //=============================================================================
285 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcher
286             (const char* theCommand, const GEOM::ListOfDouble& theWorkingPlane)
287 {
288   GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_nil();
289
290   //Set a not done flag
291   GetOperations()->SetNotDone();
292
293   int ind = 0;
294   int aLen = theWorkingPlane.length();
295   list<double> aWorkingPlane;
296   for (; ind < aLen; ind++)
297     aWorkingPlane.push_back(theWorkingPlane[ind]);
298
299   // Make Sketcher
300   Handle(GEOM_Object) anObject =
301     GetOperations()->MakeSketcher(strdup(theCommand), aWorkingPlane);
302   if (!GetOperations()->IsDone() || anObject.IsNull())
303     //return aGEOMObject._retn();
304     return GEOM::GEOM_Object::_nil();
305
306   return GetObject(anObject);
307 }
308
309
310 //=============================================================================
311 /*!
312  *  MakeSketcherOnPlane
313  */
314 //=============================================================================
315 GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSketcherOnPlane
316                 (const char* theCommand, GEOM::GEOM_Object_ptr theWorkingPlane)
317 {
318   GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_nil();
319
320   //Set a not done flag
321   GetOperations()->SetNotDone();
322
323   Handle(GEOM_Object) aWorkingPlane = GetOperations()->GetEngine()->GetObject
324     (theWorkingPlane->GetStudyID(), theWorkingPlane->GetEntry());
325
326   // Make Sketcher
327   Handle(GEOM_Object) anObject =
328       GetOperations()->MakeSketcherOnPlane(strdup(theCommand), aWorkingPlane);
329   if (!GetOperations()->IsDone() || anObject.IsNull())
330     return aGEOMObject._retn();
331
332   return GetObject(anObject);
333 }