1 // Copyright (C) 2007-2019 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, or (at your option) any later version.
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 : implementation 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 <SALOMEDS_wrap.hxx>
31 #include <TopoDS_Shape.hxx>
35 //=======================================================================
36 //function : GeomObjectToEntry
37 //purpose : Return study entry of GEOM Object
38 //=======================================================================
40 std::string StdMeshers_ObjRefUlils::GeomObjectToEntry(GEOM::GEOM_Object_ptr theGeomObject)
42 if ( CORBA::is_nil( theGeomObject ))
45 CORBA::String_var entry = theGeomObject->GetStudyEntry();
49 //=======================================================================
50 //function : EntryOrShapeToGeomObject
51 //purpose : Return GEOM Object by its sytudy entry or TopoDS_Shape
52 //=======================================================================
55 StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject (const std::string& theEntry,
56 const TopoDS_Shape& theShape)
58 GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_nil();
61 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
62 if ( ! theEntry.empty() ) {
63 SALOMEDS::SObject_wrap sobj = SMESH_Gen_i::getStudyServant()->FindObjectID( theEntry.c_str() );
64 CORBA::Object_var obj = gen->SObjectToObject( sobj );
65 geom = GEOM::GEOM_Object::_narrow( obj );
68 // try by TopoDS_Shape
69 if ( geom->_is_nil() )
70 geom = ShapeToGeomObject( theShape );
75 //================================================================================
77 * \brief Store the shape in the stream
78 * \param theShape - shape to store
79 * \param stream - the stream
81 //================================================================================
83 void StdMeshers_ObjRefUlils::SaveToStream( const TopoDS_Shape& theShape, ostream & stream)
86 if ( !theShape.IsNull() ) {
87 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
88 GEOM::GEOM_Object_var geom = gen->ShapeToGeomObject( theShape );
89 if ( ! geom->_is_nil() ) {
90 SALOMEDS::SObject_wrap sobj = gen->ObjectToSObject( geom );
91 if ( !sobj->_is_nil() ) {
92 CORBA::String_var entry = sobj->GetID();
93 stream << " " << entry.in();
100 stream << " NULL_SHAPE ";
103 //================================================================================
105 * \brief Retrieve a shape from the stream
106 * \param stream - the stream
107 * \retval TopoDS_Shape - resulting shape
109 //================================================================================
111 TopoDS_Shape StdMeshers_ObjRefUlils::LoadFromStream( istream & stream,
118 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
119 SALOMEDS::SObject_wrap sobj = SMESH_Gen_i::getStudyServant()->FindObjectID( str.c_str() );
120 CORBA::Object_var obj = gen->SObjectToObject( sobj );
121 GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( obj );
122 return gen->GeomObjectToShape( geom.in() );
127 return TopoDS_Shape();
130 //================================================================================
132 * \brief Store the CORBA object in the stream
133 * \param obj - object to store
134 * \param stream - the stream
136 //================================================================================
138 void StdMeshers_ObjRefUlils::SaveToStream( CORBA::Object_ptr obj,
139 std::ostream & stream)
142 if ( !CORBA::is_nil( obj ) ) {
143 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
144 stream << " " << gen->GetObjectId( obj );
149 stream << " NULL_OBJECT ";
152 //=======================================================================
153 //function : SaveToStream
154 //purpose : Store the study entry of object in the stream
155 //=======================================================================
157 void StdMeshers_ObjRefUlils::SaveToStream( const std::string& studyEntry,
158 std::ostream & stream)
160 if ( studyEntry.find_first_not_of( ' ' ) == std::string::npos )
161 stream << " NULL_OBJECT ";
163 stream << " " << studyEntry;
166 //=======================================================================
167 //function : EntryToShape
168 //purpose : Return TopoDS_Shape by a study entry
169 //=======================================================================
171 TopoDS_Shape StdMeshers_ObjRefUlils::EntryToShape(const std::string theEntry)
175 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) {
176 SALOMEDS::SObject_wrap sobj = SMESH_Gen_i::getStudyServant()->FindObjectID( theEntry.c_str() );
177 CORBA::Object_var obj = gen->SObjectToObject( sobj );
178 GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( obj );
179 shape = gen->GeomObjectToShape( geom.in() );