Salome HOME
Copyrights update
[modules/geom.git] / src / GEOM_I / GEOM_IShapesOperations_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/
19 //
20 #include <Standard_Stream.hxx>
21
22 #include "GEOM_IShapesOperations_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 #include <TColStd_HSequenceOfTransient.hxx>
32 #include <TColStd_HArray1OfInteger.hxx>
33
34 //=============================================================================
35 /*!
36  *   constructor:
37  */
38 //=============================================================================
39 GEOM_IShapesOperations_i::GEOM_IShapesOperations_i (PortableServer::POA_ptr thePOA,
40                                                     GEOM::GEOM_Gen_ptr theEngine,
41                                                     ::GEOMImpl_IShapesOperations* theImpl)
42 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
43 {
44   MESSAGE("GEOM_IShapesOperations_i::GEOM_IShapesOperations_i");
45 }
46
47 //=============================================================================
48 /*!
49  *  destructor
50  */
51 //=============================================================================
52 GEOM_IShapesOperations_i::~GEOM_IShapesOperations_i()
53 {
54   MESSAGE("GEOM_IShapesOperations_i::~GEOM_IShapesOperations_i");
55 }
56
57
58 //=============================================================================
59 /*!
60  *  MakeEdge
61  */
62 //=============================================================================
63 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeEdge
64                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2)
65 {
66   GEOM::GEOM_Object_var aGEOMObject;
67
68   //Set a not done flag
69   GetOperations()->SetNotDone();
70
71   if (thePnt1 == NULL || thePnt2 == NULL) return aGEOMObject._retn();
72
73   //Get the reference points
74   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
75     (thePnt1->GetStudyID(), thePnt1->GetEntry());
76   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
77     (thePnt2->GetStudyID(), thePnt2->GetEntry());
78
79   if (aPnt1.IsNull() || aPnt2.IsNull()) return aGEOMObject._retn();
80
81   //Create the Edge
82   Handle(GEOM_Object) anObject = GetOperations()->MakeEdge(aPnt1, aPnt2);
83   if (!GetOperations()->IsDone() || anObject.IsNull())
84     return aGEOMObject._retn();
85
86   return GetObject(anObject);
87 }
88
89 //=============================================================================
90 /*!
91  *  MakeWire
92  */
93 //=============================================================================
94 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeWire
95                                       (const GEOM::ListOfGO& theEdgesAndWires)
96 {
97   GEOM::GEOM_Object_var aGEOMObject;
98
99   //Set a not done flag
100   GetOperations()->SetNotDone();
101
102   int ind, aLen;
103   list<Handle(GEOM_Object)> aShapes;
104
105   //Get the shapes
106   aLen = theEdgesAndWires.length();
107   for (ind = 0; ind < aLen; ind++) {
108     if (theEdgesAndWires[ind] == NULL) return aGEOMObject._retn();
109     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
110       (theEdgesAndWires[ind]->GetStudyID(), theEdgesAndWires[ind]->GetEntry());
111     if (aSh.IsNull()) return aGEOMObject._retn();
112     aShapes.push_back(aSh);
113   }
114
115   // Make Solid
116   Handle(GEOM_Object) anObject =
117     GetOperations()->MakeWire(aShapes);
118   if (!GetOperations()->IsDone() || anObject.IsNull())
119     return aGEOMObject._retn();
120
121   return GetObject(anObject);
122 }
123
124 //=============================================================================
125 /*!
126  *  MakeFace
127  */
128 //=============================================================================
129 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFace
130                       (GEOM::GEOM_Object_ptr theWire,
131                        const CORBA::Boolean  isPlanarWanted)
132 {
133   GEOM::GEOM_Object_var aGEOMObject;
134
135   //Set a not done flag
136   GetOperations()->SetNotDone();
137
138   if (theWire == NULL) return aGEOMObject._retn();
139
140   //Get the reference wire
141   Handle(GEOM_Object) aWire = GetOperations()->GetEngine()->GetObject
142     (theWire->GetStudyID(), theWire->GetEntry());
143
144   if (aWire.IsNull()) return aGEOMObject._retn();
145
146   //Create the Face
147   Handle(GEOM_Object) anObject = GetOperations()->MakeFace(aWire, isPlanarWanted);
148   if (!GetOperations()->IsDone() || anObject.IsNull())
149     return aGEOMObject._retn();
150
151   return GetObject(anObject);
152 }
153
154 //=============================================================================
155 /*!
156  *  MakeFaceWires
157  */
158 //=============================================================================
159 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFaceWires
160                                          (const GEOM::ListOfGO& theWires,
161                                           const CORBA::Boolean  isPlanarWanted)
162 {
163   GEOM::GEOM_Object_var aGEOMObject;
164
165   //Set a not done flag
166   GetOperations()->SetNotDone();
167
168   int ind, aLen;
169   list<Handle(GEOM_Object)> aShapes;
170
171   //Get the shapes
172   aLen = theWires.length();
173   for (ind = 0; ind < aLen; ind++) {
174     if (theWires[ind] == NULL) return aGEOMObject._retn();
175     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
176       (theWires[ind]->GetStudyID(), theWires[ind]->GetEntry());
177     if (aSh.IsNull()) return aGEOMObject._retn();
178     aShapes.push_back(aSh);
179   }
180
181   // Make Face
182   Handle(GEOM_Object) anObject =
183     GetOperations()->MakeFaceWires(aShapes, isPlanarWanted);
184   if (!GetOperations()->IsDone() || anObject.IsNull())
185     return aGEOMObject._retn();
186
187   return GetObject(anObject);
188 }
189
190 //=============================================================================
191 /*!
192  *  MakeShell
193  */
194 //=============================================================================
195 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeShell
196                                       (const GEOM::ListOfGO& theFacesAndShells)
197 {
198   GEOM::GEOM_Object_var aGEOMObject;
199
200   //Set a not done flag
201   GetOperations()->SetNotDone();
202
203   int ind, aLen;
204   list<Handle(GEOM_Object)> aShapes;
205
206   //Get the shapes
207   aLen = theFacesAndShells.length();
208   for (ind = 0; ind < aLen; ind++) {
209     if (theFacesAndShells[ind] == NULL) return aGEOMObject._retn();
210     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
211       (theFacesAndShells[ind]->GetStudyID(), theFacesAndShells[ind]->GetEntry());
212     if (aSh.IsNull()) return aGEOMObject._retn();
213     aShapes.push_back(aSh);
214   }
215
216   // Make Solid
217   Handle(GEOM_Object) anObject =
218     GetOperations()->MakeShell(aShapes);
219   if (!GetOperations()->IsDone() || anObject.IsNull())
220     return aGEOMObject._retn();
221
222   return GetObject(anObject);
223 }
224
225 //=============================================================================
226 /*!
227  *  MakeSolidShell
228  */
229 //=============================================================================
230 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeSolidShell
231                                                 (GEOM::GEOM_Object_ptr theShell)
232 {
233   GEOM::GEOM_Object_var aGEOMObject;
234
235   //Set a not done flag
236   GetOperations()->SetNotDone();
237
238   if (theShell == NULL) return aGEOMObject._retn();
239
240   //Get the reference objects
241   Handle(GEOM_Object) aShell = GetOperations()->GetEngine()->GetObject
242     (theShell->GetStudyID(), theShell->GetEntry());
243
244   if (aShell.IsNull()) return aGEOMObject._retn();
245
246   //Create the Solid
247   Handle(GEOM_Object) anObject = GetOperations()->MakeSolidShell(aShell);
248   if (!GetOperations()->IsDone() || anObject.IsNull())
249     return aGEOMObject._retn();
250
251   return GetObject(anObject);
252 }
253
254 //=============================================================================
255 /*!
256  *  MakeSolidShells
257  */
258 //=============================================================================
259 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeSolidShells
260                                       (const GEOM::ListOfGO& theShells)
261 {
262   GEOM::GEOM_Object_var aGEOMObject;
263
264   //Set a not done flag
265   GetOperations()->SetNotDone();
266
267   int ind, aLen;
268   list<Handle(GEOM_Object)> aShapes;
269
270   //Get the shapes
271   aLen = theShells.length();
272   for (ind = 0; ind < aLen; ind++) {
273     if (theShells[ind] == NULL) return aGEOMObject._retn();
274     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
275       (theShells[ind]->GetStudyID(), theShells[ind]->GetEntry());
276     if (aSh.IsNull()) return aGEOMObject._retn();
277     aShapes.push_back(aSh);
278   }
279
280   // Make Solid
281   Handle(GEOM_Object) anObject =
282     GetOperations()->MakeSolidShells(aShapes);
283   if (!GetOperations()->IsDone() || anObject.IsNull())
284     return aGEOMObject._retn();
285
286   return GetObject(anObject);
287 }
288
289 //=============================================================================
290 /*!
291  *  MakeCompound
292  */
293 //=============================================================================
294 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeCompound
295                                       (const GEOM::ListOfGO& theShapes)
296 {
297   GEOM::GEOM_Object_var aGEOMObject;
298
299   //Set a not done flag
300   GetOperations()->SetNotDone();
301
302   int ind, aLen;
303   list<Handle(GEOM_Object)> aShapes;
304
305   //Get the shapes
306   aLen = theShapes.length();
307   for (ind = 0; ind < aLen; ind++) {
308     if (theShapes[ind] == NULL) return aGEOMObject._retn();
309     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
310       (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
311     if (aSh.IsNull()) return aGEOMObject._retn();
312     aShapes.push_back(aSh);
313   }
314
315   // Make Solid
316   Handle(GEOM_Object) anObject =
317     GetOperations()->MakeCompound(aShapes);
318   if (!GetOperations()->IsDone() || anObject.IsNull())
319     return aGEOMObject._retn();
320
321   return GetObject(anObject);
322 }
323
324 //=============================================================================
325 /*!
326  *  MakeGlueFaces
327  */
328 //=============================================================================
329 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeGlueFaces
330                                            (GEOM::GEOM_Object_ptr theShape,
331                                             const CORBA::Double   theTolerance)
332 {
333   GEOM::GEOM_Object_var aGEOMObject;
334
335   //Set a not done flag
336   GetOperations()->SetNotDone();
337
338   if (theShape == NULL) return aGEOMObject._retn();
339
340   //Get the reference objects
341   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
342     (theShape->GetStudyID(), theShape->GetEntry());
343
344   if (aShape.IsNull()) return aGEOMObject._retn();
345
346   //Perform the gluing
347   Handle(GEOM_Object) anObject =
348     GetOperations()->MakeGlueFaces(aShape, theTolerance);
349   //if (!GetOperations()->IsDone() || anObject.IsNull())
350   // to allow warning
351   if (anObject.IsNull())
352     return aGEOMObject._retn();
353
354   return GetObject(anObject);
355 }
356
357 //=============================================================================
358 /*!
359  *  MakeExplode
360  */
361 //=============================================================================
362 GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeExplode (GEOM::GEOM_Object_ptr theShape,
363                                                        const CORBA::Long     theShapeType,
364                                                        const CORBA::Boolean  isSorted)
365 {
366   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
367   if (theShape == NULL) return aSeq._retn();
368
369   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
370     (theShape->GetStudyID(), theShape->GetEntry());
371
372   Handle(TColStd_HSequenceOfTransient) aHSeq =
373     GetOperations()->MakeExplode(aShape, theShapeType, isSorted);
374   if (!GetOperations()->IsDone() || aHSeq.IsNull())
375     return aSeq._retn();
376
377   Standard_Integer aLength = aHSeq->Length();
378   aSeq->length(aLength);
379   for (Standard_Integer i = 1; i <= aLength; i++)
380     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
381
382   return aSeq._retn();
383 }
384
385 //=============================================================================
386 /*!
387  *  SubShapeAllIDs
388  */
389 //=============================================================================
390 GEOM::ListOfLong* GEOM_IShapesOperations_i::SubShapeAllIDs (GEOM::GEOM_Object_ptr theShape,
391                                                             const CORBA::Long     theShapeType,
392                                                             const CORBA::Boolean  isSorted)
393 {
394   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
395   if (theShape == NULL) return aSeq._retn();
396
397   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
398     (theShape->GetStudyID(), theShape->GetEntry());
399
400   Handle(TColStd_HSequenceOfInteger) aHSeq =
401     GetOperations()->SubShapeAllIDs(aShape, theShapeType, isSorted);
402   if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
403
404   Standard_Integer aLength = aHSeq->Length();
405   aSeq->length(aLength);
406   for (Standard_Integer i = 1; i <= aLength; i++)
407     aSeq[i-1] = aHSeq->Value(i);
408
409   return aSeq._retn();
410 }
411
412 //=============================================================================
413 /*!
414  *  GetSubShape
415  */
416 //=============================================================================
417 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetSubShape
418                                            (GEOM::GEOM_Object_ptr theMainShape,
419                                             const CORBA::Long     theID)
420 {
421   GEOM::GEOM_Object_var aGEOMObject;
422
423   //Set a not done flag
424   GetOperations()->SetNotDone();
425
426   if (theMainShape == NULL) return aGEOMObject._retn();
427
428   //Get the reference objects
429   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
430     (theMainShape->GetStudyID(), theMainShape->GetEntry());
431
432   if (aShape.IsNull()) return aGEOMObject._retn();
433
434   Handle(GEOM_Object) anObject = GetOperations()->GetSubShape(aShape, theID);
435   if (!GetOperations()->IsDone() || anObject.IsNull())
436     return aGEOMObject._retn();
437
438   return GetObject(anObject);
439 }
440
441 //=============================================================================
442 /*!
443  *  NumberOfFaces
444  */
445 //=============================================================================
446 CORBA::Long GEOM_IShapesOperations_i::NumberOfFaces (GEOM::GEOM_Object_ptr theShape)
447 {
448   if (theShape == NULL) return -1;
449
450   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
451     (theShape->GetStudyID(), theShape->GetEntry());
452
453   CORBA::Long aNb = GetOperations()->NumberOfFaces(aShape);
454   if (!GetOperations()->IsDone()) return -1;
455
456   return aNb;
457 }
458
459 //=============================================================================
460 /*!
461  *  NumberOfEdges
462  */
463 //=============================================================================
464 CORBA::Long GEOM_IShapesOperations_i::NumberOfEdges (GEOM::GEOM_Object_ptr theShape)
465 {
466   if (theShape == NULL) return -1;
467
468   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
469     (theShape->GetStudyID(), theShape->GetEntry());
470
471   CORBA::Long aNb = GetOperations()->NumberOfEdges(aShape);
472   if (!GetOperations()->IsDone()) return -1;
473
474   return aNb;
475 }
476
477 //=============================================================================
478 /*!
479  *  ChangeOrientation
480  */
481 //=============================================================================
482 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::ChangeOrientation
483                                                 (GEOM::GEOM_Object_ptr theShape)
484 {
485   GEOM::GEOM_Object_var aGEOMObject;
486
487   //Set a not done flag
488   GetOperations()->SetNotDone();
489
490   if (theShape == NULL) return aGEOMObject._retn();
491
492   //Get the reference objects
493   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
494     (theShape->GetStudyID(), theShape->GetEntry());
495
496   if (aShape.IsNull()) return aGEOMObject._retn();
497
498   //Create the Solid
499   Handle(GEOM_Object) anObject = GetOperations()->ReverseShape(aShape);
500   if (!GetOperations()->IsDone() || anObject.IsNull())
501     return aGEOMObject._retn();
502
503   return GetObject(anObject);
504 }
505
506 //=============================================================================
507 /*!
508  *  GetFreeFacesIDs
509  */
510 //=============================================================================
511 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetFreeFacesIDs (GEOM::GEOM_Object_ptr theShape)
512 {
513   //Set a not done flag
514   GetOperations()->SetNotDone();
515
516   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
517   if (theShape == NULL) return aSeq._retn();
518
519   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
520     (theShape->GetStudyID(), theShape->GetEntry());
521
522   Handle(TColStd_HSequenceOfInteger) aHSeq =
523     GetOperations()->GetFreeFacesIDs(aShape);
524   if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
525
526   Standard_Integer aLength = aHSeq->Length();
527   aSeq->length(aLength);
528   for (Standard_Integer i = 1; i <= aLength; i++)
529     aSeq[i-1] = aHSeq->Value(i);
530
531   return aSeq._retn();
532 }
533
534 //=============================================================================
535 /*!
536  *  GetSharedShapes
537  */
538 //=============================================================================
539 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetSharedShapes
540                                           (GEOM::GEOM_Object_ptr theShape1,
541                                            GEOM::GEOM_Object_ptr theShape2,
542                                            const CORBA::Long     theShapeType)
543 {
544   //Set a not done flag
545   GetOperations()->SetNotDone();
546
547   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
548   if (theShape1 == NULL ||
549       theShape2 == NULL) return aSeq._retn();
550
551   Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
552     (theShape1->GetStudyID(), theShape1->GetEntry());
553   Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
554     (theShape2->GetStudyID(), theShape2->GetEntry());
555
556   if (aShape1.IsNull() ||
557       aShape2.IsNull()) return aSeq._retn();
558
559   Handle(TColStd_HSequenceOfTransient) aHSeq =
560     GetOperations()->GetSharedShapes(aShape1, aShape2, theShapeType);
561   if (!GetOperations()->IsDone() || aHSeq.IsNull())
562     return aSeq._retn();
563
564   Standard_Integer aLength = aHSeq->Length();
565   aSeq->length(aLength);
566   for (Standard_Integer i = 1; i <= aLength; i++)
567     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
568
569   return aSeq._retn();
570 }
571
572 static GEOMAlgo_State ShapeState (const GEOM::shape_state theState)
573 {
574   GEOMAlgo_State aState = GEOMAlgo_ST_UNKNOWN;
575
576   switch (theState) {
577   case GEOM::ST_ON:
578     aState = GEOMAlgo_ST_ON;
579     break;
580   case GEOM::ST_OUT:
581     aState = GEOMAlgo_ST_OUT;
582     break;
583   case GEOM::ST_ONOUT:
584     aState = GEOMAlgo_ST_ONOUT;
585     break;
586   case GEOM::ST_IN:
587     aState = GEOMAlgo_ST_IN;
588     break;
589   case GEOM::ST_ONIN:
590     aState = GEOMAlgo_ST_ONIN;
591     break;
592   default:
593     break;
594   }
595
596   return aState;
597 }
598
599 //=============================================================================
600 /*!
601  *  GetShapesOnPlane
602  */
603 //=============================================================================
604 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnPlane
605                                                 (GEOM::GEOM_Object_ptr   theShape,
606                                                  const CORBA::Long       theShapeType,
607                                                  GEOM::GEOM_Object_ptr   theAx1,
608                                                  const GEOM::shape_state theState)
609 {
610   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
611
612   //Set a not done flag
613   GetOperations()->SetNotDone();
614
615   if (theShape == NULL || theAx1 == NULL) return aSeq._retn();
616
617   //Get the reference objects
618   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
619     (theShape->GetStudyID(), theShape->GetEntry());
620   Handle(GEOM_Object) anAx1 = GetOperations()->GetEngine()->GetObject
621     (theAx1->GetStudyID(), theAx1->GetEntry());
622
623   if (aShape.IsNull() || anAx1.IsNull()) return aSeq._retn();
624
625   //Get Shapes On Plane
626   Handle(TColStd_HSequenceOfTransient) aHSeq =
627     GetOperations()->GetShapesOnPlane(aShape, theShapeType, anAx1, ShapeState(theState));
628   if (!GetOperations()->IsDone() || aHSeq.IsNull())
629     return aSeq._retn();
630
631   Standard_Integer aLength = aHSeq->Length();
632   aSeq->length(aLength);
633   for (Standard_Integer i = 1; i <= aLength; i++)
634     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
635
636   return aSeq._retn();
637 }
638
639 //=============================================================================
640 /*!
641  *  GetShapesOnCylinder
642  */
643 //=============================================================================
644 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnCylinder
645                                                 (GEOM::GEOM_Object_ptr   theShape,
646                                                  const CORBA::Long       theShapeType,
647                                                  GEOM::GEOM_Object_ptr   theAxis,
648                                                  const CORBA::Double     theRadius,
649                                                  const GEOM::shape_state theState)
650 {
651   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
652
653   //Set a not done flag
654   GetOperations()->SetNotDone();
655
656   if (theShape == NULL || theAxis == NULL) return aSeq._retn();
657
658   //Get the reference objects
659   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
660     (theShape->GetStudyID(), theShape->GetEntry());
661   Handle(GEOM_Object) anAxis = GetOperations()->GetEngine()->GetObject
662     (theAxis->GetStudyID(), theAxis->GetEntry());
663
664   if (aShape.IsNull() || anAxis.IsNull()) return aSeq._retn();
665
666   //Get Shapes On Cylinder
667   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnCylinder
668     (aShape, theShapeType, anAxis, theRadius, ShapeState(theState));
669   if (!GetOperations()->IsDone() || aHSeq.IsNull())
670     return aSeq._retn();
671
672   Standard_Integer aLength = aHSeq->Length();
673   aSeq->length(aLength);
674   for (Standard_Integer i = 1; i <= aLength; i++)
675     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
676
677   return aSeq._retn();
678 }
679
680 //=============================================================================
681 /*!
682  *  GetShapesOnSphere
683  */
684 //=============================================================================
685 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnSphere
686                                                 (GEOM::GEOM_Object_ptr   theShape,
687                                                  const CORBA::Long       theShapeType,
688                                                  GEOM::GEOM_Object_ptr   theCenter,
689                                                  const CORBA::Double     theRadius,
690                                                  const GEOM::shape_state theState)
691 {
692   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
693
694   //Set a not done flag
695   GetOperations()->SetNotDone();
696
697   if (theShape == NULL || theCenter == NULL) return aSeq._retn();
698
699   //Get the reference objects
700   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
701     (theShape->GetStudyID(), theShape->GetEntry());
702   Handle(GEOM_Object) aCenter = GetOperations()->GetEngine()->GetObject
703     (theCenter->GetStudyID(), theCenter->GetEntry());
704
705   if (aShape.IsNull() || aCenter.IsNull()) return aSeq._retn();
706
707   //Get Shapes On Sphere
708   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnSphere
709     (aShape, theShapeType, aCenter, theRadius, ShapeState(theState));
710   if (!GetOperations()->IsDone() || aHSeq.IsNull())
711     return aSeq._retn();
712
713   Standard_Integer aLength = aHSeq->Length();
714   aSeq->length(aLength);
715   for (Standard_Integer i = 1; i <= aLength; i++)
716     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
717
718   return aSeq._retn();
719 }
720
721 //=============================================================================
722 /*!
723  *  GetShapesOnQuadrangle
724  */
725 //=============================================================================
726 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnQuadrangle
727                                                 (GEOM::GEOM_Object_ptr theShape,
728                                                  CORBA::Long           theShapeType,
729                                                  GEOM::GEOM_Object_ptr theTopLeftPoint,
730                                                  GEOM::GEOM_Object_ptr theTopRigthPoint,
731                                                  GEOM::GEOM_Object_ptr theBottomLeftPoint,
732                                                  GEOM::GEOM_Object_ptr theBottomRigthPoint,
733                                                  GEOM::shape_state     theState)
734 {
735   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
736
737   //Set a not done flag
738   GetOperations()->SetNotDone();
739
740   if (theShape            == NULL ||
741       theTopLeftPoint     == NULL ||   
742       theTopRigthPoint    == NULL || 
743       theBottomLeftPoint  == NULL ||
744       theBottomRigthPoint == NULL )
745     return aSeq._retn();
746
747   //Get the reference objects
748   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
749     (theShape->GetStudyID(), theShape->GetEntry());
750   Handle(GEOM_Object) aTopLeftPoint = GetOperations()->GetEngine()->GetObject
751     (theShape->GetStudyID(), theTopLeftPoint->GetEntry());
752   Handle(GEOM_Object) aTopRigthPoint = GetOperations()->GetEngine()->GetObject
753     (theShape->GetStudyID(), theTopRigthPoint->GetEntry());
754   Handle(GEOM_Object) aBottomLeftPoint = GetOperations()->GetEngine()->GetObject
755     (theShape->GetStudyID(), theBottomLeftPoint->GetEntry());
756   Handle(GEOM_Object) aBottomRigthPoint = GetOperations()->GetEngine()->GetObject
757     (theShape->GetStudyID(), theBottomRigthPoint->GetEntry());
758
759   if (aShape.IsNull() ||
760       aTopLeftPoint.IsNull() ||
761       aTopRigthPoint.IsNull() ||
762       aBottomLeftPoint.IsNull() ||
763       aBottomRigthPoint.IsNull() )
764     return aSeq._retn();
765
766   //Get Shapes On Quadrangle
767   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnQuadrangle
768     (aShape, theShapeType,
769      aTopLeftPoint, aTopRigthPoint, aBottomLeftPoint, aBottomRigthPoint,
770      ShapeState(theState));
771   if (!GetOperations()->IsDone() || aHSeq.IsNull())
772     return aSeq._retn();
773
774   Standard_Integer aLength = aHSeq->Length();
775   aSeq->length(aLength);
776   for (Standard_Integer i = 1; i <= aLength; i++)
777     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
778
779   return aSeq._retn();
780 }
781
782 //=============================================================================
783 /*!
784  *  GetShapesOnPlaneIDs
785  */
786 //=============================================================================
787 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnPlaneIDs
788                                                 (GEOM::GEOM_Object_ptr   theShape,
789                                                  const CORBA::Long       theShapeType,
790                                                  GEOM::GEOM_Object_ptr   theAx1,
791                                                  const GEOM::shape_state theState)
792 {
793   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
794
795   //Set a not done flag
796   GetOperations()->SetNotDone();
797
798   if (theShape == NULL || theAx1 == NULL) return aSeq._retn();
799
800   //Get the reference objects
801   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
802     (theShape->GetStudyID(), theShape->GetEntry());
803   Handle(GEOM_Object) anAx1 = GetOperations()->GetEngine()->GetObject
804     (theAx1->GetStudyID(), theAx1->GetEntry());
805
806   if (aShape.IsNull() || anAx1.IsNull()) return aSeq._retn();
807
808   //Get Shapes On Plane
809   Handle(TColStd_HSequenceOfInteger) aHSeq =
810     GetOperations()->GetShapesOnPlaneIDs(aShape, theShapeType, anAx1, ShapeState(theState));
811   if (!GetOperations()->IsDone() || aHSeq.IsNull())
812     return aSeq._retn();
813
814   Standard_Integer aLength = aHSeq->Length();
815   aSeq->length(aLength);
816   for (Standard_Integer i = 1; i <= aLength; i++)
817     aSeq[i-1] = aHSeq->Value(i);
818
819   return aSeq._retn();
820 }
821
822 //=============================================================================
823 /*!
824  *  GetShapesOnCylinderIDs
825  */
826 //=============================================================================
827 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnCylinderIDs
828                                                 (GEOM::GEOM_Object_ptr   theShape,
829                                                  const CORBA::Long       theShapeType,
830                                                  GEOM::GEOM_Object_ptr   theAxis,
831                                                  const CORBA::Double     theRadius,
832                                                  const GEOM::shape_state theState)
833 {
834   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
835
836   //Set a not done flag
837   GetOperations()->SetNotDone();
838
839   if (theShape == NULL || theAxis == NULL) return aSeq._retn();
840
841   //Get the reference objects
842   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
843     (theShape->GetStudyID(), theShape->GetEntry());
844   Handle(GEOM_Object) anAxis = GetOperations()->GetEngine()->GetObject
845     (theAxis->GetStudyID(), theAxis->GetEntry());
846
847   if (aShape.IsNull() || anAxis.IsNull()) return aSeq._retn();
848
849   //Get Shapes On Cylinder
850   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnCylinderIDs
851     (aShape, theShapeType, anAxis, theRadius, ShapeState(theState));
852   if (!GetOperations()->IsDone() || aHSeq.IsNull())
853     return aSeq._retn();
854
855   Standard_Integer aLength = aHSeq->Length();
856   aSeq->length(aLength);
857   for (Standard_Integer i = 1; i <= aLength; i++)
858     aSeq[i-1] = aHSeq->Value(i);
859
860   return aSeq._retn();
861 }
862
863 //=============================================================================
864 /*!
865  *  GetShapesOnSphereIDs
866  */
867 //=============================================================================
868 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnSphereIDs
869                                                 (GEOM::GEOM_Object_ptr   theShape,
870                                                  const CORBA::Long       theShapeType,
871                                                  GEOM::GEOM_Object_ptr   theCenter,
872                                                  const CORBA::Double     theRadius,
873                                                  const GEOM::shape_state theState)
874 {
875   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
876
877   //Set a not done flag
878   GetOperations()->SetNotDone();
879
880   if (theShape == NULL || theCenter == NULL) return aSeq._retn();
881
882   //Get the reference objects
883   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
884     (theShape->GetStudyID(), theShape->GetEntry());
885   Handle(GEOM_Object) aCenter = GetOperations()->GetEngine()->GetObject
886     (theCenter->GetStudyID(), theCenter->GetEntry());
887
888   if (aShape.IsNull() || aCenter.IsNull()) return aSeq._retn();
889
890   //Get Shapes On Sphere
891   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnSphereIDs
892     (aShape, theShapeType, aCenter, theRadius, ShapeState(theState));
893   if (!GetOperations()->IsDone() || aHSeq.IsNull())
894     return aSeq._retn();
895
896   Standard_Integer aLength = aHSeq->Length();
897   aSeq->length(aLength);
898   for (Standard_Integer i = 1; i <= aLength; i++)
899     aSeq[i-1] = aHSeq->Value(i);
900
901   return aSeq._retn();
902 }
903
904 //=============================================================================
905 /*!
906  *  GetShapesOnQuadrangleIDs
907  */
908 //=============================================================================
909 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnQuadrangleIDs
910                                                 (GEOM::GEOM_Object_ptr theShape,
911                                                  CORBA::Long           theShapeType,
912                                                  GEOM::GEOM_Object_ptr theTopLeftPoint,
913                                                  GEOM::GEOM_Object_ptr theTopRigthPoint,
914                                                  GEOM::GEOM_Object_ptr theBottomLeftPoint,
915                                                  GEOM::GEOM_Object_ptr theBottomRigthPoint,
916                                                  GEOM::shape_state     theState)
917 {
918   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
919
920   //Set a not done flag
921   GetOperations()->SetNotDone();
922
923   if (theShape            == NULL ||
924       theTopLeftPoint     == NULL ||   
925       theTopRigthPoint    == NULL || 
926       theBottomLeftPoint  == NULL ||
927       theBottomRigthPoint == NULL )
928     return aSeq._retn();
929
930   //Get the reference objects
931   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
932     (theShape->GetStudyID(), theShape->GetEntry());
933   Handle(GEOM_Object) aTopLeftPoint = GetOperations()->GetEngine()->GetObject
934     (theShape->GetStudyID(), theTopLeftPoint->GetEntry());
935   Handle(GEOM_Object) aTopRigthPoint = GetOperations()->GetEngine()->GetObject
936     (theShape->GetStudyID(), theTopRigthPoint->GetEntry());
937   Handle(GEOM_Object) aBottomLeftPoint = GetOperations()->GetEngine()->GetObject
938     (theShape->GetStudyID(), theBottomLeftPoint->GetEntry());
939   Handle(GEOM_Object) aBottomRigthPoint = GetOperations()->GetEngine()->GetObject
940     (theShape->GetStudyID(), theBottomRigthPoint->GetEntry());
941
942   if (aShape.IsNull() ||
943       aTopLeftPoint.IsNull() ||
944       aTopRigthPoint.IsNull() ||
945       aBottomLeftPoint.IsNull() ||
946       aBottomRigthPoint.IsNull() )
947     return aSeq._retn();
948
949   //Get Shapes On Quadrangle
950   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnQuadrangleIDs
951     (aShape, theShapeType,
952      aTopLeftPoint, aTopRigthPoint, aBottomLeftPoint, aBottomRigthPoint,
953      ShapeState(theState));
954   if (!GetOperations()->IsDone() || aHSeq.IsNull())
955     return aSeq._retn();
956
957   Standard_Integer aLength = aHSeq->Length();
958   aSeq->length(aLength);
959   for (Standard_Integer i = 1; i <= aLength; i++)
960     aSeq[i-1] = aHSeq->Value(i);
961
962   return aSeq._retn();
963 }
964
965 //=============================================================================
966 /*!
967  *  GetInPlace
968  */
969 //=============================================================================
970 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetInPlace
971                                           (GEOM::GEOM_Object_ptr theShapeWhere,
972                                            GEOM::GEOM_Object_ptr theShapeWhat)
973 {
974   GEOM::GEOM_Object_var aGEOMObject;
975
976   //Set a not done flag
977   GetOperations()->SetNotDone();
978
979   if (theShapeWhere == NULL ||
980       theShapeWhat == NULL) return aGEOMObject._retn();
981
982   //Get the reference objects
983   Handle(GEOM_Object) aShapeWhere = GetOperations()->GetEngine()->GetObject
984     (theShapeWhere->GetStudyID(), theShapeWhere->GetEntry());
985   Handle(GEOM_Object) aShapeWhat = GetOperations()->GetEngine()->GetObject
986     (theShapeWhat->GetStudyID(), theShapeWhat->GetEntry());
987
988   if (aShapeWhere.IsNull() ||
989       aShapeWhat.IsNull()) return aGEOMObject._retn();
990
991   //Get Shapes in place of aShapeWhat
992   Handle(GEOM_Object) anObject =
993     GetOperations()->GetInPlace(aShapeWhere, aShapeWhat);
994   if (!GetOperations()->IsDone() || anObject.IsNull())
995     return aGEOMObject._retn();
996
997   return GetObject(anObject);
998 }