Version: 6.3.1

src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  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.cxx
00025 // Created   : Wed Oct 18 15:38:22 2006
00026 // Author    : Edward AGAPOV (eap)
00027 //
00028 #include "StdMeshers_ObjRefUlils.hxx"
00029 
00030 #include <TopoDS_Shape.hxx>
00031 
00032 using namespace std;
00033 
00034 //================================================================================
00040 //================================================================================
00041 
00042 void StdMeshers_ObjRefUlils::SaveToStream( const TopoDS_Shape& theShape, ostream & stream)
00043 {
00044   bool ok = false;
00045   if ( !theShape.IsNull() ) {
00046     if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
00047       GEOM::GEOM_Object_var geom = gen->ShapeToGeomObject( theShape );
00048       if ( ! geom->_is_nil() ) {
00049         SALOMEDS::SObject_var sobj = gen->ObjectToSObject( gen->GetCurrentStudy(), geom );
00050         if ( !sobj->_is_nil() ) {
00051           stream << " " << sobj->GetID();
00052           ok = true;
00053         }
00054       }
00055     }
00056   }
00057   if ( ! ok )
00058     stream << " NULL_SHAPE ";
00059 }
00060 
00061 //================================================================================
00067 //================================================================================
00068 
00069 TopoDS_Shape StdMeshers_ObjRefUlils::LoadFromStream( istream & stream)
00070 {
00071   if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
00072     SALOMEDS::Study_var study = gen->GetCurrentStudy();
00073     if ( ! study->_is_nil() ) {
00074       string str;
00075       if (stream >> str) {
00076         SALOMEDS::SObject_var sobj= study->FindObjectID( str.c_str() );
00077         CORBA::Object_var obj = gen->SObjectToObject( sobj );
00078         GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( obj );
00079         return gen->GeomObjectToShape( geom.in() );
00080       }
00081     }
00082   }
00083   return TopoDS_Shape();
00084 }
00085 
00086 //================================================================================
00092 //================================================================================
00093 
00094 void StdMeshers_ObjRefUlils::SaveToStream( CORBA::Object_ptr obj,
00095                                            std::ostream & stream)
00096 {
00097   bool ok = false;
00098   if ( !CORBA::is_nil( obj ) ) {
00099     if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
00100       stream << " " << gen->GetObjectId( obj );
00101       ok = true;
00102     }
00103   }
00104   if ( ! ok )
00105     stream << " NULL_OBJECT ";
00106 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS