Back to index

salome-smesh  6.5.0
StdMeshers_ObjRefUlils.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESH : implementaion of SMESH idl descriptions
00024 // File      : StdMeshers_ObjRefUlils.hxx
00025 // Created   : Wed Oct 18 15:15:27 2006
00026 // Author    : Edward AGAPOV (eap)
00027 //
00028 #ifndef StdMeshers_ObjRefUlils_HeaderFile
00029 #define StdMeshers_ObjRefUlils_HeaderFile
00030 
00031 #include "SMESH_Gen_i.hxx"
00032 
00041 class StdMeshers_ObjRefUlils
00042 {
00043 public:
00049    static GEOM::GEOM_Object_ptr ShapeToGeomObject (const TopoDS_Shape& theShape ) {
00050      if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen())
00051        return gen->ShapeToGeomObject( theShape );
00052      else
00053        return GEOM::GEOM_Object::_nil();
00054    }
00055 
00061   static TopoDS_Shape GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject) {
00062      if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen())
00063        return gen->GeomObjectToShape( theGeomObject );
00064      else
00065        return TopoDS_Shape();
00066   }
00067 
00071   static std::string GeomObjectToEntry(GEOM::GEOM_Object_ptr&  theGeomObject);
00072 
00076   static GEOM::GEOM_Object_ptr EntryOrShapeToGeomObject (const std::string&  theEntry,
00077                                                          const TopoDS_Shape& theShape);
00078 
00079 
00085   static void SaveToStream( const TopoDS_Shape& theShape, std::ostream & stream);
00086 
00092   static TopoDS_Shape LoadFromStream( std::istream & stream );
00093 
00099   static void SaveToStream( CORBA::Object_ptr obj, std::ostream & stream );
00100 
00106   template<class TInterface> 
00107   static 
00108   typename TInterface::_var_type LoadObjectFromStream( std::istream & stream )
00109   {
00110     if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
00111       std::string str;
00112       if (stream >> str) {
00113         if ( StudyContext* myStudyContext = gen->GetCurrentStudyContext() ) {
00114           string ior = myStudyContext->getIORbyOldId( atoi( str.c_str() ));
00115           if ( !ior.empty() )
00116              return TInterface::_narrow(gen->GetORB()->string_to_object( ior.c_str() ));
00117         }
00118       }
00119     }
00120     return TInterface::_nil();
00121   }
00122 
00128   static void SaveToStream( const std::string& studyEntry, std::ostream & stream);
00129 
00130 };
00131 
00132 #endif