Salome HOME
12b1602ed38716870e0f896a246561d75a1d9d4f
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IGroupOperations.cxx
1 using namespace std;
2
3 #include "GEOMImpl_IGroupOperations.hxx"
4
5 #include "GEOMImpl_Types.hxx"
6
7 #include "GEOM_Function.hxx"
8 #include "GEOM_ISubShape.hxx"
9
10 #include "utilities.h"
11 #include "OpUtil.hxx"
12 #include "Utils_ExceptHandlers.hxx"
13
14 #include <TFunction_DriverTable.hxx>
15 #include <TFunction_Driver.hxx>
16 #include <TFunction_Logbook.hxx>
17 #include <TDF_Tool.hxx>
18 #include <TDataStd_Integer.hxx>
19
20 #include <TopExp.hxx>
21 #include <TopTools_IndexedMapOfShape.hxx>
22
23 #include <TColStd_HArray1OfInteger.hxx>
24 #include <TColStd_MapOfInteger.hxx>
25 #include <TColStd_ListOfInteger.hxx>
26 #include <TColStd_ListIteratorOfListOfInteger.hxx>
27
28 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
29
30 //=============================================================================
31 /*!
32  *   constructor:
33  */
34 //=============================================================================
35 GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations (GEOM_Engine* theEngine, int theDocID) 
36 : GEOM_IOperations(theEngine, theDocID)
37 {
38   MESSAGE("GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations");
39 }
40
41 //=============================================================================
42 /*!
43  *  destructor
44  */
45 //=============================================================================
46 GEOMImpl_IGroupOperations::~GEOMImpl_IGroupOperations()
47 {
48   MESSAGE("GEOMImpl_IGroupOperations::~GEOMImpl_IGroupOperations");
49 }
50
51
52 //=============================================================================
53 /*!
54  *  CreateGroup
55  */
56 //=============================================================================
57 Handle(GEOM_Object) GEOMImpl_IGroupOperations::CreateGroup(Handle(GEOM_Object) theMainShape, TopAbs_ShapeEnum  theShapeType)
58 {
59   SetErrorCode(KO);
60
61   Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1);
62   anArray->SetValue(1, -1);
63
64   //Add a new Fillet object  
65   Handle(GEOM_Object) aGroup = GetEngine()->AddSubShape(theMainShape, anArray);
66
67   //Set a GROUP type
68   aGroup->SetType(GEOM_GROUP);
69
70   //Set a sub shape type
71   TDF_Label aFreeLabel = aGroup->GetFreeLabel();
72   TDataStd_Integer::Set(aFreeLabel, (Standard_Integer)theShapeType);
73  
74   //Make a Python command 
75   TCollection_AsciiString anEntry, aDescr("");
76   TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
77   aDescr = anEntry + " = IGroupOperations.CreateGroup(";
78   TDF_Tool::Entry(theMainShape->GetEntry(), anEntry);
79   aDescr += (anEntry+", ");
80   aDescr += (TCollection_AsciiString((int)theShapeType)+")");
81
82   Handle(GEOM_Function) aFunction = aGroup->GetFunction(1);
83   aFunction->SetDescription(aDescr);
84
85   SetErrorCode(OK);
86   return aGroup; 
87 }
88
89 //=============================================================================
90 /*!
91  *  AddObject
92  */
93 //=============================================================================
94 void GEOMImpl_IGroupOperations::AddObject(Handle(GEOM_Object) theGroup, int theSubShapeID)
95 {
96   SetErrorCode(KO);
97   if(theGroup.IsNull()) return;
98
99   Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
100   if(aFunction.IsNull()) return;
101
102   GEOM_ISubShape aSSI(aFunction);
103   Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
104   if(aSeq.IsNull()) return;
105   if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {
106     aSeq->SetValue(1, theSubShapeID);
107   }
108   else {
109     Standard_Integer aLength = aSeq->Length();
110     Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aLength+1);
111     for(Standard_Integer i = 1; i<=aLength; i++) {
112       aNewSeq->SetValue(i, aSeq->Value(i));
113       if(aSeq->Value(i) == theSubShapeID) {
114         SetErrorCode(ALREADY_PRESENT);
115         return; //
116       }
117     }
118     aNewSeq->SetValue(aLength+1, theSubShapeID);
119     aSSI.SetIndices(aNewSeq);
120   }
121
122   SetErrorCode(OK);
123   return; 
124 }
125
126 //=============================================================================
127 /*!
128  *  RemoveObject
129  */
130 //=============================================================================
131 void GEOMImpl_IGroupOperations::RemoveObject(Handle(GEOM_Object) theGroup, int theSubShapeID)
132 {
133   SetErrorCode(KO);
134   if(theGroup.IsNull()) return;
135
136   Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
137   if(aFunction.IsNull()) return;
138
139   GEOM_ISubShape aSSI(aFunction);
140   Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
141   if(aSeq.IsNull()) return;
142   if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {
143     SetErrorCode(NOT_EXISTS);
144     return;
145   }
146   else {
147     Handle(TColStd_HArray1OfInteger) aNewSeq;
148     Standard_Integer aLength = aSeq->Length();
149     if(aLength == 1) {
150       if(aSeq->Value(1) != theSubShapeID) {
151         SetErrorCode(NOT_EXISTS);
152         return;         
153       }
154       aNewSeq = new TColStd_HArray1OfInteger(1,1);
155       aNewSeq->SetValue(1, -1);
156     }
157     else {
158       aNewSeq = new TColStd_HArray1OfInteger(1, aLength-1);
159       Standard_Boolean isFound = Standard_False;
160       for(Standard_Integer i = 1, k=1; i<=aLength; i++) {
161         if(i == aLength && !isFound) {
162           SetErrorCode(NOT_EXISTS);
163           return; 
164         }
165         if(aSeq->Value(i) == theSubShapeID) {
166           isFound = Standard_True;
167           continue;
168         }
169         aNewSeq->SetValue(k, aSeq->Value(i));
170         k++;
171       }
172
173       if(!isFound) {
174         SetErrorCode(NOT_EXISTS);
175         return; 
176       }
177     }
178
179     aSSI.SetIndices(aNewSeq);
180   }
181
182   SetErrorCode(OK);
183   return; 
184 }
185
186 //=============================================================================
187 /*!
188  *  UnionList
189  */
190 //=============================================================================
191 void GEOMImpl_IGroupOperations::UnionList (Handle(GEOM_Object) theGroup,
192                                            const Handle(TColStd_HSequenceOfTransient)& theSubShapes)
193 {
194   SetErrorCode(KO);
195   if (theGroup.IsNull()) return;
196
197   Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
198   if (aFunction.IsNull()) return;
199
200   GEOM_ISubShape aSSI (aFunction);
201
202   // New contents of the group
203   TColStd_ListOfInteger aNewIDs;
204   TColStd_MapOfInteger mapIDs;
205
206   // Add current IDs to the list
207   Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
208   if (aSeq.IsNull()) return;
209   Standard_Integer val_j, aLength = aSeq->Length();
210
211   for (Standard_Integer j = 1; j <= aLength; j++) {
212     val_j = aSeq->Value(j);
213     if (val_j > 0 && mapIDs.Add(val_j)) {
214       aNewIDs.Append(val_j);
215     }
216   }
217
218   // Get Main Shape
219   Handle(GEOM_Function) aMainShapeFunc = aSSI.GetMainShape();
220   if (aMainShapeFunc.IsNull()) return;
221   TDF_Label aLabel = aMainShapeFunc->GetOwnerEntry();
222   if (aLabel.IsRoot()) return;
223   Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
224   if (aMainObj.IsNull()) return;
225   TopoDS_Shape aMainShape = aMainObj->GetValue();
226   if (aMainShape.IsNull()) return;
227
228   TopTools_IndexedMapOfShape mapIndices;
229   TopExp::MapShapes(aMainShape, mapIndices);
230
231   // Get IDs of sub-shapes to add
232   Standard_Integer i, new_id, aLen = theSubShapes->Length();
233   for (i = 1; i <= aLen; i++) {
234     Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theSubShapes->Value(i));
235
236     if (anObj_i->IsMainShape()) {
237       TopoDS_Shape aShape_i = anObj_i->GetValue();
238       if (mapIndices.Contains(aShape_i)) {
239         new_id = mapIndices.FindIndex(aShape_i);
240         if (mapIDs.Add(new_id)) {
241           aNewIDs.Append(new_id);
242         }
243       } else {
244         SetErrorCode("One of given objects can not be added to the group, because it is not a sub-shape of the group's main shape");
245         return;
246       }
247     } else {
248       // Check main shape of sub-shape to add
249       Handle(GEOM_Function) aFunc_i = anObj_i->GetFunction(1);
250       if (aFunc_i.IsNull()) return;
251
252       GEOM_ISubShape aSSI_i (aFunc_i);
253
254       Handle(GEOM_Function) aMainShapeFunc_i = aSSI_i.GetMainShape();
255       if (aMainShapeFunc_i.IsNull()) return;
256       TDF_Label aLabel_i = aMainShapeFunc_i->GetOwnerEntry();
257       if (aLabel_i.IsRoot()) return;
258       Handle(GEOM_Object) aMainObj_i = GEOM_Object::GetObject(aLabel);
259       if (aMainObj_i.IsNull()) return;
260       TopoDS_Shape aMainShape_i = aMainObj_i->GetValue();
261       if (aMainShape_i.IsNull()) return;
262
263       if (aMainShape_i.IsSame(aMainShape)) {
264         // add all sub-shape IDs to the list
265
266         // Get IDs
267         Handle(TColStd_HArray1OfInteger) aSeq_i = aSSI_i.GetIndices();
268         if (aSeq_i.IsNull()) return;
269         Standard_Integer aLength_i = aSeq_i->Length();
270
271         for (Standard_Integer i_j = 1; i_j <= aLength_i; i_j++) {
272           new_id = aSeq_i->Value(i_j);
273           if (new_id > 0) {
274             if (mapIDs.Add(new_id)) {
275               aNewIDs.Append(new_id);
276             }
277           }
278         }
279
280       } else if (mapIndices.Contains(aMainShape_i)) {
281         // compute new IDs and add them to the list
282         TopTools_IndexedMapOfShape mapIndices_i;
283         TopExp::MapShapes(aMainShape_i, mapIndices_i);
284
285         // Get IDs
286         Handle(TColStd_HArray1OfInteger) aSeq_i = aSSI_i.GetIndices();
287         if (aSeq_i.IsNull()) return;
288         Standard_Integer aLength_i = aSeq_i->Length();
289
290         for (Standard_Integer i_j = 1; i_j <= aLength_i; i_j++) {
291           if (aSeq_i->Value(i_j) > 0) {
292             TopoDS_Shape aShape_i_j = mapIndices_i.FindKey(i_j);
293             new_id = mapIndices.FindIndex(aShape_i_j);
294             if (mapIDs.Add(new_id)) {
295               aNewIDs.Append(new_id);
296             }
297           }
298         }
299
300       } else {
301         SetErrorCode("One of given objects can not be added to the group, because it is not a sub-shape of the group's main shape");
302         return;
303       }
304     }
305   }
306
307   if (aNewIDs.Extent() > 0) {
308     Standard_Integer k = 1;
309     TColStd_ListIteratorOfListOfInteger aNewIDsIter (aNewIDs);
310     Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aNewIDs.Extent());
311     for (; aNewIDsIter.More(); aNewIDsIter.Next(), k++) {
312       aNewSeq->SetValue(k, aNewIDsIter.Value());
313     }
314
315     aSSI.SetIndices(aNewSeq);
316   }
317
318   SetErrorCode(OK);
319 }
320
321 //=============================================================================
322 /*!
323  *  DifferenceList
324  */
325 //=============================================================================
326 void GEOMImpl_IGroupOperations::DifferenceList (Handle(GEOM_Object) theGroup,
327                                                 const Handle(TColStd_HSequenceOfTransient)& theSubShapes)
328 {
329   SetErrorCode(KO);
330   if (theGroup.IsNull()) return;
331
332   Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
333   if (aFunction.IsNull()) return;
334
335   GEOM_ISubShape aSSI (aFunction);
336
337   // Map of IDs to be removed
338   TColStd_MapOfInteger mapIDsToRemove;
339
340   // Map of current IDs
341   Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
342   if (aSeq.IsNull()) return;
343   Standard_Integer aLength = aSeq->Length();
344
345   if (aLength == 1 && aSeq->Value(1) == -1) // empty group
346     return;
347
348   TColStd_MapOfInteger mapIDsCurrent;
349   Standard_Integer j = 1;
350   for (; j <= aLength; j++) {
351     mapIDsCurrent.Add(aSeq->Value(j));
352   }
353
354   // Get Main Shape
355   Handle(GEOM_Function) aMainShapeFunc = aSSI.GetMainShape();
356   if (aMainShapeFunc.IsNull()) return;
357   TDF_Label aLabel = aMainShapeFunc->GetOwnerEntry();
358   if (aLabel.IsRoot()) return;
359   Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
360   if (aMainObj.IsNull()) return;
361   TopoDS_Shape aMainShape = aMainObj->GetValue();
362   if (aMainShape.IsNull()) return;
363
364   TopTools_IndexedMapOfShape mapIndices;
365   TopExp::MapShapes(aMainShape, mapIndices);
366
367   // Get IDs of sub-shapes to be removed
368   Standard_Integer i, rem_id, aLen = theSubShapes->Length();
369   for (i = 1; i <= aLen; i++) {
370     Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theSubShapes->Value(i));
371
372     if (anObj_i->IsMainShape()) {
373       TopoDS_Shape aShape_i = anObj_i->GetValue();
374       if (mapIndices.Contains(aShape_i)) {
375         rem_id = mapIndices.FindIndex(aShape_i);
376         if (mapIDsCurrent.Contains(rem_id)) {
377           mapIDsToRemove.Add(rem_id);
378         }
379       } else {
380         SetErrorCode("One of given objects can not be removed from the group, because it is not a sub-shape of the group's main shape");
381         return;
382       }
383     } else {
384       // Check main shape of sub-shape to be removed
385       Handle(GEOM_Function) aFunc_i = anObj_i->GetFunction(1);
386       if (aFunc_i.IsNull()) return;
387
388       GEOM_ISubShape aSSI_i (aFunc_i);
389
390       Handle(GEOM_Function) aMainShapeFunc_i = aSSI_i.GetMainShape();
391       if (aMainShapeFunc_i.IsNull()) return;
392       TDF_Label aLabel_i = aMainShapeFunc_i->GetOwnerEntry();
393       if (aLabel_i.IsRoot()) return;
394       Handle(GEOM_Object) aMainObj_i = GEOM_Object::GetObject(aLabel);
395       if (aMainObj_i.IsNull()) return;
396       TopoDS_Shape aMainShape_i = aMainObj_i->GetValue();
397       if (aMainShape_i.IsNull()) return;
398
399       if (aMainShape_i.IsSame(aMainShape)) {
400         // remove all sub-shapes
401
402         // Get IDs
403         Handle(TColStd_HArray1OfInteger) aSeq_i = aSSI_i.GetIndices();
404         if (aSeq_i.IsNull()) return;
405         Standard_Integer aLength_i = aSeq_i->Length();
406
407         for (Standard_Integer i_j = 1; i_j <= aLength_i; i_j++) {
408           rem_id = aSeq_i->Value(i_j);
409           if (rem_id > 0) {
410             if (mapIDsCurrent.Contains(rem_id)) {
411               mapIDsToRemove.Add(rem_id);
412             }
413           }
414         }
415
416       } else if (mapIndices.Contains(aMainShape_i)) {
417         // compute new IDs and add them to the map of ids to be removed
418         TopTools_IndexedMapOfShape mapIndices_i;
419         TopExp::MapShapes(aMainShape_i, mapIndices_i);
420
421         // Get IDs
422         Handle(TColStd_HArray1OfInteger) aSeq_i = aSSI_i.GetIndices();
423         if (aSeq_i.IsNull()) return;
424         Standard_Integer aLength_i = aSeq_i->Length();
425
426         for (Standard_Integer i_j = 1; i_j <= aLength_i; i_j++) {
427           if (aSeq_i->Value(i_j) > 0) {
428             TopoDS_Shape aShape_i_j = mapIndices_i.FindKey(i_j);
429             rem_id = mapIndices.FindIndex(aShape_i_j);
430             if (mapIDsCurrent.Contains(rem_id)) {
431               mapIDsToRemove.Add(rem_id);
432             }
433           }
434         }
435
436       } else {
437         SetErrorCode("One of given objects can not be removed from the group, because it is not a sub-shape of the group's main shape");
438         return;
439       }
440     }
441   }
442
443   if (mapIDsToRemove.Extent() > 0) {
444     Standard_Integer k = 1, aRemLength = mapIDsToRemove.Extent();
445     Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aLength - aRemLength);
446
447     for (j = 1; j <= aLength; j++) {
448       if (!mapIDsToRemove.Contains(aSeq->Value(j))) {
449         aNewSeq->SetValue(k, aSeq->Value(j));
450         k++;
451       }
452     }
453
454     aSSI.SetIndices(aNewSeq);
455   }
456
457   SetErrorCode(OK);
458 }
459
460 //=============================================================================
461 /*!
462  *  UnionIDs
463  */
464 //=============================================================================
465 void GEOMImpl_IGroupOperations::UnionIDs (Handle(GEOM_Object) theGroup,
466                                           const Handle(TColStd_HSequenceOfInteger)& theSubShapes)
467 {
468   SetErrorCode(KO);
469   if (theGroup.IsNull()) return;
470
471   Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
472   if (aFunction.IsNull()) return;
473
474   GEOM_ISubShape aSSI (aFunction);
475
476   // New contents of the group
477   TColStd_ListOfInteger aNewIDs;
478   TColStd_MapOfInteger mapIDs;
479
480   // Add current IDs to the list
481   Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
482   if (aSeq.IsNull()) return;
483   Standard_Integer val_j, aLength = aSeq->Length();
484
485   for (Standard_Integer j = 1; j <= aLength; j++) {
486     val_j = aSeq->Value(j);
487     if (val_j > 0 && mapIDs.Add(val_j)) {
488       aNewIDs.Append(val_j);
489     }
490   }
491
492   // Get Main Shape
493   Handle(GEOM_Function) aMainShapeFunc = aSSI.GetMainShape();
494   if (aMainShapeFunc.IsNull()) return;
495   TDF_Label aLabel = aMainShapeFunc->GetOwnerEntry();
496   if (aLabel.IsRoot()) return;
497   Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
498   if (aMainObj.IsNull()) return;
499   TopoDS_Shape aMainShape = aMainObj->GetValue();
500   if (aMainShape.IsNull()) return;
501
502   TopTools_IndexedMapOfShape mapIndices;
503   TopExp::MapShapes(aMainShape, mapIndices);
504
505   // Get IDs of sub-shapes to add
506   Standard_Integer i, new_id, aLen = theSubShapes->Length();
507   for (i = 1; i <= aLen; i++) {
508     new_id = theSubShapes->Value(i);
509
510     if (0 < new_id && new_id <= mapIndices.Extent()) {
511       if (mapIDs.Add(new_id)) {
512         aNewIDs.Append(new_id);
513       }
514     }
515   }
516
517   if (aNewIDs.Extent() > 0) {
518     Standard_Integer k = 1;
519     TColStd_ListIteratorOfListOfInteger aNewIDsIter (aNewIDs);
520     Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aNewIDs.Extent());
521     for (; aNewIDsIter.More(); aNewIDsIter.Next(), k++) {
522       aNewSeq->SetValue(k, aNewIDsIter.Value());
523     }
524
525     aSSI.SetIndices(aNewSeq);
526   }
527
528   SetErrorCode(OK);
529 }
530
531 //=============================================================================
532 /*!
533  *  DifferenceIDs
534  */
535 //=============================================================================
536 void GEOMImpl_IGroupOperations::DifferenceIDs (Handle(GEOM_Object) theGroup,
537                                                const Handle(TColStd_HSequenceOfInteger)& theSubShapes)
538 {
539   SetErrorCode(KO);
540   if (theGroup.IsNull()) return;
541
542   Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
543   if (aFunction.IsNull()) return;
544
545   GEOM_ISubShape aSSI (aFunction);
546
547   // Map of IDs to be removed
548   TColStd_MapOfInteger mapIDsToRemove;
549
550   // Map of current IDs
551   Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
552   if (aSeq.IsNull()) return;
553   Standard_Integer aLength = aSeq->Length();
554
555   if (aLength == 1 && aSeq->Value(1) == -1) // empty group
556     return;
557
558   TColStd_MapOfInteger mapIDsCurrent;
559   Standard_Integer j = 1;
560   for (; j <= aLength; j++) {
561     mapIDsCurrent.Add(aSeq->Value(j));
562   }
563
564   // Get Main Shape
565   Handle(GEOM_Function) aMainShapeFunc = aSSI.GetMainShape();
566   if (aMainShapeFunc.IsNull()) return;
567   TDF_Label aLabel = aMainShapeFunc->GetOwnerEntry();
568   if (aLabel.IsRoot()) return;
569   Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel);
570   if (aMainObj.IsNull()) return;
571   TopoDS_Shape aMainShape = aMainObj->GetValue();
572   if (aMainShape.IsNull()) return;
573
574   TopTools_IndexedMapOfShape mapIndices;
575   TopExp::MapShapes(aMainShape, mapIndices);
576
577   // Get IDs of sub-shapes to be removed
578   Standard_Integer i, rem_id, aLen = theSubShapes->Length();
579   for (i = 1; i <= aLen; i++) {
580     rem_id = theSubShapes->Value(i);
581     if (mapIDsCurrent.Contains(rem_id)) {
582       mapIDsToRemove.Add(rem_id);
583     }
584   }
585
586   if (mapIDsToRemove.Extent() > 0) {
587     Standard_Integer k = 1, aRemLength = mapIDsToRemove.Extent();
588     Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aLength - aRemLength);
589
590     for (j = 1; j <= aLength; j++) {
591       if (!mapIDsToRemove.Contains(aSeq->Value(j))) {
592         aNewSeq->SetValue(k, aSeq->Value(j));
593         k++;
594       }
595     }
596
597     aSSI.SetIndices(aNewSeq);
598   }
599
600   SetErrorCode(OK);
601 }
602
603 //=============================================================================
604 /*!
605  *  GetType
606  */
607 //=============================================================================
608 TopAbs_ShapeEnum GEOMImpl_IGroupOperations::GetType(Handle(GEOM_Object) theGroup)
609 {
610   SetErrorCode(KO);
611
612   TDF_Label aFreeLabel = theGroup->GetFreeLabel();
613   Handle(TDataStd_Integer) anAttrib;
614   if(!aFreeLabel.FindAttribute(TDataStd_Integer::GetID(), anAttrib)) return TopAbs_SHAPE;
615  
616   SetErrorCode(OK);
617   return (TopAbs_ShapeEnum) anAttrib->Get(); 
618 }
619
620 //=============================================================================
621 /*!
622  *  GetMainShape
623  */
624 //=============================================================================
625 Handle(GEOM_Object) GEOMImpl_IGroupOperations::GetMainShape(Handle(GEOM_Object) theGroup)
626 {
627   SetErrorCode(KO);
628
629   if(theGroup.IsNull()) return NULL;
630
631   Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
632   if(aFunction.IsNull()) return NULL;
633   
634   GEOM_ISubShape aSSI(aFunction);
635   aFunction = aSSI.GetMainShape();
636   if(aFunction.IsNull()) return NULL;
637
638   TDF_Label aLabel = aFunction->GetOwnerEntry();
639   Handle(GEOM_Object) aMainShape = GEOM_Object::GetObject(aLabel);
640   if(aMainShape.IsNull()) return NULL;
641   
642   SetErrorCode(OK);
643   return aMainShape; 
644 }
645
646 //=============================================================================
647 /*!
648  *  GetObjects
649  */
650 //=============================================================================
651 Handle(TColStd_HArray1OfInteger) GEOMImpl_IGroupOperations::GetObjects(Handle(GEOM_Object) theGroup)
652 {
653   SetErrorCode(KO);
654   
655    if(theGroup.IsNull()) return NULL;
656
657   Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
658   if(aFunction.IsNull()) return NULL;
659   
660   GEOM_ISubShape aSSI(aFunction);
661   Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
662   if(aSeq.IsNull()) return NULL;
663
664   if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {
665     SetErrorCode(OK);
666     return NULL;
667   }
668
669   SetErrorCode(OK);
670   return aSeq;
671 }