IPAL54414: MED file info is not persistent

This commit is contained in:
eap 2018-07-18 18:15:22 +03:00
parent b4ddd97db8
commit fe4d201b78
5 changed files with 119 additions and 13 deletions

View File

@ -32,40 +32,49 @@ SMESHGUI_FileInfoDlg::SMESHGUI_FileInfoDlg( QWidget* parent, SMESH::MedFileInfo*
{ {
setWindowTitle( tr( "CAPTION" ) ); setWindowTitle( tr( "CAPTION" ) );
setSizeGripEnabled( true ); setSizeGripEnabled( true );
QLineEdit* fname = new QLineEdit( mainFrame() ); QLineEdit* fname = new QLineEdit( mainFrame() );
fname->setReadOnly( true ); fname->setReadOnly( true );
QLineEdit* fsize = new QLineEdit( mainFrame() ); QLineEdit* fsize = new QLineEdit( mainFrame() );
fsize->setReadOnly( true ); fsize->setReadOnly( true );
QLineEdit* medversion = new QLineEdit( mainFrame() ); QLineEdit* medversion = new QLineEdit( mainFrame() );
medversion->setReadOnly( true ); medversion->setReadOnly( true );
QLabel* medversionlabel = new QLabel( tr( "MED_VERSION" ), mainFrame() );
fname->setMinimumWidth( 300 ); fname->setMinimumWidth( 300 );
QGridLayout* lay = new QGridLayout( mainFrame() ); QGridLayout* lay = new QGridLayout( mainFrame() );
lay->setMargin( 5 ); lay->setSpacing( 5 ); lay->setMargin( 5 ); lay->setSpacing( 5 );
lay->addWidget( new QLabel( tr( "FILE_NAME" ), mainFrame() ), 0, 0 ); lay->addWidget( new QLabel( tr( "FILE_NAME" ), mainFrame() ), 0, 0 );
lay->addWidget( fname, 0, 1 ); lay->addWidget( fname, 0, 1 );
lay->addWidget( new QLabel( tr( "FILE_SIZE" ), mainFrame() ), 1, 0 ); lay->addWidget( new QLabel( tr( "FILE_SIZE" ), mainFrame() ), 1, 0 );
lay->addWidget( fsize, 1, 1 ); lay->addWidget( fsize, 1, 1 );
lay->addWidget( new QLabel( tr( "MED_VERSION" ), mainFrame() ), 2, 0 ); lay->addWidget( medversionlabel, 2, 0 );
lay->addWidget( medversion, 2, 1 ); lay->addWidget( medversion, 2, 1 );
fname->setText( (char*)inf->fileName ); fname->setText( (char*)inf->fileName );
fname->home( false ); fname->home( false );
fsize->setText( QString::number( inf->fileSize ) ); fsize->setText( QString::number( inf->fileSize ) );
QString version; if ( fname->text().endsWith("med"))
if( inf->major>=0 )
{ {
version = QString::number( inf->major ); QString version;
if( inf->minor>=0 ) if( inf->major>=0 )
{ {
version += "." + QString::number( inf->minor ); version = QString::number( inf->major );
if( inf->release>=0 ) if( inf->minor>=0 )
version += "." + QString::number( inf->release ); {
version += "." + QString::number( inf->minor );
if( inf->release>=0 )
version += "." + QString::number( inf->release );
}
} }
medversion->setText( version );
}
else
{
medversionlabel->hide();
medversion->hide();
} }
medversion->setText( version );
} }
SMESHGUI_FileInfoDlg::~SMESHGUI_FileInfoDlg() SMESHGUI_FileInfoDlg::~SMESHGUI_FileInfoDlg()

View File

@ -4321,7 +4321,7 @@ Use Display Entity menu command to show them.
</message> </message>
<message> <message>
<source>MEN_FILE_INFO</source> <source>MEN_FILE_INFO</source>
<translation>MED File Information</translation> <translation>File Information</translation>
</message> </message>
<message> <message>
<source>SMESH_WRN_NO_APPROPRIATE_SELECTION</source> <source>SMESH_WRN_NO_APPROPRIATE_SELECTION</source>

View File

@ -3075,7 +3075,6 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
myMesh->Load(); // load from study file if not yet done myMesh->Load(); // load from study file if not yet done
TPythonDump pd; // not to dump GetGroups() TPythonDump pd; // not to dump GetGroups()
SMESH::ListOfGroups_var groups = myMesh->GetGroups(); SMESH::ListOfGroups_var groups = myMesh->GetGroups();
pd << ""; // to avoid optimizing pd out
for ( CORBA::ULong i = 0; i < groups->length(); ++i ) for ( CORBA::ULong i = 0; i < groups->length(); ++i )
{ {
SMESH_GroupBase_i* grImpl = SMESH::DownCast<SMESH_GroupBase_i*>( groups[i]); SMESH_GroupBase_i* grImpl = SMESH::DownCast<SMESH_GroupBase_i*>( groups[i]);
@ -3329,6 +3328,17 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
} }
} }
// Store file info
std::string info = myImpl->FileInfoToString();
if ( !info.empty() )
{
aSize[ 0 ] = info.size();
aDataset = new HDFdataset( "file info", aTopGroup, HDF_STRING, aSize, 1 );
aDataset->CreateOnDisk();
aDataset->WriteOnDisk( (char*) info.data() );
aDataset->CloseOnDisk();
}
// write applied hypotheses if exist // write applied hypotheses if exist
SALOMEDS::SObject_wrap myHypBranch; SALOMEDS::SObject_wrap myHypBranch;
found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch.inout() ); found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch.inout() );
@ -4353,6 +4363,18 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
myNewMeshImpl->GetImpl().GetMeshDS()->SetPersistentId( *meshPersistentId ); myNewMeshImpl->GetImpl().GetMeshDS()->SetPersistentId( *meshPersistentId );
delete [] meshPersistentId; delete [] meshPersistentId;
} }
// Restore file info
if ( aTopGroup->ExistInternalObject( "file info" ))
{
aDataset = new HDFdataset( "file info", aTopGroup );
aDataset->OpenOnDisk();
size = aDataset->GetSize();
std::string info( size, ' ');
aDataset->ReadFromDisk( (char*) info.data() );
aDataset->CloseOnDisk();
myNewMeshImpl->FileInfoFromString( info );
}
} }
} }
} // reading MESHes } // reading MESHes

