Salome HOME
23368: [CEA 1865] Possibility to define faces to mesh as a single one: transpatch...
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_ObjRefUlils.cxx
index 910d0aaa870d886314d0a6cd276ee3d0405a7ff7..89cca0caad9342c425e057005b8cbc4c90e81383 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,6 +27,7 @@
 //
 #include "StdMeshers_ObjRefUlils.hxx"
 
+#include <SALOMEDS_wrap.hxx>
 #include <TopoDS_Shape.hxx>
 
 using namespace std;
@@ -36,7 +37,7 @@ using namespace std;
 //purpose  : Return study entry of GEOM Object
 //=======================================================================
 
-std::string StdMeshers_ObjRefUlils::GeomObjectToEntry(GEOM::GEOM_Object_ptr theGeomObject)
+std::string StdMeshers_ObjRefUlils::GeomObjectToEntry(GEOM::GEOM_Object_ptr theGeomObject)
 {
   if ( CORBA::is_nil( theGeomObject ))
     return "NULL_OBJECT";
@@ -60,8 +61,8 @@ StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject (const std::string&  theEntry,
   if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
     SALOMEDS::Study_var study = gen->GetCurrentStudy();
     if ( ! theEntry.empty() && ! study->_is_nil() ) {
-      SALOMEDS::SObject_var sobj= study->FindObjectID( theEntry.c_str() );
-      CORBA::Object_var obj = gen->SObjectToObject( sobj );
+      SALOMEDS::SObject_wrap sobj = study->FindObjectID( theEntry.c_str() );
+      CORBA::Object_var       obj = gen->SObjectToObject( sobj );
       geom = GEOM::GEOM_Object::_narrow( obj );
     }
   }
@@ -87,9 +88,10 @@ void StdMeshers_ObjRefUlils::SaveToStream( const TopoDS_Shape& theShape, ostream
     if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
       GEOM::GEOM_Object_var geom = gen->ShapeToGeomObject( theShape );
       if ( ! geom->_is_nil() ) {
-        SALOMEDS::SObject_var sobj = gen->ObjectToSObject( gen->GetCurrentStudy(), geom );
+        SALOMEDS::SObject_wrap sobj = gen->ObjectToSObject( gen->GetCurrentStudy(), geom );
         if ( !sobj->_is_nil() ) {
-          stream << " " << sobj->GetID();
+          CORBA::String_var entry = sobj->GetID();
+          stream << " " << entry.in();
           ok = true;
         }
       }
@@ -107,20 +109,25 @@ void StdMeshers_ObjRefUlils::SaveToStream( const TopoDS_Shape& theShape, ostream
    */
 //================================================================================
 
-TopoDS_Shape StdMeshers_ObjRefUlils::LoadFromStream( istream & stream)
+TopoDS_Shape StdMeshers_ObjRefUlils::LoadFromStream( istream &    stream,
+                                                     std::string* entry)
 {
-  if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
-    SALOMEDS::Study_var study = gen->GetCurrentStudy();
-    if ( ! study->_is_nil() ) {
-      string str;
-      if (stream >> str) {
-        SALOMEDS::SObject_var sobj= study->FindObjectID( str.c_str() );
-        CORBA::Object_var obj = gen->SObjectToObject( sobj );
-        GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( obj );
+  string str;
+  if (stream >> str) {
+    if ( entry )
+      * entry = str;
+    if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
+      SALOMEDS::Study_var study = gen->GetCurrentStudy();
+      if ( ! study->_is_nil() ) {
+        SALOMEDS::SObject_wrap sobj = study->FindObjectID( str.c_str() );
+        CORBA::Object_var       obj = gen->SObjectToObject( sobj );
+        GEOM::GEOM_Object_var  geom = GEOM::GEOM_Object::_narrow( obj );
         return gen->GeomObjectToShape( geom.in() );
       }
     }
   }
+  if ( entry )
+    entry->clear();
   return TopoDS_Shape();
 }