Salome HOME
Update mail address
[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  *  MakeFilletFaces
120  */
121 //=============================================================================
122 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeFilletFaces
123                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theR,
124                        const GEOM::ListOfLong& theFaces)
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 faces
136   int ind = 0;
137   int aLen = theFaces.length();
138   list<int> aFaces;
139   for (; ind < aLen; ind++) {
140     aFaces.push_back(theFaces[ind]);
141   }
142
143   //Create the Fillet
144   Handle(GEOM_Object) anObject =
145     GetOperations()->MakeFilletFaces(aShapeRef, theR, aFaces);
146   if (!GetOperations()->IsDone() || anObject.IsNull())
147     return aGEOMObject._retn();
148
149   return GetObject(anObject);
150 }
151
152 //=============================================================================
153 /*!
154  *  MakeChamferAll
155  */
156 //=============================================================================
157 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferAll
158                       (GEOM::GEOM_Object_ptr theShape, CORBA::Double theD)
159 {
160   GEOM::GEOM_Object_var aGEOMObject;
161
162   if (theShape == NULL) return aGEOMObject._retn();
163
164   //Get the reference shape
165   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
166     (theShape->GetStudyID(), theShape->GetEntry());
167
168   if (aShapeRef.IsNull()) return aGEOMObject._retn();
169
170   //Create the Chamfer
171   Handle(GEOM_Object) anObject =
172     GetOperations()->MakeChamferAll(aShapeRef, theD);
173   if (!GetOperations()->IsDone() || anObject.IsNull())
174     return aGEOMObject._retn();
175
176   return GetObject(anObject);
177 }
178
179 //=============================================================================
180 /*!
181  *  MakeChamferEdge
182  */
183 //=============================================================================
184 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferEdge
185                       (GEOM::GEOM_Object_ptr theShape,
186                        CORBA::Double theD1, CORBA::Double theD2,
187                        CORBA::Long theFace1, CORBA::Long theFace2)
188 {
189   GEOM::GEOM_Object_var aGEOMObject;
190
191   if (theShape == NULL) return aGEOMObject._retn();
192
193   //Get the reference shape
194   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
195     (theShape->GetStudyID(), theShape->GetEntry());
196   if (aShapeRef.IsNull()) return aGEOMObject._retn();
197
198   //Create the Chamfer
199   Handle(GEOM_Object) anObject =
200     GetOperations()->MakeChamferEdge(aShapeRef, theD1, theD2, theFace1, theFace2);
201   if (!GetOperations()->IsDone() || anObject.IsNull())
202     return aGEOMObject._retn();
203
204   return GetObject(anObject);
205 }
206
207 //=============================================================================
208 /*!
209  *  MakeChamferFaces
210  */
211 //=============================================================================
212 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeChamferFaces
213                       (GEOM::GEOM_Object_ptr theShape,
214                        CORBA::Double theD1, CORBA::Double theD2,
215                        const GEOM::ListOfLong& theFaces)
216 {
217   GEOM::GEOM_Object_var aGEOMObject;
218
219   if (theShape == NULL) return aGEOMObject._retn();
220
221   //Get the reference shape
222   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
223     (theShape->GetStudyID(), theShape->GetEntry());
224   if (aShapeRef.IsNull()) return aGEOMObject._retn();
225
226   //Get the reference faces
227   int ind = 0;
228   int aLen = theFaces.length();
229   list<int> aFaces;
230   for (; ind < aLen; ind++) {
231     aFaces.push_back(theFaces[ind]);
232   }
233
234   //Create the Chamfer
235   Handle(GEOM_Object) anObject =
236     GetOperations()->MakeChamferFaces(aShapeRef, theD1, theD2, aFaces);
237   if (!GetOperations()->IsDone() || anObject.IsNull())
238     return aGEOMObject._retn();
239
240   return GetObject(anObject);
241 }
242
243 //=============================================================================
244 /*!
245  *  MakeArchimede
246  */
247 //=============================================================================
248 GEOM::GEOM_Object_ptr GEOM_ILocalOperations_i::MakeArchimede (GEOM::GEOM_Object_ptr theShape,
249                                                               CORBA::Double theWeight,
250                                                               CORBA::Double theWaterDensity,
251                                                               CORBA::Double theMeshingDeflection)
252 {
253   GEOM::GEOM_Object_var aGEOMObject;
254
255   if (theShape == NULL) return aGEOMObject._retn();
256
257   //Get the reference shape
258   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
259     (theShape->GetStudyID(), theShape->GetEntry());
260   if (aShapeRef.IsNull()) return aGEOMObject._retn();
261
262   //Create the Archimede
263   Handle(GEOM_Object) anObject = GetOperations()->MakeArchimede
264     (aShapeRef, theWeight, theWaterDensity, theMeshingDeflection);
265   if (!GetOperations()->IsDone() || anObject.IsNull())
266     return aGEOMObject._retn();
267
268   return GetObject(anObject);
269 }
270
271 //=============================================================================
272 /*!
273  *  GetSubShapeIndex
274  */
275 //=============================================================================
276 CORBA::Long GEOM_ILocalOperations_i::GetSubShapeIndex
277   (GEOM::GEOM_Object_ptr theShape, GEOM::GEOM_Object_ptr theSubShape)
278 {
279   if (theShape == NULL || theSubShape == NULL) return -1;
280
281   //Get the reference shapes
282   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject
283     (theShape->GetStudyID(), theShape->GetEntry());
284   Handle(GEOM_Object) aSubShapeRef = GetOperations()->GetEngine()->GetObject
285     (theSubShape->GetStudyID(), theSubShape->GetEntry());
286   if (aShapeRef.IsNull() || aSubShapeRef.IsNull()) return -1;
287
288   //Get the unique ID of <theSubShape> inside <theShape>
289   CORBA::Long anID = GetOperations()->GetSubShapeIndex(aShapeRef, aSubShapeRef);
290   if (!GetOperations()->IsDone())
291     return -1;
292
293   return anID;
294 }