mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-01-13 10:10:33 +05:00
debug exporting MED files, adding meshes, different MED versions...
This commit is contained in:
parent
49ff23c94f
commit
c58add1af5
@ -422,10 +422,15 @@ module SMESH
|
|||||||
string GetMEDVersion(in string theFileName);
|
string GetMEDVersion(in string theFileName);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Check compatibility of file with MED format being used.
|
* \brief Check compatibility of file with MED format being used, for read only.
|
||||||
*/
|
*/
|
||||||
boolean CheckCompatibility(in string theFileName);
|
boolean CheckCompatibility(in string theFileName);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Check compatibility of file with MED format being used, for append on write.
|
||||||
|
*/
|
||||||
|
boolean CheckWriteCompatibility(in string theFileName);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Get names of meshes defined in file with the specified name.
|
* \brief Get names of meshes defined in file with the specified name.
|
||||||
*/
|
*/
|
||||||
|
@ -35,6 +35,7 @@ extern "C"
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#include <utilities.h>
|
||||||
|
|
||||||
namespace MED
|
namespace MED
|
||||||
{
|
{
|
||||||
@ -47,22 +48,24 @@ namespace MED
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckCompatibility(const std::string& fileName)
|
bool CheckCompatibility(const std::string& fileName, bool isForAppend)
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
// check that file is accessible
|
// check that file is accessible
|
||||||
if ( exists(fileName) ) {
|
if ( exists(fileName) ) {
|
||||||
// check HDF5 && MED compatibility
|
// check HDF5 && MED compatibility
|
||||||
med_bool hdfok, medok;
|
med_bool hdfok, medok;
|
||||||
MEDfileCompatibility(fileName.c_str(), &hdfok, &medok);
|
med_err r0 = MEDfileCompatibility(fileName.c_str(), &hdfok, &medok);
|
||||||
if ( hdfok && medok ) {
|
//MESSAGE(r0 << " " << hdfok << " " << medok);
|
||||||
|
if ( r0==0 && hdfok && medok ) {
|
||||||
med_idt aFid = MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
|
med_idt aFid = MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
|
||||||
if (aFid >= 0) {
|
if (aFid >= 0) {
|
||||||
med_int major, minor, release;
|
med_int major, minor, release;
|
||||||
med_err ret = MEDfileNumVersionRd(aFid, &major, &minor, &release);
|
med_err ret = MEDfileNumVersionRd(aFid, &major, &minor, &release);
|
||||||
|
//MESSAGE(ret << " " << major << "." << minor << "." << release);
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
int version = 100*major + minor;
|
bool isReadOnly = !isForAppend;
|
||||||
if (version >= 202)
|
if ( isReadOnly || ((major == MED_MAJOR_NUM) && (minor == MED_MINOR_NUM)))
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +116,7 @@ namespace MED
|
|||||||
|
|
||||||
PWrapper CrWrapperW(const std::string& fileName, int theMinor)
|
PWrapper CrWrapperW(const std::string& fileName, int theMinor)
|
||||||
{
|
{
|
||||||
if (!CheckCompatibility(fileName))
|
if (!CheckCompatibility(fileName, true))
|
||||||
remove(fileName.c_str());
|
remove(fileName.c_str());
|
||||||
return new MED::TWrapper(fileName, theMinor);
|
return new MED::TWrapper(fileName, theMinor);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ namespace MED
|
|||||||
bool GetMEDVersion( const std::string&, int&, int&, int& );
|
bool GetMEDVersion( const std::string&, int&, int&, int& );
|
||||||
|
|
||||||
MEDWRAPPER_EXPORT
|
MEDWRAPPER_EXPORT
|
||||||
bool CheckCompatibility( const std::string& );
|
bool CheckCompatibility( const std::string& , bool isForAppend=false);
|
||||||
|
|
||||||
MEDWRAPPER_EXPORT
|
MEDWRAPPER_EXPORT
|
||||||
PWrapper CrWrapperR( const std::string& );
|
PWrapper CrWrapperR( const std::string& );
|
||||||
|
@ -655,7 +655,8 @@ namespace
|
|||||||
// Get parameters of export operation
|
// Get parameters of export operation
|
||||||
|
|
||||||
QString aFilename;
|
QString aFilename;
|
||||||
int aFormat =-1; // for MED minor versions
|
int aFormat =-1; // for MED minor versions
|
||||||
|
bool isOkToWrite = true; // to check MED file version compatibility before adding a mesh in an existing file
|
||||||
|
|
||||||
// Init the parameters with the default values
|
// Init the parameters with the default values
|
||||||
bool aIsASCII_STL = true;
|
bool aIsASCII_STL = true;
|
||||||
@ -708,7 +709,7 @@ namespace
|
|||||||
|
|
||||||
if ( fd->exec() )
|
if ( fd->exec() )
|
||||||
aFilename = fd->selectedFile();
|
aFilename = fd->selectedFile();
|
||||||
toOverwrite = fv->isOverwrite();
|
toOverwrite = fv->isOverwrite(aFilename);
|
||||||
toCreateGroups = fd->IsChecked(0);
|
toCreateGroups = fd->IsChecked(0);
|
||||||
SMESHGUI::resourceMgr()->setValue("SMESH", theByTypeResource, toCreateGroups );
|
SMESHGUI::resourceMgr()->setValue("SMESH", theByTypeResource, toCreateGroups );
|
||||||
|
|
||||||
@ -747,19 +748,19 @@ namespace
|
|||||||
if ( isMED ) {
|
if ( isMED ) {
|
||||||
//filters << QObject::tr( "MED_FILES_FILTER" ) + " (*.med)";
|
//filters << QObject::tr( "MED_FILES_FILTER" ) + " (*.med)";
|
||||||
QString vmed (aMesh->GetVersionString(-1, 2));
|
QString vmed (aMesh->GetVersionString(-1, 2));
|
||||||
MESSAGE("MED version: " << vmed.toStdString());
|
//MESSAGE("MED version: " << vmed.toStdString());
|
||||||
int minor = vmed.split(".").last().toInt();
|
int minor = vmed.split(".").last().toInt();
|
||||||
MESSAGE("MED version minor: "<< minor);
|
//MESSAGE("MED version minor: "<< minor);
|
||||||
minor +=3; // TODO test, to remove
|
//minor +=3; // TODO remove: test multiple minor
|
||||||
aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vmed ) + " (*.med)", minor );
|
aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vmed ) + " (*.med)", minor );
|
||||||
for (int ii=0; ii<minor; ii++)
|
for (int ii=0; ii<minor; ii++)
|
||||||
{
|
{
|
||||||
QString vs = aMesh->GetVersionString(ii, 2);
|
QString vs = aMesh->GetVersionString(ii, 2);
|
||||||
std::ostringstream vss; // TODO test, to remove
|
//std::ostringstream vss; // TODO remove: test multiple minor
|
||||||
vss << "4."; //
|
//vss << "4."; // TODO remove: test multiple minor
|
||||||
vss << ii; //
|
//vss << ii; // TODO remove: test multiple minor
|
||||||
vs = vss.str().c_str(); // TODO test, to remove
|
//vs = vss.str().c_str(); // TODO remove: test multiple minor
|
||||||
MESSAGE("MED version: " << vs.toStdString());
|
//MESSAGE("MED version: " << vs.toStdString());
|
||||||
aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vs ) + " (*.med)", ii);
|
aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vs ) + " (*.med)", ii);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -810,6 +811,8 @@ namespace
|
|||||||
|
|
||||||
bool is_ok = false;
|
bool is_ok = false;
|
||||||
while (!is_ok) {
|
while (!is_ok) {
|
||||||
|
//MESSAGE("******* Loop on file dialog ***********");
|
||||||
|
isOkToWrite =true;
|
||||||
if ( fd->exec() )
|
if ( fd->exec() )
|
||||||
aFilename = fd->selectedFile();
|
aFilename = fd->selectedFile();
|
||||||
else {
|
else {
|
||||||
@ -817,13 +820,13 @@ namespace
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
aFormat = aFilterMap[fd->selectedNameFilter()];
|
aFormat = aFilterMap[fd->selectedNameFilter()];
|
||||||
MESSAGE("selected minor: " << aFormat);
|
//MESSAGE("selected minor: " << aFormat << " file: " << aFilename.toUtf8().constData());
|
||||||
toOverwrite = fv->isOverwrite();
|
toOverwrite = fv->isOverwrite(aFilename);
|
||||||
is_ok = true;
|
is_ok = true;
|
||||||
if ( !aFilename.isEmpty() ) {
|
if ( !aFilename.isEmpty() ) {
|
||||||
if( !toOverwrite ) {
|
if( !toOverwrite ) {
|
||||||
// can't append to an existing using other format
|
// can't append to an existing using other format
|
||||||
bool isVersionOk = SMESHGUI::GetSMESHGen()->CheckCompatibility( aFilename.toUtf8().constData() );
|
bool isVersionOk = SMESHGUI::GetSMESHGen()->CheckWriteCompatibility( aFilename.toUtf8().constData() );
|
||||||
if ( !isVersionOk ) {
|
if ( !isVersionOk ) {
|
||||||
int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
|
int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
|
||||||
QObject::tr("SMESH_WRN_WARNING"),
|
QObject::tr("SMESH_WRN_WARNING"),
|
||||||
@ -831,11 +834,17 @@ namespace
|
|||||||
QObject::tr("SMESH_BUT_YES"),
|
QObject::tr("SMESH_BUT_YES"),
|
||||||
QObject::tr("SMESH_BUT_NO"), 0, 1);
|
QObject::tr("SMESH_BUT_NO"), 0, 1);
|
||||||
if (aRet == 0)
|
if (aRet == 0)
|
||||||
toOverwrite = true;
|
{
|
||||||
|
toOverwrite = true;
|
||||||
|
MESSAGE("incompatible MED file version for add, overwrite accepted");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
is_ok = false;
|
{
|
||||||
|
isOkToWrite = false;
|
||||||
|
is_ok = false;
|
||||||
|
MESSAGE("incompatible MED file version for add, overwrite refused");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList aMeshNamesCollisionList;
|
QStringList aMeshNamesCollisionList;
|
||||||
SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toUtf8().constData() );
|
SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toUtf8().constData() );
|
||||||
for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
|
for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
|
||||||
@ -848,7 +857,8 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( !aMeshNamesCollisionList.isEmpty() ) {
|
if( !aMeshNamesCollisionList.isEmpty() ) {
|
||||||
|
isOkToWrite = false;
|
||||||
QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
|
QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
|
||||||
int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
|
int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
|
||||||
QObject::tr("SMESH_WRN_WARNING"),
|
QObject::tr("SMESH_WRN_WARNING"),
|
||||||
@ -856,14 +866,18 @@ namespace
|
|||||||
QObject::tr("SMESH_BUT_YES"),
|
QObject::tr("SMESH_BUT_YES"),
|
||||||
QObject::tr("SMESH_BUT_NO"),
|
QObject::tr("SMESH_BUT_NO"),
|
||||||
QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
|
QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
|
||||||
if (aRet == 0)
|
//MESSAGE("answer collision name " << aRet);
|
||||||
|
if (aRet == 0) {
|
||||||
toOverwrite = true;
|
toOverwrite = true;
|
||||||
|
isOkToWrite = true;
|
||||||
|
}
|
||||||
else if (aRet == 2)
|
else if (aRet == 2)
|
||||||
is_ok = false;
|
is_ok = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//MESSAGE(" ****** end of file dialog loop")
|
||||||
toCreateGroups = fd->IsChecked(0);
|
toCreateGroups = fd->IsChecked(0);
|
||||||
toFindOutDim = fd->IsChecked(1);
|
toFindOutDim = fd->IsChecked(1);
|
||||||
fieldSelWdg->GetSelectedFields();
|
fieldSelWdg->GetSelectedFields();
|
||||||
@ -898,8 +912,9 @@ namespace
|
|||||||
// if ( SMESHGUI::automaticUpdate() )
|
// if ( SMESHGUI::automaticUpdate() )
|
||||||
// SMESH::UpdateView();
|
// SMESH::UpdateView();
|
||||||
// }
|
// }
|
||||||
if ( isMED )
|
if ( isMED && isOkToWrite)
|
||||||
{
|
{
|
||||||
|
//MESSAGE("OK to write MED file "<< aFilename.toUtf8().constData());
|
||||||
aMeshIter = aMeshList.begin();
|
aMeshIter = aMeshList.begin();
|
||||||
for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
|
for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
|
||||||
{
|
{
|
||||||
|
@ -72,3 +72,10 @@ bool SMESHGUI_FileValidator::canSave( const QString& fileName, bool checkPermiss
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SMESHGUI_FileValidator::isOverwrite( const QString& fileName) const
|
||||||
|
{
|
||||||
|
if ( QFile::exists( fileName ) )
|
||||||
|
return myIsOverwrite;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
|
|
||||||
virtual bool canSave( const QString&, bool = true );
|
virtual bool canSave( const QString&, bool = true );
|
||||||
|
|
||||||
bool isOverwrite() const { return myIsOverwrite; }
|
bool isOverwrite( const QString& fileName) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool myIsOverwrite;
|
bool myIsOverwrite;
|
||||||
|
@ -2959,7 +2959,7 @@ char* SMESH_Gen_i::GetMEDVersion(const char* theFileName)
|
|||||||
/*!
|
/*!
|
||||||
* SMESH_Gen_i::CheckCompatibility
|
* SMESH_Gen_i::CheckCompatibility
|
||||||
*
|
*
|
||||||
* Check compatibility of file with MED format being used.
|
* Check compatibility of file with MED format being used, read only.
|
||||||
*/
|
*/
|
||||||
//================================================================================
|
//================================================================================
|
||||||
CORBA::Boolean SMESH_Gen_i::CheckCompatibility(const char* theFileName)
|
CORBA::Boolean SMESH_Gen_i::CheckCompatibility(const char* theFileName)
|
||||||
@ -2967,6 +2967,18 @@ CORBA::Boolean SMESH_Gen_i::CheckCompatibility(const char* theFileName)
|
|||||||
return MED::CheckCompatibility( theFileName );
|
return MED::CheckCompatibility( theFileName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//================================================================================
|
||||||
|
/*!
|
||||||
|
* SMESH_Gen_i::CheckWriteCompatibility
|
||||||
|
*
|
||||||
|
* Check compatibility of file with MED format being used, for append on write.
|
||||||
|
*/
|
||||||
|
//================================================================================
|
||||||
|
CORBA::Boolean SMESH_Gen_i::CheckWriteCompatibility(const char* theFileName)
|
||||||
|
{
|
||||||
|
return MED::CheckCompatibility( theFileName, true );
|
||||||
|
}
|
||||||
|
|
||||||
//================================================================================
|
//================================================================================
|
||||||
/*!
|
/*!
|
||||||
* SMESH_Gen_i::GetMeshNames
|
* SMESH_Gen_i::GetMeshNames
|
||||||
@ -2976,10 +2988,12 @@ CORBA::Boolean SMESH_Gen_i::CheckCompatibility(const char* theFileName)
|
|||||||
//================================================================================
|
//================================================================================
|
||||||
SMESH::string_array* SMESH_Gen_i::GetMeshNames(const char* theFileName)
|
SMESH::string_array* SMESH_Gen_i::GetMeshNames(const char* theFileName)
|
||||||
{
|
{
|
||||||
|
//MESSAGE("GetMeshNames " << theFileName);
|
||||||
SMESH::string_array_var aResult = new SMESH::string_array();
|
SMESH::string_array_var aResult = new SMESH::string_array();
|
||||||
MED::PWrapper aMed = MED::CrWrapperR( theFileName );
|
MED::PWrapper aMed = MED::CrWrapperR( theFileName );
|
||||||
MED::TErr anErr;
|
MED::TErr anErr;
|
||||||
MED::TInt aNbMeshes = aMed->GetNbMeshes( &anErr );
|
MED::TInt aNbMeshes = aMed->GetNbMeshes( &anErr );
|
||||||
|
//MESSAGE("---" << aNbMeshes);
|
||||||
if( anErr >= 0 ) {
|
if( anErr >= 0 ) {
|
||||||
aResult->length( aNbMeshes );
|
aResult->length( aNbMeshes );
|
||||||
for( MED::TInt i = 0; i < aNbMeshes; i++ ) {
|
for( MED::TInt i = 0; i < aNbMeshes; i++ ) {
|
||||||
|
@ -348,9 +348,12 @@ public:
|
|||||||
// Get MED version of the file by its name
|
// Get MED version of the file by its name
|
||||||
char* GetMEDVersion(const char* theFileName);
|
char* GetMEDVersion(const char* theFileName);
|
||||||
|
|
||||||
// Check compatibility of file with MED format being used.
|
// Check compatibility of file with MED format being used, read only.
|
||||||
CORBA::Boolean CheckCompatibility(const char* theFileName);
|
CORBA::Boolean CheckCompatibility(const char* theFileName);
|
||||||
|
|
||||||
|
// Check compatibility of file with MED format being used, for append on write.
|
||||||
|
CORBA::Boolean CheckWriteCompatibility(const char* theFileName);
|
||||||
|
|
||||||
// Get names of meshes defined in file with the specified name
|
// Get names of meshes defined in file with the specified name
|
||||||
SMESH::string_array* GetMeshNames(const char* theFileName);
|
SMESH::string_array* GetMeshNames(const char* theFileName);
|
||||||
|
|
||||||
|
@ -3005,7 +3005,7 @@ void SMESH_Mesh_i::ExportMED(const char* file,
|
|||||||
CORBA::Boolean autoDimension)
|
CORBA::Boolean autoDimension)
|
||||||
throw(SALOME::SALOME_Exception)
|
throw(SALOME::SALOME_Exception)
|
||||||
{
|
{
|
||||||
MESSAGE("MED minor version: "<< minor);
|
//MESSAGE("MED minor version: "<< minor);
|
||||||
SMESH_TRY;
|
SMESH_TRY;
|
||||||
if ( _preMeshInfo )
|
if ( _preMeshInfo )
|
||||||
_preMeshInfo->FullLoadFromFile();
|
_preMeshInfo->FullLoadFromFile();
|
||||||
@ -3136,7 +3136,7 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
|
|||||||
const char* geomAssocFields)
|
const char* geomAssocFields)
|
||||||
throw (SALOME::SALOME_Exception)
|
throw (SALOME::SALOME_Exception)
|
||||||
{
|
{
|
||||||
MESSAGE("MED minor version: "<< minor);
|
//MESSAGE("MED minor version: "<< minor);
|
||||||
SMESH_TRY;
|
SMESH_TRY;
|
||||||
if ( _preMeshInfo )
|
if ( _preMeshInfo )
|
||||||
_preMeshInfo->FullLoadFromFile();
|
_preMeshInfo->FullLoadFromFile();
|
||||||
|
Loading…
Reference in New Issue
Block a user