Salome HOME
Fix for bug Bug IPAL20288 (4x: CRASH after trying to build a sketch).
[modules/geom.git] / src / GEOM_I / GEOM_ILocalOperations_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_ILocalOperations_i.hh"
23
24 #include "utilities.h"
25 #include "OpUtil.hxx"
26 #include "Utils_ExceptHandlers.hxx"
27
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
30
31 //=============================================================================
32 /*!
33  *   constructor:
34  */
35 //=============================================================================
36 GEOM_ILocalOperations_i::GEOM_ILocalOperations_i (PortableServer::POA_ptr thePOA,
37                                                   GEOM::GEOM_Gen_ptr theEngine,
38                                                   ::GEOMImpl_ILocalOperations* theImpl)
39      :GEOM_IOperations_i(thePOA, theEngine, theImpl)
40 {
41   MESSAGE("GEOM_ILocalOperations_i::GEOM_ILocalOperations_i");
42 }
43
44 //=============================================================================
45 /*!
46  *  destructor
47  */
48 //=============================================================================
49 GEOM_ILocalOperations_i::~GEOM_ILocalOperations_i()
50 {
51   MESSAGE("GEOM_ILocalOperations_i::~GEOM_ILocalOperations_i");
52 }
53
54
55 //=============================================================================
56 /*!
57  *  MakeFilletAll
58  */
59 //=============================================================================
60 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFilletAll
61                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR)
62 {
63   GEOM::GEOM_Object_var aGEOMObject;
64
65   if (theShape == NULL) return aGEOMObject._retn();
66
67   //Get the reference shape
68   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
69     (theShape->GetStudyID(), theShape->GetEntry());
70
71   if (aShapeRef.IsNull()) return aGEOMObject._retn();
72
73   //Create the Fillet
74   Handle(GEOM_Object) anObject =
75     GetOperations()->MakeFilletAll(aShapeRef, theR);
76   if (!GetOperations()->IsDone() || anObject.IsNull())
77     return aGEOMObject._retn();
78
79   return GetObject(anObject);
80 }
81
82 //=============================================================================
83 /*!
84  *  MakeFilletEdges
85  */
86 //=============================================================================
87 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFilletEdges
88                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR,
89                        const GEOM::ListOfLong& theEdges)
90 {
91   GEOM::GEOM_Object_var aGEOMObject;
92
93   if (theShape == NULL) return aGEOMObject._retn();
94
95   //Get the reference shape
96   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
97     (theShape->GetStudyID(), theShape->GetEntry());
98   if (aShapeRef.IsNull()) return aGEOMObject._retn();
99
100   //Get the reference edges
101   int ind = 0;
102   int aLen = theEdges.length();
103   list<int> anEdges;
104   for (; ind < aLen; ind++) {
105     anEdges.push_back(theEdges[ind]);
106   }
107
108   //Create the Fillet
109   Handle(GEOM_Object) anObject =
110     GetOperations()->MakeFilletEdges(aShapeRef, theR, anEdges);
111   if (!GetOperations()->IsDone() || anObject.IsNull())
112     return aGEOMObject._retn();
113
114   return GetObject(anObject);
115 }
116
117 //=============================================================================
118 /*!
119  *  MakeFilletEdges R1 R2
120  */
121 //=============================================================================
122 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFilletEdgesR1R2
123                      (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR1,
124                       CORBA::Double theR2, const GEOM::ListOfLong& theEdges)
125 {
126   GEOM::GEOM_Object_var aGEOMObject;
127
128   if (theShape == NULL) return aGEOMObject._retn();
129
130   //Get the reference shape
131   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
132     (theShape->GetStudyID(), theShape->GetEntry());
133   if (aShapeRef.IsNull()) return aGEOMObject._retn();
134
135   //Get the reference edges
136   int ind = 0;
137   int aLen = theEdges.length();
138   list<int> anEdges;
139   for (; ind < aLen; ind++) {
140     anEdges.push_back(theEdges[ind]);
141   }
142
143   //Create the Fillet
144   Handle(GEOM_Object) anObject =
145     GetOperations()->MakeFilletEdgesR1R2(aShapeRef, theR1, theR2, anEdges);
146   if (!GetOperations()->IsDone() || anObject.IsNull())
147     return aGEOMObject._retn();
148
149   return GetObject(anObject);
150 }
151
152 //=============================================================================
153 /*!
154  *  MakeFilletFaces
155  */
156 //=============================================================================
157 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFilletFaces
158                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR,
159                        const GEOM::ListOfLong& theFaces)
160 {
161   GEOM::GEOM_Object_var aGEOMObject;
162
163   if (theShape == NULL) return aGEOMObject._retn();
164
165   //Get the reference shape
166   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
167     (theShape->GetStudyID(), theShape->GetEntry());
168   if (aShapeRef.IsNull()) return aGEOMObject._retn();
169
170   //Get the reference faces
171   int ind = 0;
172   int aLen = theFaces.length();
173   list<int> aFaces;
174   for (; ind < aLen; ind++) {
175     aFaces.push_back(theFaces[ind]);
176   }
177
178   //Create the Fillet
179   Handle(GEOM_Object) anObject =
180     GetOperations()->MakeFilletFaces(aShapeRef, theR, aFaces);
181   if (!GetOperations()->IsDone() || anObject.IsNull())
182     return aGEOMObject._retn();
183
184   return GetObject(anObject);
185 }
186
187 //=============================================================================
188 /*!
189  *  MakeFilletFaces R1 R2
190  */
191 //=============================================================================
192 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFilletFacesR1R2
193                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR1,
194                        CORBA::Double theR2, const GEOM::ListOfLong& theFaces)
195 {
196   GEOM::GEOM_Object_var aGEOMObject;
197
198   if (theShape == NULL) return aGEOMObject._retn();
199
200   //Get the reference shape
201   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
202     (theShape->GetStudyID(), theShape->GetEntry());
203   if (aShapeRef.IsNull()) return aGEOMObject._retn();
204
205   //Get the reference faces
206   int ind = 0;
207   int aLen = theFaces.length();
208   list<int> aFaces;
209   for (; ind < aLen; ind++) {
210     aFaces.push_back(theFaces[ind]);
211   }
212
213   //Create the Fillet
214   Handle(GEOM_Object) anObject =
215     GetOperations()->MakeFilletFacesR1R2(aShapeRef, theR1, theR2, aFaces);
216   if (!GetOperations()->IsDone() || anObject.IsNull())
217     return aGEOMObject._retn();
218
219   return GetObject(anObject);
220 }
221
222 //=============================================================================
223 /*!
224  *  MakeChamferAll
225  */
226 //=============================================================================
227 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferAll
228                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theD)
229 {
230   GEOM::GEOM_Object_var aGEOMObject;
231
232   if (theShape == NULL) return aGEOMObject._retn();
233
234   //Get the reference shape
235   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
236     (theShape->GetStudyID(), theShape->GetEntry());
237
238   if (aShapeRef.IsNull()) return aGEOMObject._retn();
239
240   //Create the Chamfer
241   Handle(GEOM_Object) anObject =
242     GetOperations()->MakeChamferAll(aShapeRef, theD);
243   if (!GetOperations()->IsDone() || anObject.IsNull())
244     return aGEOMObject._retn();
245
246   return GetObject(anObject);
247 }
248
249 //=============================================================================
250 /*!
251  *  MakeChamferEdge
252  */
253 //=============================================================================
254 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferEdge
255                       (GEOM::GEOM_Object_ptr theShape,
256                        CORBA::Double theD1, CORBA::Double theD2,
257                        CORBA::Long theFace1, CORBA::Long theFace2)
258 {
259   GEOM::GEOM_Object_var aGEOMObject;
260
261   if (theShape == NULL) return aGEOMObject._retn();
262
263   //Get the reference shape
264   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
265     (theShape->GetStudyID(), theShape->GetEntry());
266   if (aShapeRef.IsNull()) return aGEOMObject._retn();
267
268   //Create the Chamfer
269   Handle(GEOM_Object) anObject =
270     GetOperations()->MakeChamferEdge(aShapeRef, theD1, theD2, theFace1, theFace2);
271   if (!GetOperations()->IsDone() || anObject.IsNull())
272     return aGEOMObject._retn();
273
274   return GetObject(anObject);
275 }
276 //=============================================================================
277 /*!
278  *  MakeChamferEdgeAD
279  */
280 //=============================================================================
281 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferEdgeAD
282                       (GEOM::GEOM_Object_ptr theShape,
283                        CORBA::Double theD, CORBA::Double theAngle,
284                        CORBA::Long theFace1, CORBA::Long theFace2)
285 {
286   GEOM::GEOM_Object_var aGEOMObject;
287
288   if (theShape == NULL) return aGEOMObject._retn();
289
290   //Get the reference shape
291   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
292     (theShape->GetStudyID(), theShape->GetEntry());
293   if (aShapeRef.IsNull()) return aGEOMObject._retn();
294
295   //Create the Chamfer
296   Handle(GEOM_Object) anObject =
297     GetOperations()->MakeChamferEdgeAD(aShapeRef, theD, theAngle, theFace1, theFace2);
298   if (!GetOperations()->IsDone() || anObject.IsNull())
299     return aGEOMObject._retn();
300
301   return GetObject(anObject);
302 }
303
304 //=============================================================================
305 /*!
306  *  MakeChamferFaces
307  */
308 //=============================================================================
309 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferFaces
310                       (GEOM::GEOM_Object_ptr theShape,
311                        CORBA::Double theD1, CORBA::Double theD2,
312                        const GEOM::ListOfLong& theFaces)
313 {
314   GEOM::GEOM_Object_var aGEOMObject;
315
316   if (theShape == NULL) return aGEOMObject._retn();
317
318   //Get the reference shape
319   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
320     (theShape->GetStudyID(), theShape->GetEntry());
321   if (aShapeRef.IsNull()) return aGEOMObject._retn();
322
323   //Get the reference faces
324   int ind = 0;
325   int aLen = theFaces.length();
326   list<int> aFaces;
327   for (; ind < aLen; ind++) {
328     aFaces.push_back(theFaces[ind]);
329   }
330
331   //Create the Chamfer
332   Handle(GEOM_Object) anObject =
333     GetOperations()->MakeChamferFaces(aShapeRef, theD1, theD2, aFaces);
334   if (!GetOperations()->IsDone() || anObject.IsNull())
335     return aGEOMObject._retn();
336
337   return GetObject(anObject);
338 }
339 //=============================================================================
340 /*!
341  *  MakeChamferFacesAD
342  */
343 //=============================================================================
344 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferFacesAD
345                       (GEOM::GEOM_Object_ptr theShape,
346                        CORBA::Double theD, CORBA::Double theAngle,
347                        const GEOM::ListOfLong& theFaces)
348 {
349   GEOM::GEOM_Object_var aGEOMObject;
350
351   if (theShape == NULL) return aGEOMObject._retn();
352
353   //Get the reference shape
354   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
355     (theShape->GetStudyID(), theShape->GetEntry());
356   if (aShapeRef.IsNull()) return aGEOMObject._retn();
357
358   //Get the reference faces
359   int ind = 0;
360   int aLen = theFaces.length();
361   list<int> aFaces;
362   for (; ind < aLen; ind++) {
363     aFaces.push_back(theFaces[ind]);
364   }
365
366   //Create the Chamfer
367   Handle(GEOM_Object) anObject =
368     GetOperations()->MakeChamferFacesAD(aShapeRef, theD, theAngle, aFaces);
369   if (!GetOperations()->IsDone() || anObject.IsNull())
370     return aGEOMObject._retn();
371
372   return GetObject(anObject);
373 }
374
375 //=============================================================================
376 /*!
377  *  MakeChamferEdges
378  */
379 //=============================================================================
380 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferEdges
381                       (GEOM::GEOM_Object_ptr theShape,
382                        CORBA::Double theD1, CORBA::Double theD2,
383                        const GEOM::ListOfLong& theEdges)
384 {
385   GEOM::GEOM_Object_var aGEOMObject;
386
387   if (theShape == NULL) return aGEOMObject._retn();
388
389   //Get the reference shape
390   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
391     (theShape->GetStudyID(), theShape->GetEntry());
392   if (aShapeRef.IsNull()) return aGEOMObject._retn();
393
394   //Get the reference edges
395   int ind = 0;
396   int aLen = theEdges.length();
397   list<int> aEdges;
398   for (; ind < aLen; ind++) {
399     aEdges.push_back(theEdges[ind]);
400   }
401
402   //Create the Chamfer
403   Handle(GEOM_Object) anObject =
404     GetOperations()->MakeChamferEdges(aShapeRef, theD1, theD2, aEdges);
405   if (!GetOperations()->IsDone() || anObject.IsNull())
406     return aGEOMObject._retn();
407
408   return GetObject(anObject);
409 }
410
411 //=============================================================================
412 /*!
413  *  MakeChamferEdgesAD
414  */
415 //=============================================================================
416 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferEdgesAD
417                       (GEOM::GEOM_Object_ptr theShape,
418                        CORBA::Double theD, CORBA::Double theAngle,
419                        const GEOM::ListOfLong& theEdges)
420 {
421   GEOM::GEOM_Object_var aGEOMObject;
422
423   if (theShape == NULL) return aGEOMObject._retn();
424
425   //Get the reference shape
426   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
427     (theShape->GetStudyID(), theShape->GetEntry());
428   if (aShapeRef.IsNull()) return aGEOMObject._retn();
429
430   //Get the reference edges
431   int ind = 0;
432   int aLen = theEdges.length();
433   list<int> aEdges;
434   for (; ind < aLen; ind++) {
435     aEdges.push_back(theEdges[ind]);
436   }
437
438   //Create the Chamfer
439   Handle(GEOM_Object) anObject =
440     GetOperations()->MakeChamferEdgesAD(aShapeRef, theD, theAngle, aEdges);
441   if (!GetOperations()->IsDone() || anObject.IsNull())
442     return aGEOMObject._retn();
443
444   return GetObject(anObject);
445 }
446
447 //=============================================================================
448 /*!
449  *  MakeArchimede
450  */
451 //=============================================================================
452 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeArchimede (GEOM::GEOM_Object_ptr theShape,
453                                                               CORBA::Double theWeight,
454                                                               CORBA::Double theWaterDensity,
455                                                               CORBA::Double theMeshingDeflection)
456 {
457   GEOM::GEOM_Object_var aGEOMObject;
458
459   if (theShape == NULL) return aGEOMObject._retn();
460
461   //Get the reference shape
462   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
463     (theShape->GetStudyID(), theShape->GetEntry());
464   if (aShapeRef.IsNull()) return aGEOMObject._retn();
465
466   //Create the Archimede
467   Handle(GEOM_Object) anObject = GetOperations()->MakeArchimede
468     (aShapeRef, theWeight, theWaterDensity, theMeshingDeflection);
469   if (!GetOperations()->IsDone() || anObject.IsNull())
470     return aGEOMObject._retn();
471
472   return GetObject(anObject);
473 }
474
475 //=============================================================================
476 /*!
477  *  GetSubShapeIndex
478  */
479 //=============================================================================
480 CORBA::Long GEOM_ILocalOperations_i::GetSubShapeIndex
481   (GEOM::GEOM_Object_ptr theShape, GEOM::GEOM_Object_ptr theSubShape)
482 {
483   if (theShape == NULL || theSubShape == NULL) return -1;
484
485   //Get the reference shapes
486   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
487     (theShape->GetStudyID(), theShape->GetEntry());
488   Handle(GEOM_Object) aSubShapeRef = GetOperations()->GetEngine()->GetObject
489     (theSubShape->GetStudyID(), theSubShape->GetEntry());
490   if (aShapeRef.IsNull() || aSubShapeRef.IsNull()) return -1;
491
492   //Get the unique ID of <theSubShape> inside <theShape>
493   CORBA::Long anID = GetOperations()->GetSubShapeIndex(aShapeRef, aSubShapeRef);
494   if (!GetOperations()->IsDone())
495     return -1;
496
497   return anID;
498 }