From: Paul RASCLE Date: Wed, 10 Oct 2018 11:51:29 +0000 (+0200) Subject: Merge branch 'master' into pre/medCompatibility X-Git-Tag: V9_2_0a2~12 X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=commitdiff_plain;h=a63fc78c25199b018fae4f5b182e6a348be0abf2;hp=f2614ea1d552edc74c317ba7ff2840bcd33d92f2 Merge branch 'master' into pre/medCompatibility --- diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index 46f4a40b7..9daba34f4 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -622,10 +622,13 @@ module SMESH * the groups Group_On_All_Nodes, Group_On_All_Faces, ... ; * the typical use is auto_groups=false. * - overwrite : boolean parameter for overwriting/not overwriting the file, if it exists - * - minor : define the minor version of MED file format. + * - version : define the version of MED file format, coded with major and minor digits (release digit not used) + * for instance med 3.2.1 is coded 3*10+2 = 32, med 4.0.0 is coded 4*10+0 = 40. + * The rules of compatibility to write a mesh in an older version than the current version + * depend on the current version. For instance, with med 4.0 it is possible to write/append + * med files in 4.0.0 (default format) or 3.2.1 or 3.3.1 formats. * The minor must be between 0 and the current minor version of MED file library. - * If minor is equal to -1, the minor version is not changed (default). - * The major version cannot be changed. + * If version is equal to -1, the version is not changed (default). * - autoDimension : if @c true, a space dimension of a MED mesh can be either * - 1D if all mesh nodes lie on OX coordinate axis, or * - 2D if all mesh nodes lie on XOY coordinate plane, or @@ -634,7 +637,7 @@ module SMESH */ void ExportMED( in string fileName, in boolean auto_groups, - in long minor, + in long version, in boolean overwrite, in boolean autoDimension) raises (SALOME::SALOME_Exception); @@ -644,10 +647,13 @@ module SMESH * - meshPart : a part of mesh to store * - fileName : name of the MED file * - overwrite : boolean parameter for overwriting/not overwriting the file, if it exists - * - minor : define the minor version (y, where version is x.y.z) of MED file format. + * - version : define the version of MED file format, coded with major and minor digits (release digit not used) + * for instance med 3.2.1 is coded 3*10+2 = 32, med 4.0.0 is coded 4*10+0 = 40. + * The rules of compatibility to write a mesh in an older version than the current version + * depend on the current version. For instance, with med 4.0 it is possible to write/append + * med files in 4.0.0 (default format) or 3.2.1 or 3.3.1 formats. * The minor must be between 0 and the current minor version of MED file library. - * If minor is equal to -1, the minor version is not changed (default). - * The major version (x, where version is x.y.z) cannot be changed. + * If version is equal to -1, the version is not changed (default). * - autoDimension : if @c True, a space dimension for export is defined by mesh * configuration; for example a planar mesh lying on XOY plane * will be exported as a mesh in 2D space. @@ -663,7 +669,7 @@ module SMESH void ExportPartToMED( in SMESH_IDSource meshPart, in string fileName, in boolean auto_groups, - in long minor, + in long version, in boolean overwrite, in boolean autoDimension, in GEOM::ListOfFields fields, @@ -680,7 +686,13 @@ module SMESH * Return string representation of a MED file version comprising nbDigits */ string GetVersionString(in long minor, in short nbDigits); - + + /*! + * Return the list of med versions compatibles for write/append, + * encoded in 10*major+minor (for instance, code for med 3.2.1 is 32) + */ + long_array GetMEDVersionsCompatibleForAppend(); + /*! * Export Mesh to different Formats * (UNV supported version is I-DEAS 10) diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx index a1902daac..63c69c992 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx @@ -61,12 +61,13 @@ DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh(): myDoGroupOfBalls(false), myAutoDimension(false), myAddODOnVertices(false), - myDoAllInGroups(false) + myDoAllInGroups(false), + myVersion(-1) {} -void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theMinor) +void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theVersion) { - myMinor = theMinor; + myVersion = theVersion; Driver_SMESHDS_Mesh::SetFile(theFileName); } @@ -74,7 +75,7 @@ void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theMi * MED version is either the latest available, or with an inferior minor, * to ensure backward compatibility on writing med files. */ -string DriverMED_W_SMESHDS_Mesh::GetVersionString(int theVersion, int theNbDigits) +string DriverMED_W_SMESHDS_Mesh::GetVersionString(int theMinor, int theNbDigits) { TInt majeur, mineur, release; majeur=MED_MAJOR_NUM; @@ -82,12 +83,12 @@ string DriverMED_W_SMESHDS_Mesh::GetVersionString(int theVersion, int theNbDigit release=MED_RELEASE_NUM; TInt imposedMineur = mineur; - if (theVersion < 0) + if (theMinor < 0) imposedMineur = mineur; - else if (theVersion > MED_MINOR_NUM) + else if (theMinor > MED_MINOR_NUM) imposedMineur = mineur; else - imposedMineur = theVersion; + imposedMineur = theMinor; ostringstream name; if ( theNbDigits > 0 ) @@ -457,7 +458,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() } } - MED::PWrapper myMed = CrWrapperW(myFile, myMinor); + MED::PWrapper myMed = CrWrapperW(myFile, myVersion); PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName); //MESSAGE("Add - aMeshName : "<GetName()); myMed->SetMeshInfo(aMeshInfo); diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h index 60261dd62..2b04c05f9 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h @@ -48,10 +48,10 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh DriverMED_W_SMESHDS_Mesh(); - void SetFile(const std::string& theFileName, int theMinor=-1); + void SetFile(const std::string& theFileName, int theVersion=-1); void SetAutoDimension(bool toFindOutDimension) { myAutoDimension = toFindOutDimension; } - static std::string GetVersionString(int theVersion, int theNbDigits=2); + static std::string GetVersionString(int theMinor, int theNbDigits=2); void AddGroupOfNodes(); void AddGroupOfEdges(); @@ -89,7 +89,7 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh bool myAutoDimension; bool myAddODOnVertices; bool myDoAllInGroups; - int myMinor; + int myVersion; }; #endif diff --git a/src/MEDWrapper/MED_Factory.cxx b/src/MEDWrapper/MED_Factory.cxx index dbe60c051..37c8d4f13 100644 --- a/src/MEDWrapper/MED_Factory.cxx +++ b/src/MEDWrapper/MED_Factory.cxx @@ -27,6 +27,7 @@ #include #include #include +#include #include extern "C" @@ -41,6 +42,49 @@ extern "C" #include #endif +// ------------------------------------------------------------------------------------------------------------------- +// --- MED file compatibility: write using a lower major version implies append on an empty file of the target version + +#define MED_MAJOR_EXPECTED 4 +#define MED_MINOR_EXPECTED 0 +#if MED_MAJOR_NUM != MED_MAJOR_EXPECTED + #error "MED major version does not correspond to the expected version, fix the minor and major compatibility values in CheckCompatibility method (MED_VERSIONS_APPEND_COMPATIBLE) and set the correct expected version" +#endif +#if MED_MINOR_NUM != MED_MINOR_EXPECTED + #error "MED minor version does not correspond to the expected version, fix the minor and major compatibility values in CheckCompatibility method (MED_VERSIONS_APPEND_COMPATIBLE) and set the correct expected version" +#endif +#define MED_VERSIONS_APPEND_COMPATIBLE {40, 32, 33} // --- 10*major + minor (the 3rd digit, release, is not used here, + // med uses always the latest available) + // --- The first in the list should be the default: current version +// --- empty med file content for the different MED versions with a different major. +// ==> correct accordingly CreateEmptyMEDFile method below! +#define EMPTY_FILE_32 {0x89,0x48,0x44,0x46,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0x0,0x0,0x8,0x8,0x0,0x4,0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe8,0x7,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x60,0x0,0x0,0x0,0x0,0x0,0x0,0x0,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,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0} +/* --- bytes hexa representation of MED file built in Python +f= open('vide_321.med', 'rb') +data=f.read() +ba=bytearray(data) +a="" +for i in ba: + a+=hex(i) + a+=',' +print a +*/ + +//! internal use: fileName and version must be checked before call +bool CreateEmptyMEDFile(const std::string& fileName, int version) +{ + MESSAGE("create an empty med file of the right version, for append " << version); + static const unsigned char empty_32[] = EMPTY_FILE_32; + static const unsigned char empty_33[] = EMPTY_FILE_33; + std::ofstream ofs(fileName); + if (version == 32) + ofs.write(reinterpret_cast(empty_32),sizeof(empty_32)); + else if (version == 33) + ofs.write(reinterpret_cast(empty_33),sizeof(empty_33)); + return true; +} +// ------------------------------------------------------------------------------------------------------------------- namespace MED { @@ -61,25 +105,51 @@ namespace MED #endif } + /*! + * Return the list of med versions compatibles for write/append, + * encoded in 10*major+minor (for instance, code for med 3.2.1 is 32) + */ + std::vector GetMEDVersionsAppendCompatible() + { + int mvok[] = MED_VERSIONS_APPEND_COMPATIBLE; + std::vector MEDVersionsOK(mvok, mvok + sizeof(mvok)/sizeof(int)); + return MEDVersionsOK; + } + + /*! + * \brief: Check read or write(append) Compatibility of a med file + * \param [in] : fileName - the file to read or to append to + * \param [in] : isforAppend - when true, check if the med file version is OK to append a mesh, + * when false, check if the med file is readable. + */ bool CheckCompatibility(const std::string& fileName, bool isForAppend) { bool ok = false; + int medVersionsOK[] = MED_VERSIONS_APPEND_COMPATIBLE; // check that file is accessible if ( exists(fileName) ) { // check HDF5 && MED compatibility med_bool hdfok, medok; med_err r0 = MEDfileCompatibility(fileName.c_str(), &hdfok, &medok); - //MESSAGE(r0 << " " << hdfok << " " << medok); + MESSAGE(r0 << " " << hdfok << " " << medok); if ( r0==0 && hdfok && medok ) { med_idt aFid = MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY); if (aFid >= 0) { med_int major, minor, release; med_err ret = MEDfileNumVersionRd(aFid, &major, &minor, &release); - //MESSAGE(ret << " " << major << "." << minor << "." << release); + MESSAGE(ret << " " << major << "." << minor << "." << release); if (ret >= 0) { bool isReadOnly = !isForAppend; - if ( isReadOnly || ((major == MED_MAJOR_NUM) && (minor == MED_MINOR_NUM))) + if (isReadOnly) ok = true; + else { + int medVersion = 10*major + minor; + for (int ii=0; ii < sizeof(medVersionsOK)/sizeof(int); ii++) + if (medVersionsOK[ii] == medVersion) { + ok =true; + break; + } + } } } MEDfileClose(aFid); @@ -127,10 +197,43 @@ namespace MED return new MED::TWrapper(fileName); } - PWrapper CrWrapperW(const std::string& fileName, int theMinor) + PWrapper CrWrapperW(const std::string& fileName, int theVersion) { + bool isCreated = false; if (!CheckCompatibility(fileName, true)) - remove(fileName.c_str()); - return new MED::TWrapper(fileName, theMinor); + { + remove(fileName.c_str()); + isCreated = true; + } + int minor = -1; + if (isCreated) + { + med_int wantedMajor = MED_MAJOR_NUM; + med_int wantedMinor = MED_MINOR_NUM; + if (theVersion > 0) + { + wantedMajor = theVersion/10; + wantedMinor = theVersion%10; + } + if (wantedMajor == MED_MAJOR_NUM) // the med file will be actually created + { + if (wantedMinor < MED_MINOR_NUM) + minor = wantedMinor; + } + else // an empty existing med file of the right version will be used for append + { + int medVersionsOK[] = MED_VERSIONS_APPEND_COMPATIBLE; + bool isVersionOK = false; + for (int ii=0; ii < sizeof(medVersionsOK)/sizeof(int); ii++) + if (medVersionsOK[ii] == theVersion) + { + isVersionOK =true; + break; + } + if (isVersionOK) // copy an empty existing med file of the right version, for append + CreateEmptyMEDFile(fileName, theVersion); + } + } + return new MED::TWrapper(fileName, minor); } } diff --git a/src/MEDWrapper/MED_Factory.hxx b/src/MEDWrapper/MED_Factory.hxx index fe5e0032c..84087d138 100644 --- a/src/MEDWrapper/MED_Factory.hxx +++ b/src/MEDWrapper/MED_Factory.hxx @@ -27,6 +27,7 @@ #include "MED_Wrapper.hxx" #include +#include namespace MED { @@ -39,11 +40,14 @@ namespace MED MEDWRAPPER_EXPORT bool CheckCompatibility( const std::string& , bool isForAppend=false); + MEDWRAPPER_EXPORT + std::vector GetMEDVersionsAppendCompatible(); + MEDWRAPPER_EXPORT PWrapper CrWrapperR( const std::string& ); MEDWRAPPER_EXPORT - PWrapper CrWrapperW( const std::string&, int theMinor=-1 ); + PWrapper CrWrapperW( const std::string&, int theVersion=-1 ); } #endif // MED_Factory_HeaderFile diff --git a/src/MEDWrapper/MED_Wrapper.hxx b/src/MEDWrapper/MED_Wrapper.hxx index 05b0496c2..159d45714 100644 --- a/src/MEDWrapper/MED_Wrapper.hxx +++ b/src/MEDWrapper/MED_Wrapper.hxx @@ -52,7 +52,7 @@ namespace MED TWrapper& operator=(const TWrapper&); public: - TWrapper(const std::string& theFileName, TInt theMinor=-1); + TWrapper(const std::string& theFileName, TInt theVersion=-1); virtual ~TWrapper(); diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 226800af2..4e7368ab6 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -1422,18 +1422,18 @@ bool SMESH_Mesh::HasDuplicatedGroupNamesMED() void SMESH_Mesh::ExportMED(const char * file, const char* theMeshName, bool theAutoGroups, - int theMinor, + int theVersion, const SMESHDS_Mesh* meshPart, bool theAutoDimension, bool theAddODOnVertices, bool theAllElemsToGroup) throw(SALOME_Exception) { - //MESSAGE("MED_VERSION:"<< theVersion); + MESSAGE("MED_VERSION:"<< theVersion); SMESH_TRY; DriverMED_W_SMESHDS_Mesh myWriter; - myWriter.SetFile ( file , theMinor); + myWriter.SetFile ( file , theVersion); myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS ); myWriter.SetAutoDimension( theAutoDimension ); myWriter.AddODOnVertices ( theAddODOnVertices ); diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx index dbe14fed8..59ad490b1 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -254,7 +254,7 @@ class SMESH_EXPORT SMESH_Mesh void ExportMED(const char * theFile, const char* theMeshName = NULL, bool theAutoGroups = true, - int TheMinor = -1, + int theVersion = -1, const SMESHDS_Mesh* theMeshPart = 0, bool theAutoDimension = false, bool theAddODOnVertices = false, diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 1225963f6..99ae22dd2 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -655,7 +655,7 @@ namespace // Get parameters of export operation QString aFilename; - int aFormat =-1; // for MED minor versions + int aFormat =-1; // for MED version used for write bool isOkToWrite = true; // to check MED file version compatibility before adding a mesh in an existing file // Init the parameters with the default values @@ -744,38 +744,39 @@ namespace } else if ( isMED || isSAUV ) // Export to MED or SAUV { + int defaultVersion = 0; QMap aFilterMap; if ( isMED ) { //filters << QObject::tr( "MED_FILES_FILTER" ) + " (*.med)"; - QString vmed (aMesh->GetVersionString(-1, 2)); + //QString vmed (aMesh->GetVersionString(-1, 2)); //MESSAGE("MED version: " << vmed.toStdString()); - int minor = vmed.split(".").last().toInt(); - //MESSAGE("MED version minor: "<< minor); - //minor +=3; // TODO remove: test multiple minor - aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vmed ) + " (*.med)", minor ); - for (int ii=0; iiGetMEDVersionsCompatibleForAppend(); + for ( int i = 0; i < mvok->length(); ++i ) // i=0 must correspond to the current version to set the default filter on it { - QString vs = aMesh->GetVersionString(ii, 2); - //std::ostringstream vss; // TODO remove: test multiple minor - //vss << "4."; // TODO remove: test multiple minor - //vss << ii; // TODO remove: test multiple minor - //vs = vss.str().c_str(); // TODO remove: test multiple minor - //MESSAGE("MED version: " << vs.toStdString()); - aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vs ) + " (*.med)", ii); + int versionInt = mvok[i]; + if (i == 0) + defaultVersion = versionInt; + std::ostringstream vss; + vss << versionInt/10; + vss << "."; + vss << versionInt%10; + QString vs = vss.str().c_str(); + MESSAGE("MED version: " << vs.toStdString()); + aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vs ) + " (*.med)", versionInt); } } else { // isSAUV aFilterMap.insert("All files (*)", -1 ); - aFilterMap.insert("SAUV files (*.sauv)", -1 ); + aFilterMap.insert("SAUV files (*.sauv)", defaultVersion ); // 0 = default filter (defaultVersion) aFilterMap.insert("SAUV files (*.sauve)", -1 ); } - + MESSAGE("default version="<< defaultVersion); QStringList filters; - QString aDefaultFilter; QMap::const_iterator it = aFilterMap.begin(); + QString aDefaultFilter = it.key(); for ( ; it != aFilterMap.end(); ++it ) { filters.push_back( it.key() ); - if (it.key() == 0) + if (it.value() == defaultVersion) // explicit default for MED = current MED version aDefaultFilter = it.key(); } QStringList checkBoxes; @@ -790,6 +791,7 @@ namespace new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true, wdgList ); fd->setWindowTitle( aTitle ); fd->setNameFilters( filters ); + fd->selectNameFilter( aDefaultFilter ); fd->SetChecked( toCreateGroups, 0 ); fd->SetChecked( toFindOutDim, 1 ); if ( !anInitialPath.isEmpty() ) @@ -820,13 +822,13 @@ namespace break; } aFormat = aFilterMap[fd->selectedNameFilter()]; - MESSAGE("selected minor: " << aFormat << " file: " << aFilename.toUtf8().constData()); + MESSAGE("selected version: " << aFormat << " file: " << aFilename.toUtf8().constData()); toOverwrite = fv->isOverwrite(aFilename); MESSAGE("toOverwrite:" << toOverwrite); is_ok = true; if ( !aFilename.isEmpty() ) { if( !toOverwrite ) { - // can't append to an existing using other format + // append is only possible if the existing file format is compatible bool isVersionOk = SMESHGUI::GetSMESHGen()->CheckWriteCompatibility( aFilename.toUtf8().constData() ); MESSAGE("Append check, isVersionOk:" << isVersionOk); if ( !isVersionOk ) { diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 128dbed1c..26fcc1e97 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -468,6 +468,23 @@ char* SMESH_Mesh_i::GetVersionString(CORBA::Long minor, CORBA::Short nbDigits) return CORBA::string_dup( ver.c_str() ); } +//================================================================================ +/*! + * Return the list of med versions compatibles for write/append, + * encoded in 10*major+minor (for instance, code for med 3.2.1 is 32) + */ +//================================================================================ +SMESH::long_array* SMESH_Mesh_i::GetMEDVersionsCompatibleForAppend() +{ + SMESH::long_array_var aResult = new SMESH::long_array(); + std::vector mvok = MED::GetMEDVersionsAppendCompatible(); + long nbver = mvok.size(); + aResult->length( nbver ); + for ( int i = 0; i < nbver; i++ ) + aResult[i] = mvok[i]; + return aResult._retn(); +} + //============================================================================= /*! * ImportUNVFile @@ -3062,7 +3079,7 @@ string SMESH_Mesh_i::prepareMeshNameAndGroups(const char* file, void SMESH_Mesh_i::ExportMED(const char* file, CORBA::Boolean auto_groups, - CORBA::Long minor, + CORBA::Long version, CORBA::Boolean overwrite, CORBA::Boolean autoDimension) throw(SALOME::SALOME_Exception) @@ -3073,12 +3090,12 @@ void SMESH_Mesh_i::ExportMED(const char* file, _preMeshInfo->FullLoadFromFile(); string aMeshName = prepareMeshNameAndGroups(file, overwrite); - _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, 0, autoDimension ); + _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, 0, autoDimension ); TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportMED( r'" << file << "', " << "auto_groups=" <FullLoadFromFile(); @@ -3245,7 +3262,7 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart, SMESH::DownCast< SMESH_Mesh_i* >( meshPart )) { aMeshName = prepareMeshNameAndGroups(file, overwrite); - _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, + _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, 0, autoDimension, /*addODOnVertices=*/have0dField); meshDS = _impl->GetMeshDS(); } @@ -3263,7 +3280,7 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart, } SMESH_MeshPartDS* partDS = new SMESH_MeshPartDS( meshPart ); - _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, + _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, partDS, autoDimension, /*addODOnVertices=*/have0dField); meshDS = tmpDSDeleter._obj = partDS; } @@ -3292,7 +3309,7 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart, << meshPart << ", r'" << file << "', " << auto_groups << ", " - << minor << ", " + << version << ", " << overwrite << ", " << autoDimension << ", " << goList << ", '" diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 7e612be13..41bbce48b 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -225,14 +225,21 @@ public: * Consider maximum group name length stored in MED file. */ CORBA::Boolean HasDuplicatedGroupNamesMED(); + /*! * Return string representation of a MED file version comprising nbDigits */ char* GetVersionString(CORBA::Long minor, CORBA::Short nbDigits); + /*! + * Return the list of med versions compatibles for write/append, + * encoded in 10*major+minor (for instance, code for med 3.2.1 is 32) + */ + SMESH::long_array* GetMEDVersionsCompatibleForAppend(); + void ExportMED( const char* file, CORBA::Boolean auto_groups, - CORBA::Long minor, + CORBA::Long version, CORBA::Boolean overwrite, CORBA::Boolean autoDimension = true) throw (SALOME::SALOME_Exception); @@ -252,7 +259,7 @@ public: void ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart, const char* file, CORBA::Boolean auto_groups, - CORBA::Long minor, + CORBA::Long version, CORBA::Boolean overwrite, CORBA::Boolean autoDim, const GEOM::ListOfFields& fields,