X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FStdMeshers_I%2FStdMeshers_ObjRefUlils.cxx;h=363e3132111ccc917d994780bed10ea36973f729;hp=53330557b72f55d0af148e60b5e69a4b2c0aa637;hb=0fc0831670e27a5611b941c52dc152fd63964515;hpb=0635c9fc80f67d1e5dc0e94ec85f487286a92070 diff --git a/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx b/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx index 53330557b..363e31321 100644 --- a/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx +++ b/src/StdMeshers_I/StdMeshers_ObjRefUlils.cxx @@ -1,35 +1,77 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2020 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 +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// SMESH SMESH : implementaion of SMESH idl descriptions + +// SMESH SMESH : implementation of SMESH idl descriptions // File : StdMeshers_ObjRefUlils.cxx // Created : Wed Oct 18 15:38:22 2006 // Author : Edward AGAPOV (eap) // #include "StdMeshers_ObjRefUlils.hxx" +#include #include 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()) { + if ( ! theEntry.empty() ) { + SALOMEDS::SObject_wrap sobj = SMESH_Gen_i::getStudyServant()->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 @@ -45,9 +87,10 @@ void StdMeshers_ObjRefUlils::SaveToStream( const TopoDS_Shape& theShape, ostream if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) { GEOM::GEOM_Object_var geom = gen->ShapeToGeomObject( theShape ); if ( ! geom->_is_nil() ) { - SALOMEDS::SObject_var sobj = gen->ObjectToSObject( gen->GetCurrentStudy(), geom ); + SALOMEDS::SObject_wrap sobj = gen->ObjectToSObject( geom ); if ( !sobj->_is_nil() ) { - stream << " " << sobj->GetID(); + CORBA::String_var entry = sobj->GetID(); + stream << " " << entry.in(); ok = true; } } @@ -65,20 +108,22 @@ void StdMeshers_ObjRefUlils::SaveToStream( const TopoDS_Shape& theShape, ostream */ //================================================================================ -TopoDS_Shape StdMeshers_ObjRefUlils::LoadFromStream( istream & stream) +TopoDS_Shape StdMeshers_ObjRefUlils::LoadFromStream( istream & stream, + std::string* entry) { - if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) { - SALOMEDS::Study_var study = gen->GetCurrentStudy(); - if ( ! study->_is_nil() ) { - string str; - if (stream >> str) { - SALOMEDS::SObject_var sobj= study->FindObjectID( str.c_str() ); - CORBA::Object_var obj = gen->SObjectToObject( sobj ); - GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( obj ); - return gen->GeomObjectToShape( geom.in() ); - } + string str; + if (stream >> str) { + if ( entry ) + * entry = str; + if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) { + SALOMEDS::SObject_wrap sobj = SMESH_Gen_i::getStudyServant()->FindObjectID( str.c_str() ); + CORBA::Object_var obj = gen->SObjectToObject( sobj ); + GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( obj ); + return gen->GeomObjectToShape( geom.in() ); } } + if ( entry ) + entry->clear(); return TopoDS_Shape(); } @@ -103,3 +148,35 @@ 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; +} + +//======================================================================= +//function : EntryToShape +//purpose : Return TopoDS_Shape by a study entry +//======================================================================= + +TopoDS_Shape StdMeshers_ObjRefUlils::EntryToShape(const std::string theEntry) +{ + TopoDS_Shape shape; + + if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen()) { + SALOMEDS::SObject_wrap sobj = SMESH_Gen_i::getStudyServant()->FindObjectID( theEntry.c_str() ); + CORBA::Object_var obj = gen->SObjectToObject( sobj ); + GEOM::GEOM_Object_var geom = GEOM::GEOM_Object::_narrow( obj ); + shape = gen->GeomObjectToShape( geom.in() ); + } + return shape; +}