Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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                                             CORBA::Double   theTolerance,
332                                             CORBA::Boolean  doKeepNonSolids)
333 {
334   GEOM::GEOM_Object_var aGEOMObject;
335
336   //Set a not done flag
337   GetOperations()->SetNotDone();
338
339   if (theShape == NULL) return aGEOMObject._retn();
340
341   //Get the reference objects
342   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
343     (theShape->GetStudyID(), theShape->GetEntry());
344
345   if (aShape.IsNull()) return aGEOMObject._retn();
346
347   //Perform the gluing
348   Handle(GEOM_Object) anObject =
349     GetOperations()->MakeGlueFaces(aShape, theTolerance, doKeepNonSolids);
350   //if (!GetOperations()->IsDone() || anObject.IsNull())
351   // to allow warning
352   if (anObject.IsNull())
353     return aGEOMObject._retn();
354
355   return GetObject(anObject);
356 }
357
358
359 //=============================================================================
360 /*!
361  *  GetGlueFaces
362  */
363 //=============================================================================
364 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetGlueFaces
365                                            (GEOM::GEOM_Object_ptr theShape,
366                                             const CORBA::Double   theTolerance)
367 {
368   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
369
370   //Set a not done flag
371   GetOperations()->SetNotDone();
372
373   if (theShape == NULL) return aSeq._retn();
374
375   //Get the reference objects
376   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
377     (theShape->GetStudyID(), theShape->GetEntry());
378   if (aShape.IsNull()) return aSeq._retn();
379
380   Handle(TColStd_HSequenceOfTransient) aHSeq =
381     GetOperations()->GetGlueFaces(aShape, theTolerance);
382
383   //if (!GetOperations()->IsDone() || aHSeq.IsNull())
384   // to allow warning
385   if(aHSeq.IsNull())
386     return aSeq._retn();
387
388   Standard_Integer aLength = aHSeq->Length();
389   aSeq->length(aLength);
390   for (Standard_Integer i = 1; i <= aLength; i++)
391     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
392
393   return aSeq._retn();
394 }
395
396
397 //=============================================================================
398 /*!
399  *  MakeGlueFacesByList
400  */
401 //=============================================================================
402 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeGlueFacesByList
403                                            (GEOM::GEOM_Object_ptr theShape,
404                                             CORBA::Double   theTolerance,
405                                             const GEOM::ListOfGO& theFaces,
406                                             CORBA::Boolean  doKeepNonSolids)
407 {
408   GEOM::GEOM_Object_var aGEOMObject;
409
410   //Set a not done flag
411   GetOperations()->SetNotDone();
412
413   if (theShape == NULL) return aGEOMObject._retn();
414
415   //Get the reference objects
416   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
417     (theShape->GetStudyID(), theShape->GetEntry());
418
419   if (aShape.IsNull()) return aGEOMObject._retn();
420
421   int ind, aLen;
422   list<Handle(GEOM_Object)> aFaces;
423   //Get the shapes
424   aLen = theFaces.length();
425   for (ind = 0; ind < aLen; ind++) {
426     if (theFaces[ind] == NULL) return aGEOMObject._retn();
427     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
428       (theFaces[ind]->GetStudyID(), theFaces[ind]->GetEntry());
429     if (aSh.IsNull()) return aGEOMObject._retn();
430     aFaces.push_back(aSh);
431   }
432
433   //Perform the gluing
434   Handle(GEOM_Object) anObject =
435     GetOperations()->MakeGlueFacesByList(aShape, theTolerance, aFaces, doKeepNonSolids);
436   //if (!GetOperations()->IsDone() || anObject.IsNull())
437   // to allow warning
438   if (anObject.IsNull())
439     return aGEOMObject._retn();
440
441   return GetObject(anObject);
442 }
443
444
445 //=============================================================================
446 /*!
447  *  MakeExplode
448  */
449 //=============================================================================
450 GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeExplode (GEOM::GEOM_Object_ptr theShape,
451                                                        const CORBA::Long     theShapeType,
452                                                        const CORBA::Boolean  isSorted)
453 {
454   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
455   if (theShape == NULL) return aSeq._retn();
456
457   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
458     (theShape->GetStudyID(), theShape->GetEntry());
459
460   Handle(TColStd_HSequenceOfTransient) aHSeq =
461     GetOperations()->MakeExplode(aShape, theShapeType, isSorted);
462   if (!GetOperations()->IsDone() || aHSeq.IsNull())
463     return aSeq._retn();
464
465   Standard_Integer aLength = aHSeq->Length();
466   aSeq->length(aLength);
467   for (Standard_Integer i = 1; i <= aLength; i++)
468     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
469
470   return aSeq._retn();
471 }
472
473 //=============================================================================
474 /*!
475  *  SubShapeAllIDs
476  */
477 //=============================================================================
478 GEOM::ListOfLong* GEOM_IShapesOperations_i::SubShapeAllIDs (GEOM::GEOM_Object_ptr theShape,
479                                                             const CORBA::Long     theShapeType,
480                                                             const CORBA::Boolean  isSorted)
481 {
482   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
483   if (theShape == NULL) return aSeq._retn();
484
485   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
486     (theShape->GetStudyID(), theShape->GetEntry());
487
488   Handle(TColStd_HSequenceOfInteger) aHSeq =
489     GetOperations()->SubShapeAllIDs(aShape, theShapeType, isSorted);
490   if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
491
492   Standard_Integer aLength = aHSeq->Length();
493   aSeq->length(aLength);
494   for (Standard_Integer i = 1; i <= aLength; i++)
495     aSeq[i-1] = aHSeq->Value(i);
496
497   return aSeq._retn();
498 }
499
500 //=============================================================================
501 /*!
502  *  GetSubShape
503  */
504 //=============================================================================
505 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetSubShape
506                                            (GEOM::GEOM_Object_ptr theMainShape,
507                                             const CORBA::Long     theID)
508 {
509   GEOM::GEOM_Object_var aGEOMObject;
510
511   //Set a not done flag
512   GetOperations()->SetNotDone();
513
514   if (theMainShape == NULL) return aGEOMObject._retn();
515
516   //Get the reference objects
517   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
518     (theMainShape->GetStudyID(), theMainShape->GetEntry());
519
520   if (aShape.IsNull()) return aGEOMObject._retn();
521
522   Handle(GEOM_Object) anObject = GetOperations()->GetSubShape(aShape, theID);
523   if (!GetOperations()->IsDone() || anObject.IsNull())
524     return aGEOMObject._retn();
525
526   return GetObject(anObject);
527 }
528
529 //=============================================================================
530 /*!
531  *  GetSubShapeIndex
532  */
533 //=============================================================================
534 CORBA::Long GEOM_IShapesOperations_i::GetSubShapeIndex
535   (GEOM::GEOM_Object_ptr theMainShape, GEOM::GEOM_Object_ptr theSubShape)
536 {
537   if (theMainShape == NULL || theSubShape == NULL) return -1;
538
539   //Get the reference shapes
540   Handle(GEOM_Object) aMainShapeRef = GetOperations()->GetEngine()->GetObject
541     (theMainShape->GetStudyID(), theMainShape->GetEntry());
542   Handle(GEOM_Object) aSubShapeRef = GetOperations()->GetEngine()->GetObject
543     (theSubShape->GetStudyID(), theSubShape->GetEntry());
544   if (aMainShapeRef.IsNull() || aSubShapeRef.IsNull()) return -1;
545
546   //Get the unique ID of <theSubShape> inside <theMainShape>
547   CORBA::Long anID = GetOperations()->GetSubShapeIndex(aMainShapeRef, aSubShapeRef);
548   if (!GetOperations()->IsDone())
549     return -1;
550
551   return anID;
552 }
553
554 //=============================================================================
555 /*!
556  *  GetTopologyIndex
557  */
558 //=============================================================================
559 CORBA::Long GEOM_IShapesOperations_i::GetTopologyIndex
560   (GEOM::GEOM_Object_ptr theMainShape, GEOM::GEOM_Object_ptr theSubShape)
561 {
562   if (theMainShape == NULL || theSubShape == NULL) return -1;
563
564   //Get the reference shapes
565   Handle(GEOM_Object) aMainShapeRef = GetOperations()->GetEngine()->GetObject
566     (theMainShape->GetStudyID(), theMainShape->GetEntry());
567   Handle(GEOM_Object) aSubShapeRef = GetOperations()->GetEngine()->GetObject
568     (theSubShape->GetStudyID(), theSubShape->GetEntry());
569   if (aMainShapeRef.IsNull() || aSubShapeRef.IsNull()) return -1;
570
571   //Get an ID of <theSubShape>, unique among all sub-shapes of <theMainShape> of the same type
572   CORBA::Long anID = GetOperations()->GetTopologyIndex(aMainShapeRef, aSubShapeRef);
573   if (!GetOperations()->IsDone())
574     return -1;
575
576   return anID;
577 }
578
579 //=============================================================================
580 /*!
581  *  GetShapeTypeString
582  */
583 //=============================================================================
584 char* GEOM_IShapesOperations_i::GetShapeTypeString (GEOM::GEOM_Object_ptr theShape)
585 {
586   if (theShape == NULL) return NULL;
587
588   //Get the reference shape
589   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
590     (theShape->GetStudyID(), theShape->GetEntry());
591
592   if (aShape.IsNull()) return NULL;
593
594   // Get shape parameters
595   TCollection_AsciiString aDescription = GetOperations()->GetShapeTypeString(aShape);
596   return CORBA::string_dup(aDescription.ToCString());
597 }
598
599 //=============================================================================
600 /*!
601  *  NumberOfFaces
602  */
603 //=============================================================================
604 CORBA::Long GEOM_IShapesOperations_i::NumberOfFaces (GEOM::GEOM_Object_ptr theShape)
605 {
606   if (theShape == NULL) return -1;
607
608   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
609     (theShape->GetStudyID(), theShape->GetEntry());
610
611   CORBA::Long aNb = GetOperations()->NumberOfFaces(aShape);
612   if (!GetOperations()->IsDone()) return -1;
613
614   return aNb;
615 }
616
617 //=============================================================================
618 /*!
619  *  NumberOfEdges
620  */
621 //=============================================================================
622 CORBA::Long GEOM_IShapesOperations_i::NumberOfEdges (GEOM::GEOM_Object_ptr theShape)
623 {
624   if (theShape == NULL) return -1;
625
626   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
627     (theShape->GetStudyID(), theShape->GetEntry());
628
629   CORBA::Long aNb = GetOperations()->NumberOfEdges(aShape);
630   if (!GetOperations()->IsDone()) return -1;
631
632   return aNb;
633 }
634
635 //=============================================================================
636 /*!
637  *  ChangeOrientation
638  */
639 //=============================================================================
640 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::ChangeOrientation
641                                                 (GEOM::GEOM_Object_ptr theShape)
642 {
643   GEOM::GEOM_Object_var aGEOMObject;
644
645   //Set a not done flag
646   GetOperations()->SetNotDone();
647
648   if (theShape == NULL) return aGEOMObject._retn();
649
650   //Get the reference objects
651   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
652     (theShape->GetStudyID(), theShape->GetEntry());
653
654   if (aShape.IsNull()) return aGEOMObject._retn();
655
656   //Create the Solid
657   Handle(GEOM_Object) anObject = GetOperations()->ReverseShape(aShape);
658   if (!GetOperations()->IsDone() || anObject.IsNull())
659     return aGEOMObject._retn();
660
661   return GetObject(anObject);
662 }
663
664 //=============================================================================
665 /*!
666  *  GetFreeFacesIDs
667  */
668 //=============================================================================
669 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetFreeFacesIDs (GEOM::GEOM_Object_ptr theShape)
670 {
671   //Set a not done flag
672   GetOperations()->SetNotDone();
673
674   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
675   if (theShape == NULL) return aSeq._retn();
676
677   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
678     (theShape->GetStudyID(), theShape->GetEntry());
679
680   Handle(TColStd_HSequenceOfInteger) aHSeq =
681     GetOperations()->GetFreeFacesIDs(aShape);
682   if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
683
684   Standard_Integer aLength = aHSeq->Length();
685   aSeq->length(aLength);
686   for (Standard_Integer i = 1; i <= aLength; i++)
687     aSeq[i-1] = aHSeq->Value(i);
688
689   return aSeq._retn();
690 }
691
692 //=============================================================================
693 /*!
694  *  GetSharedShapes
695  */
696 //=============================================================================
697 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetSharedShapes
698                                           (GEOM::GEOM_Object_ptr theShape1,
699                                            GEOM::GEOM_Object_ptr theShape2,
700                                            const CORBA::Long     theShapeType)
701 {
702   //Set a not done flag
703   GetOperations()->SetNotDone();
704
705   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
706   if (theShape1 == NULL ||
707       theShape2 == NULL) return aSeq._retn();
708
709   Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
710     (theShape1->GetStudyID(), theShape1->GetEntry());
711   Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
712     (theShape2->GetStudyID(), theShape2->GetEntry());
713
714   if (aShape1.IsNull() ||
715       aShape2.IsNull()) return aSeq._retn();
716
717   Handle(TColStd_HSequenceOfTransient) aHSeq =
718     GetOperations()->GetSharedShapes(aShape1, aShape2, theShapeType);
719   if (!GetOperations()->IsDone() || aHSeq.IsNull())
720     return aSeq._retn();
721
722   Standard_Integer aLength = aHSeq->Length();
723   aSeq->length(aLength);
724   for (Standard_Integer i = 1; i <= aLength; i++)
725     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
726
727   return aSeq._retn();
728 }
729
730 static GEOMAlgo_State ShapeState (const GEOM::shape_state theState)
731 {
732   GEOMAlgo_State aState = GEOMAlgo_ST_UNKNOWN;
733
734   switch (theState) {
735   case GEOM::ST_ON:
736     aState = GEOMAlgo_ST_ON;
737     break;
738   case GEOM::ST_OUT:
739     aState = GEOMAlgo_ST_OUT;
740     break;
741   case GEOM::ST_ONOUT:
742     aState = GEOMAlgo_ST_ONOUT;
743     break;
744   case GEOM::ST_IN:
745     aState = GEOMAlgo_ST_IN;
746     break;
747   case GEOM::ST_ONIN:
748     aState = GEOMAlgo_ST_ONIN;
749     break;
750   default:
751     break;
752   }
753
754   return aState;
755 }
756
757 //=============================================================================
758 /*!
759  *  GetShapesOnPlane
760  */
761 //=============================================================================
762 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnPlane
763                                                 (GEOM::GEOM_Object_ptr   theShape,
764                                                  const CORBA::Long       theShapeType,
765                                                  GEOM::GEOM_Object_ptr   theAx1,
766                                                  const GEOM::shape_state theState)
767 {
768   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
769
770   //Set a not done flag
771   GetOperations()->SetNotDone();
772
773   if (theShape == NULL || theAx1 == NULL) return aSeq._retn();
774
775   //Get the reference objects
776   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
777     (theShape->GetStudyID(), theShape->GetEntry());
778   Handle(GEOM_Object) anAx1 = GetOperations()->GetEngine()->GetObject
779     (theAx1->GetStudyID(), theAx1->GetEntry());
780
781   if (aShape.IsNull() || anAx1.IsNull()) return aSeq._retn();
782
783   //Get Shapes On Plane
784   Handle(TColStd_HSequenceOfTransient) aHSeq =
785     GetOperations()->GetShapesOnPlane(aShape, theShapeType, anAx1, ShapeState(theState));
786   if (!GetOperations()->IsDone() || aHSeq.IsNull())
787     return aSeq._retn();
788
789   Standard_Integer aLength = aHSeq->Length();
790   aSeq->length(aLength);
791   for (Standard_Integer i = 1; i <= aLength; i++)
792     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
793
794   return aSeq._retn();
795 }
796
797 //=============================================================================
798 /*!
799  *  GetShapesOnPlaneWithLocation
800  */
801 //=============================================================================
802 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnPlaneWithLocation
803                                                 (GEOM::GEOM_Object_ptr   theShape,
804                                                  const CORBA::Long       theShapeType,
805                                                  GEOM::GEOM_Object_ptr   theAx1,
806                                                  GEOM::GEOM_Object_ptr   thePnt,
807                                                  const GEOM::shape_state theState)
808 {
809   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
810
811   //Set a not done flag
812   GetOperations()->SetNotDone();
813
814   if (theShape == NULL || theAx1 == NULL || thePnt == NULL) return aSeq._retn();
815
816   //Get the reference objects
817   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
818     (theShape->GetStudyID(), theShape->GetEntry());
819   Handle(GEOM_Object) anAx1 = GetOperations()->GetEngine()->GetObject
820     (theAx1->GetStudyID(), theAx1->GetEntry());
821   Handle(GEOM_Object) anPnt = GetOperations()->GetEngine()->GetObject
822     (thePnt->GetStudyID(), thePnt->GetEntry());
823
824   if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return aSeq._retn();
825
826   //Get Shapes On Plane
827   Handle(TColStd_HSequenceOfTransient) aHSeq =
828     GetOperations()->GetShapesOnPlaneWithLocation(aShape, theShapeType, anAx1, anPnt, ShapeState(theState));
829   if (!GetOperations()->IsDone() || aHSeq.IsNull())
830     return aSeq._retn();
831
832   Standard_Integer aLength = aHSeq->Length();
833   aSeq->length(aLength);
834   for (Standard_Integer i = 1; i <= aLength; i++)
835     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
836
837   return aSeq._retn();
838 }
839
840 //=============================================================================
841 /*!
842  *  GetShapesOnCylinder
843  */
844 //=============================================================================
845 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnCylinder
846                                                 (GEOM::GEOM_Object_ptr   theShape,
847                                                  const CORBA::Long       theShapeType,
848                                                  GEOM::GEOM_Object_ptr   theAxis,
849                                                  const CORBA::Double     theRadius,
850                                                  const GEOM::shape_state theState)
851 {
852   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
853
854   //Set a not done flag
855   GetOperations()->SetNotDone();
856
857   if (theShape == NULL || theAxis == NULL) return aSeq._retn();
858
859   //Get the reference objects
860   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
861     (theShape->GetStudyID(), theShape->GetEntry());
862   Handle(GEOM_Object) anAxis = GetOperations()->GetEngine()->GetObject
863     (theAxis->GetStudyID(), theAxis->GetEntry());
864
865   if (aShape.IsNull() || anAxis.IsNull()) return aSeq._retn();
866
867   //Get Shapes On Cylinder
868   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnCylinder
869     (aShape, theShapeType, anAxis, theRadius, ShapeState(theState));
870   if (!GetOperations()->IsDone() || aHSeq.IsNull())
871     return aSeq._retn();
872
873   Standard_Integer aLength = aHSeq->Length();
874   aSeq->length(aLength);
875   for (Standard_Integer i = 1; i <= aLength; i++)
876     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
877
878   return aSeq._retn();
879 }
880
881 //=============================================================================
882 /*!
883  *  GetShapesOnSphere
884  */
885 //=============================================================================
886 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnSphere
887                                                 (GEOM::GEOM_Object_ptr   theShape,
888                                                  const CORBA::Long       theShapeType,
889                                                  GEOM::GEOM_Object_ptr   theCenter,
890                                                  const CORBA::Double     theRadius,
891                                                  const GEOM::shape_state theState)
892 {
893   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
894
895   //Set a not done flag
896   GetOperations()->SetNotDone();
897
898   if (theShape == NULL || theCenter == NULL) return aSeq._retn();
899
900   //Get the reference objects
901   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
902     (theShape->GetStudyID(), theShape->GetEntry());
903   Handle(GEOM_Object) aCenter = GetOperations()->GetEngine()->GetObject
904     (theCenter->GetStudyID(), theCenter->GetEntry());
905
906   if (aShape.IsNull() || aCenter.IsNull()) return aSeq._retn();
907
908   //Get Shapes On Sphere
909   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnSphere
910     (aShape, theShapeType, aCenter, theRadius, ShapeState(theState));
911   if (!GetOperations()->IsDone() || aHSeq.IsNull())
912     return aSeq._retn();
913
914   Standard_Integer aLength = aHSeq->Length();
915   aSeq->length(aLength);
916   for (Standard_Integer i = 1; i <= aLength; i++)
917     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
918
919   return aSeq._retn();
920 }
921
922 //=============================================================================
923 /*!
924  *  GetShapesOnQuadrangle
925  */
926 //=============================================================================
927 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnQuadrangle
928                                                 (GEOM::GEOM_Object_ptr theShape,
929                                                  CORBA::Long           theShapeType,
930                                                  GEOM::GEOM_Object_ptr theTopLeftPoint,
931                                                  GEOM::GEOM_Object_ptr theTopRigthPoint,
932                                                  GEOM::GEOM_Object_ptr theBottomLeftPoint,
933                                                  GEOM::GEOM_Object_ptr theBottomRigthPoint,
934                                                  GEOM::shape_state     theState)
935 {
936   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
937
938   //Set a not done flag
939   GetOperations()->SetNotDone();
940
941   if (theShape            == NULL ||
942       theTopLeftPoint     == NULL ||   
943       theTopRigthPoint    == NULL || 
944       theBottomLeftPoint  == NULL ||
945       theBottomRigthPoint == NULL )
946     return aSeq._retn();
947
948   //Get the reference objects
949   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
950     (theShape->GetStudyID(), theShape->GetEntry());
951   Handle(GEOM_Object) aTopLeftPoint = GetOperations()->GetEngine()->GetObject
952     (theShape->GetStudyID(), theTopLeftPoint->GetEntry());
953   Handle(GEOM_Object) aTopRigthPoint = GetOperations()->GetEngine()->GetObject
954     (theShape->GetStudyID(), theTopRigthPoint->GetEntry());
955   Handle(GEOM_Object) aBottomLeftPoint = GetOperations()->GetEngine()->GetObject
956     (theShape->GetStudyID(), theBottomLeftPoint->GetEntry());
957   Handle(GEOM_Object) aBottomRigthPoint = GetOperations()->GetEngine()->GetObject
958     (theShape->GetStudyID(), theBottomRigthPoint->GetEntry());
959
960   if (aShape.IsNull() ||
961       aTopLeftPoint.IsNull() ||
962       aTopRigthPoint.IsNull() ||
963       aBottomLeftPoint.IsNull() ||
964       aBottomRigthPoint.IsNull() )
965     return aSeq._retn();
966
967   //Get Shapes On Quadrangle
968   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnQuadrangle
969     (aShape, theShapeType,
970      aTopLeftPoint, aTopRigthPoint, aBottomLeftPoint, aBottomRigthPoint,
971      ShapeState(theState));
972   if (!GetOperations()->IsDone() || aHSeq.IsNull())
973     return aSeq._retn();
974
975   Standard_Integer aLength = aHSeq->Length();
976   aSeq->length(aLength);
977   for (Standard_Integer i = 1; i <= aLength; i++)
978     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
979
980   return aSeq._retn();
981 }
982
983 //=============================================================================
984 /*!
985  *  GetShapesOnPlaneIDs
986  */
987 //=============================================================================
988 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnPlaneIDs
989                                                 (GEOM::GEOM_Object_ptr   theShape,
990                                                  const CORBA::Long       theShapeType,
991                                                  GEOM::GEOM_Object_ptr   theAx1,
992                                                  const GEOM::shape_state theState)
993 {
994   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
995
996   //Set a not done flag
997   GetOperations()->SetNotDone();
998
999   if (theShape == NULL || theAx1 == NULL) return aSeq._retn();
1000
1001   //Get the reference objects
1002   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
1003     (theShape->GetStudyID(), theShape->GetEntry());
1004   Handle(GEOM_Object) anAx1 = GetOperations()->GetEngine()->GetObject
1005     (theAx1->GetStudyID(), theAx1->GetEntry());
1006
1007   if (aShape.IsNull() || anAx1.IsNull()) return aSeq._retn();
1008
1009   //Get Shapes On Plane
1010   Handle(TColStd_HSequenceOfInteger) aHSeq =
1011     GetOperations()->GetShapesOnPlaneIDs(aShape, theShapeType, anAx1, ShapeState(theState));
1012   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1013     return aSeq._retn();
1014
1015   Standard_Integer aLength = aHSeq->Length();
1016   aSeq->length(aLength);
1017   for (Standard_Integer i = 1; i <= aLength; i++)
1018     aSeq[i-1] = aHSeq->Value(i);
1019
1020   return aSeq._retn();
1021 }
1022
1023 //=============================================================================
1024 /*!
1025  *  GetShapesOnPlaneWithLocationIDs
1026  */
1027 //=============================================================================
1028 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnPlaneWithLocationIDs
1029                                                 (GEOM::GEOM_Object_ptr   theShape,
1030                                                  const CORBA::Long       theShapeType,
1031                                                  GEOM::GEOM_Object_ptr   theAx1,
1032                                                  GEOM::GEOM_Object_ptr   thePnt,
1033                                                  const GEOM::shape_state theState)
1034 {
1035   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1036
1037   //Set a not done flag
1038   GetOperations()->SetNotDone();
1039
1040   if (theShape == NULL || theAx1 == NULL || thePnt == NULL) return aSeq._retn();
1041
1042   //Get the reference objects
1043   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
1044     (theShape->GetStudyID(), theShape->GetEntry());
1045   Handle(GEOM_Object) anAx1 = GetOperations()->GetEngine()->GetObject
1046     (theAx1->GetStudyID(), theAx1->GetEntry());
1047   Handle(GEOM_Object) anPnt = GetOperations()->GetEngine()->GetObject
1048     (thePnt->GetStudyID(), thePnt->GetEntry());
1049
1050   if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return aSeq._retn();
1051
1052   //Get Shapes On Plane
1053   Handle(TColStd_HSequenceOfInteger) aHSeq =
1054     GetOperations()->GetShapesOnPlaneWithLocationIDs(aShape, theShapeType, anAx1, anPnt, ShapeState(theState));
1055   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1056     return aSeq._retn();
1057
1058   Standard_Integer aLength = aHSeq->Length();
1059   aSeq->length(aLength);
1060   for (Standard_Integer i = 1; i <= aLength; i++)
1061     aSeq[i-1] = aHSeq->Value(i);
1062
1063   return aSeq._retn();
1064 }
1065
1066 //=============================================================================
1067 /*!
1068  *  GetShapesOnCylinderIDs
1069  */
1070 //=============================================================================
1071 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnCylinderIDs
1072                                                 (GEOM::GEOM_Object_ptr   theShape,
1073                                                  const CORBA::Long       theShapeType,
1074                                                  GEOM::GEOM_Object_ptr   theAxis,
1075                                                  const CORBA::Double     theRadius,
1076                                                  const GEOM::shape_state theState)
1077 {
1078   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1079
1080   //Set a not done flag
1081   GetOperations()->SetNotDone();
1082
1083   if (theShape == NULL || theAxis == NULL) return aSeq._retn();
1084
1085   //Get the reference objects
1086   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
1087     (theShape->GetStudyID(), theShape->GetEntry());
1088   Handle(GEOM_Object) anAxis = GetOperations()->GetEngine()->GetObject
1089     (theAxis->GetStudyID(), theAxis->GetEntry());
1090
1091   if (aShape.IsNull() || anAxis.IsNull()) return aSeq._retn();
1092
1093   //Get Shapes On Cylinder
1094   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnCylinderIDs
1095     (aShape, theShapeType, anAxis, theRadius, ShapeState(theState));
1096   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1097     return aSeq._retn();
1098
1099   Standard_Integer aLength = aHSeq->Length();
1100   aSeq->length(aLength);
1101   for (Standard_Integer i = 1; i <= aLength; i++)
1102     aSeq[i-1] = aHSeq->Value(i);
1103
1104   return aSeq._retn();
1105 }
1106
1107 //=============================================================================
1108 /*!
1109  *  GetShapesOnSphereIDs
1110  */
1111 //=============================================================================
1112 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnSphereIDs
1113                                                 (GEOM::GEOM_Object_ptr   theShape,
1114                                                  const CORBA::Long       theShapeType,
1115                                                  GEOM::GEOM_Object_ptr   theCenter,
1116                                                  const CORBA::Double     theRadius,
1117                                                  const GEOM::shape_state theState)
1118 {
1119   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1120
1121   //Set a not done flag
1122   GetOperations()->SetNotDone();
1123
1124   if (theShape == NULL || theCenter == NULL) return aSeq._retn();
1125
1126   //Get the reference objects
1127   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
1128     (theShape->GetStudyID(), theShape->GetEntry());
1129   Handle(GEOM_Object) aCenter = GetOperations()->GetEngine()->GetObject
1130     (theCenter->GetStudyID(), theCenter->GetEntry());
1131
1132   if (aShape.IsNull() || aCenter.IsNull()) return aSeq._retn();
1133
1134   //Get Shapes On Sphere
1135   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnSphereIDs
1136     (aShape, theShapeType, aCenter, theRadius, ShapeState(theState));
1137   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1138     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  *  GetShapesOnQuadrangleIDs
1151  */
1152 //=============================================================================
1153 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnQuadrangleIDs
1154                                                 (GEOM::GEOM_Object_ptr theShape,
1155                                                  CORBA::Long           theShapeType,
1156                                                  GEOM::GEOM_Object_ptr theTopLeftPoint,
1157                                                  GEOM::GEOM_Object_ptr theTopRigthPoint,
1158                                                  GEOM::GEOM_Object_ptr theBottomLeftPoint,
1159                                                  GEOM::GEOM_Object_ptr theBottomRigthPoint,
1160                                                  GEOM::shape_state     theState)
1161 {
1162   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1163
1164   //Set a not done flag
1165   GetOperations()->SetNotDone();
1166
1167   if (theShape            == NULL ||
1168       theTopLeftPoint     == NULL ||   
1169       theTopRigthPoint    == NULL || 
1170       theBottomLeftPoint  == NULL ||
1171       theBottomRigthPoint == NULL )
1172     return aSeq._retn();
1173
1174   //Get the reference objects
1175   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
1176     (theShape->GetStudyID(), theShape->GetEntry());
1177   Handle(GEOM_Object) aTopLeftPoint = GetOperations()->GetEngine()->GetObject
1178     (theShape->GetStudyID(), theTopLeftPoint->GetEntry());
1179   Handle(GEOM_Object) aTopRigthPoint = GetOperations()->GetEngine()->GetObject
1180     (theShape->GetStudyID(), theTopRigthPoint->GetEntry());
1181   Handle(GEOM_Object) aBottomLeftPoint = GetOperations()->GetEngine()->GetObject
1182     (theShape->GetStudyID(), theBottomLeftPoint->GetEntry());
1183   Handle(GEOM_Object) aBottomRigthPoint = GetOperations()->GetEngine()->GetObject
1184     (theShape->GetStudyID(), theBottomRigthPoint->GetEntry());
1185
1186   if (aShape.IsNull() ||
1187       aTopLeftPoint.IsNull() ||
1188       aTopRigthPoint.IsNull() ||
1189       aBottomLeftPoint.IsNull() ||
1190       aBottomRigthPoint.IsNull() )
1191     return aSeq._retn();
1192
1193   //Get Shapes On Quadrangle
1194   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnQuadrangleIDs
1195     (aShape, theShapeType,
1196      aTopLeftPoint, aTopRigthPoint, aBottomLeftPoint, aBottomRigthPoint,
1197      ShapeState(theState));
1198   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1199     return aSeq._retn();
1200
1201   Standard_Integer aLength = aHSeq->Length();
1202   aSeq->length(aLength);
1203   for (Standard_Integer i = 1; i <= aLength; i++)
1204     aSeq[i-1] = aHSeq->Value(i);
1205
1206   return aSeq._retn();
1207 }
1208
1209 //=============================================================================
1210 /*!
1211  *  GetShapesOnBox
1212  */
1213 //=============================================================================
1214 GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnBox
1215                                                 (GEOM::GEOM_Object_ptr theBox,
1216                                                  GEOM::GEOM_Object_ptr theShape,
1217                                                  CORBA::Long           theShapeType,
1218                                                  GEOM::shape_state     theState)
1219 {
1220   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1221
1222   //Set a not done flag
1223   GetOperations()->SetNotDone();
1224
1225   if ( theShape == NULL ||  theBox == NULL )
1226     return aSeq._retn();
1227
1228   //Get the reference objects
1229   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
1230     (theShape->GetStudyID(), theShape->GetEntry());
1231   Handle(GEOM_Object) aBox = GetOperations()->GetEngine()->GetObject
1232     (theShape->GetStudyID(), theBox->GetEntry());
1233
1234   if (aShape.IsNull() || aBox.IsNull() )
1235     return aSeq._retn();
1236
1237   //Get Shapes On Box
1238   Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnBox
1239     (aBox,aShape, theShapeType,ShapeState(theState));
1240   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1241     return aSeq._retn();
1242
1243   Standard_Integer aLength = aHSeq->Length();
1244   aSeq->length(aLength);
1245   for (Standard_Integer i = 1; i <= aLength; i++)
1246     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
1247
1248   return aSeq._retn();
1249 }
1250
1251 //=============================================================================
1252 /*!
1253  *  GetShapesOnQuadrangleIDs
1254  */
1255 //=============================================================================
1256 GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnBoxIDs
1257                                                 (GEOM::GEOM_Object_ptr theBox,
1258                                                  GEOM::GEOM_Object_ptr theShape,
1259                                                  CORBA::Long           theShapeType,
1260                                                  GEOM::shape_state     theState)
1261 {
1262   GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
1263
1264   //Set a not done flag
1265   GetOperations()->SetNotDone();
1266
1267   if ( theShape == NULL ||  theBox == NULL )
1268     return aSeq._retn();
1269
1270   //Get the reference objects
1271   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
1272     (theShape->GetStudyID(), theShape->GetEntry());
1273   Handle(GEOM_Object) aBox = GetOperations()->GetEngine()->GetObject
1274     (theShape->GetStudyID(), theBox->GetEntry());
1275
1276   if (aShape.IsNull() || aBox.IsNull() )
1277     return aSeq._retn();
1278
1279   //Get Shapes On Box
1280   Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnBoxIDs
1281     (aBox,aShape, theShapeType,ShapeState(theState));
1282   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1283     return aSeq._retn();
1284
1285   Standard_Integer aLength = aHSeq->Length();
1286   aSeq->length(aLength);
1287   for (Standard_Integer i = 1; i <= aLength; i++)
1288     aSeq[i-1] = aHSeq->Value(i);
1289
1290   return aSeq._retn();
1291 }
1292
1293 //=============================================================================
1294 /*!
1295  *  GetInPlace
1296  */
1297 //=============================================================================
1298 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetInPlace
1299                                           (GEOM::GEOM_Object_ptr theShapeWhere,
1300                                            GEOM::GEOM_Object_ptr theShapeWhat)
1301 {
1302   GEOM::GEOM_Object_var aGEOMObject;
1303
1304   //Set a not done flag
1305   GetOperations()->SetNotDone();
1306
1307   if (theShapeWhere == NULL ||
1308       theShapeWhat == NULL) return aGEOMObject._retn();
1309
1310   //Get the reference objects
1311   Handle(GEOM_Object) aShapeWhere = GetOperations()->GetEngine()->GetObject
1312     (theShapeWhere->GetStudyID(), theShapeWhere->GetEntry());
1313   Handle(GEOM_Object) aShapeWhat = GetOperations()->GetEngine()->GetObject
1314     (theShapeWhat->GetStudyID(), theShapeWhat->GetEntry());
1315
1316   if (aShapeWhere.IsNull() ||
1317       aShapeWhat.IsNull()) return aGEOMObject._retn();
1318
1319   //Get Shapes in place of aShapeWhat
1320   Handle(GEOM_Object) anObject =
1321     GetOperations()->GetInPlace(aShapeWhere, aShapeWhat);
1322   if (!GetOperations()->IsDone() || anObject.IsNull())
1323     return aGEOMObject._retn();
1324
1325   return GetObject(anObject);
1326 }
1327
1328 //=============================================================================
1329 /*!
1330  *  GetInPlaceByHistory
1331  */
1332 //=============================================================================
1333 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetInPlaceByHistory
1334                                           (GEOM::GEOM_Object_ptr theShapeWhere,
1335                                            GEOM::GEOM_Object_ptr theShapeWhat)
1336 {
1337   GEOM::GEOM_Object_var aGEOMObject;
1338
1339   //Set a not done flag
1340   GetOperations()->SetNotDone();
1341
1342   if (theShapeWhere == NULL ||
1343       theShapeWhat == NULL) return aGEOMObject._retn();
1344
1345   //Get the reference objects
1346   Handle(GEOM_Object) aShapeWhere = GetOperations()->GetEngine()->GetObject
1347     (theShapeWhere->GetStudyID(), theShapeWhere->GetEntry());
1348   Handle(GEOM_Object) aShapeWhat = GetOperations()->GetEngine()->GetObject
1349     (theShapeWhat->GetStudyID(), theShapeWhat->GetEntry());
1350
1351   if (aShapeWhere.IsNull() ||
1352       aShapeWhat.IsNull()) return aGEOMObject._retn();
1353
1354   //Get Shapes in place of aShapeWhat
1355   Handle(GEOM_Object) anObject =
1356     GetOperations()->GetInPlaceByHistory(aShapeWhere, aShapeWhat);
1357   if (!GetOperations()->IsDone() || anObject.IsNull())
1358     return aGEOMObject._retn();
1359
1360   return GetObject(anObject);
1361 }
1362
1363 //=============================================================================
1364 /*!
1365  *  GetSame
1366  */
1367 //=============================================================================
1368 GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetSame
1369                                           (GEOM::GEOM_Object_ptr theShapeWhere,
1370                                            GEOM::GEOM_Object_ptr theShapeWhat)
1371 {
1372   GEOM::GEOM_Object_var aGEOMObject;
1373
1374   //Set a not done flag
1375   GetOperations()->SetNotDone();
1376
1377   if (theShapeWhere == NULL ||
1378       theShapeWhat == NULL) return aGEOMObject._retn();
1379
1380   //Get the reference objects
1381   Handle(GEOM_Object) aShapeWhere = GetOperations()->GetEngine()->GetObject
1382     (theShapeWhere->GetStudyID(), theShapeWhere->GetEntry());
1383   Handle(GEOM_Object) aShapeWhat = GetOperations()->GetEngine()->GetObject
1384     (theShapeWhat->GetStudyID(), theShapeWhat->GetEntry());
1385
1386   if (aShapeWhere.IsNull() ||
1387       aShapeWhat.IsNull()) return aGEOMObject._retn();
1388
1389   //Get Shapes in place of aShapeWhat
1390   Handle(GEOM_Object) anObject =
1391     GetOperations()->GetSame(aShapeWhere, aShapeWhat);
1392   if (!GetOperations()->IsDone() || anObject.IsNull())
1393     return aGEOMObject._retn();
1394
1395   return GetObject(anObject);
1396 }
1397