Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[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/ or email : webmaster.salome@opencascade.com
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  *  GetSubShapeIndex
444  */
445 //=============================================================================
446 CORBA::Long GEOM_IShapesOperations_i::GetSubShapeIndex
447   (GEOM::GEOM_Object_ptr theMainShape, GEOM::GEOM_Object_ptr theSubShape)
448 {
449   if (theMainShape == NULL || theSubShape == NULL) return -1;
450
451   //Get the reference shapes
452   Handle(GEOM_Object) aMainShapeRef = GetOperations()->GetEngine()->GetObject
453     (theMainShape->GetStudyID(), theMainShape->GetEntry());
454   Handle(GEOM_Object) aSubShapeRef = GetOperations()->GetEngine()->GetObject
455     (theSubShape->GetStudyID(), theSubShape->GetEntry());
456   if (aMainShapeRef.IsNull() || aSubShapeRef.IsNull()) return -1;
457
458   //Get the unique ID of <theSubShape> inside <theMainShape>
459   CORBA::Long anID = GetOperations()->GetSubShapeIndex(aMainShapeRef, aSubShapeRef);
460   if (!GetOperations()->IsDone())
461     return -1;
462
463   return anID;
464 }
465
466 //=============================================================================
467 /*!
468  *  GetTopologyIndex
469  */
470 //=============================================================================
471 CORBA::Long GEOM_IShapesOperations_i::GetTopologyIndex
472   (GEOM::GEOM_Object_ptr theMainShape, GEOM::GEOM_Object_ptr theSubShape)
473 {
474   if (theMainShape == NULL || theSubShape == NULL) return -1;
475
476   //Get the reference shapes
477   Handle(GEOM_Object) aMainShapeRef = GetOperations()->GetEngine()->GetObject
478     (theMainShape->GetStudyID(), theMainShape->GetEntry());
479   Handle(GEOM_Object) aSubShapeRef = GetOperations()->GetEngine()->GetObject
480     (theSubShape->GetStudyID(), theSubShape->GetEntry());
481   if (aMainShapeRef.IsNull() || aSubShapeRef.IsNull()) return -1;
482
483   //Get an ID of <theSubShape>, unique among all sub-shapes of <theMainShape> of the same type
484   CORBA::Long anID = GetOperations()->GetTopologyIndex(aMainShapeRef, aSubShapeRef);
485   if (!GetOperations()->IsDone())
486     return -1;
487
488   return anID;
489 }
490
491 //=============================================================================
492 /*!
493  *  GetShapeTypeString
494  */
495 //=============================================================================
496 char* GEOM_IShapesOperations_i::GetShapeTypeString (GEOM::GEOM_Object_ptr theShape)
497 {
498   if (theShape == NULL) return NULL;
499
500   //Get the reference shape
501   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
502     (theShape->GetStudyID(), theShape->GetEntry());
503
504   if (aShape.IsNull()) return NULL;
505
506   // Get shape parameters
507   TCollection_AsciiString aDescription = GetOperations()->GetShapeTypeString(aShape);
508   return CORBA::string_dup(aDescription.ToCString());
509 }
510
511 //=============================================================================
512 /*!
513  *  NumberOfFaces
514  */
515 //=============================================================================
516 CORBA::Long GEOM_IShapesOperations_i::NumberOfFaces (GEOM::GEOM_Object_ptr theShape)
517 {
518   if (theShape == NULL) return -1;
519
520   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
521     (theShape->GetStudyID(), theShape->GetEntry());
522
523   CORBA::Long aNb = GetOperations()->NumberOfFaces(aShape);
524   if (!GetOperations()->IsDone()) return -1;
525
526   return aNb;
527 }
528
529 //=============================================================================
530 /*!
531  *  NumberOfEdges
532  */
533 //=============================================================================
534 CORBA::Long GEOM_IShapesOperations_i::NumberOfEdges (GEOM::GEOM_Object_ptr theShape)
535 {
536   if (theShape == NULL) return -1;
537
538   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
539     (theShape->GetStudyID(), theShape->GetEntry());
540
541   CORBA::Long aNb = GetOperations()->NumberOfEdges(aShape);
542   if (!GetOperations()->IsDone()) return -1;
543
544   return aNb;
545 }
546
547 //=============================================================================
548 /*!
549  *  ChangeOrientation
550  */
551 //=============================================================================
552 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::ChangeOrientation
553                                                 (GEOM::GEOM_Object_ptr theShape)
554 {
555   GEOM::GEOM_Object_var aGEOMObject;
556
557   //Set a not done flag
558   GetOperations()->SetNotDone();
559
560   if (theShape == NULL) return aGEOMObject._retn();
561
562   //Get the reference objects
563   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
564     (theShape->GetStudyID(), theShape->GetEntry());
565
566   if (aShape.IsNull()) return aGEOMObject._retn();
567
568   //Create the Solid
569   Handle(GEOM_Object) anObject = GetOperations()->ReverseShape(aShape);
570   if (!GetOperations()->IsDone() || anObject.IsNull())
571     return aGEOMObject._retn();
572
573   return GetObject(anObject);
574 }
575
576 //=============================================================================
577 /*!
578  *  GetFreeFacesIDs
579  */
580 //=============================================================================
581 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetFreeFacesIDs (GEOM::GEOM_Object_ptr theShape)
582 {
583   //Set a not done flag
584   GetOperations()->SetNotDone();
585
586   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
587   if (theShape == NULL) return aSeq._retn();
588
589   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
590     (theShape->GetStudyID(), theShape->GetEntry());
591
592   Handle(TColStd_HSequenceOfInteger) aHSeq =
593     GetOperations()->GetFreeFacesIDs(aShape);
594   if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
595
596   Standard_Integer aLength = aHSeq->Length();
597   aSeq->length(aLength);
598   for (Standard_Integer i = 1; i <= aLength; i++)
599     aSeq[i-1] = aHSeq->Value(i);
600
601   return aSeq._retn();
602 }
603
604 //=============================================================================
605 /*!
606  *  GetSharedShapes
607  */
608 //=============================================================================
609 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetSharedShapes
610                                           (GEOM::GEOM_Object_ptr theShape1,
611                                            GEOM::GEOM_Object_ptr theShape2,
612                                            const CORBA::Long     theShapeType)
613 {
614   //Set a not done flag
615   GetOperations()->SetNotDone();
616
617   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
618   if (theShape1 == NULL ||
619       theShape2 == NULL) return aSeq._retn();
620
621   Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
622     (theShape1->GetStudyID(), theShape1->GetEntry());
623   Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
624     (theShape2->GetStudyID(), theShape2->GetEntry());
625
626   if (aShape1.IsNull() ||
627       aShape2.IsNull()) return aSeq._retn();
628
629   Handle(TColStd_HSequenceOfTransient) aHSeq =
630     GetOperations()->GetSharedShapes(aShape1, aShape2, theShapeType);
631   if (!GetOperations()->IsDone() || aHSeq.IsNull())
632     return aSeq._retn();
633
634   Standard_Integer aLength = aHSeq->Length();
635   aSeq->length(aLength);
636   for (Standard_Integer i = 1; i <= aLength; i++)
637     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
638
639   return aSeq._retn();
640 }
641
642 static GEOMAlgo_State ShapeState (const GEOM::shape_state theState)
643 {
644   GEOMAlgo_State aState = GEOMAlgo_ST_UNKNOWN;
645
646   switch (theState) {
647   case GEOM::ST_ON:
648     aState = GEOMAlgo_ST_ON;
649     break;
650   case GEOM::ST_OUT:
651     aState = GEOMAlgo_ST_OUT;
652     break;
653   case GEOM::ST_ONOUT:
654     aState = GEOMAlgo_ST_ONOUT;
655     break;
656   case GEOM::ST_IN:
657     aState = GEOMAlgo_ST_IN;
658     break;
659   case GEOM::ST_ONIN:
660     aState = GEOMAlgo_ST_ONIN;
661     break;
662   default:
663     break;
664   }
665
666   return aState;
667 }
668
669 //=============================================================================
670 /*!
671  *  GetShapesOnPlane
672  */
673 //=============================================================================
674 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnPlane
675                                                 (GEOM::GEOM_Object_ptr   theShape,
676                                                  const CORBA::Long       theShapeType,
677                                                  GEOM::GEOM_Object_ptr   theAx1,
678                                                  const GEOM::shape_state theState)
679 {
680   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
681
682   //Set a not done flag
683   GetOperations()->SetNotDone();
684
685   if (theShape == NULL || theAx1 == NULL) return aSeq._retn();
686
687   //Get the reference objects
688   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
689     (theShape->GetStudyID(), theShape->GetEntry());
690   Handle(GEOM_Object) anAx1 = GetOperations()->GetEngine()->GetObject
691     (theAx1->GetStudyID(), theAx1->GetEntry());
692
693   if (aShape.IsNull() || anAx1.IsNull()) return aSeq._retn();
694
695   //Get Shapes On Plane
696   Handle(TColStd_HSequenceOfTransient) aHSeq =
697     GetOperations()->GetShapesOnPlane(aShape, theShapeType, anAx1, ShapeState(theState));
698   if (!GetOperations()->IsDone() || aHSeq.IsNull())
699     return aSeq._retn();
700
701   Standard_Integer aLength = aHSeq->Length();
702   aSeq->length(aLength);
703   for (Standard_Integer i = 1; i <= aLength; i++)
704     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
705
706   return aSeq._retn();
707 }
708
709 //=============================================================================
710 /*!
711  *  GetShapesOnCylinder
712  */
713 //=============================================================================
714 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnCylinder
715                                                 (GEOM::GEOM_Object_ptr   theShape,
716                                                  const CORBA::Long       theShapeType,
717                                                  GEOM::GEOM_Object_ptr   theAxis,
718                                                  const CORBA::Double     theRadius,
719                                                  const GEOM::shape_state theState)
720 {
721   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
722
723   //Set a not done flag
724   GetOperations()->SetNotDone();
725
726   if (theShape == NULL || theAxis == NULL) return aSeq._retn();
727
728   //Get the reference objects
729   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
730     (theShape->GetStudyID(), theShape->GetEntry());
731   Handle(GEOM_Object) anAxis = GetOperations()->GetEngine()->GetObject
732     (theAxis->GetStudyID(), theAxis->GetEntry());
733
734   if (aShape.IsNull() || anAxis.IsNull()) return aSeq._retn();
735
736   //Get Shapes On Cylinder
737   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnCylinder
738     (aShape, theShapeType, anAxis, theRadius, ShapeState(theState));
739   if (!GetOperations()->IsDone() || aHSeq.IsNull())
740     return aSeq._retn();
741
742   Standard_Integer aLength = aHSeq->Length();
743   aSeq->length(aLength);
744   for (Standard_Integer i = 1; i <= aLength; i++)
745     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
746
747   return aSeq._retn();
748 }
749
750 //=============================================================================
751 /*!
752  *  GetShapesOnSphere
753  */
754 //=============================================================================
755 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnSphere
756                                                 (GEOM::GEOM_Object_ptr   theShape,
757                                                  const CORBA::Long       theShapeType,
758                                                  GEOM::GEOM_Object_ptr   theCenter,
759                                                  const CORBA::Double     theRadius,
760                                                  const GEOM::shape_state theState)
761 {
762   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
763
764   //Set a not done flag
765   GetOperations()->SetNotDone();
766
767   if (theShape == NULL || theCenter == NULL) return aSeq._retn();
768
769   //Get the reference objects
770   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
771     (theShape->GetStudyID(), theShape->GetEntry());
772   Handle(GEOM_Object) aCenter = GetOperations()->GetEngine()->GetObject
773     (theCenter->GetStudyID(), theCenter->GetEntry());
774
775   if (aShape.IsNull() || aCenter.IsNull()) return aSeq._retn();
776
777   //Get Shapes On Sphere
778   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnSphere
779     (aShape, theShapeType, aCenter, theRadius, ShapeState(theState));
780   if (!GetOperations()->IsDone() || aHSeq.IsNull())
781     return aSeq._retn();
782
783   Standard_Integer aLength = aHSeq->Length();
784   aSeq->length(aLength);
785   for (Standard_Integer i = 1; i <= aLength; i++)
786     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
787
788   return aSeq._retn();
789 }
790
791 //=============================================================================
792 /*!
793  *  GetShapesOnQuadrangle
794  */
795 //=============================================================================
796 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnQuadrangle
797                                                 (GEOM::GEOM_Object_ptr theShape,
798                                                  CORBA::Long           theShapeType,
799                                                  GEOM::GEOM_Object_ptr theTopLeftPoint,
800                                                  GEOM::GEOM_Object_ptr theTopRigthPoint,
801                                                  GEOM::GEOM_Object_ptr theBottomLeftPoint,
802                                                  GEOM::GEOM_Object_ptr theBottomRigthPoint,
803                                                  GEOM::shape_state     theState)
804 {
805   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
806
807   //Set a not done flag
808   GetOperations()->SetNotDone();
809
810   if (theShape            == NULL ||
811       theTopLeftPoint     == NULL ||   
812       theTopRigthPoint    == NULL || 
813       theBottomLeftPoint  == NULL ||
814       theBottomRigthPoint == NULL )
815     return aSeq._retn();
816
817   //Get the reference objects
818   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
819     (theShape->GetStudyID(), theShape->GetEntry());
820   Handle(GEOM_Object) aTopLeftPoint = GetOperations()->GetEngine()->GetObject
821     (theShape->GetStudyID(), theTopLeftPoint->GetEntry());
822   Handle(GEOM_Object) aTopRigthPoint = GetOperations()->GetEngine()->GetObject
823     (theShape->GetStudyID(), theTopRigthPoint->GetEntry());
824   Handle(GEOM_Object) aBottomLeftPoint = GetOperations()->GetEngine()->GetObject
825     (theShape->GetStudyID(), theBottomLeftPoint->GetEntry());
826   Handle(GEOM_Object) aBottomRigthPoint = GetOperations()->GetEngine()->GetObject
827     (theShape->GetStudyID(), theBottomRigthPoint->GetEntry());
828
829   if (aShape.IsNull() ||
830       aTopLeftPoint.IsNull() ||
831       aTopRigthPoint.IsNull() ||
832       aBottomLeftPoint.IsNull() ||
833       aBottomRigthPoint.IsNull() )
834     return aSeq._retn();
835
836   //Get Shapes On Quadrangle
837   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnQuadrangle
838     (aShape, theShapeType,
839      aTopLeftPoint, aTopRigthPoint, aBottomLeftPoint, aBottomRigthPoint,
840      ShapeState(theState));
841   if (!GetOperations()->IsDone() || aHSeq.IsNull())
842     return aSeq._retn();
843
844   Standard_Integer aLength = aHSeq->Length();
845   aSeq->length(aLength);
846   for (Standard_Integer i = 1; i <= aLength; i++)
847     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
848
849   return aSeq._retn();
850 }
851
852 //=============================================================================
853 /*!
854  *  GetShapesOnPlaneIDs
855  */
856 //=============================================================================
857 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnPlaneIDs
858                                                 (GEOM::GEOM_Object_ptr   theShape,
859                                                  const CORBA::Long       theShapeType,
860                                                  GEOM::GEOM_Object_ptr   theAx1,
861                                                  const GEOM::shape_state theState)
862 {
863   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
864
865   //Set a not done flag
866   GetOperations()->SetNotDone();
867
868   if (theShape == NULL || theAx1 == NULL) return aSeq._retn();
869
870   //Get the reference objects
871   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
872     (theShape->GetStudyID(), theShape->GetEntry());
873   Handle(GEOM_Object) anAx1 = GetOperations()->GetEngine()->GetObject
874     (theAx1->GetStudyID(), theAx1->GetEntry());
875
876   if (aShape.IsNull() || anAx1.IsNull()) return aSeq._retn();
877
878   //Get Shapes On Plane
879   Handle(TColStd_HSequenceOfInteger) aHSeq =
880     GetOperations()->GetShapesOnPlaneIDs(aShape, theShapeType, anAx1, ShapeState(theState));
881   if (!GetOperations()->IsDone() || aHSeq.IsNull())
882     return aSeq._retn();
883
884   Standard_Integer aLength = aHSeq->Length();
885   aSeq->length(aLength);
886   for (Standard_Integer i = 1; i <= aLength; i++)
887     aSeq[i-1] = aHSeq->Value(i);
888
889   return aSeq._retn();
890 }
891
892 //=============================================================================
893 /*!
894  *  GetShapesOnCylinderIDs
895  */
896 //=============================================================================
897 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnCylinderIDs
898                                                 (GEOM::GEOM_Object_ptr   theShape,
899                                                  const CORBA::Long       theShapeType,
900                                                  GEOM::GEOM_Object_ptr   theAxis,
901                                                  const CORBA::Double     theRadius,
902                                                  const GEOM::shape_state theState)
903 {
904   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
905
906   //Set a not done flag
907   GetOperations()->SetNotDone();
908
909   if (theShape == NULL || theAxis == NULL) return aSeq._retn();
910
911   //Get the reference objects
912   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
913     (theShape->GetStudyID(), theShape->GetEntry());
914   Handle(GEOM_Object) anAxis = GetOperations()->GetEngine()->GetObject
915     (theAxis->GetStudyID(), theAxis->GetEntry());
916
917   if (aShape.IsNull() || anAxis.IsNull()) return aSeq._retn();
918
919   //Get Shapes On Cylinder
920   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnCylinderIDs
921     (aShape, theShapeType, anAxis, theRadius, ShapeState(theState));
922   if (!GetOperations()->IsDone() || aHSeq.IsNull())
923     return aSeq._retn();
924
925   Standard_Integer aLength = aHSeq->Length();
926   aSeq->length(aLength);
927   for (Standard_Integer i = 1; i <= aLength; i++)
928     aSeq[i-1] = aHSeq->Value(i);
929
930   return aSeq._retn();
931 }
932
933 //=============================================================================
934 /*!
935  *  GetShapesOnSphereIDs
936  */
937 //=============================================================================
938 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnSphereIDs
939                                                 (GEOM::GEOM_Object_ptr   theShape,
940                                                  const CORBA::Long       theShapeType,
941                                                  GEOM::GEOM_Object_ptr   theCenter,
942                                                  const CORBA::Double     theRadius,
943                                                  const GEOM::shape_state theState)
944 {
945   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
946
947   //Set a not done flag
948   GetOperations()->SetNotDone();
949
950   if (theShape == NULL || theCenter == NULL) return aSeq._retn();
951
952   //Get the reference objects
953   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
954     (theShape->GetStudyID(), theShape->GetEntry());
955   Handle(GEOM_Object) aCenter = GetOperations()->GetEngine()->GetObject
956     (theCenter->GetStudyID(), theCenter->GetEntry());
957
958   if (aShape.IsNull() || aCenter.IsNull()) return aSeq._retn();
959
960   //Get Shapes On Sphere
961   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnSphereIDs
962     (aShape, theShapeType, aCenter, theRadius, ShapeState(theState));
963   if (!GetOperations()->IsDone() || aHSeq.IsNull())
964     return aSeq._retn();
965
966   Standard_Integer aLength = aHSeq->Length();
967   aSeq->length(aLength);
968   for (Standard_Integer i = 1; i <= aLength; i++)
969     aSeq[i-1] = aHSeq->Value(i);
970
971   return aSeq._retn();
972 }
973
974 //=============================================================================
975 /*!
976  *  GetShapesOnQuadrangleIDs
977  */
978 //=============================================================================
979 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnQuadrangleIDs
980                                                 (GEOM::GEOM_Object_ptr theShape,
981                                                  CORBA::Long           theShapeType,
982                                                  GEOM::GEOM_Object_ptr theTopLeftPoint,
983                                                  GEOM::GEOM_Object_ptr theTopRigthPoint,
984                                                  GEOM::GEOM_Object_ptr theBottomLeftPoint,
985                                                  GEOM::GEOM_Object_ptr theBottomRigthPoint,
986                                                  GEOM::shape_state     theState)
987 {
988   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
989
990   //Set a not done flag
991   GetOperations()->SetNotDone();
992
993   if (theShape            == NULL ||
994       theTopLeftPoint     == NULL ||   
995       theTopRigthPoint    == NULL || 
996       theBottomLeftPoint  == NULL ||
997       theBottomRigthPoint == NULL )
998     return aSeq._retn();
999
1000   //Get the reference objects
1001   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
1002     (theShape->GetStudyID(), theShape->GetEntry());
1003   Handle(GEOM_Object) aTopLeftPoint = GetOperations()->GetEngine()->GetObject
1004     (theShape->GetStudyID(), theTopLeftPoint->GetEntry());
1005   Handle(GEOM_Object) aTopRigthPoint = GetOperations()->GetEngine()->GetObject
1006     (theShape->GetStudyID(), theTopRigthPoint->GetEntry());
1007   Handle(GEOM_Object) aBottomLeftPoint = GetOperations()->GetEngine()->GetObject
1008     (theShape->GetStudyID(), theBottomLeftPoint->GetEntry());
1009   Handle(GEOM_Object) aBottomRigthPoint = GetOperations()->GetEngine()->GetObject
1010     (theShape->GetStudyID(), theBottomRigthPoint->GetEntry());
1011
1012   if (aShape.IsNull() ||
1013       aTopLeftPoint.IsNull() ||
1014       aTopRigthPoint.IsNull() ||
1015       aBottomLeftPoint.IsNull() ||
1016       aBottomRigthPoint.IsNull() )
1017     return aSeq._retn();
1018
1019   //Get Shapes On Quadrangle
1020   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnQuadrangleIDs
1021     (aShape, theShapeType,
1022      aTopLeftPoint, aTopRigthPoint, aBottomLeftPoint, aBottomRigthPoint,
1023      ShapeState(theState));
1024   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1025     return aSeq._retn();
1026
1027   Standard_Integer aLength = aHSeq->Length();
1028   aSeq->length(aLength);
1029   for (Standard_Integer i = 1; i <= aLength; i++)
1030     aSeq[i-1] = aHSeq->Value(i);
1031
1032   return aSeq._retn();
1033 }
1034
1035 //=============================================================================
1036 /*!
1037  *  GetInPlace
1038  */
1039 //=============================================================================
1040 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetInPlace
1041                                           (GEOM::GEOM_Object_ptr theShapeWhere,
1042                                            GEOM::GEOM_Object_ptr theShapeWhat)
1043 {
1044   GEOM::GEOM_Object_var aGEOMObject;
1045
1046   //Set a not done flag
1047   GetOperations()->SetNotDone();
1048
1049   if (theShapeWhere == NULL ||
1050       theShapeWhat == NULL) return aGEOMObject._retn();
1051
1052   //Get the reference objects
1053   Handle(GEOM_Object) aShapeWhere = GetOperations()->GetEngine()->GetObject
1054     (theShapeWhere->GetStudyID(), theShapeWhere->GetEntry());
1055   Handle(GEOM_Object) aShapeWhat = GetOperations()->GetEngine()->GetObject
1056     (theShapeWhat->GetStudyID(), theShapeWhat->GetEntry());
1057
1058   if (aShapeWhere.IsNull() ||
1059       aShapeWhat.IsNull()) return aGEOMObject._retn();
1060
1061   //Get Shapes in place of aShapeWhat
1062   Handle(GEOM_Object) anObject =
1063     GetOperations()->GetInPlace(aShapeWhere, aShapeWhat);
1064   if (!GetOperations()->IsDone() || anObject.IsNull())
1065     return aGEOMObject._retn();
1066
1067   return GetObject(anObject);
1068 }