From fe4d201b78c5a39c2c1186498a481323d537e928 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 18 Jul 2018 18:15:22 +0300 Subject: [PATCH] IPAL54414: MED file info is not persistent --- src/SMESHGUI/SMESHGUI_FileInfoDlg.cxx | 31 +++++++----- src/SMESHGUI/SMESH_msg_en.ts | 2 +- src/SMESH_I/SMESH_Gen_i.cxx | 24 +++++++++- src/SMESH_I/SMESH_Mesh_i.cxx | 69 +++++++++++++++++++++++++++ src/SMESH_I/SMESH_Mesh_i.hxx | 6 +++ 5 files changed, 119 insertions(+), 13 deletions(-) diff --git a/src/SMESHGUI/SMESHGUI_FileInfoDlg.cxx b/src/SMESHGUI/SMESHGUI_FileInfoDlg.cxx index b7f1b0dde..e12e5829c 100644 --- a/src/SMESHGUI/SMESHGUI_FileInfoDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_FileInfoDlg.cxx @@ -32,40 +32,49 @@ SMESHGUI_FileInfoDlg::SMESHGUI_FileInfoDlg( QWidget* parent, SMESH::MedFileInfo* { setWindowTitle( tr( "CAPTION" ) ); setSizeGripEnabled( true ); - + QLineEdit* fname = new QLineEdit( mainFrame() ); fname->setReadOnly( true ); QLineEdit* fsize = new QLineEdit( mainFrame() ); fsize->setReadOnly( true ); QLineEdit* medversion = new QLineEdit( mainFrame() ); medversion->setReadOnly( true ); + QLabel* medversionlabel = new QLabel( tr( "MED_VERSION" ), mainFrame() ); fname->setMinimumWidth( 300 ); - + QGridLayout* lay = new QGridLayout( mainFrame() ); lay->setMargin( 5 ); lay->setSpacing( 5 ); lay->addWidget( new QLabel( tr( "FILE_NAME" ), mainFrame() ), 0, 0 ); lay->addWidget( fname, 0, 1 ); lay->addWidget( new QLabel( tr( "FILE_SIZE" ), mainFrame() ), 1, 0 ); 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 ); fname->setText( (char*)inf->fileName ); fname->home( false ); fsize->setText( QString::number( inf->fileSize ) ); - QString version; - if( inf->major>=0 ) + if ( fname->text().endsWith("med")) { - version = QString::number( inf->major ); - if( inf->minor>=0 ) + QString version; + if( inf->major>=0 ) { - version += "." + QString::number( inf->minor ); - if( inf->release>=0 ) - version += "." + QString::number( inf->release ); + version = QString::number( inf->major ); + if( inf->minor>=0 ) + { + 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() diff --git a/src/SMESHGUI/SMESH_msg_en.ts b/src/SMESHGUI/SMESH_msg_en.ts index 8af2e2d7c..f8c8ba3d2 100644 --- a/src/SMESHGUI/SMESH_msg_en.ts +++ b/src/SMESHGUI/SMESH_msg_en.ts @@ -4321,7 +4321,7 @@ Use Display Entity menu command to show them. MEN_FILE_INFO - MED File Information + File Information SMESH_WRN_NO_APPROPRIATE_SELECTION diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index f01646e74..f3d2d4324 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -3075,7 +3075,6 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, myMesh->Load(); // load from study file if not yet done TPythonDump pd; // not to dump GetGroups() SMESH::ListOfGroups_var groups = myMesh->GetGroups(); - pd << ""; // to avoid optimizing pd out for ( CORBA::ULong i = 0; i < groups->length(); ++i ) { SMESH_GroupBase_i* grImpl = SMESH::DownCast( 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 SALOMEDS::SObject_wrap myHypBranch; found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch.inout() ); @@ -4353,6 +4363,18 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, myNewMeshImpl->GetImpl().GetMeshDS()->SetPersistentId( *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 diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index c7c3f54eb..94b83e290 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -445,6 +445,13 @@ SMESH::DriverMED_ReadStatus SMESH_Mesh_i::ImportCGNSFile( const char* theFileNa 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); } @@ -466,6 +473,13 @@ int SMESH_Mesh_i::ImportUNVFile( const char* theFileName ) 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 ); return 1; @@ -490,6 +504,12 @@ int SMESH_Mesh_i::ImportSTLFile( const char* theFileName ) SALOMEDS::SObject_wrap meshSO = _gen_i->ObjectToSObject( _this() ); _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 ); @@ -528,6 +548,13 @@ SMESH::ComputeError* SMESH_Mesh_i::ImportGMFFile( const char* theFileName, 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 ); #undef SMESH_CAUGHT #define SMESH_CAUGHT @@ -5050,6 +5077,48 @@ SMESH::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo() 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 diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 9fdde438c..3ce8ae711 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -594,6 +594,12 @@ public: */ 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 */ -- 2.39.2