Salome HOME
Copyright update 2022
[modules/geom.git] / src / GEOM_I / GEOM_IShapesOperations_i.cc
1 // Copyright (C) 2007-2022  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_IShapesOperations_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 #include <TopAbs.hxx>
35 #include <TColStd_HSequenceOfTransient.hxx>
36 #include <TColStd_HArray1OfInteger.hxx>
37
38 #include <vector>
39
40 /**
41  * This function converts GEOM::comparison_condition type into
42  * GEOMUtils::ComparisonCondition type.
43  *
44  * \param theCondition the condition of GEOM::comparison_condition type
45  * \return the condition of GEOMUtils::ComparisonCondition type.
46  */
47 static GEOMUtils::ComparisonCondition ComparisonCondition
48                     (const GEOM::comparison_condition theCondition)
49 {
50   GEOMUtils::ComparisonCondition aResult = GEOMUtils::CC_GT;
51
52   switch (theCondition) {
53   case GEOM::CC_GE:
54     aResult = GEOMUtils::CC_GE;
55     break;
56   case GEOM::CC_LT:
57     aResult = GEOMUtils::CC_LT;
58     break;
59   case GEOM::CC_LE:
60     aResult = GEOMUtils::CC_LE;
61     break;
62   default:
63     break;
64   }
65
66   return aResult;
67 }
68
69 //=============================================================================
70 /*!
71  *   constructor:
72  */
73 //=============================================================================
74 GEOM_IShapesOperations_i::GEOM_IShapesOperations_i (PortableServer::POA_ptr thePOA,
75                                                     GEOM::GEOM_Gen_ptr theEngine,
76                                                     ::GEOMImpl_IShapesOperations* theImpl)
77 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
78 {
79   MESSAGE("GEOM_IShapesOperations_i::GEOM_IShapesOperations_i");
80 }
81
82 //=============================================================================
83 /*!
84  *  destructor
85  */
86 //=============================================================================
87 GEOM_IShapesOperations_i::~GEOM_IShapesOperations_i()
88 {
89   MESSAGE("GEOM_IShapesOperations_i::~GEOM_IShapesOperations_i");
90 }
91
92
93 //=============================================================================
94 /*!
95  *  MakeEdge
96  */
97 //=============================================================================
98 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeEdge
99                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2)
100 {
101   GEOM::GEOM_Object_var aGEOMObject;
102
103   //Set a not done flag
104   GetOperations()->SetNotDone();
105
106   //Get the reference points
107   Handle(::GEOM_Object) aPnt1 = GetObjectImpl(thePnt1);
108   Handle(::GEOM_Object) aPnt2 = GetObjectImpl(thePnt2);
109
110   if (aPnt1.IsNull() || aPnt2.IsNull()) return aGEOMObject._retn();
111
112   //Create the Edge
113   Handle(::GEOM_Object) anObject = GetOperations()->MakeEdge(aPnt1, aPnt2);
114   if (!GetOperations()->IsDone() || anObject.IsNull())
115     return aGEOMObject._retn();
116
117   return GetObject(anObject);
118 }
119
120 //=============================================================================
121 /*!
122  *  MakeEdgeOnCurveByLength
123  */
124 //=============================================================================
125 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeEdgeOnCurveByLength
126                   (GEOM::GEOM_Object_ptr theCurve,
127                    CORBA::Double         theLength,
128                    GEOM::GEOM_Object_ptr theStartPoint)
129 {
130   GEOM::GEOM_Object_var aGEOMObject;
131
132   //Set a not done flag
133   GetOperations()->SetNotDone();
134
135   //Get the reference curve
136   Handle(::GEOM_Object) aRefCurve = GetObjectImpl(theCurve);
137   if (aRefCurve.IsNull()) return aGEOMObject._retn();
138
139   //Get the reference point (can be NULL)
140   Handle(::GEOM_Object) aRefPoint;
141   if (!CORBA::is_nil(theStartPoint)) {
142     aRefPoint = GetObjectImpl(theStartPoint);
143   }
144
145   //Create the point
146   Handle(::GEOM_Object) anObject =
147     GetOperations()->MakeEdgeOnCurveByLength(aRefCurve, theLength, aRefPoint);
148   if (!GetOperations()->IsDone() || anObject.IsNull())
149     return aGEOMObject._retn();
150
151   return GetObject(anObject);
152 }
153
154 //=============================================================================
155 /*!
156  *  MakeEdgeWire
157  */
158 //=============================================================================
159 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeEdgeWire
160                       (GEOM::GEOM_Object_ptr theWire,
161                        const CORBA::Double theLinearTolerance,
162                        const CORBA::Double theAngularTolerance)
163 {
164   GEOM::GEOM_Object_var aGEOMObject;
165
166   //Set a not done flag
167   GetOperations()->SetNotDone();
168
169   //Get the source wire
170   Handle(::GEOM_Object) aWire = GetObjectImpl(theWire);
171
172   if (aWire.IsNull()) return aGEOMObject._retn();
173
174   //Create the Edge
175   Handle(::GEOM_Object) anObject = GetOperations()->MakeEdgeWire(aWire, theLinearTolerance, theAngularTolerance);
176   if (!GetOperations()->IsDone() || anObject.IsNull())
177     return aGEOMObject._retn();
178
179   return GetObject(anObject);
180 }
181
182 //=============================================================================
183 /*!
184  *  MakeWire
185  */
186 //=============================================================================
187 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeWire
188                            (const GEOM::ListOfGO& theEdgesAndWires,
189                             const CORBA::Double   theTolerance)
190 {
191   GEOM::GEOM_Object_var aGEOMObject;
192
193   //Set a not done flag
194   GetOperations()->SetNotDone();
195
196   int ind, aLen;
197   std::list<Handle(::GEOM_Object)> aShapes;
198
199   //Get the shapes
200   aLen = theEdgesAndWires.length();
201   for (ind = 0; ind < aLen; ind++) {
202     Handle(::GEOM_Object) aSh = GetObjectImpl(theEdgesAndWires[ind]);
203     if (aSh.IsNull()) return aGEOMObject._retn();
204     aShapes.push_back(aSh);
205   }
206
207   // Make Solid
208   Handle(::GEOM_Object) anObject =
209     GetOperations()->MakeWire(aShapes, theTolerance);
210   if (!GetOperations()->IsDone() || anObject.IsNull())
211     return aGEOMObject._retn();
212
213   return GetObject(anObject);
214 }
215
216 //=============================================================================
217 /*!
218  *  MakeFace
219  */
220 //=============================================================================
221 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFace
222                       (GEOM::GEOM_Object_ptr theWire,
223                        const CORBA::Boolean  isPlanarWanted)
224 {
225   GEOM::GEOM_Object_var aGEOMObject;
226
227   //Set a not done flag
228   GetOperations()->SetNotDone();
229
230   //Get the reference wire
231   Handle(::GEOM_Object) aWire = GetObjectImpl(theWire);
232   if (aWire.IsNull()) return aGEOMObject._retn();
233
234   //Create the Face
235   Handle(::GEOM_Object) anObject = GetOperations()->MakeFace(aWire, isPlanarWanted);
236   //if (!GetOperations()->IsDone() || anObject.IsNull())
237   // enable warning status
238   if (anObject.IsNull())
239     return aGEOMObject._retn();
240
241   return GetObject(anObject);
242 }
243
244 //=============================================================================
245 /*!
246  *  MakeFaceWires
247  */
248 //=============================================================================
249 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFaceWires
250                                          (const GEOM::ListOfGO& theWires,
251                                           const CORBA::Boolean  isPlanarWanted)
252 {
253   GEOM::GEOM_Object_var aGEOMObject;
254
255   //Set a not done flag
256   GetOperations()->SetNotDone();
257
258   int ind, aLen;
259   std::list<Handle(::GEOM_Object)> aShapes;
260
261   //Get the shapes
262   aLen = theWires.length();
263   for (ind = 0; ind < aLen; ind++) {
264     Handle(::GEOM_Object) aSh = GetObjectImpl(theWires[ind]);
265     if (aSh.IsNull()) return aGEOMObject._retn();
266     aShapes.push_back(aSh);
267   }
268
269   // Make Face
270   Handle(::GEOM_Object) anObject =
271     GetOperations()->MakeFaceWires(aShapes, isPlanarWanted);
272   //if (!GetOperations()->IsDone() || anObject.IsNull())
273   // enable warning status
274   if (anObject.IsNull())
275     return aGEOMObject._retn();
276
277   return GetObject(anObject);
278 }
279
280 //=============================================================================
281 /*!
282  *  MakeFaceFromSurface
283  */
284 //=============================================================================
285 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFaceFromSurface
286                                   (GEOM::GEOM_Object_ptr theFace,
287                                    GEOM::GEOM_Object_ptr theWire)
288 {
289   GEOM::GEOM_Object_var aGEOMObject;
290
291   //Set a not done flag
292   GetOperations()->SetNotDone();
293
294   //Get the reference face and wire
295   Handle(::GEOM_Object) aFace = GetObjectImpl(theFace);
296   Handle(::GEOM_Object) aWire = GetObjectImpl(theWire);
297
298   if (aFace.IsNull() || aWire.IsNull()) {
299     return aGEOMObject._retn();
300   }
301
302   //Create the Face
303   Handle(::GEOM_Object) anObject =
304     GetOperations()->MakeFaceFromSurface(aFace, aWire);
305
306   if (anObject.IsNull()) {
307     return aGEOMObject._retn();
308   }
309
310   return GetObject(anObject);
311 }
312
313 //=============================================================================
314 /*!
315  *  MakeFaceWithConstraints
316  */
317 //=============================================================================
318 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFaceWithConstraints
319                                                 (const GEOM::ListOfGO& theConstraints)
320 {
321   GEOM::GEOM_Object_var aGEOMObject;
322
323   //Set a not done flag
324   GetOperations()->SetNotDone();
325
326   //Get the shapes
327   std::list<Handle(::GEOM_Object)> aConstraints;
328   for( CORBA::ULong ind = 0; ind < theConstraints.length(); ind++ ) {
329     Handle(::GEOM_Object) anObject = GetObjectImpl( theConstraints[ind] );
330     aConstraints.push_back(anObject);
331   }
332
333   // Make Face
334   Handle(::GEOM_Object) anObject =
335     GetOperations()->MakeFaceWithConstraints( aConstraints );
336
337   // enable warning status
338   if (anObject.IsNull())
339     return aGEOMObject._retn();
340
341   return GetObject(anObject);
342 }
343
344 //=============================================================================
345 /*!
346  *  MakeShell
347  */
348 //=============================================================================
349 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeShell
350                                       (const GEOM::ListOfGO& theFacesAndShells)
351 {
352   GEOM::GEOM_Object_var aGEOMObject;
353
354   //Set a not done flag
355   GetOperations()->SetNotDone();
356
357   int ind, aLen;
358   std::list<Handle(::GEOM_Object)> aShapes;
359
360   //Get the shapes
361   aLen = theFacesAndShells.length();
362   for (ind = 0; ind < aLen; ind++) {
363     Handle(::GEOM_Object) aSh = GetObjectImpl(theFacesAndShells[ind]);
364     if (aSh.IsNull()) return aGEOMObject._retn();
365     aShapes.push_back(aSh);
366   }
367
368   // Make Solid
369   Handle(::GEOM_Object) anObject =
370     GetOperations()->MakeShell(aShapes);
371   if (!GetOperations()->IsDone() || anObject.IsNull())
372     return aGEOMObject._retn();
373
374   return GetObject(anObject);
375 }
376
377 //=============================================================================
378 /*!
379  *  MakeSolidShell
380  */
381 //=============================================================================
382 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeSolidShell
383                                                 (GEOM::GEOM_Object_ptr theShell)
384 {
385   GEOM::GEOM_Object_var aGEOMObject;
386
387   //Set a not done flag
388   GetOperations()->SetNotDone();
389
390   //Get the reference objects
391   Handle(::GEOM_Object) aShell = GetObjectImpl(theShell);
392   if (aShell.IsNull()) return aGEOMObject._retn();
393
394   std::list<Handle(::GEOM_Object)> aShapes;
395   aShapes.push_back(aShell);
396
397   //Create the Solid
398   Handle(::GEOM_Object) anObject = GetOperations()->MakeSolidShells(aShapes);
399   if (!GetOperations()->IsDone() || anObject.IsNull())
400     return aGEOMObject._retn();
401
402   return GetObject(anObject);
403 }
404
405 //=============================================================================
406 /*!
407  *  MakeSolidShells
408  */
409 //=============================================================================
410 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeSolidShells
411                                       (const GEOM::ListOfGO& theShells)
412 {
413   GEOM::GEOM_Object_var aGEOMObject;
414
415   //Set a not done flag
416   GetOperations()->SetNotDone();
417
418   int ind, aLen;
419   std::list<Handle(::GEOM_Object)> aShapes;
420
421   //Get the shapes
422   aLen = theShells.length();
423   for (ind = 0; ind < aLen; ind++) {
424     Handle(::GEOM_Object) aSh = GetObjectImpl(theShells[ind]);
425     if (aSh.IsNull()) return aGEOMObject._retn();
426     aShapes.push_back(aSh);
427   }
428
429   // Make Solid
430   Handle(::GEOM_Object) anObject =
431     GetOperations()->MakeSolidShells(aShapes);
432   if (!GetOperations()->IsDone() || anObject.IsNull())
433     return aGEOMObject._retn();
434
435   return GetObject(anObject);
436 }
437
438 //=============================================================================
439 /*!
440  *  MakeCompound
441  */
442 //=============================================================================
443 GEOM::GEOM_Object_ptr
444 GEOM_IShapesOperations_i::MakeCompound (const GEOM::ListOfGO& theShapes)
445 {
446   GEOM::GEOM_Object_var aGEOMObject;
447
448   //Set a not done flag
449   GetOperations()->SetNotDone();
450
451   int ind, aLen;
452   std::list<Handle(::GEOM_Object)> aShapes;
453
454   //Get the shapes
455   aLen = theShapes.length();
456   for (ind = 0; ind < aLen; ind++) {
457     Handle(::GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
458     if (aSh.IsNull()) return aGEOMObject._retn();
459     aShapes.push_back(aSh);
460   }
461
462   // Make Solid
463   Handle(::GEOM_Object) anObject =
464     GetOperations()->MakeCompound(aShapes);
465   if (!GetOperations()->IsDone() || anObject.IsNull())
466     return aGEOMObject._retn();
467
468   return GetObject(anObject);
469 }
470
471 //=============================================================================
472 /*!
473  *  MakeSolidFromConnectedFaces
474  */
475 //=============================================================================
476 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeSolidFromConnectedFaces
477                                       (const GEOM::ListOfGO& theFacesOrShells,
478                                        const CORBA::Boolean  isIntersect)
479 {
480   GEOM::GEOM_Object_var aGEOMObject;
481
482   //Set a not done flag
483   GetOperations()->SetNotDone();
484
485   int ind, aLen;
486   std::list<Handle(::GEOM_Object)> aShapes;
487
488   //Get the shapes
489   aLen = theFacesOrShells.length();
490   for (ind = 0; ind < aLen; ind++) {
491     ::Handle(::GEOM_Object) aSh = GetObjectImpl(theFacesOrShells[ind]);
492     if (aSh.IsNull()) return aGEOMObject._retn();
493     aShapes.push_back(aSh);
494   }
495
496   // Make Solid
497   Handle(::GEOM_Object) anObject =
498     GetOperations()->MakeSolidFromConnectedFaces(aShapes, isIntersect);
499   if (!GetOperations()->IsDone() || anObject.IsNull())
500     return aGEOMObject._retn();
501
502   return GetObject(anObject);
503 }
504
505 //=============================================================================
506 /*!
507  *  MakeGlueFaces
508  */
509 //=============================================================================
510 GEOM::GEOM_Object_ptr
511 GEOM_IShapesOperations_i::MakeGlueFaces (const GEOM::ListOfGO& theShapes,
512                                          CORBA::Double         theTolerance,
513                                          CORBA::Boolean  doKeepNonSolids)
514 {
515   GEOM::GEOM_Object_var aGEOMObject;
516
517   //Set a not done flag
518   GetOperations()->SetNotDone();
519
520   //Get the reference objects
521   std::list< Handle(::GEOM_Object) > aShapes;
522   if (! GetListOfObjectsImpl( theShapes, aShapes ))
523     return aGEOMObject._retn();
524
525   //Perform the gluing
526   Handle(::GEOM_Object) anObject =
527     GetOperations()->MakeGlueFaces(aShapes, theTolerance, doKeepNonSolids);
528   //if (!GetOperations()->IsDone() || anObject.IsNull())
529   // to allow warning
530   if (anObject.IsNull())
531     return aGEOMObject._retn();
532
533   return GetObject(anObject);
534 }
535
536 //=============================================================================
537 /*!
538  *  GetGlueFaces
539  */
540 //=============================================================================
541 GEOM::ListOfGO*
542 GEOM_IShapesOperations_i::GetGlueFaces (const GEOM::ListOfGO& theShapes,
543                                         const CORBA::Double   theTolerance)
544 {
545   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
546
547   //Set a not done flag
548   GetOperations()->SetNotDone();
549
550   //Get the reference objects
551   std::list< Handle(::GEOM_Object) > aShapes;
552   if (! GetListOfObjectsImpl( theShapes, aShapes ))
553     return aSeq._retn();
554
555   Handle(TColStd_HSequenceOfTransient) aHSeq =
556     GetOperations()->GetGlueShapes(aShapes, theTolerance, TopAbs_FACE);
557
558   //if (!GetOperations()->IsDone() || aHSeq.IsNull())
559   // to allow warning
560   if(aHSeq.IsNull())
561     return aSeq._retn();
562
563   Standard_Integer aLength = aHSeq->Length();
564   aSeq->length(aLength);
565   for (Standard_Integer i = 1; i <= aLength; i++)
566     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
567
568   return aSeq._retn();
569 }
570
571 //=============================================================================
572 /*!
573  *  MakeGlueFacesByList
574  */
575 //=============================================================================
576 GEOM::GEOM_Object_ptr
577 GEOM_IShapesOperations_i::MakeGlueFacesByList (const GEOM::ListOfGO& theShapes,
578                                                CORBA::Double         theTolerance,
579                                                const GEOM::ListOfGO& theFaces,
580                                                CORBA::Boolean        doKeepNonSolids,
581                                                CORBA::Boolean        doGlueAllEdges)
582 {
583   GEOM::GEOM_Object_var aGEOMObject;
584
585   //Set a not done flag
586   GetOperations()->SetNotDone();
587
588   //Get the reference objects
589   std::list< Handle(::GEOM_Object) > aShapes;
590   if (! GetListOfObjectsImpl( theShapes, aShapes ))
591     return aGEOMObject._retn();
592
593   //Get the shapes
594   std::list<Handle(::GEOM_Object)> aFaces;
595   if (! GetListOfObjectsImpl( theFaces, aFaces ))
596     return aGEOMObject._retn();
597
598   //Perform the gluing
599   Handle(::GEOM_Object) anObject =
600     GetOperations()->MakeGlueFacesByList(aShapes, theTolerance, aFaces,
601                                          doKeepNonSolids, doGlueAllEdges);
602   //if (!GetOperations()->IsDone() || anObject.IsNull())
603   // to allow warning
604   if (anObject.IsNull())
605     return aGEOMObject._retn();
606
607   return GetObject(anObject);
608 }
609
610 //=============================================================================
611 /*!
612  *  MakeGlueEdges
613  */
614 //=============================================================================
615 GEOM::GEOM_Object_ptr
616 GEOM_IShapesOperations_i::MakeGlueEdges (const GEOM::ListOfGO& theShapes,
617                                          CORBA::Double         theTolerance)
618 {
619   GEOM::GEOM_Object_var aGEOMObject;
620
621   //Set a not done flag
622   GetOperations()->SetNotDone();
623
624   //Get the reference objects
625   std::list< Handle(::GEOM_Object) > aShapes;
626   if (! GetListOfObjectsImpl( theShapes, aShapes ))
627     return aGEOMObject._retn();
628
629   //Perform the gluing
630   Handle(::GEOM_Object) anObject =
631     GetOperations()->MakeGlueEdges(aShapes, theTolerance);
632   //if (!GetOperations()->IsDone() || anObject.IsNull())
633   // to allow warning
634   if (anObject.IsNull())
635     return aGEOMObject._retn();
636
637   return GetObject(anObject);
638 }
639
640 //=============================================================================
641 /*!
642  *  GetGlueEdges
643  */
644 //=============================================================================
645 GEOM::ListOfGO*
646 GEOM_IShapesOperations_i::GetGlueEdges (const GEOM::ListOfGO& theShapes,
647                                         const CORBA::Double   theTolerance)
648 {
649   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
650
651   //Set a not done flag
652   GetOperations()->SetNotDone();
653
654   //Get the reference objects
655   std::list< Handle(::GEOM_Object) > aShapes;
656   if (! GetListOfObjectsImpl( theShapes, aShapes ))
657     return aSeq._retn();
658
659   Handle(TColStd_HSequenceOfTransient) aHSeq =
660     GetOperations()->GetGlueShapes(aShapes, theTolerance, TopAbs_EDGE);
661
662   //if (!GetOperations()->IsDone() || aHSeq.IsNull())
663   // to allow warning
664   if (aHSeq.IsNull())
665     return aSeq._retn();
666
667   Standard_Integer aLength = aHSeq->Length();
668   aSeq->length(aLength);
669   for (Standard_Integer i = 1; i <= aLength; i++)
670     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
671
672   return aSeq._retn();
673 }
674
675 //=============================================================================
676 /*!
677  *  MakeGlueEdgesByList
678  */
679 //=============================================================================
680 GEOM::GEOM_Object_ptr
681 GEOM_IShapesOperations_i::MakeGlueEdgesByList (const GEOM::ListOfGO& theShapes,
682                                                CORBA::Double         theTolerance,
683                                                const GEOM::ListOfGO& theEdges)
684 {
685   GEOM::GEOM_Object_var aGEOMObject;
686
687   //Set a not done flag
688   GetOperations()->SetNotDone();
689
690   //Get the reference objects
691   std::list< Handle(::GEOM_Object) > aShapes;
692   if (! GetListOfObjectsImpl( theShapes, aShapes ))
693     return aGEOMObject._retn();
694
695   //Get the shapes
696   std::list<Handle(::GEOM_Object)> anEdges;
697   if (! GetListOfObjectsImpl( theEdges, anEdges ))
698     return aGEOMObject._retn();
699
700   //Perform the gluing
701   Handle(::GEOM_Object) anObject =
702     GetOperations()->MakeGlueEdgesByList(aShapes, theTolerance, anEdges);
703   //if (!GetOperations()->IsDone() || anObject.IsNull())
704   // to allow warning
705   if (anObject.IsNull())
706     return aGEOMObject._retn();
707
708   return GetObject(anObject);
709 }
710
711 //=============================================================================
712 /*!
713  *  GetExistingSubObjects
714  */
715 //=============================================================================
716 GEOM::ListOfGO*
717 GEOM_IShapesOperations_i::GetExistingSubObjects (GEOM::GEOM_Object_ptr theShape,
718                                                  CORBA::Boolean        theGroupsOnly)
719 {
720   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
721
722   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
723   if (aShape.IsNull()) return aSeq._retn();
724
725   Handle(TColStd_HSequenceOfTransient) aHSeq =
726     GetOperations()->GetExistingSubObjects(aShape, (Standard_Boolean)theGroupsOnly);
727   if (!GetOperations()->IsDone() || aHSeq.IsNull())
728     return aSeq._retn();
729
730   Standard_Integer aLength = aHSeq->Length();
731   aSeq->length(aLength);
732   for (Standard_Integer i = 1; i <= aLength; i++)
733     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
734
735   return aSeq._retn();
736 }
737
738 //=============================================================================
739 /*!
740  *  MakeExplode (including theShape itself, bad sorting)
741  */
742 //=============================================================================
743 GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeExplode (GEOM::GEOM_Object_ptr theShape,
744                                                        const CORBA::Long     theShapeType,
745                                                        const CORBA::Boolean  isSorted)
746 {
747   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
748
749   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
750   if (aShape.IsNull()) return aSeq._retn();
751
752   Handle(TColStd_HSequenceOfTransient) aHSeq =
753     GetOperations()->MakeExplode(aShape, theShapeType, isSorted,
754                                  GEOMImpl_IShapesOperations::EXPLODE_OLD_INCLUDE_MAIN);
755   if (!GetOperations()->IsDone() || aHSeq.IsNull())
756     return aSeq._retn();
757
758   Standard_Integer aLength = aHSeq->Length();
759   aSeq->length(aLength);
760   for (Standard_Integer i = 1; i <= aLength; i++)
761     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
762
763   return aSeq._retn();
764 }
765
766 //=============================================================================
767 /*!
768  *  MakeAllSubShapes (including theShape itself, good sorting)
769  */
770 //=============================================================================
771 GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeAllSubShapes (GEOM::GEOM_Object_ptr theShape,
772                                                             const CORBA::Long     theShapeType,
773                                                             const CORBA::Boolean  isSorted)
774 {
775   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
776
777   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
778   if (aShape.IsNull()) return aSeq._retn();
779
780   Handle(TColStd_HSequenceOfTransient) aHSeq =
781     GetOperations()->MakeExplode(aShape, theShapeType, isSorted,
782                                  GEOMImpl_IShapesOperations::EXPLODE_NEW_INCLUDE_MAIN);
783   if (!GetOperations()->IsDone() || aHSeq.IsNull())
784     return aSeq._retn();
785
786   Standard_Integer aLength = aHSeq->Length();
787   aSeq->length(aLength);
788   for (Standard_Integer i = 1; i <= aLength; i++)
789     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
790
791   return aSeq._retn();
792 }
793
794 //=============================================================================
795 /*!
796  *  ExtractSubShapes (excluding theShape itself, good sorting)
797  */
798 //=============================================================================
799 GEOM::ListOfGO* GEOM_IShapesOperations_i::ExtractSubShapes (GEOM::GEOM_Object_ptr theShape,
800                                                             const CORBA::Long     theShapeType,
801                                                             const CORBA::Boolean  isSorted)
802 {
803   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
804
805   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
806   if (aShape.IsNull()) return aSeq._retn();
807
808   Handle(TColStd_HSequenceOfTransient) aHSeq =
809     // TODO: enum instead of bool for the last argument
810     GetOperations()->MakeExplode(aShape, theShapeType, isSorted,
811                                  GEOMImpl_IShapesOperations::EXPLODE_NEW_EXCLUDE_MAIN);
812   if (!GetOperations()->IsDone() || aHSeq.IsNull())
813     return aSeq._retn();
814
815   Standard_Integer aLength = aHSeq->Length();
816   aSeq->length(aLength);
817   for (Standard_Integer i = 1; i <= aLength; i++)
818     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
819
820   return aSeq._retn();
821 }
822
823 //=============================================================================
824 /*!
825  *  SubShapeAllIDs
826  */
827 //=============================================================================
828 GEOM::ListOfLong* GEOM_IShapesOperations_i::SubShapeAllIDs (GEOM::GEOM_Object_ptr theShape,
829                                                             const CORBA::Long     theShapeType,
830                                                             const CORBA::Boolean  isSorted)
831 {
832   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
833
834   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
835   if (aShape.IsNull()) return aSeq._retn();
836
837   Handle(TColStd_HSequenceOfInteger) aHSeq =
838     GetOperations()->SubShapeAllIDs(aShape, theShapeType, isSorted,
839                                     GEOMImpl_IShapesOperations::EXPLODE_OLD_INCLUDE_MAIN);
840   if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
841
842   Standard_Integer aLength = aHSeq->Length();
843   aSeq->length(aLength);
844   for (Standard_Integer i = 1; i <= aLength; i++)
845     aSeq[i-1] = aHSeq->Value(i);
846
847   return aSeq._retn();
848 }
849
850 //=============================================================================
851 /*!
852  *  GetAllSubShapesIDs
853  */
854 //=============================================================================
855 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetAllSubShapesIDs (GEOM::GEOM_Object_ptr theShape,
856                                                                 const CORBA::Long     theShapeType,
857                                                                 const CORBA::Boolean  isSorted)
858 {
859   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
860
861   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
862   if (aShape.IsNull()) return aSeq._retn();
863
864   Handle(TColStd_HSequenceOfInteger) aHSeq =
865     GetOperations()->SubShapeAllIDs(aShape, theShapeType, isSorted,
866                                     GEOMImpl_IShapesOperations::EXPLODE_NEW_INCLUDE_MAIN);
867   if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
868
869   Standard_Integer aLength = aHSeq->Length();
870   aSeq->length(aLength);
871   for (Standard_Integer i = 1; i <= aLength; i++)
872     aSeq[i-1] = aHSeq->Value(i);
873
874   return aSeq._retn();
875 }
876
877 //=============================================================================
878 /*!
879  *  GetSubShape
880  */
881 //=============================================================================
882 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetSubShape
883                                            (GEOM::GEOM_Object_ptr theMainShape,
884                                             const CORBA::Long     theID)
885 {
886   GEOM::GEOM_Object_var aGEOMObject;
887
888   //Set a not done flag
889   GetOperations()->SetNotDone();
890
891   //Get the reference objects
892   Handle(::GEOM_Object) aShape = GetObjectImpl(theMainShape);
893   if (aShape.IsNull()) return aGEOMObject._retn();
894
895   Handle(::GEOM_Object) anObject = GetOperations()->GetSubShape(aShape, theID);
896   if (!GetOperations()->IsDone() || anObject.IsNull())
897     return aGEOMObject._retn();
898
899   return GetObject(anObject);
900 }
901
902 //=============================================================================
903 /*!
904  *  MakeSubShapes
905  */
906 //=============================================================================
907 GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeSubShapes (GEOM::GEOM_Object_ptr theMainShape,
908                                                          const GEOM::ListOfLong& theIndices)
909 {
910   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
911
912   //Set a not done flag
913   GetOperations()->SetNotDone();
914
915   if (theIndices.length() < 1)
916     return aSeq._retn();
917
918   Handle(::GEOM_Object) aShape = GetObjectImpl(theMainShape);
919   if (aShape.IsNull()) return aSeq._retn();
920
921   Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger (1, theIndices.length());
922   for (CORBA::ULong i = 0; i < theIndices.length(); i++)
923     anArray->SetValue(i+1, theIndices[i]);
924
925   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->MakeSubShapes(aShape, anArray);
926   if (!GetOperations()->IsDone() || aHSeq.IsNull())
927     return aSeq._retn();
928
929   Standard_Integer aLength = aHSeq->Length();
930   aSeq->length(aLength);
931   for (int i = 0; i < aLength; i++)
932     aSeq[i] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i+1)));
933
934   return aSeq._retn();
935 }
936
937 //=============================================================================
938 /*!
939  *  GetSubShapeIndex
940  */
941 //=============================================================================
942 CORBA::Long GEOM_IShapesOperations_i::GetSubShapeIndex
943   (GEOM::GEOM_Object_ptr theMainShape, GEOM::GEOM_Object_ptr theSubShape)
944 {
945   //Get the reference shapes
946   Handle(::GEOM_Object) aMainShapeRef = GetObjectImpl(theMainShape);
947   Handle(::GEOM_Object) aSubShapeRef = GetObjectImpl(theSubShape);
948
949   if (aMainShapeRef.IsNull() || aSubShapeRef.IsNull()) return -1;
950
951   //Get the unique ID of <theSubShape> inside <theMainShape>
952   CORBA::Long anID = GetOperations()->GetSubShapeIndex(aMainShapeRef, aSubShapeRef);
953   if (!GetOperations()->IsDone())
954     return -1;
955
956   return anID;
957 }
958
959 //=============================================================================
960 /*!
961  *  GetSubShapesIndices
962  */
963 //=============================================================================
964 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetSubShapesIndices
965   (GEOM::GEOM_Object_ptr theMainShape, const GEOM::ListOfGO& theSubShapes)
966 {
967   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
968   
969   //Get the reference main shape
970   Handle(::GEOM_Object) aMainShapeRef = GetObjectImpl(theMainShape);
971   if (aMainShapeRef.IsNull()) return aSeq._retn();
972       
973   //Get the subshapes
974   std::list<Handle(::GEOM_Object)> aShapes;
975   int aLen = theSubShapes.length();
976   for (int ind = 0; ind < aLen; ind++) {
977     Handle(::GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
978     if (aSh.IsNull())
979     {
980       MESSAGE("NULL shape")
981       return aSeq._retn();
982     }
983     aShapes.push_back(aSh);
984   }
985
986   //Get the IDs of <theSubShapes> inside <theMainShape>
987   Handle(TColStd_HSequenceOfInteger) aHSeq = 
988   GetOperations()->GetSubShapesIndices(aMainShapeRef, aShapes);
989   
990   if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
991
992   Standard_Integer aLength = aHSeq->Length();
993   aSeq->length(aLength);
994   
995   for (Standard_Integer i = 1; i <= aLength; i++)
996     aSeq[i-1] = aHSeq->Value(i);
997
998   return aSeq._retn();
999 }
1000
1001
1002 //=============================================================================
1003 /*!
1004  *  GetTopologyIndex
1005  */
1006 //=============================================================================
1007 CORBA::Long GEOM_IShapesOperations_i::GetTopologyIndex
1008   (GEOM::GEOM_Object_ptr theMainShape, GEOM::GEOM_Object_ptr theSubShape)
1009 {
1010   //Get the reference shapes
1011   Handle(::GEOM_Object) aMainShapeRef = GetObjectImpl(theMainShape);
1012   Handle(::GEOM_Object) aSubShapeRef = GetObjectImpl(theSubShape);
1013
1014   if (aMainShapeRef.IsNull() || aSubShapeRef.IsNull()) return -1;
1015
1016   //Get an ID of <theSubShape>, unique among all sub-shapes of <theMainShape> of the same type
1017   CORBA::Long anID = GetOperations()->GetTopologyIndex(aMainShapeRef, aSubShapeRef);
1018   if (!GetOperations()->IsDone())
1019     return -1;
1020
1021   return anID;
1022 }
1023
1024 //=============================================================================
1025 /*!
1026  *  GetShapeTypeString
1027  */
1028 //=============================================================================
1029 char* GEOM_IShapesOperations_i::GetShapeTypeString (GEOM::GEOM_Object_ptr theShape)
1030 {
1031   //Get the reference shape
1032   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1033   if (aShape.IsNull()) return NULL;
1034
1035   // Get shape parameters
1036   TCollection_AsciiString aDescription = GetOperations()->GetShapeTypeString(aShape);
1037   return CORBA::string_dup(aDescription.ToCString());
1038 }
1039
1040 //=============================================================================
1041 /*!
1042  *  IsSubShapeBelongsTo
1043  */
1044 //=============================================================================
1045 CORBA::Boolean GEOM_IShapesOperations_i::IsSubShapeBelongsTo( GEOM::GEOM_Object_ptr theSubObject,
1046                                                               const CORBA::Long theSubObjectIndex,
1047                                                               GEOM::GEOM_Object_ptr theObject,
1048                                                               const CORBA::Long theObjectIndex)
1049 {
1050   Handle(::GEOM_Object) aSubObject = GetObjectImpl( theSubObject );
1051   Handle(::GEOM_Object) anObject = GetObjectImpl( theObject );
1052   if( anObject.IsNull() || aSubObject.IsNull() )
1053     return false;
1054
1055   // Get parameters
1056   return GetOperations()->IsSubShapeBelongsTo( aSubObject, theSubObjectIndex, anObject, theObjectIndex );
1057 }
1058
1059 //=============================================================================
1060 /*!
1061  *  NumberOfFaces
1062  */
1063 //=============================================================================
1064 CORBA::Long GEOM_IShapesOperations_i::NumberOfFaces (GEOM::GEOM_Object_ptr theShape)
1065 {
1066   return NumberOfSubShapes(theShape, Standard_Integer(TopAbs_FACE));
1067 }
1068
1069 //=============================================================================
1070 /*!
1071  *  NumberOfEdges
1072  */
1073 //=============================================================================
1074 CORBA::Long GEOM_IShapesOperations_i::NumberOfEdges (GEOM::GEOM_Object_ptr theShape)
1075 {
1076   return NumberOfSubShapes(theShape, Standard_Integer(TopAbs_EDGE));
1077 }
1078
1079 //=============================================================================
1080 /*!
1081  *  NumberOfSubShapes
1082  */
1083 //=============================================================================
1084 CORBA::Long GEOM_IShapesOperations_i::NumberOfSubShapes (GEOM::GEOM_Object_ptr theShape,
1085                                                          const CORBA::Long     theShapeType)
1086 {
1087   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1088   if (aShape.IsNull()) return -1;
1089
1090   CORBA::Long aNb = GetOperations()->NumberOfSubShapes(aShape, theShapeType);
1091   if (!GetOperations()->IsDone()) return -1;
1092
1093   return aNb;
1094 }
1095
1096 //=============================================================================
1097 /*!
1098  *  ChangeOrientation
1099  */
1100 //=============================================================================
1101 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::ChangeOrientation
1102                                                 (GEOM::GEOM_Object_ptr theShape)
1103 {
1104   GEOM::GEOM_Object_var aGEOMObject;
1105
1106   //Set a not done flag
1107   GetOperations()->SetNotDone();
1108
1109   //Get the reference objects
1110   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1111   if (aShape.IsNull()) return aGEOMObject._retn();
1112
1113   //Create the Solid
1114   Handle(::GEOM_Object) anObject = GetOperations()->ReverseShape(aShape);
1115   if (!GetOperations()->IsDone() || anObject.IsNull())
1116     return aGEOMObject._retn();
1117
1118   return GetObject(anObject);
1119 }
1120
1121 //=============================================================================
1122 /*!
1123  *  GetFreeFacesIDs
1124  */
1125 //=============================================================================
1126 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetFreeFacesIDs (GEOM::GEOM_Object_ptr theShape)
1127 {
1128   //Set a not done flag
1129   GetOperations()->SetNotDone();
1130
1131   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1132
1133   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1134   if (aShape.IsNull()) return aSeq._retn();
1135
1136   Handle(TColStd_HSequenceOfInteger) aHSeq =
1137     GetOperations()->GetFreeFacesIDs(aShape);
1138   if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
1139
1140   Standard_Integer aLength = aHSeq->Length();
1141   aSeq->length(aLength);
1142   for (Standard_Integer i = 1; i <= aLength; i++)
1143     aSeq[i-1] = aHSeq->Value(i);
1144
1145   return aSeq._retn();
1146 }
1147
1148 //=============================================================================
1149 /*!
1150  *  GetSharedShapes
1151  */
1152 //=============================================================================
1153 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetSharedShapes
1154                                           (GEOM::GEOM_Object_ptr theShape1,
1155                                            GEOM::GEOM_Object_ptr theShape2,
1156                                            const CORBA::Long     theShapeType)
1157 {
1158   //Set a not done flag
1159   GetOperations()->SetNotDone();
1160
1161   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1162
1163   Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
1164   Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
1165
1166   if (aShape1.IsNull() || aShape2.IsNull()) return aSeq._retn();
1167
1168   Handle(TColStd_HSequenceOfTransient) aHSeq =
1169     GetOperations()->GetSharedShapes(aShape1, aShape2, theShapeType);
1170   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1171     return aSeq._retn();
1172
1173   Standard_Integer aLength = aHSeq->Length();
1174   aSeq->length(aLength);
1175   for (Standard_Integer i = 1; i <= aLength; i++)
1176     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1177
1178   return aSeq._retn();
1179 }
1180
1181 //=============================================================================
1182 /*!
1183  *  GetSharedShapesMulti
1184  */
1185 //=============================================================================
1186 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetSharedShapesMulti
1187                                           (const GEOM::ListOfGO& theShapes,
1188                                            const CORBA::Long     theShapeType,
1189                                            CORBA::Boolean        theMultiShare)
1190 {
1191   //Set a not done flag
1192   GetOperations()->SetNotDone();
1193
1194   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1195
1196   //Get the shapes
1197   std::list<Handle(::GEOM_Object)> aShapes;
1198   if (! GetListOfObjectsImpl( theShapes, aShapes ))
1199     return aSeq._retn();
1200
1201   Handle(TColStd_HSequenceOfTransient) aHSeq =
1202     GetOperations()->GetSharedShapes(aShapes, theShapeType, theMultiShare);
1203   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1204     return aSeq._retn();
1205
1206   Standard_Integer aLength = aHSeq->Length();
1207   aSeq->length(aLength);
1208   for (Standard_Integer i = 1; i <= aLength; i++)
1209     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1210
1211   return aSeq._retn();
1212 }
1213
1214 static GEOMAlgo_State ShapeState (const GEOM::shape_state theState)
1215 {
1216   GEOMAlgo_State aState = GEOMAlgo_ST_UNKNOWN;
1217
1218   switch (theState) {
1219   case GEOM::ST_ON:
1220     aState = GEOMAlgo_ST_ON;
1221     break;
1222   case GEOM::ST_OUT:
1223     aState = GEOMAlgo_ST_OUT;
1224     break;
1225   case GEOM::ST_ONOUT:
1226     aState = GEOMAlgo_ST_ONOUT;
1227     break;
1228   case GEOM::ST_IN:
1229     aState = GEOMAlgo_ST_IN;
1230     break;
1231   case GEOM::ST_ONIN:
1232     aState = GEOMAlgo_ST_ONIN;
1233     break;
1234   default:
1235     break;
1236   }
1237
1238   return aState;
1239 }
1240
1241 //=============================================================================
1242 /*!
1243  *  GetShapesOnPlane
1244  */
1245 //=============================================================================
1246 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnPlane
1247                                                 (GEOM::GEOM_Object_ptr   theShape,
1248                                                  const CORBA::Long       theShapeType,
1249                                                  GEOM::GEOM_Object_ptr   theAx1,
1250                                                  const GEOM::shape_state theState)
1251 {
1252   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1253
1254   //Set a not done flag
1255   GetOperations()->SetNotDone();
1256
1257   //Get the reference objects
1258   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1259   Handle(::GEOM_Object) anAx1 = GetObjectImpl(theAx1);
1260
1261   if (aShape.IsNull() || anAx1.IsNull()) return aSeq._retn();
1262
1263   //Get Shapes On Plane
1264   Handle(TColStd_HSequenceOfTransient) aHSeq =
1265     GetOperations()->GetShapesOnPlane(aShape, theShapeType, anAx1, ShapeState(theState));
1266   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1267     return aSeq._retn();
1268
1269   Standard_Integer aLength = aHSeq->Length();
1270   aSeq->length(aLength);
1271   for (Standard_Integer i = 1; i <= aLength; i++)
1272     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1273
1274   return aSeq._retn();
1275 }
1276
1277 //=============================================================================
1278 /*!
1279  *  GetShapesOnPlaneWithLocation
1280  */
1281 //=============================================================================
1282 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnPlaneWithLocation
1283                                                 (GEOM::GEOM_Object_ptr   theShape,
1284                                                  const CORBA::Long       theShapeType,
1285                                                  GEOM::GEOM_Object_ptr   theAx1,
1286                                                  GEOM::GEOM_Object_ptr   thePnt,
1287                                                  const GEOM::shape_state theState)
1288 {
1289   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1290
1291   //Set a not done flag
1292   GetOperations()->SetNotDone();
1293
1294   //Get the reference objects
1295   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1296   Handle(::GEOM_Object) anAx1 = GetObjectImpl(theAx1);
1297   Handle(::GEOM_Object) anPnt = GetObjectImpl(thePnt);
1298
1299   if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return aSeq._retn();
1300
1301   //Get Shapes On Plane
1302   Handle(TColStd_HSequenceOfTransient) aHSeq =
1303     GetOperations()->GetShapesOnPlaneWithLocation(aShape, theShapeType, anAx1, anPnt, ShapeState(theState));
1304   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1305     return aSeq._retn();
1306
1307   Standard_Integer aLength = aHSeq->Length();
1308   aSeq->length(aLength);
1309   for (Standard_Integer i = 1; i <= aLength; i++)
1310     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1311
1312   return aSeq._retn();
1313 }
1314
1315 //=============================================================================
1316 /*!
1317  *  GetShapesOnCylinder
1318  */
1319 //=============================================================================
1320 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnCylinder
1321                                                 (GEOM::GEOM_Object_ptr   theShape,
1322                                                  const CORBA::Long       theShapeType,
1323                                                  GEOM::GEOM_Object_ptr   theAxis,
1324                                                  const CORBA::Double     theRadius,
1325                                                  const GEOM::shape_state theState)
1326 {
1327   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1328
1329   //Set a not done flag
1330   GetOperations()->SetNotDone();
1331
1332   //Get the reference objects
1333   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1334   Handle(::GEOM_Object) anAxis = GetObjectImpl(theAxis);
1335
1336   if (aShape.IsNull() || anAxis.IsNull()) return aSeq._retn();
1337
1338   //Get Shapes On Cylinder
1339   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnCylinder
1340     (aShape, theShapeType, anAxis, theRadius, ShapeState(theState));
1341   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1342     return aSeq._retn();
1343
1344   Standard_Integer aLength = aHSeq->Length();
1345   aSeq->length(aLength);
1346   for (Standard_Integer i = 1; i <= aLength; i++)
1347     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1348
1349   return aSeq._retn();
1350 }
1351
1352 //=============================================================================
1353 /*!
1354  *  GetShapesOnCylinderWithLocation
1355  */
1356 //=============================================================================
1357 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnCylinderWithLocation
1358                                                 (GEOM::GEOM_Object_ptr   theShape,
1359                                                  const CORBA::Long       theShapeType,
1360                                                  GEOM::GEOM_Object_ptr   theAxis,
1361                                                  GEOM::GEOM_Object_ptr   thePnt,
1362                                                  const CORBA::Double     theRadius,
1363                                                  const GEOM::shape_state theState)
1364 {
1365   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1366
1367   //Set a not done flag
1368   GetOperations()->SetNotDone();
1369
1370   //Get the reference objects
1371   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1372   Handle(::GEOM_Object) anAxis = GetObjectImpl(theAxis);
1373   Handle(::GEOM_Object) aPnt   = GetObjectImpl(thePnt);
1374
1375   if (aShape.IsNull() || anAxis.IsNull() || aPnt.IsNull()) return aSeq._retn();
1376
1377   //Get Shapes On Cylinder
1378   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnCylinderWithLocation
1379     (aShape, theShapeType, anAxis, aPnt, theRadius, ShapeState(theState));
1380   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1381     return aSeq._retn();
1382
1383   Standard_Integer aLength = aHSeq->Length();
1384   aSeq->length(aLength);
1385   for (Standard_Integer i = 1; i <= aLength; i++)
1386     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1387
1388   return aSeq._retn();
1389 }
1390
1391 //=============================================================================
1392 /*!
1393  *  GetShapesOnSphere
1394  */
1395 //=============================================================================
1396 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnSphere
1397                                                 (GEOM::GEOM_Object_ptr   theShape,
1398                                                  const CORBA::Long       theShapeType,
1399                                                  GEOM::GEOM_Object_ptr   theCenter,
1400                                                  const CORBA::Double     theRadius,
1401                                                  const GEOM::shape_state theState)
1402 {
1403   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1404
1405   //Set a not done flag
1406   GetOperations()->SetNotDone();
1407
1408   //Get the reference objects
1409   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1410   Handle(::GEOM_Object) aCenter = GetObjectImpl(theCenter);
1411
1412   if (aShape.IsNull() || aCenter.IsNull()) return aSeq._retn();
1413
1414   //Get Shapes On Sphere
1415   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnSphere
1416     (aShape, theShapeType, aCenter, theRadius, ShapeState(theState));
1417   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1418     return aSeq._retn();
1419
1420   Standard_Integer aLength = aHSeq->Length();
1421   aSeq->length(aLength);
1422   for (Standard_Integer i = 1; i <= aLength; i++)
1423     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1424
1425   return aSeq._retn();
1426 }
1427
1428 //=============================================================================
1429 /*!
1430  *  GetShapesOnQuadrangle
1431  */
1432 //=============================================================================
1433 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnQuadrangle
1434                                                 (GEOM::GEOM_Object_ptr theShape,
1435                                                  CORBA::Long           theShapeType,
1436                                                  GEOM::GEOM_Object_ptr theTopLeftPoint,
1437                                                  GEOM::GEOM_Object_ptr theTopRightPoint,
1438                                                  GEOM::GEOM_Object_ptr theBottomLeftPoint,
1439                                                  GEOM::GEOM_Object_ptr theBottomRightPoint,
1440                                                  GEOM::shape_state     theState)
1441 {
1442   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1443
1444   //Set a not done flag
1445   GetOperations()->SetNotDone();
1446
1447   //Get the reference objects
1448   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1449   Handle(::GEOM_Object) aTopLeftPoint = GetObjectImpl(theTopLeftPoint);
1450   Handle(::GEOM_Object) aTopRightPoint = GetObjectImpl(theTopRightPoint);
1451   Handle(::GEOM_Object) aBottomLeftPoint = GetObjectImpl(theBottomLeftPoint);
1452   Handle(::GEOM_Object) aBottomRightPoint = GetObjectImpl(theBottomRightPoint);
1453
1454   if (aShape.IsNull() ||
1455       aTopLeftPoint.IsNull() ||
1456       aTopRightPoint.IsNull() ||
1457       aBottomLeftPoint.IsNull() ||
1458       aBottomRightPoint.IsNull())
1459     return aSeq._retn();
1460
1461   //Get Shapes On Quadrangle
1462   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnQuadrangle
1463     (aShape, theShapeType,
1464      aTopLeftPoint, aTopRightPoint, aBottomLeftPoint, aBottomRightPoint,
1465      ShapeState(theState));
1466   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1467     return aSeq._retn();
1468
1469   Standard_Integer aLength = aHSeq->Length();
1470   aSeq->length(aLength);
1471   for (Standard_Integer i = 1; i <= aLength; i++)
1472     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1473
1474   return aSeq._retn();
1475 }
1476
1477 //=============================================================================
1478 /*!
1479  *  GetShapesOnPlaneIDs
1480  */
1481 //=============================================================================
1482 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnPlaneIDs
1483                                                 (GEOM::GEOM_Object_ptr   theShape,
1484                                                  const CORBA::Long       theShapeType,
1485                                                  GEOM::GEOM_Object_ptr   theAx1,
1486                                                  const GEOM::shape_state theState)
1487 {
1488   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1489
1490   //Set a not done flag
1491   GetOperations()->SetNotDone();
1492
1493   //Get the reference objects
1494   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1495   Handle(::GEOM_Object) anAx1 = GetObjectImpl(theAx1);
1496
1497   if (aShape.IsNull() || anAx1.IsNull()) return aSeq._retn();
1498
1499   //Get Shapes On Plane
1500   Handle(TColStd_HSequenceOfInteger) aHSeq =
1501     GetOperations()->GetShapesOnPlaneIDs(aShape, theShapeType, anAx1, ShapeState(theState));
1502   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1503     return aSeq._retn();
1504
1505   Standard_Integer aLength = aHSeq->Length();
1506   aSeq->length(aLength);
1507   for (Standard_Integer i = 1; i <= aLength; i++)
1508     aSeq[i-1] = aHSeq->Value(i);
1509
1510   return aSeq._retn();
1511 }
1512
1513 //=============================================================================
1514 /*!
1515  *  GetShapesOnPlaneWithLocationIDs
1516  */
1517 //=============================================================================
1518 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnPlaneWithLocationIDs
1519                                                 (GEOM::GEOM_Object_ptr   theShape,
1520                                                  const CORBA::Long       theShapeType,
1521                                                  GEOM::GEOM_Object_ptr   theAx1,
1522                                                  GEOM::GEOM_Object_ptr   thePnt,
1523                                                  const GEOM::shape_state theState)
1524 {
1525   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1526
1527   //Set a not done flag
1528   GetOperations()->SetNotDone();
1529
1530   //Get the reference objects
1531   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1532   Handle(::GEOM_Object) anAx1 = GetObjectImpl(theAx1);
1533   Handle(::GEOM_Object) anPnt = GetObjectImpl(thePnt);
1534
1535   if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return aSeq._retn();
1536
1537   //Get Shapes On Plane
1538   Handle(TColStd_HSequenceOfInteger) aHSeq =
1539     GetOperations()->GetShapesOnPlaneWithLocationIDs(aShape, theShapeType,
1540                                                      anAx1, anPnt, ShapeState(theState));
1541   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1542     return aSeq._retn();
1543
1544   Standard_Integer aLength = aHSeq->Length();
1545   aSeq->length(aLength);
1546   for (Standard_Integer i = 1; i <= aLength; i++)
1547     aSeq[i-1] = aHSeq->Value(i);
1548
1549   return aSeq._retn();
1550 }
1551
1552 //=============================================================================
1553 /*!
1554  *  GetShapesOnCylinderIDs
1555  */
1556 //=============================================================================
1557 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnCylinderIDs
1558                                                 (GEOM::GEOM_Object_ptr   theShape,
1559                                                  const CORBA::Long       theShapeType,
1560                                                  GEOM::GEOM_Object_ptr   theAxis,
1561                                                  const CORBA::Double     theRadius,
1562                                                  const GEOM::shape_state theState)
1563 {
1564   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1565
1566   //Set a not done flag
1567   GetOperations()->SetNotDone();
1568
1569   //Get the reference objects
1570   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1571   Handle(::GEOM_Object) anAxis = GetObjectImpl(theAxis);
1572
1573   if (aShape.IsNull() || anAxis.IsNull()) return aSeq._retn();
1574
1575   //Get Shapes On Cylinder
1576   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnCylinderIDs
1577     (aShape, theShapeType, anAxis, theRadius, ShapeState(theState));
1578   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1579     return aSeq._retn();
1580
1581   Standard_Integer aLength = aHSeq->Length();
1582   aSeq->length(aLength);
1583   for (Standard_Integer i = 1; i <= aLength; i++)
1584     aSeq[i-1] = aHSeq->Value(i);
1585
1586   return aSeq._retn();
1587 }
1588
1589 //=============================================================================
1590 /*!
1591  *  GetShapesOnCylinderWithLocationIDs
1592  */
1593 //=============================================================================
1594 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnCylinderWithLocationIDs
1595                                                 (GEOM::GEOM_Object_ptr   theShape,
1596                                                  const CORBA::Long       theShapeType,
1597                                                  GEOM::GEOM_Object_ptr   theAxis,
1598                                                  GEOM::GEOM_Object_ptr   thePnt,
1599                                                  const CORBA::Double     theRadius,
1600                                                  const GEOM::shape_state theState)
1601 {
1602   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1603
1604   //Set a not done flag
1605   GetOperations()->SetNotDone();
1606
1607   //Get the reference objects
1608   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1609   Handle(::GEOM_Object) anAxis = GetObjectImpl(theAxis);
1610   Handle(::GEOM_Object) aPnt   = GetObjectImpl(thePnt);
1611
1612   if (aShape.IsNull() || anAxis.IsNull() || aPnt.IsNull()) return aSeq._retn();
1613
1614   //Get Shapes On Cylinder
1615   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnCylinderWithLocationIDs
1616     (aShape, theShapeType, anAxis, aPnt, theRadius, ShapeState(theState));
1617   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1618     return aSeq._retn();
1619
1620   Standard_Integer aLength = aHSeq->Length();
1621   aSeq->length(aLength);
1622   for (Standard_Integer i = 1; i <= aLength; i++)
1623     aSeq[i-1] = aHSeq->Value(i);
1624
1625   return aSeq._retn();
1626 }
1627
1628 //=============================================================================
1629 /*!
1630  *  GetShapesOnSphereIDs
1631  */
1632 //=============================================================================
1633 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnSphereIDs
1634                                                 (GEOM::GEOM_Object_ptr   theShape,
1635                                                  const CORBA::Long       theShapeType,
1636                                                  GEOM::GEOM_Object_ptr   theCenter,
1637                                                  const CORBA::Double     theRadius,
1638                                                  const GEOM::shape_state theState)
1639 {
1640   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1641
1642   //Set a not done flag
1643   GetOperations()->SetNotDone();
1644
1645   //Get the reference objects
1646   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1647   Handle(::GEOM_Object) aCenter = GetObjectImpl(theCenter);
1648
1649   if (aShape.IsNull() || aCenter.IsNull()) return aSeq._retn();
1650
1651   //Get Shapes On Sphere
1652   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnSphereIDs
1653     (aShape, theShapeType, aCenter, theRadius, ShapeState(theState));
1654   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1655     return aSeq._retn();
1656
1657   Standard_Integer aLength = aHSeq->Length();
1658   aSeq->length(aLength);
1659   for (Standard_Integer i = 1; i <= aLength; i++)
1660     aSeq[i-1] = aHSeq->Value(i);
1661
1662   return aSeq._retn();
1663 }
1664
1665 //=============================================================================
1666 /*!
1667  *  GetShapesOnQuadrangleIDs
1668  */
1669 //=============================================================================
1670 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnQuadrangleIDs
1671                                                 (GEOM::GEOM_Object_ptr theShape,
1672                                                  CORBA::Long           theShapeType,
1673                                                  GEOM::GEOM_Object_ptr theTopLeftPoint,
1674                                                  GEOM::GEOM_Object_ptr theTopRightPoint,
1675                                                  GEOM::GEOM_Object_ptr theBottomLeftPoint,
1676                                                  GEOM::GEOM_Object_ptr theBottomRightPoint,
1677                                                  GEOM::shape_state     theState)
1678 {
1679   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1680
1681   //Set a not done flag
1682   GetOperations()->SetNotDone();
1683
1684   //Get the reference objects
1685   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1686   Handle(::GEOM_Object) aTopLeftPoint = GetObjectImpl(theTopLeftPoint);
1687   Handle(::GEOM_Object) aTopRightPoint = GetObjectImpl(theTopRightPoint);
1688   Handle(::GEOM_Object) aBottomLeftPoint = GetObjectImpl(theBottomLeftPoint);
1689   Handle(::GEOM_Object) aBottomRightPoint = GetObjectImpl(theBottomRightPoint);
1690
1691   if (aShape.IsNull() ||
1692       aTopLeftPoint.IsNull() ||
1693       aTopRightPoint.IsNull() ||
1694       aBottomLeftPoint.IsNull() ||
1695       aBottomRightPoint.IsNull() )
1696     return aSeq._retn();
1697
1698   //Get Shapes On Quadrangle
1699   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnQuadrangleIDs
1700     (aShape, theShapeType,
1701      aTopLeftPoint, aTopRightPoint, aBottomLeftPoint, aBottomRightPoint,
1702      ShapeState(theState));
1703   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1704     return aSeq._retn();
1705
1706   Standard_Integer aLength = aHSeq->Length();
1707   aSeq->length(aLength);
1708   for (Standard_Integer i = 1; i <= aLength; i++)
1709     aSeq[i-1] = aHSeq->Value(i);
1710
1711   return aSeq._retn();
1712 }
1713
1714 //=============================================================================
1715 /*!
1716  *  GetShapesOnBox
1717  */
1718 //=============================================================================
1719 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnBox
1720                                                 (GEOM::GEOM_Object_ptr theBox,
1721                                                  GEOM::GEOM_Object_ptr theShape,
1722                                                  CORBA::Long           theShapeType,
1723                                                  GEOM::shape_state     theState)
1724 {
1725   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1726
1727   //Set a not done flag
1728   GetOperations()->SetNotDone();
1729
1730   //Get the reference objects
1731   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1732   Handle(::GEOM_Object) aBox = GetObjectImpl(theBox);
1733
1734   if (aShape.IsNull() || aBox.IsNull() )
1735     return aSeq._retn();
1736
1737   //Get Shapes On Box
1738   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnBox
1739     (aBox,aShape, theShapeType,ShapeState(theState));
1740   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1741     return aSeq._retn();
1742
1743   Standard_Integer aLength = aHSeq->Length();
1744   aSeq->length(aLength);
1745   for (Standard_Integer i = 1; i <= aLength; i++)
1746     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1747
1748   return aSeq._retn();
1749 }
1750
1751 //=============================================================================
1752 /*!
1753  *  GetShapesOnQuadrangleIDs
1754  */
1755 //=============================================================================
1756 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnBoxIDs
1757                                                 (GEOM::GEOM_Object_ptr theBox,
1758                                                  GEOM::GEOM_Object_ptr theShape,
1759                                                  CORBA::Long           theShapeType,
1760                                                  GEOM::shape_state     theState)
1761 {
1762   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1763
1764   //Set a not done flag
1765   GetOperations()->SetNotDone();
1766
1767   //Get the reference objects
1768   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1769   Handle(::GEOM_Object) aBox = GetObjectImpl(theBox);
1770
1771   if (aShape.IsNull() || aBox.IsNull() )
1772     return aSeq._retn();
1773
1774   //Get Shapes On Box
1775   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnBoxIDs
1776     (aBox,aShape, theShapeType,ShapeState(theState));
1777   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1778     return aSeq._retn();
1779
1780   Standard_Integer aLength = aHSeq->Length();
1781   aSeq->length(aLength);
1782   for (Standard_Integer i = 1; i <= aLength; i++)
1783     aSeq[i-1] = aHSeq->Value(i);
1784
1785   return aSeq._retn();
1786 }
1787
1788
1789 //=============================================================================
1790 /*!
1791  *  GetShapesOnShape
1792  */
1793 //=============================================================================
1794 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnShape
1795                                            (GEOM::GEOM_Object_ptr theCheckShape,
1796                                             GEOM::GEOM_Object_ptr theShape,
1797                                             CORBA::Short          theShapeType,
1798                                             GEOM::shape_state     theState)
1799 {
1800   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1801
1802   //Set a not done flag
1803   GetOperations()->SetNotDone();
1804
1805   //Get the reference objects
1806   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1807   Handle(::GEOM_Object) aCheckShape = GetObjectImpl(theCheckShape);
1808
1809   if (aShape.IsNull() || aCheckShape.IsNull() )
1810     return aSeq._retn();
1811
1812   //Get Shapes On Shape
1813   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnShape
1814     (aCheckShape,aShape, theShapeType,ShapeState(theState));
1815
1816   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1817     return aSeq._retn();
1818
1819   Standard_Integer aLength = aHSeq->Length();
1820   aSeq->length(aLength);
1821   for (Standard_Integer i = 1; i <= aLength; i++)
1822     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1823
1824   return aSeq._retn();
1825 }
1826
1827
1828 //=============================================================================
1829 /*!
1830  *  GetShapesOnShapeAsCompound
1831  */
1832 //=============================================================================
1833 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetShapesOnShapeAsCompound
1834                                            (GEOM::GEOM_Object_ptr theCheckShape,
1835                                             GEOM::GEOM_Object_ptr theShape,
1836                                             CORBA::Short          theShapeType,
1837                                             GEOM::shape_state     theState)
1838 {
1839   GEOM::GEOM_Object_var aGEOMObject;
1840
1841   //Set a not done flag
1842   GetOperations()->SetNotDone();
1843
1844   //Get the reference objects
1845   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1846   Handle(::GEOM_Object) aCheckShape = GetObjectImpl(theCheckShape);
1847
1848   if (aShape.IsNull() || aCheckShape.IsNull() )
1849     return aGEOMObject._retn();
1850
1851   //Get Shapes On Shape
1852   Handle(::GEOM_Object) anObject = GetOperations()->GetShapesOnShapeAsCompound
1853     (aCheckShape,aShape, theShapeType,ShapeState(theState));
1854
1855   if (anObject.IsNull())
1856     return aGEOMObject._retn();
1857
1858   return GetObject(anObject);
1859 }
1860
1861
1862 //=============================================================================
1863 /*!
1864  *  GetShapesOnShapeIDs
1865  */
1866 //=============================================================================
1867 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnShapeIDs
1868                                            (GEOM::GEOM_Object_ptr theCheckShape,
1869                                             GEOM::GEOM_Object_ptr theShape,
1870                                             CORBA::Short          theShapeType,
1871                                             GEOM::shape_state     theState)
1872 {
1873   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1874
1875   //Set a not done flag
1876   GetOperations()->SetNotDone();
1877
1878   //Get the reference objects
1879   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1880   Handle(::GEOM_Object) aCheckShape = GetObjectImpl(theCheckShape);
1881
1882   if (aShape.IsNull() || aCheckShape.IsNull() )
1883     return aSeq._retn();
1884
1885   //Get Shapes On Shape
1886   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnShapeIDs
1887     (aCheckShape,aShape, theShapeType,ShapeState(theState));
1888   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1889     return aSeq._retn();
1890
1891   Standard_Integer aLength = aHSeq->Length();
1892   aSeq->length(aLength);
1893   for (Standard_Integer i = 1; i <= aLength; i++)
1894     aSeq[i-1] = aHSeq->Value(i);
1895
1896   return aSeq._retn();
1897 }
1898
1899
1900 //=============================================================================
1901 /*!
1902  *  GetInPlace
1903  */
1904 //=============================================================================
1905 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetInPlace
1906                                           (GEOM::GEOM_Object_ptr theShapeWhere,
1907                                            GEOM::GEOM_Object_ptr theShapeWhat)
1908 {
1909   GEOM::GEOM_Object_var aGEOMObject;
1910
1911   //Set a not done flag
1912   GetOperations()->SetNotDone();
1913
1914   //Get the reference objects
1915   Handle(::GEOM_Object) aShapeWhere = GetObjectImpl(theShapeWhere);
1916   Handle(::GEOM_Object) aShapeWhat = GetObjectImpl(theShapeWhat);
1917
1918   if (aShapeWhere.IsNull() ||
1919       aShapeWhat.IsNull()) return aGEOMObject._retn();
1920
1921   //Get Shapes in place of aShapeWhat
1922   Handle(::GEOM_Object) anObject =
1923     GetOperations()->GetInPlace(aShapeWhere, aShapeWhat);
1924   if (!GetOperations()->IsDone() || anObject.IsNull())
1925     return aGEOMObject._retn();
1926
1927   return GetObject(anObject);
1928 }
1929
1930 //=============================================================================
1931 /*!
1932  *  GetInPlaceOld
1933  */
1934 //=============================================================================
1935 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetInPlaceOld
1936                                           (GEOM::GEOM_Object_ptr theShapeWhere,
1937                                            GEOM::GEOM_Object_ptr theShapeWhat)
1938 {
1939   GEOM::GEOM_Object_var aGEOMObject;
1940
1941   //Set a not done flag
1942   GetOperations()->SetNotDone();
1943
1944   //Get the reference objects
1945   Handle(::GEOM_Object) aShapeWhere = GetObjectImpl(theShapeWhere);
1946   Handle(::GEOM_Object) aShapeWhat = GetObjectImpl(theShapeWhat);
1947
1948   if (aShapeWhere.IsNull() ||
1949       aShapeWhat.IsNull()) return aGEOMObject._retn();
1950
1951   //Get Shapes in place of aShapeWhat
1952   Handle(::GEOM_Object) anObject =
1953     GetOperations()->GetInPlaceOld(aShapeWhere, aShapeWhat);
1954   if (!GetOperations()->IsDone() || anObject.IsNull())
1955     return aGEOMObject._retn();
1956
1957   return GetObject(anObject);
1958 }
1959
1960 //=============================================================================
1961 /*!
1962  *  GetInPlaceByHistory
1963  */
1964 //=============================================================================
1965 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetInPlaceByHistory
1966                                           (GEOM::GEOM_Object_ptr theShapeWhere,
1967                                            GEOM::GEOM_Object_ptr theShapeWhat)
1968 {
1969   GEOM::GEOM_Object_var aGEOMObject;
1970
1971   //Set a not done flag
1972   GetOperations()->SetNotDone();
1973
1974   //Get the reference objects
1975   Handle(::GEOM_Object) aShapeWhere = GetObjectImpl(theShapeWhere);
1976   Handle(::GEOM_Object) aShapeWhat = GetObjectImpl(theShapeWhat);
1977
1978   if (aShapeWhere.IsNull() ||
1979       aShapeWhat.IsNull()) return aGEOMObject._retn();
1980
1981   //Get Shapes in place of aShapeWhat
1982   Handle(::GEOM_Object) anObject =
1983     GetOperations()->GetInPlaceByHistory(aShapeWhere, aShapeWhat);
1984   if (!GetOperations()->IsDone() || anObject.IsNull())
1985     return aGEOMObject._retn();
1986
1987   return GetObject(anObject);
1988 }
1989
1990 //=============================================================================
1991 /*!
1992  *  GetInPlaceMap
1993  */
1994 //=============================================================================
1995 GEOM::ListOfListOfLong*
1996 GEOM_IShapesOperations_i::GetInPlaceMap (GEOM::GEOM_Object_ptr theShapeWhere,
1997                                          GEOM::GEOM_Object_ptr theShapeWhat)
1998 {
1999   GEOM::ListOfListOfLong_var aResult = new GEOM::ListOfListOfLong();
2000
2001   //Get the reference objects
2002   Handle(::GEOM_Object) aShapeWhere = GetObjectImpl(theShapeWhere);
2003   Handle(::GEOM_Object) aShapeWhat = GetObjectImpl(theShapeWhat);
2004
2005   if (!aShapeWhere.IsNull() &&
2006       !aShapeWhat.IsNull())
2007   {
2008     std::vector< std::vector< int > > resVec;
2009     GetOperations()->GetInPlaceMap(aShapeWhere, aShapeWhat, resVec);
2010
2011     aResult->length( resVec.size() );
2012     for ( size_t i = 0; i < resVec.size(); ++i )
2013     {
2014       //if ( !resVec[i].empty() )
2015       aResult[i].length( resVec[i].size() );
2016       for ( size_t j = 0; j < resVec[i].size(); ++j )
2017         aResult[i][j] = resVec[i][j];
2018     }
2019   }
2020   return aResult._retn();
2021 }
2022
2023 //=============================================================================
2024 /*!
2025  *  GetSame
2026  */
2027 //=============================================================================
2028 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetSame
2029                                           (GEOM::GEOM_Object_ptr theShapeWhere,
2030                                            GEOM::GEOM_Object_ptr theShapeWhat)
2031 {
2032   GEOM::GEOM_Object_var aGEOMObject;
2033
2034   //Set a not done flag
2035   GetOperations()->SetNotDone();
2036
2037   //Get the reference objects
2038   Handle(::GEOM_Object) aShapeWhere = GetObjectImpl(theShapeWhere);
2039   Handle(::GEOM_Object) aShapeWhat = GetObjectImpl(theShapeWhat);
2040
2041   if (aShapeWhere.IsNull() ||
2042       aShapeWhat.IsNull()) return aGEOMObject._retn();
2043
2044   //Get Shapes in place of aShapeWhat
2045   Handle(::GEOM_Object) anObject =
2046     GetOperations()->GetSame(aShapeWhere, aShapeWhat);
2047   if (!GetOperations()->IsDone() || anObject.IsNull())
2048     return aGEOMObject._retn();
2049
2050   return GetObject(anObject);
2051 }
2052
2053 //=============================================================================
2054 /*!
2055  *  GetSameIDs
2056  */
2057 //=============================================================================
2058 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetSameIDs
2059                                           (GEOM::GEOM_Object_ptr theShapeWhere,
2060                                            GEOM::GEOM_Object_ptr theShapeWhat) {
2061   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
2062
2063   //Get the reference objects
2064   Handle(::GEOM_Object) aShapeWhere = GetObjectImpl(theShapeWhere);
2065   Handle(::GEOM_Object) aShapeWhat = GetObjectImpl(theShapeWhat);
2066
2067   if (aShapeWhere.IsNull() ||
2068       aShapeWhat.IsNull()) return aSeq._retn();
2069
2070
2071   Handle(TColStd_HSequenceOfInteger) aHSeq =
2072     GetOperations()->GetSameIDs(aShapeWhere, aShapeWhat);
2073
2074   if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
2075
2076   Standard_Integer aLength = aHSeq->Length();
2077   aSeq->length(aLength);
2078   for (Standard_Integer i = 1; i <= aLength; i++)
2079     aSeq[i-1] = aHSeq->Value(i);
2080
2081   return aSeq._retn();
2082 }
2083
2084 //=============================================================================
2085 /*!
2086  *  ExtendEdge
2087  */
2088 //=============================================================================
2089 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::ExtendEdge
2090                                   (GEOM::GEOM_Object_ptr theEdge,
2091                                    CORBA::Double         theMin,
2092                                    CORBA::Double         theMax)
2093 {
2094   GEOM::GEOM_Object_var aGEOMObject;
2095
2096   //Set a not done flag
2097   GetOperations()->SetNotDone();
2098
2099   //Get the reference objects
2100   Handle(::GEOM_Object) anEdge = GetObjectImpl(theEdge);
2101
2102   if (anEdge.IsNull()) {
2103     return aGEOMObject._retn();
2104   }
2105
2106   //Get Shapes in place of aShapeWhat
2107   Handle(::GEOM_Object) aNewEdge =
2108     GetOperations()->ExtendEdge(anEdge, theMin, theMax);
2109
2110   if (!GetOperations()->IsDone() || aNewEdge.IsNull()) {
2111     return aGEOMObject._retn();
2112   }
2113
2114   return GetObject(aNewEdge);
2115 }
2116
2117 //=============================================================================
2118 /*!
2119  *  ExtendFace
2120  */
2121 //=============================================================================
2122 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::ExtendFace
2123                                   (GEOM::GEOM_Object_ptr theFace,
2124                                    CORBA::Double         theUMin,
2125                                    CORBA::Double         theUMax,
2126                                    CORBA::Double         theVMin,
2127                                    CORBA::Double         theVMax)
2128 {
2129   GEOM::GEOM_Object_var aGEOMObject;
2130
2131   //Set a not done flag
2132   GetOperations()->SetNotDone();
2133
2134   //Get the reference objects
2135   Handle(::GEOM_Object) aFace = GetObjectImpl(theFace);
2136
2137   if (aFace.IsNull()) {
2138     return aGEOMObject._retn();
2139   }
2140
2141   //Get Shapes in place of aShapeWhat
2142   Handle(::GEOM_Object) aNewFace =
2143     GetOperations()->ExtendFace(aFace, theUMin, theUMax, theVMin, theVMax);
2144
2145   if (!GetOperations()->IsDone() || aNewFace.IsNull()) {
2146     return aGEOMObject._retn();
2147   }
2148
2149   return GetObject(aNewFace);
2150 }
2151
2152 //=============================================================================
2153 /*!
2154  *  MakeSurfaceFromFace
2155  */
2156 //=============================================================================
2157 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeSurfaceFromFace
2158                                   (GEOM::GEOM_Object_ptr theFace)
2159 {
2160   GEOM::GEOM_Object_var aGEOMObject;
2161
2162   //Set a not done flag
2163   GetOperations()->SetNotDone();
2164
2165   //Get the reference object
2166   Handle(::GEOM_Object) aFace = GetObjectImpl(theFace);
2167
2168   if (aFace.IsNull()) {
2169     return aGEOMObject._retn();
2170   }
2171
2172   //Get Shapes in place of aShapeWhat
2173   Handle(::GEOM_Object) aNewFace = GetOperations()->MakeSurfaceFromFace(aFace);
2174
2175   if (!GetOperations()->IsDone() || aNewFace.IsNull()) {
2176     return aGEOMObject._retn();
2177   }
2178
2179   return GetObject(aNewFace);
2180 }
2181
2182 //=============================================================================
2183 /*!
2184  *  GetSubShapeEdgeSorted
2185  */
2186 //=============================================================================
2187 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetSubShapeEdgeSorted
2188                                         (GEOM::GEOM_Object_ptr theShape,
2189                                          GEOM::GEOM_Object_ptr theStartPoint)
2190 {
2191   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
2192
2193   //Set a not done flag
2194   GetOperations()->SetNotDone();
2195
2196   //Get the reference objects
2197   Handle(::GEOM_Object) aShape      = GetObjectImpl(theShape);
2198   Handle(::GEOM_Object) aStartPoint = GetObjectImpl(theStartPoint);
2199
2200   if (aShape.IsNull() || aStartPoint.IsNull()) {
2201     return aSeq._retn();
2202   }
2203
2204   //Get Shapes On Shape
2205   Handle(TColStd_HSequenceOfTransient) aHSeq =
2206       GetOperations()->GetSubShapeEdgeSorted(aShape, aStartPoint);
2207
2208   if (!GetOperations()->IsDone() || aHSeq.IsNull())
2209     return aSeq._retn();
2210
2211   const Standard_Integer aLength = aHSeq->Length();
2212   Standard_Integer       i;
2213
2214   aSeq->length(aLength);
2215
2216   for (i = 1; i <= aLength; i++) {
2217     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
2218   }
2219
2220   return aSeq._retn();
2221 }
2222
2223 //=============================================================================
2224 /*!
2225  *  GetSubShapesWithTolerance
2226  */
2227 //=============================================================================
2228 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetSubShapesWithTolerance
2229                      (GEOM::GEOM_Object_ptr      theShape,
2230                       CORBA::Short               theShapeType,
2231                       GEOM::comparison_condition theCondition,
2232                       CORBA::Double              theTolerance)
2233 {
2234   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
2235
2236   //Set a not done flag
2237   GetOperations()->SetNotDone();
2238
2239   //Get the reference objects
2240   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
2241
2242   if (aShape.IsNull()) {
2243     return aSeq._retn();
2244   }
2245
2246   //Get Shapes On Shape
2247   const GEOMUtils::ComparisonCondition aCondition =
2248                 ComparisonCondition(theCondition);
2249   Handle(TColStd_HSequenceOfTransient) aHSeq      =
2250       GetOperations()->GetSubShapesWithTolerance
2251                 (aShape, theShapeType, aCondition, theTolerance);
2252
2253   if (!GetOperations()->IsDone() || aHSeq.IsNull())
2254     return aSeq._retn();
2255
2256   const Standard_Integer aLength = aHSeq->Length();
2257   Standard_Integer       i;
2258
2259   aSeq->length(aLength);
2260
2261   for (i = 1; i <= aLength; i++) {
2262     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
2263   }
2264
2265   return aSeq._retn();
2266 }
2267
2268 //=============================================================================
2269 /*!
2270  *  MakeExtraction
2271  */
2272 //=============================================================================
2273 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeExtraction
2274          (GEOM::GEOM_Object_ptr                              theShape,
2275           const GEOM::ListOfLong                            &theSubShapeIDs,
2276           GEOM::GEOM_IShapesOperations::ExtractionStats_out  theStats)
2277 {
2278   GEOM::GEOM_Object_var aGEOMObject;
2279
2280   //Set a not done flag
2281   theStats = new GEOM::GEOM_IShapesOperations::ExtractionStats;
2282   GetOperations()->SetNotDone();
2283
2284   //Get the reference object
2285   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
2286
2287   if (aShape.IsNull()) {
2288     return aGEOMObject._retn();
2289   }
2290
2291   const int aNbIDs = theSubShapeIDs.length();
2292
2293   if (aNbIDs == 0) {
2294     return aGEOMObject._retn();
2295   }
2296
2297   int                              i;
2298   Handle(TColStd_HArray1OfInteger) anArray =
2299     new TColStd_HArray1OfInteger (1, aNbIDs);
2300
2301   for (i = 0; i < aNbIDs; i++) {
2302     anArray->SetValue(i + 1, theSubShapeIDs[i]);
2303   }
2304
2305   //Get Shapes in place of aShapeWhat
2306   std::list<GEOMImpl_IShapesOperations::ExtractionStat> aStats;
2307   Handle(GEOM_Object)                                   aResult =
2308           GetOperations()->MakeExtraction(aShape, anArray, aStats);
2309
2310   if (!GetOperations()->IsDone() || aResult.IsNull()) {
2311     return aGEOMObject._retn();
2312   }
2313
2314   // Convert statistics.
2315   const int aNbStats = aStats.size();
2316
2317   theStats->length(aNbStats);
2318
2319   // fill the local CORBA array with values from lists
2320   std::list<GEOMImpl_IShapesOperations::ExtractionStat>::const_iterator
2321     anIt = aStats.begin();
2322
2323   for (i = 0; anIt != aStats.end(); i++, anIt++) {
2324     GEOM::GEOM_IShapesOperations::ExtractionStat_var aResStat =
2325       new GEOM::GEOM_IShapesOperations::ExtractionStat;
2326
2327     // Copy type
2328     switch (anIt->type) {
2329     case GEOMImpl_IShapesOperations::EST_Removed:
2330       aResStat->type = GEOM::GEOM_IShapesOperations::EST_Removed;
2331       break;
2332     case GEOMImpl_IShapesOperations::EST_Modified:
2333       aResStat->type = GEOM::GEOM_IShapesOperations::EST_Modified;
2334       break;
2335     case GEOMImpl_IShapesOperations::EST_Added:
2336       aResStat->type = GEOM::GEOM_IShapesOperations::EST_Added;
2337       break;
2338     default:
2339       break;
2340     }
2341
2342     // Copy the list of IDs
2343     std::list<Standard_Integer> aIDList    = anIt->indices;
2344     GEOM::ListOfLong_var        aResIDList = new GEOM::ListOfLong;
2345
2346     aResIDList->length(aIDList.size());
2347
2348     std::list<Standard_Integer>::iterator anIDIt = aIDList.begin();
2349     int j = 0;
2350
2351     for (; anIDIt != aIDList.end(); j++, anIDIt++) {
2352       aResIDList[j] = *anIDIt;
2353     }
2354
2355     aResStat->indices = aResIDList;
2356
2357     theStats[(_CORBA_ULong)i] = aResStat;
2358   }
2359
2360   return GetObject(aResult);
2361 }