diff --git a/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx b/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx index c184c76ed..3667a852a 100644 --- a/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx +++ b/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx @@ -31,6 +31,33 @@ using namespace std; +//======================================================================= +//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 +131,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; +} diff --git a/src/StdMeshers_I/StdMeshers_ObjRefUlils.hxx b/src/StdMeshers_I/StdMeshers_ObjRefUlils.hxx index 0b51dc4a8..8ab879d60 100644 --- a/src/StdMeshers_I/StdMeshers_ObjRefUlils.hxx +++ b/src/StdMeshers_I/StdMeshers_ObjRefUlils.hxx @@ -65,6 +65,12 @@ public: return TopoDS_Shape(); } + /*! + * \brief Return GEOM Object by its sytudy entry or TopoDS_Shape + */ + static GEOM::GEOM_Object_ptr EntryOrShapeToGeomObject (const std::string& theEntry, + const TopoDS_Shape& theShape); + /*! * \brief Store the shape in the stream * \param theShape - shape to store @@ -77,14 +83,14 @@ public: * \param stream - the stream * \retval TopoDS_Shape - resulting shape */ - static TopoDS_Shape LoadFromStream( std::istream & stream); + static TopoDS_Shape LoadFromStream( std::istream & stream ); /*! * \brief Store the CORBA object in the stream * \param obj - object to store * \param stream - the stream */ - static void SaveToStream( CORBA::Object_ptr obj, std::ostream & stream); + static void SaveToStream( CORBA::Object_ptr obj, std::ostream & stream ); /*! * \brief Retrieve a CORBA object from the stream @@ -107,6 +113,14 @@ public: } return TInterface::_nil(); } + + /*! + * \brief Store the study entry of object in the stream + * \param studyEntry - the study entry + * \param stream - the stream + */ + static void SaveToStream( const std::string& studyEntry, std::ostream & stream); + }; #endif