Salome HOME
Merge with PAL/SALOME 2.1.0d
[modules/geom.git] / src / GEOM_I / GEOM_IShapesOperations_i.cc
1 using namespace std;
2
3 #include "GEOM_IShapesOperations_i.hh"
4
5 #include "utilities.h"
6 #include "OpUtil.hxx"
7 #include "Utils_ExceptHandlers.hxx"
8
9 #include "GEOM_Engine.hxx"
10 #include "GEOM_Object.hxx"
11
12 #include <TColStd_HSequenceOfTransient.hxx>
13 #include <TColStd_HArray1OfInteger.hxx>
14
15 //=============================================================================
16 /*!
17  *   constructor:
18  */
19 //=============================================================================
20 GEOM_IShapesOperations_i::GEOM_IShapesOperations_i (PortableServer::POA_ptr thePOA,
21                                                     GEOM::GEOM_Gen_ptr theEngine,
22                                                     ::GEOMImpl_IShapesOperations* theImpl)
23 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
24 {
25   MESSAGE("GEOM_IShapesOperations_i::GEOM_IShapesOperations_i");
26 }
27
28 //=============================================================================
29 /*!
30  *  destructor
31  */
32 //=============================================================================
33 GEOM_IShapesOperations_i::~GEOM_IShapesOperations_i()
34 {
35   MESSAGE("GEOM_IShapesOperations_i::~GEOM_IShapesOperations_i");
36 }
37
38
39 //=============================================================================
40 /*!
41  *  MakeEdge
42  */
43 //=============================================================================
44 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeEdge
45                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2)
46 {
47   GEOM::GEOM_Object_var aGEOMObject;
48
49   //Set a not done flag
50   GetOperations()->SetNotDone();
51
52   if (thePnt1 == NULL || thePnt2 == NULL) return aGEOMObject._retn();
53
54   //Get the reference points
55   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
56     (thePnt1->GetStudyID(), thePnt1->GetEntry());
57   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
58     (thePnt2->GetStudyID(), thePnt2->GetEntry());
59
60   if (aPnt1.IsNull() || aPnt2.IsNull()) return aGEOMObject._retn();
61
62   //Create the Edge
63   Handle(GEOM_Object) anObject = GetOperations()->MakeEdge(aPnt1, aPnt2);
64   if (!GetOperations()->IsDone() || anObject.IsNull())
65     return aGEOMObject._retn();
66
67   return GetObject(anObject);
68 }
69
70 //=============================================================================
71 /*!
72  *  MakeWire
73  */
74 //=============================================================================
75 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeWire
76                                       (const GEOM::ListOfGO& theEdgesAndWires)
77 {
78   GEOM::GEOM_Object_var aGEOMObject;
79
80   //Set a not done flag
81   GetOperations()->SetNotDone();
82
83   int ind, aLen;
84   list<Handle(GEOM_Object)> aShapes;
85
86   //Get the shapes
87   aLen = theEdgesAndWires.length();
88   for (ind = 0; ind < aLen; ind++) {
89     if (theEdgesAndWires[ind] == NULL) return aGEOMObject._retn();
90     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
91       (theEdgesAndWires[ind]->GetStudyID(), theEdgesAndWires[ind]->GetEntry());
92     if (aSh.IsNull()) return aGEOMObject._retn();
93     aShapes.push_back(aSh);
94   }
95
96   // Make Solid
97   Handle(GEOM_Object) anObject =
98     GetOperations()->MakeWire(aShapes);
99   if (!GetOperations()->IsDone() || anObject.IsNull())
100     return aGEOMObject._retn();
101
102   return GetObject(anObject);
103 }
104
105 //=============================================================================
106 /*!
107  *  MakeFace
108  */
109 //=============================================================================
110 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFace
111                       (GEOM::GEOM_Object_ptr theWire, CORBA::Boolean isPlanarWanted)
112 {
113   GEOM::GEOM_Object_var aGEOMObject;
114
115   //Set a not done flag
116   GetOperations()->SetNotDone();
117
118   if (theWire == NULL) return aGEOMObject._retn();
119
120   //Get the reference wire
121   Handle(GEOM_Object) aWire = GetOperations()->GetEngine()->GetObject
122     (theWire->GetStudyID(), theWire->GetEntry());
123
124   if (aWire.IsNull()) return aGEOMObject._retn();
125
126   //Create the Face
127   Handle(GEOM_Object) anObject = GetOperations()->MakeFace(aWire, isPlanarWanted);
128   if (!GetOperations()->IsDone() || anObject.IsNull())
129     return aGEOMObject._retn();
130
131   return GetObject(anObject);
132 }
133
134 //=============================================================================
135 /*!
136  *  MakeFaceWires
137  */
138 //=============================================================================
139 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFaceWires
140                                          (const GEOM::ListOfGO& theWires,
141                                           CORBA::Boolean        isPlanarWanted)
142 {
143   GEOM::GEOM_Object_var aGEOMObject;
144
145   //Set a not done flag
146   GetOperations()->SetNotDone();
147
148   int ind, aLen;
149   list<Handle(GEOM_Object)> aShapes;
150
151   //Get the shapes
152   aLen = theWires.length();
153   for (ind = 0; ind < aLen; ind++) {
154     if (theWires[ind] == NULL) return aGEOMObject._retn();
155     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
156       (theWires[ind]->GetStudyID(), theWires[ind]->GetEntry());
157     if (aSh.IsNull()) return aGEOMObject._retn();
158     aShapes.push_back(aSh);
159   }
160
161   // Make Face
162   Handle(GEOM_Object) anObject =
163     GetOperations()->MakeFaceWires(aShapes, isPlanarWanted);
164   if (!GetOperations()->IsDone() || anObject.IsNull())
165     return aGEOMObject._retn();
166
167   return GetObject(anObject);
168 }
169
170 //=============================================================================
171 /*!
172  *  MakeShell
173  */
174 //=============================================================================
175 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeShell
176                                       (const GEOM::ListOfGO& theFacesAndShells)
177 {
178   GEOM::GEOM_Object_var aGEOMObject;
179
180   //Set a not done flag
181   GetOperations()->SetNotDone();
182
183   int ind, aLen;
184   list<Handle(GEOM_Object)> aShapes;
185
186   //Get the shapes
187   aLen = theFacesAndShells.length();
188   for (ind = 0; ind < aLen; ind++) {
189     if (theFacesAndShells[ind] == NULL) return aGEOMObject._retn();
190     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
191       (theFacesAndShells[ind]->GetStudyID(), theFacesAndShells[ind]->GetEntry());
192     if (aSh.IsNull()) return aGEOMObject._retn();
193     aShapes.push_back(aSh);
194   }
195
196   // Make Solid
197   Handle(GEOM_Object) anObject =
198     GetOperations()->MakeShell(aShapes);
199   if (!GetOperations()->IsDone() || anObject.IsNull())
200     return aGEOMObject._retn();
201
202   return GetObject(anObject);
203 }
204
205 //=============================================================================
206 /*!
207  *  MakeSolidShell
208  */
209 //=============================================================================
210 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeSolidShell
211                                                 (GEOM::GEOM_Object_ptr theShell)
212 {
213   GEOM::GEOM_Object_var aGEOMObject;
214
215   //Set a not done flag
216   GetOperations()->SetNotDone();
217
218   if (theShell == NULL) return aGEOMObject._retn();
219
220   //Get the reference objects
221   Handle(GEOM_Object) aShell = GetOperations()->GetEngine()->GetObject
222     (theShell->GetStudyID(), theShell->GetEntry());
223
224   if (aShell.IsNull()) return aGEOMObject._retn();
225
226   //Create the Solid
227   Handle(GEOM_Object) anObject = GetOperations()->MakeSolidShell(aShell);
228   if (!GetOperations()->IsDone() || anObject.IsNull())
229     return aGEOMObject._retn();
230
231   return GetObject(anObject);
232 }
233
234 //=============================================================================
235 /*!
236  *  MakeSolidShells
237  */
238 //=============================================================================
239 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeSolidShells
240                                       (const GEOM::ListOfGO& theShells)
241 {
242   GEOM::GEOM_Object_var aGEOMObject;
243
244   //Set a not done flag
245   GetOperations()->SetNotDone();
246
247   int ind, aLen;
248   list<Handle(GEOM_Object)> aShapes;
249
250   //Get the shapes
251   aLen = theShells.length();
252   for (ind = 0; ind < aLen; ind++) {
253     if (theShells[ind] == NULL) return aGEOMObject._retn();
254     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
255       (theShells[ind]->GetStudyID(), theShells[ind]->GetEntry());
256     if (aSh.IsNull()) return aGEOMObject._retn();
257     aShapes.push_back(aSh);
258   }
259
260   // Make Solid
261   Handle(GEOM_Object) anObject =
262     GetOperations()->MakeSolidShells(aShapes);
263   if (!GetOperations()->IsDone() || anObject.IsNull())
264     return aGEOMObject._retn();
265
266   return GetObject(anObject);
267 }
268
269 //=============================================================================
270 /*!
271  *  MakeCompound
272  */
273 //=============================================================================
274 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeCompound
275                                       (const GEOM::ListOfGO& theShapes)
276 {
277   GEOM::GEOM_Object_var aGEOMObject;
278
279   //Set a not done flag
280   GetOperations()->SetNotDone();
281
282   int ind, aLen;
283   list<Handle(GEOM_Object)> aShapes;
284
285   //Get the shapes
286   aLen = theShapes.length();
287   for (ind = 0; ind < aLen; ind++) {
288     if (theShapes[ind] == NULL) return aGEOMObject._retn();
289     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
290       (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
291     if (aSh.IsNull()) return aGEOMObject._retn();
292     aShapes.push_back(aSh);
293   }
294
295   // Make Solid
296   Handle(GEOM_Object) anObject =
297     GetOperations()->MakeCompound(aShapes);
298   if (!GetOperations()->IsDone() || anObject.IsNull())
299     return aGEOMObject._retn();
300
301   return GetObject(anObject);
302 }
303
304 //=============================================================================
305 /*!
306  *  MakeGlueFaces
307  */
308 //=============================================================================
309 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeGlueFaces
310                                            (GEOM::GEOM_Object_ptr theShape,
311                                             const CORBA::Double   theTolerance)
312 {
313   GEOM::GEOM_Object_var aGEOMObject;
314
315   //Set a not done flag
316   GetOperations()->SetNotDone();
317
318   if (theShape == NULL) return aGEOMObject._retn();
319
320   //Get the reference objects
321   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
322     (theShape->GetStudyID(), theShape->GetEntry());
323
324   if (aShape.IsNull()) return aGEOMObject._retn();
325
326   //Perform the glueing
327   Handle(GEOM_Object) anObject =
328     GetOperations()->MakeGlueFaces(aShape, theTolerance);
329   if (!GetOperations()->IsDone() || anObject.IsNull())
330     return aGEOMObject._retn();
331
332   return GetObject(anObject);
333 }
334
335 //=============================================================================
336 /*!
337  *  MakeExplode
338  */
339 //=============================================================================
340 GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeExplode (GEOM::GEOM_Object_ptr theShape,
341                                                        const CORBA::Long     theShapeType,
342                                                        const CORBA::Boolean  isSorted)
343 {
344   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
345   if (theShape == NULL)  return aSeq._retn();
346   Handle(GEOM_Object) aShape =   GetOperations()->GetEngine()->GetObject(theShape->GetStudyID(), theShape->GetEntry());
347   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->MakeExplode(aShape, theShapeType, isSorted);
348   if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
349
350   Standard_Integer aLength = aHSeq->Length();
351   aSeq->length(aLength);
352   for (Standard_Integer i = 1; i <= aLength; i++)
353     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
354
355   return aSeq._retn();
356 }
357
358 //=============================================================================
359 /*!
360  *  GetSubShape
361  */
362 //=============================================================================
363 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetSubShape
364                                            (GEOM::GEOM_Object_ptr theMainShape,
365                                             const CORBA::Long     theID)
366 {
367   GEOM::GEOM_Object_var aGEOMObject;
368
369   //Set a not done flag
370   GetOperations()->SetNotDone();
371
372   if (theMainShape == NULL) return aGEOMObject._retn();
373
374   //Get the reference objects
375   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
376     (theMainShape->GetStudyID(), theMainShape->GetEntry());
377
378   if (aShape.IsNull()) return aGEOMObject._retn();
379
380   Handle(GEOM_Object) anObject = GetOperations()->GetSubShape(aShape, theID);
381   if (!GetOperations()->IsDone() || anObject.IsNull())
382     return aGEOMObject._retn();
383
384   return GetObject(anObject);
385 }
386
387 //=============================================================================
388 /*!
389  *  NumberOfFaces
390  */
391 //=============================================================================
392 CORBA::Long GEOM_IShapesOperations_i::NumberOfFaces (GEOM::GEOM_Object_ptr theShape)
393 {
394   if (theShape == NULL) return -1;
395
396   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
397     (theShape->GetStudyID(), theShape->GetEntry());
398
399   CORBA::Long aNb = GetOperations()->NumberOfFaces(aShape);
400   if (!GetOperations()->IsDone()) return -1;
401
402   return aNb;
403 }
404
405 //=============================================================================
406 /*!
407  *  NumberOfEdges
408  */
409 //=============================================================================
410 CORBA::Long GEOM_IShapesOperations_i::NumberOfEdges (GEOM::GEOM_Object_ptr theShape)
411 {
412   if (theShape == NULL) return -1;
413
414   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
415     (theShape->GetStudyID(), theShape->GetEntry());
416
417   CORBA::Long aNb = GetOperations()->NumberOfEdges(aShape);
418   if (!GetOperations()->IsDone()) return -1;
419
420   return aNb;
421 }
422
423 //=============================================================================
424 /*!
425  *  ReverseOrientation
426  */
427 //=============================================================================
428 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::ChangeOrientation
429                                                 (GEOM::GEOM_Object_ptr theShape)
430 {
431   GEOM::GEOM_Object_var aGEOMObject;
432
433   //Set a not done flag
434   GetOperations()->SetNotDone();
435
436   if (theShape == NULL) return aGEOMObject._retn();
437
438   //Get the reference objects
439   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
440     (theShape->GetStudyID(), theShape->GetEntry());
441
442   if (aShape.IsNull()) return aGEOMObject._retn();
443
444   //Create the Solid
445   Handle(GEOM_Object) anObject = GetOperations()->ReverseShape(aShape);
446   if (!GetOperations()->IsDone() || anObject.IsNull())
447     return aGEOMObject._retn();
448
449   return GetObject(anObject);
450 }
451