-// purpose :
-//=======================================================================
-
-TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Shape_ptr aShape )
-{
-
- 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;
-}
+// purpose :
+//=======================================================================
+TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape )
+{
+ TopoDS_Shape S;
+ CORBA::String_var anIOR = geom->GetStringFromIOR(aShape);
+ TCollection_AsciiString IOR = (char*)anIOR.in();
+ Standard_Boolean anIndex = Find(IOR, S);
+
+ if (anIndex) 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 aMainShape = GetShape (geom, aShape->GetMainShape());
+ GEOM::ListOfLong_var list = aShape->GetSubShapeIndices();
+
+ CORBA::String_var aMainIOR = geom->GetStringFromIOR(aShape->GetMainShape());
+ TCollection_AsciiString mainIOR = (char*)aMainIOR.in();
+
+ //find subshapes only one time
+ if (_mySubShapes.count(mainIOR) == 0)
+ {
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes(aMainShape, anIndices);
+ Standard_Integer ii = 1, nbSubSh = anIndices.Extent();
+ for (; ii <= nbSubSh; ii++)
+ {
+ _mySubShapes[mainIOR].push_back(anIndices.FindKey(ii));
+ }
+ }
+
+ /* Case of only one subshape */
+ if (list->length() == 1 && list[0] > 0) {
+ S = _mySubShapes[mainIOR][list[0]-1];
+ }
+ else {
+ BRep_Builder B;
+ TopoDS_Compound aCompound;
+ B.MakeCompound(aCompound);
+ for (int i = 0; i < list->length(); i++) {
+ if (0 < list[i] && list[i] <= _mySubShapes[mainIOR].size()) {
+ TopoDS_Shape aSubShape = _mySubShapes[mainIOR][list[i]-1];
+ B.Add(aCompound, aSubShape);
+ }
+ }
+
+ S = aCompound;
+ }
+ Bind(IOR, S);
+ return S;
+}