Salome HOME
a2dd291fc5f6a6547d5398d7623661c024971e04
[modules/geom.git] / src / GEOM_I / GEOM_ILocalOperations_i.cc
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <Standard_Stream.hxx>
24
25 #include "GEOM_ILocalOperations_i.hh"
26
27 #include "utilities.h"
28 #include "OpUtil.hxx"
29 #include "Utils_ExceptHandlers.hxx"
30
31 #include "GEOM_Engine.hxx"
32 #include "GEOM_Object.hxx"
33
34 //=============================================================================
35 /*!
36  *   constructor:
37  */
38 //=============================================================================
39 GEOM_ILocalOperations_i::GEOM_ILocalOperations_i (PortableServer::POA_ptr thePOA,
40                                                   GEOM::GEOM_Gen_ptr theEngine,
41                                                   ::GEOMImpl_ILocalOperations* theImpl)
42      :GEOM_IOperations_i(thePOA, theEngine, theImpl)
43 {
44   MESSAGE("GEOM_ILocalOperations_i::GEOM_ILocalOperations_i");
45 }
46
47 //=============================================================================
48 /*!
49  *  destructor
50  */
51 //=============================================================================
52 GEOM_ILocalOperations_i::~GEOM_ILocalOperations_i()
53 {
54   MESSAGE("GEOM_ILocalOperations_i::~GEOM_ILocalOperations_i");
55 }
56
57
58 //=============================================================================
59 /*!
60  *  MakeFilletAll
61  */
62 //=============================================================================
63 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFilletAll
64                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR)
65 {
66   GEOM::GEOM_Object_var aGEOMObject;
67
68   //Get the reference shape
69   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
70   if (aShapeRef.IsNull()) return aGEOMObject._retn();
71
72   //Create the Fillet
73   Handle(::GEOM_Object) anObject =
74     GetOperations()->MakeFilletAll(aShapeRef, theR);
75   if (!GetOperations()->IsDone() || anObject.IsNull())
76     return aGEOMObject._retn();
77
78   return GetObject(anObject);
79 }
80
81 //=============================================================================
82 /*!
83  *  MakeFilletEdges
84  */
85 //=============================================================================
86 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFilletEdges
87                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR,
88                        const GEOM::ListOfLong& theEdges)
89 {
90   GEOM::GEOM_Object_var aGEOMObject;
91
92   //Get the reference shape
93   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
94   if (aShapeRef.IsNull()) return aGEOMObject._retn();
95
96   //Get the reference edges
97   int ind = 0;
98   int aLen = theEdges.length();
99   std::list<int> anEdges;
100   for (; ind < aLen; ind++) {
101     anEdges.push_back(theEdges[ind]);
102   }
103
104   //Create the Fillet
105   Handle(::GEOM_Object) anObject =
106     GetOperations()->MakeFilletEdges(aShapeRef, theR, anEdges);
107   if (!GetOperations()->IsDone() || anObject.IsNull())
108     return aGEOMObject._retn();
109
110   return GetObject(anObject);
111 }
112
113 //=============================================================================
114 /*!
115  *  MakeFilletEdges R1 R2
116  */
117 //=============================================================================
118 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFilletEdgesR1R2
119                      (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR1,
120                       CORBA::Double theR2, const GEOM::ListOfLong& theEdges)
121 {
122   GEOM::GEOM_Object_var aGEOMObject;
123
124   //Get the reference shape
125   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
126   if (aShapeRef.IsNull()) return aGEOMObject._retn();
127
128   //Get the reference edges
129   int ind = 0;
130   int aLen = theEdges.length();
131   std::list<int> anEdges;
132   for (; ind < aLen; ind++) {
133     anEdges.push_back(theEdges[ind]);
134   }
135
136   //Create the Fillet
137   Handle(::GEOM_Object) anObject =
138     GetOperations()->MakeFilletEdgesR1R2(aShapeRef, theR1, theR2, anEdges);
139   if (!GetOperations()->IsDone() || anObject.IsNull())
140     return aGEOMObject._retn();
141
142   return GetObject(anObject);
143 }
144
145 //=============================================================================
146 /*!
147  *  MakeFilletFaces
148  */
149 //=============================================================================
150 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFilletFaces
151                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR,
152                        const GEOM::ListOfLong& theFaces)
153 {
154   GEOM::GEOM_Object_var aGEOMObject;
155
156   //Get the reference shape
157   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
158   if (aShapeRef.IsNull()) return aGEOMObject._retn();
159
160   //Get the reference faces
161   int ind = 0;
162   int aLen = theFaces.length();
163   std::list<int> aFaces;
164   for (; ind < aLen; ind++) {
165     aFaces.push_back(theFaces[ind]);
166   }
167
168   //Create the Fillet
169   Handle(::GEOM_Object) anObject =
170     GetOperations()->MakeFilletFaces(aShapeRef, theR, aFaces);
171   if (!GetOperations()->IsDone() || anObject.IsNull())
172     return aGEOMObject._retn();
173
174   return GetObject(anObject);
175 }
176
177 //=============================================================================
178 /*!
179  *  MakeFilletFaces R1 R2
180  */
181 //=============================================================================
182 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFilletFacesR1R2
183                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR1,
184                        CORBA::Double theR2, const GEOM::ListOfLong& theFaces)
185 {
186   GEOM::GEOM_Object_var aGEOMObject;
187
188   //Get the reference shape
189   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
190   if (aShapeRef.IsNull()) return aGEOMObject._retn();
191
192   //Get the reference faces
193   int ind = 0;
194   int aLen = theFaces.length();
195   std::list<int> aFaces;
196   for (; ind < aLen; ind++) {
197     aFaces.push_back(theFaces[ind]);
198   }
199
200   //Create the Fillet
201   Handle(::GEOM_Object) anObject =
202     GetOperations()->MakeFilletFacesR1R2(aShapeRef, theR1, theR2, aFaces);
203   if (!GetOperations()->IsDone() || anObject.IsNull())
204     return aGEOMObject._retn();
205
206   return GetObject(anObject);
207 }
208
209 //=============================================================================
210 /*!
211  *  MakeFillet2D
212  */
213 //=============================================================================
214 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFillet2D
215                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR,
216                        const GEOM::ListOfLong& theVertexes)
217 {
218   GEOM::GEOM_Object_var aGEOMObject;
219
220   //Get the reference shape
221   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
222   if (aShapeRef.IsNull()) return aGEOMObject._retn();
223
224   //Get the reference vertex
225   int ind = 0;
226   int aLen = theVertexes.length();
227   std::list<int> aVertexes;
228   for (; ind < aLen; ind++) {
229     aVertexes.push_back(theVertexes[ind]);
230   }
231
232   //Create the Fillet
233   Handle(::GEOM_Object) anObject =
234     GetOperations()->MakeFillet2D(aShapeRef, theR, aVertexes);
235   if (!GetOperations()->IsDone() || anObject.IsNull())
236     return aGEOMObject._retn();
237
238   return GetObject(anObject);
239 }
240
241 //=============================================================================
242 /*!
243  *  MakeFillet1D
244  */
245 //=============================================================================
246 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFillet1D
247                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR,
248                        const GEOM::ListOfLong& theVertexes,
249                        CORBA::Boolean doIgnoreSecantVertices)
250 {
251   GEOM::GEOM_Object_var aGEOMObject;
252
253   //Get the reference shape (wire)
254   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
255   if (aShapeRef.IsNull()) return aGEOMObject._retn();
256
257   //Get the reference vertex
258   int ind = 0;
259   int aLen = theVertexes.length();
260   std::list<int> aVertexes;
261   for (; ind < aLen; ind++) {
262     aVertexes.push_back(theVertexes[ind]);
263   }
264
265   //Create the Fillet
266   Handle(::GEOM_Object) anObject =
267     GetOperations()->MakeFillet1D(aShapeRef, theR, aVertexes, doIgnoreSecantVertices);
268   if (!GetOperations()->IsDone() || anObject.IsNull())
269     return aGEOMObject._retn();
270
271   return GetObject(anObject);
272 }
273
274 //=============================================================================
275 /*!
276  *  MakeChamferAll
277  */
278 //=============================================================================
279 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferAll
280                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theD)
281 {
282   GEOM::GEOM_Object_var aGEOMObject;
283
284   //Get the reference shape
285   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
286   if (aShapeRef.IsNull()) return aGEOMObject._retn();
287
288   //Create the Chamfer
289   Handle(::GEOM_Object) anObject =
290     GetOperations()->MakeChamferAll(aShapeRef, theD);
291   if (!GetOperations()->IsDone() || anObject.IsNull())
292     return aGEOMObject._retn();
293
294   return GetObject(anObject);
295 }
296
297 //=============================================================================
298 /*!
299  *  MakeChamferEdge
300  */
301 //=============================================================================
302 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferEdge
303                       (GEOM::GEOM_Object_ptr theShape,
304                        CORBA::Double theD1, CORBA::Double theD2,
305                        CORBA::Long theFace1, CORBA::Long theFace2)
306 {
307   GEOM::GEOM_Object_var aGEOMObject;
308
309   //Get the reference shape
310   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
311   if (aShapeRef.IsNull()) return aGEOMObject._retn();
312
313   //Create the Chamfer
314   Handle(::GEOM_Object) anObject =
315     GetOperations()->MakeChamferEdge(aShapeRef, theD1, theD2, theFace1, theFace2);
316   if (!GetOperations()->IsDone() || anObject.IsNull())
317     return aGEOMObject._retn();
318
319   return GetObject(anObject);
320 }
321 //=============================================================================
322 /*!
323  *  MakeChamferEdgeAD
324  */
325 //=============================================================================
326 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferEdgeAD
327                       (GEOM::GEOM_Object_ptr theShape,
328                        CORBA::Double theD, CORBA::Double theAngle,
329                        CORBA::Long theFace1, CORBA::Long theFace2)
330 {
331   GEOM::GEOM_Object_var aGEOMObject;
332
333   //Get the reference shape
334   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
335   if (aShapeRef.IsNull()) return aGEOMObject._retn();
336
337   //Create the Chamfer
338   Handle(::GEOM_Object) anObject =
339     GetOperations()->MakeChamferEdgeAD(aShapeRef, theD, theAngle, theFace1, theFace2);
340   if (!GetOperations()->IsDone() || anObject.IsNull())
341     return aGEOMObject._retn();
342
343   return GetObject(anObject);
344 }
345
346 //=============================================================================
347 /*!
348  *  MakeChamferFaces
349  */
350 //=============================================================================
351 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferFaces
352                       (GEOM::GEOM_Object_ptr theShape,
353                        CORBA::Double theD1, CORBA::Double theD2,
354                        const GEOM::ListOfLong& theFaces)
355 {
356   GEOM::GEOM_Object_var aGEOMObject;
357
358   //Get the reference shape
359   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
360   if (aShapeRef.IsNull()) return aGEOMObject._retn();
361
362   //Get the reference faces
363   int ind = 0;
364   int aLen = theFaces.length();
365   std::list<int> aFaces;
366   for (; ind < aLen; ind++) {
367     aFaces.push_back(theFaces[ind]);
368   }
369
370   //Create the Chamfer
371   Handle(::GEOM_Object) anObject =
372     GetOperations()->MakeChamferFaces(aShapeRef, theD1, theD2, aFaces);
373   if (!GetOperations()->IsDone() || anObject.IsNull())
374     return aGEOMObject._retn();
375
376   return GetObject(anObject);
377 }
378 //=============================================================================
379 /*!
380  *  MakeChamferFacesAD
381  */
382 //=============================================================================
383 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferFacesAD
384                       (GEOM::GEOM_Object_ptr theShape,
385                        CORBA::Double theD, CORBA::Double theAngle,
386                        const GEOM::ListOfLong& theFaces)
387 {
388   GEOM::GEOM_Object_var aGEOMObject;
389
390   //Get the reference shape
391   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
392   if (aShapeRef.IsNull()) return aGEOMObject._retn();
393
394   //Get the reference faces
395   int ind = 0;
396   int aLen = theFaces.length();
397   std::list<int> aFaces;
398   for (; ind < aLen; ind++) {
399     aFaces.push_back(theFaces[ind]);
400   }
401
402   //Create the Chamfer
403   Handle(::GEOM_Object) anObject =
404     GetOperations()->MakeChamferFacesAD(aShapeRef, theD, theAngle, aFaces);
405   if (!GetOperations()->IsDone() || anObject.IsNull())
406     return aGEOMObject._retn();
407
408   return GetObject(anObject);
409 }
410
411 //=============================================================================
412 /*!
413  *  MakeChamferEdges
414  */
415 //=============================================================================
416 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferEdges
417                       (GEOM::GEOM_Object_ptr theShape,
418                        CORBA::Double theD1, CORBA::Double theD2,
419                        const GEOM::ListOfLong& theEdges)
420 {
421   GEOM::GEOM_Object_var aGEOMObject;
422
423   //Get the reference shape
424   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
425   if (aShapeRef.IsNull()) return aGEOMObject._retn();
426
427   //Get the reference edges
428   int ind = 0;
429   int aLen = theEdges.length();
430   std::list<int> aEdges;
431   for (; ind < aLen; ind++) {
432     aEdges.push_back(theEdges[ind]);
433   }
434
435   //Create the Chamfer
436   Handle(::GEOM_Object) anObject =
437     GetOperations()->MakeChamferEdges(aShapeRef, theD1, theD2, aEdges);
438   if (!GetOperations()->IsDone() || anObject.IsNull())
439     return aGEOMObject._retn();
440
441   return GetObject(anObject);
442 }
443
444 //=============================================================================
445 /*!
446  *  MakeChamferEdgesAD
447  */
448 //=============================================================================
449 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferEdgesAD
450                       (GEOM::GEOM_Object_ptr theShape,
451                        CORBA::Double theD, CORBA::Double theAngle,
452                        const GEOM::ListOfLong& theEdges)
453 {
454   GEOM::GEOM_Object_var aGEOMObject;
455
456   //Get the reference shape
457   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
458   if (aShapeRef.IsNull()) return aGEOMObject._retn();
459
460   //Get the reference edges
461   int ind = 0;
462   int aLen = theEdges.length();
463   std::list<int> aEdges;
464   for (; ind < aLen; ind++) {
465     aEdges.push_back(theEdges[ind]);
466   }
467
468   //Create the Chamfer
469   Handle(::GEOM_Object) anObject =
470     GetOperations()->MakeChamferEdgesAD(aShapeRef, theD, theAngle, aEdges);
471   if (!GetOperations()->IsDone() || anObject.IsNull())
472     return aGEOMObject._retn();
473
474   return GetObject(anObject);
475 }
476
477 //=============================================================================
478 /*!
479  *  MakeArchimede
480  */
481 //=============================================================================
482 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeArchimede (GEOM::GEOM_Object_ptr theShape,
483                                                               CORBA::Double theWeight,
484                                                               CORBA::Double theWaterDensity,
485                                                               CORBA::Double theMeshingDeflection)
486 {
487   GEOM::GEOM_Object_var aGEOMObject;
488
489   //Get the reference shape
490   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
491   if (aShapeRef.IsNull()) return aGEOMObject._retn();
492
493   //Create the Archimede
494   Handle(::GEOM_Object) anObject = GetOperations()->MakeArchimede
495     (aShapeRef, theWeight, theWaterDensity, theMeshingDeflection);
496   if (!GetOperations()->IsDone() || anObject.IsNull())
497     return aGEOMObject._retn();
498
499   return GetObject(anObject);
500 }
501
502 //=============================================================================
503 /*!
504  *  GetSubShapeIndex
505  */
506 //=============================================================================
507 CORBA::Long GEOM_ILocalOperations_i::GetSubShapeIndex
508   (GEOM::GEOM_Object_ptr theShape, GEOM::GEOM_Object_ptr theSubShape)
509 {
510   //Get the reference shapes
511   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
512   Handle(::GEOM_Object) aSubShapeRef = GetObjectImpl(theSubShape);
513   if (aShapeRef.IsNull() || aSubShapeRef.IsNull()) return -1;
514
515   //Get the unique ID of <theSubShape> inside <theShape>
516   CORBA::Long anID = GetOperations()->GetSubShapeIndex(aShapeRef, aSubShapeRef);
517   if (!GetOperations()->IsDone())
518     return -1;
519
520   return anID;
521 }