View File

@ -445,6 +445,13 @@ SMESH::DriverMED_ReadStatus SMESH_Mesh_i::ImportCGNSFile( const char* theFileNa
CreateGroupServants(); CreateGroupServants();
_medFileInfo = new SMESH::MedFileInfo();
_medFileInfo->fileName = theFileName;
_medFileInfo->major = 0;
_medFileInfo->minor = 0;
_medFileInfo->release = 0;
_medFileInfo->fileSize = SMESH_File( theFileName ).size();
return ConvertDriverMEDReadStatus(status); return ConvertDriverMEDReadStatus(status);
} }
@ -466,6 +473,13 @@ int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
CreateGroupServants(); CreateGroupServants();
_medFileInfo = new SMESH::MedFileInfo();
_medFileInfo->fileName = theFileName;
_medFileInfo->major = 0;
_medFileInfo->minor = 0;
_medFileInfo->release = 0;
_medFileInfo->fileSize = SMESH_File( theFileName ).size();
SMESH_CATCH( SMESH::throwCorbaException ); SMESH_CATCH( SMESH::throwCorbaException );
return 1; return 1;
@ -490,6 +504,12 @@ int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
SALOMEDS::SObject_wrap meshSO = _gen_i->ObjectToSObject( _this() ); SALOMEDS::SObject_wrap meshSO = _gen_i->ObjectToSObject( _this() );
_gen_i->SetName( meshSO, name.c_str() ); _gen_i->SetName( meshSO, name.c_str() );
} }
_medFileInfo = new SMESH::MedFileInfo();
_medFileInfo->fileName = theFileName;
_medFileInfo->major = 0;
_medFileInfo->minor = 0;
_medFileInfo->release = 0;
_medFileInfo->fileSize = SMESH_File( theFileName ).size();
SMESH_CATCH( SMESH::throwCorbaException ); SMESH_CATCH( SMESH::throwCorbaException );
@ -528,6 +548,13 @@ SMESH::ComputeError* SMESH_Mesh_i::ImportGMFFile( const char* theFileName,
error = _impl->GMFToMesh( theFileName, theMakeRequiredGroups ); error = _impl->GMFToMesh( theFileName, theMakeRequiredGroups );
_medFileInfo = new SMESH::MedFileInfo();
_medFileInfo->fileName = theFileName;
_medFileInfo->major = 0;
_medFileInfo->minor = 0;
_medFileInfo->release = 0;
_medFileInfo->fileSize = SMESH_File( theFileName ).size();
SMESH_CATCH( exceptionToComputeError ); SMESH_CATCH( exceptionToComputeError );
#undef SMESH_CAUGHT #undef SMESH_CAUGHT
#define SMESH_CAUGHT #define SMESH_CAUGHT
@ -5050,6 +5077,48 @@ SMESH::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
return res._retn(); return res._retn();
} }
//=======================================================================
//function : FileInfoToString
//purpose : Persistence of file info
//=======================================================================
std::string SMESH_Mesh_i::FileInfoToString()
{
std::string s;
if ( &_medFileInfo.in() && _medFileInfo->fileName[0] )
{
s = SMESH_Comment( _medFileInfo->fileSize )
<< " " << _medFileInfo->major
<< " " << _medFileInfo->minor
<< " " << _medFileInfo->release
<< " " << _medFileInfo->fileName;
}
return s;
}
//=======================================================================
//function : FileInfoFromString
//purpose : Persistence of file info
//=======================================================================
void SMESH_Mesh_i::FileInfoFromString(const std::string& info)
{
std::string size, major, minor, release, fileName;
std::istringstream is(info);
is >> size >> major >> minor >> release;
fileName = info.data() + ( size.size() + 1 +
major.size() + 1 +
minor.size() + 1 +
release.size()+ 1 );
_medFileInfo = new SMESH::MedFileInfo();
_medFileInfo->fileName = fileName.c_str();
_medFileInfo->fileSize = atoi( size.c_str() );
_medFileInfo->major = atoi( major.c_str() );
_medFileInfo->minor = atoi( minor.c_str() );
_medFileInfo->release = atoi( release.c_str() );
}
//============================================================================= //=============================================================================
/*! /*!
* \brief Pass names of mesh groups from study to mesh DS * \brief Pass names of mesh groups from study to mesh DS

View File

@ -594,6 +594,12 @@ public:
*/ */
virtual SMESH::MedFileInfo* GetMEDFileInfo(); virtual SMESH::MedFileInfo* GetMEDFileInfo();
/*!
* Persistence of file info
*/
std::string FileInfoToString();
void FileInfoFromString(const std::string& info);
/*! /*!
* Sets list of notebook variables used for Mesh operations separated by ":" symbol * Sets list of notebook variables used for Mesh operations separated by ":" symbol
*/ */