- TopoDS_Shape S;
- TCollection_AsciiString IOR(aShape->Name());
- Standard_Integer anIndex = Find(IOR, S);
-
- BRep_Builder B;
-
- if (anIndex !=0 ) {
- return S ;
- }
-
- /******* in case of a MAIN GEOM::SHAPE ********/
- if (aShape->IsMainShape()) {
- S = Load(geom, aShape);
- Bind(IOR,S);
- return S;
- }
-
- /******* in case of SUB GEOM::SHAPE ***********/
- // Load and Explore the Main Shape
- TopoDS_Shape MainShape = GetShape (geom, geom->GetIORFromString(aShape->MainName()));
- GEOM::GEOM_Shape::ListOfSubShapeID_var list = aShape->Index();
-
- Standard_Integer j = 1;
- TopExp_Explorer exp;
- TopAbs_ShapeEnum ShapeType = TopAbs_ShapeEnum(aShape->ShapeType());
-
- /* Case of only one subshape */
- if (list->length() == 1)
- {
- if (ShapeType == TopAbs_COMPOUND)
- {
- TopoDS_Iterator it;
- TopTools_ListOfShape CL;
- CL.Append( MainShape );
- TopTools_ListIteratorOfListOfShape itC;
- for (itC.Initialize( CL ); itC.More(); itC.Next())
- {
- for (it.Initialize( itC.Value() ); it.More(); it.Next())
- {
- if ( it.Value().ShapeType() == TopAbs_COMPOUND)
- {
- if (j == list[0])
- {
- S = it.Value();
- Bind(IOR, S);
- return S;
- }
- j++;
- CL.Append( it.Value() );
- }
- }
- }
- }
- else
- {
- TopTools_MapOfShape M;
- for (exp.Init(MainShape, ShapeType); exp.More(); exp.Next()) {
- if ( M.Add(exp.Current()) )
- {
- if (j == list[0])
- {
- S = exp.Current();
- Bind(IOR, S);
- return S;
- }
- j++;
- }
- }
- }
- }
-
- /* Case of a compound containing two or more sub shapes (not a main shape compound !) */
-
- /* Warning : the compound when representing sub shapes must be explored in a sub type */
- /* that is NOT ShapeType=aShape->ShapeType()= TopAbs_COMPOUND ! */
- /* We have to retrieve the exact sub type of shapes contained in the compound first ! */
- TopoDS_Iterator it ;
- TopAbs_ShapeEnum exactSubType ;
- S = Load( geom, aShape );
- it.Initialize( S, true, true ) ;
- it.More();
- exactSubType = it.Value().ShapeType() ;
-
- TColStd_MapOfInteger MapIndex;
- Standard_Integer nbSS = list->length();
- TopoDS_Compound Comp;
- B.MakeCompound(Comp);
-
- for (Standard_Integer i=1; i<=nbSS; i++)
- MapIndex.Add(list[i-1]);
-
- for (exp.Init(MainShape, exactSubType), j=1; exp.More() ; exp.Next(), j++) {
- if ( MapIndex.Contains(j) ) {
- B.Add( Comp, exp.Current() );
- }
- }
- Bind(IOR, Comp);
- return Comp;
-}
+ /******* in case of a MAIN GEOM::SHAPE ********/
+ if (aShape->IsMainShape()) {
+ S = Load(geom, aShape);
+ Bind(IOR, S);
+ return S;
+ }
+
+ /******* in case of SUB GEOM::SHAPE ***********/
+ // Load and Explore the Main Shape
+ TopoDS_Shape aMainShape = GetShape (geom, aShape->GetMainShape());
+ GEOM::ListOfLong_var list = aShape->GetSubShapeIndices();
+
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes(aMainShape, anIndices);
+
+ /* Case of only one subshape */
+ if (list->length() == 1) {
+ S = anIndices.FindKey(list[0]);
+ }
+ else {
+ BRep_Builder B;
+ TopoDS_Compound aCompound;
+ B.MakeCompound(aCompound);
+ for (int i = 0; i < list->length(); i++) {
+ if (0 < list[i] && list[i] <= anIndices.Extent()) {
+ TopoDS_Shape aSubShape = anIndices.FindKey(list[i]);
+ B.Add(aCompound, aSubShape);
+ }
+ }
+
+ S = aCompound;
+ }
+ Bind(IOR, S);
+ return S;
+}