fix SWP12968

Implementation of methods SMESH_Gen_i::LoadASCII and SMESH_Gen_i::SaveASCII.
This commit is contained in:
abd 2006-08-29 05:41:25 +00:00
parent 7a3868cfc4
commit 961309c8a4

View File

@ -1214,7 +1214,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
{ {
INFOS( "SMESH_Gen_i::Save" ); INFOS( "SMESH_Gen_i::Save" );
// ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() ) // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
// san -- in case <myCurrentStudy> differs from theComponent's study, // san -- in case <myCurrentStudy> differs from theComponent's study,
// use that of the component // use that of the component
if ( myCurrentStudy->_is_nil() || if ( myCurrentStudy->_is_nil() ||
@ -1305,9 +1305,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
if ( myImpl ) { if ( myImpl ) {
string hypname = string( myHyp->GetName() ); string hypname = string( myHyp->GetName() );
string libname = string( myHyp->GetLibName() ); string libname = string( myHyp->GetLibName() );
// BUG SWP13062 // BUG SWP13062
// Needs for save crossplatform libname, i.e. parth of name ( ".dll" for // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
// WNT and ".so" for X-system) must be deleted // WNT and ".so" for X-system) must be deleted
int libname_len = libname.length(); int libname_len = libname.length();
#ifdef WNT #ifdef WNT
if( libname_len > 4 ) if( libname_len > 4 )
@ -1370,9 +1370,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
if ( myImpl ) { if ( myImpl ) {
string hypname = string( myHyp->GetName() ); string hypname = string( myHyp->GetName() );
string libname = string( myHyp->GetLibName() ); string libname = string( myHyp->GetLibName() );
// BUG SWP13062 // BUG SWP13062
// Needs for save crossplatform libname, i.e. parth of name ( ".dll" for // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
// WNT and ".so" for X-system) must be deleted // WNT and ".so" for X-system) must be deleted
int libname_len = libname.length(); int libname_len = libname.length();
#ifdef WNT #ifdef WNT
if( libname_len > 4 ) if( libname_len > 4 )
@ -1996,7 +1996,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
/*! /*!
* SMESH_Gen_i::SaveASCII * SMESH_Gen_i::SaveASCII
* *
* Save SMESH module's data in ASCII format (not implemented yet) * Save SMESH module's data in ASCII format
*/ */
//============================================================================= //=============================================================================
@ -2005,7 +2005,19 @@ SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent
bool isMultiFile ) { bool isMultiFile ) {
if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" ); if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile ); SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
return aStreamFile._retn();
//after usual saving needs to encipher binary to text string
//Any binary symbol will be represent as "|xx" () hexadecimal format number
int size = aStreamFile.in().length();
_CORBA_Octet* buffer = new _CORBA_Octet[size*3+1];
for ( int i = 0; i < size; i++ )
sprintf( (char*)&(buffer[i*3]), "|%02x", (char*)(aStreamFile[i]) );
buffer[size * 3] = '\0';
SALOMEDS::TMPFile_var anAsciiStreamFile = new SALOMEDS::TMPFile(size*3, size*3, buffer, 1);
return anAsciiStreamFile._retn();
} }
//============================================================================= //=============================================================================
@ -2851,7 +2863,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
/*! /*!
* SMESH_Gen_i::LoadASCII * SMESH_Gen_i::LoadASCII
* *
* Load SMESH module's data in ASCII format (not implemented yet) * Load SMESH module's data in ASCII format
*/ */
//============================================================================= //=============================================================================
@ -2860,7 +2872,29 @@ bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
const char* theURL, const char* theURL,
bool isMultiFile ) { bool isMultiFile ) {
if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" ); if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
return Load( theComponent, theStream, theURL, isMultiFile );
//before call main ::Load method it's need for decipher text format to
//binary ( "|xx" => x' )
int size = theStream.length();
if ( int((size / 3 )*3) != size ) //error size of buffer
return false;
int real_size = int(size / 3);
_CORBA_Octet* buffer = new _CORBA_Octet[real_size];
char tmp[3];
tmp[2]='\0';
int c = -1;
for ( int i = 0; i < real_size; i++ )
{
memcpy( &(tmp[0]), &(theStream[i*3+1]), 2 );
sscanf( tmp, "%x", &c );
sprintf( (char*)&(buffer[i]), "%c", (char)c );
}
SALOMEDS::TMPFile_var aRealStreamFile = new SALOMEDS::TMPFile(real_size, real_size, buffer, 1);
return Load( theComponent, *(aRealStreamFile._retn()), theURL, isMultiFile );
} }
//============================================================================= //=============================================================================