Salome HOME
Bug 0020043: EDF 865 GEOM: Object is non valid after translation. Fix object after...
[modules/geom.git] / src / GEOMClient / GEOM_Client.cxx
index 1bdf7482c72a253d6669ac7dc826d65ab615011a..08fa4dbfe37cf1e7d34deda2589412583eb74e84 100644 (file)
@@ -17,7 +17,7 @@
 //  License along with this library; if not, write to the Free Software 
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
 // 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
@@ -34,7 +34,7 @@
 
 #include "GEOM_Client.hxx"
 #include <SALOMEconfig.h>
-#include "OpUtil.hxx"
+#include "Basics_Utils.hxx"
 #include "utilities.h"
 
 #include <BRep_Builder.hxx>
@@ -66,7 +66,7 @@
 //=======================================================================
 TopoDS_Shape GEOM_Client::Load( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape )
 {
-    string hst_client = GetHostname();
+    std::string hst_client = Kernel_Utils::GetHostname();
 
     Engines::Container_var ctn_server = geom->GetContainerRef();
     long                   pid_server = ctn_server->getPID();
@@ -81,7 +81,7 @@ TopoDS_Shape GEOM_Client::Load( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr a
         int sizebuf = SeqFile->length();
         char* buf;
         buf = (char*) &SeqFile[0];
-        istrstream streamBrep(buf,sizebuf);
+        std::istrstream streamBrep(buf,sizebuf);
         BRep_Builder aBuilder;
         BRepTools::Read(S, streamBrep, aBuilder);
         return(S);
@@ -198,47 +198,46 @@ unsigned int GEOM_Client::BufferLength()
 // function : GetShape()
 // purpose  : 
 //=======================================================================
+TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape )
+{
+  TopoDS_Shape S;
+  TCollection_AsciiString IOR = geom->GetStringFromIOR(aShape);
+  Standard_Integer anIndex = Find(IOR, S);
 
-TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape ) 
-{ 
-  TopoDS_Shape            S; 
-  TCollection_AsciiString IOR = geom->GetStringFromIOR(aShape); 
-  Standard_Integer anIndex = Find(IOR, S); 
-  
-  if (anIndex !=0 ) return S ;  
+  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 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(); 
+  /******* 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]); 
-  } 
+  /* Case of only one subshape */
+  if (list->length() == 1 && list[0] > 0) {
+    S = anIndices.FindKey(list[0]);
+  }
   else {
     BRep_Builder B;
     TopoDS_Compound aCompound;
     B.MakeCompound(aCompound);
-    for(int i=0; i<list->length(); i++) {
-      TopoDS_Shape aSubShape = anIndices.FindKey(list[i]); 
-      B.Add(aCompound, aSubShape);
+    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; 
-} 
-
+  Bind(IOR, S);
+  return S;
+}