X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FStdMeshers_I%2FStdMeshers_ObjRefUlils.cxx;h=910d0aaa870d886314d0a6cd276ee3d0405a7ff7;hp=c184c76edb521f57e65becc4b4a9cebf5c0e2c37;hb=d4a710ce52f6e76786a7b3845e2f7975dc9a00b1;hpb=2c607013a23bd4e7ba07e72e0c04dee2c1209cff diff --git a/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx b/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx index c184c76ed..910d0aaa8 100644 --- a/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx +++ b/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -31,6 +31,47 @@ using namespace std; +//======================================================================= +//function : GeomObjectToEntry +//purpose : Return study entry of GEOM Object +//======================================================================= + +std::string StdMeshers_ObjRefUlils::GeomObjectToEntry(GEOM::GEOM_Object_ptr& theGeomObject) +{ + if ( CORBA::is_nil( theGeomObject )) + return "NULL_OBJECT"; + + CORBA::String_var entry = theGeomObject->GetStudyEntry(); + return entry.in(); +} + +//======================================================================= +//function : EntryOrShapeToGeomObject +//purpose : Return GEOM Object by its sytudy entry or TopoDS_Shape +//======================================================================= + +GEOM::GEOM_Object_ptr +StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject (const std::string& theEntry, + const TopoDS_Shape& theShape) +{ + GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_nil(); + + // try by entry + if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) { + SALOMEDS::Study_var study = gen->GetCurrentStudy(); + if ( ! theEntry.empty() && ! study->_is_nil() ) { + SALOMEDS::SObject_var sobj= study->FindObjectID( theEntry.c_str() ); + CORBA::Object_var obj = gen->SObjectToObject( sobj ); + geom = GEOM::GEOM_Object::_narrow( obj ); + } + } + // try by TopoDS_Shape + if ( geom->_is_nil() ) + geom = ShapeToGeomObject( theShape ); + + return geom._retn(); +} + //================================================================================ /*! * \brief Store the shape in the stream @@ -104,3 +145,17 @@ void StdMeshers_ObjRefUlils::SaveToStream( CORBA::Object_ptr obj, if ( ! ok ) stream << " NULL_OBJECT "; } + +//======================================================================= +//function : SaveToStream +//purpose : Store the study entry of object in the stream +//======================================================================= + +void StdMeshers_ObjRefUlils::SaveToStream( const std::string& studyEntry, + std::ostream & stream) +{ + if ( studyEntry.find_first_not_of( ' ' ) == std::string::npos ) + stream << " NULL_OBJECT "; + else + stream << " " << studyEntry; +}