1 // Copyright (C) 2007-2011 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
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : StdMeshers_ObjRefUlils.cxx
25 // Created : Wed Oct 18 15:38:22 2006
26 // Author : Edward AGAPOV (eap)
28 #include "StdMeshers_ObjRefUlils.hxx"
30 #include <TopoDS_Shape.hxx>
34 //=======================================================================
35 //function : EntryOrShapeToGeomObject
36 //purpose : Return GEOM Object by its sytudy entry or TopoDS_Shape
37 //=======================================================================
40 StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject (const std::string& theEntry,
41 const TopoDS_Shape& theShape)
43 GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_nil();
46 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
47 SALOMEDS::Study_var study = gen->GetCurrentStudy();
48 if ( ! theEntry.empty() && ! study->_is_nil() ) {
49 SALOMEDS::SObject_var sobj= study->FindObjectID( theEntry.c_str() );
50 CORBA::Object_var obj = gen->SObjectToObject( sobj );
51 geom = GEOM::GEOM_Object::_narrow( obj );
54 // try by TopoDS_Shape
55 if ( geom->_is_nil() )
56 geom = ShapeToGeomObject( theShape );
61 //================================================================================
63 * \brief Store the shape in the stream
64 * \param theShape - shape to store
65 * \param stream - the stream
67 //================================================================================
69 void StdMeshers_ObjRefUlils::SaveToStream( const TopoDS_Shape& theShape, ostream & stream)
72 if ( !theShape.IsNull() ) {
73 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
74 GEOM::GEOM_Object_var geom = gen->ShapeToGeomObject( theShape );
75 if ( ! geom->_is_nil() ) {
76 SALOMEDS::SObject_var sobj = gen->ObjectToSObject( gen->GetCurrentStudy(), geom );
77 if ( !sobj->_is_nil() ) {
78 stream << " " << sobj->GetID();
85 stream << " NULL_SHAPE ";
88 //================================================================================
90 * \brief Retrieve a shape from the stream
91 * \param stream - the stream
92 * \retval TopoDS_Shape - resulting shape
94 //================================================================================
96 TopoDS_Shape StdMeshers_ObjRefUlils::LoadFromStream( istream & stream)
98 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
99 SALOMEDS::Study_var study = gen->GetCurrentStudy();
100 if ( ! study->_is_nil() ) {
103 SALOMEDS::SObject_var sobj= study->FindObjectID( str.c_str() );
104 CORBA::Object_var obj = gen->SObjectToObject( sobj );
105 GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( obj );
106 return gen->GeomObjectToShape( geom.in() );
110 return TopoDS_Shape();
113 //================================================================================
115 * \brief Store the CORBA object in the stream
116 * \param obj - object to store
117 * \param stream - the stream
119 //================================================================================
121 void StdMeshers_ObjRefUlils::SaveToStream( CORBA::Object_ptr obj,
122 std::ostream & stream)
125 if ( !CORBA::is_nil( obj ) ) {
126 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
127 stream << " " << gen->GetObjectId( obj );
132 stream << " NULL_OBJECT ";
135 //=======================================================================
136 //function : SaveToStream
137 //purpose : Store the study entry of object in the stream
138 //=======================================================================
140 void StdMeshers_ObjRefUlils::SaveToStream( const std::string& studyEntry,
141 std::ostream & stream)
143 if ( studyEntry.find_first_not_of( ' ' ) == std::string::npos )
144 stream << " NULL_OBJECT ";
146 stream << " " << studyEntry;