1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH : implementaion of SMESH idl descriptions
23 // File : StdMeshers_ObjRefUlils.cxx
24 // Created : Wed Oct 18 15:38:22 2006
25 // Author : Edward AGAPOV (eap)
27 #include "StdMeshers_ObjRefUlils.hxx"
29 #include <TopoDS_Shape.hxx>
33 //================================================================================
35 * \brief Store the shape in the stream
36 * \param theShape - shape to store
37 * \param stream - the stream
39 //================================================================================
41 void StdMeshers_ObjRefUlils::SaveToStream( const TopoDS_Shape& theShape, ostream & stream)
44 if ( !theShape.IsNull() ) {
45 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
46 GEOM::GEOM_Object_var geom = gen->ShapeToGeomObject( theShape );
47 if ( ! geom->_is_nil() ) {
48 SALOMEDS::SObject_var sobj = gen->ObjectToSObject( gen->GetCurrentStudy(), geom );
49 if ( !sobj->_is_nil() ) {
50 stream << " " << sobj->GetID();
57 stream << " NULL_SHAPE ";
60 //================================================================================
62 * \brief Retrieve a shape from the stream
63 * \param stream - the stream
64 * \retval TopoDS_Shape - resulting shape
66 //================================================================================
68 TopoDS_Shape StdMeshers_ObjRefUlils::LoadFromStream( istream & stream)
70 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
71 SALOMEDS::Study_var study = gen->GetCurrentStudy();
72 if ( ! study->_is_nil() ) {
75 SALOMEDS::SObject_var sobj= study->FindObjectID( str.c_str() );
76 CORBA::Object_var obj = gen->SObjectToObject( sobj );
77 GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( obj );
78 return gen->GeomObjectToShape( geom.in() );
82 return TopoDS_Shape();
85 //================================================================================
87 * \brief Store the CORBA object in the stream
88 * \param obj - object to store
89 * \param stream - the stream
91 //================================================================================
93 void StdMeshers_ObjRefUlils::SaveToStream( CORBA::Object_ptr obj,
94 std::ostream & stream)
97 if ( !CORBA::is_nil( obj ) ) {
98 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
99 stream << " " << gen->GetObjectId( obj );
104 stream << " NULL_OBJECT ";