From: Paul RASCLE Date: Tue, 9 Oct 2018 13:06:17 +0000 (+0200) Subject: MED write/append with a lower major version of MED file format: second step X-Git-Tag: V9_2_0a2~16 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=90761b482c7efd124a056799c0b5579190fdb390;p=modules%2Fsmesh.git MED write/append with a lower major version of MED file format: second step --- 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 5ae8e43de..2ffcfe69f 100644 --- a/src/MEDWrapper/MED_Factory.cxx +++ b/src/MEDWrapper/MED_Factory.cxx @@ -164,10 +164,45 @@ 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 + { + MESSAGE("copy an empty existing med file of the right version, for append" << theVersion); + } + } + } + return new MED::TWrapper(fileName, minor); } } diff --git a/src/MEDWrapper/MED_Factory.hxx b/src/MEDWrapper/MED_Factory.hxx index 402f97cb9..84087d138 100644 --- a/src/MEDWrapper/MED_Factory.hxx +++ b/src/MEDWrapper/MED_Factory.hxx @@ -47,7 +47,7 @@ namespace MED 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 4ee7e09c0..2a19d6e73 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -1421,18 +1421,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 e9a49327c..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,36 +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)); //MESSAGE("MED version: " << vmed.toStdString()); SMESH::long_array_var mvok = aMesh->GetMEDVersionsCompatibleForAppend(); - for ( int i = 0; i < mvok->length(); ++i ) + for ( int i = 0; i < mvok->length(); ++i ) // i=0 must correspond to the current version to set the default filter on it { 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)", i); + aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vs ) + " (*.med)", versionInt); } } else { // isSAUV aFilterMap.insert("All files (*)", -1 ); - aFilterMap.insert("SAUV files (*.sauv)", 0 ); + aFilterMap.insert("SAUV files (*.sauv)", defaultVersion ); // 0 = default filter (defaultVersion) aFilterMap.insert("SAUV files (*.sauve)", -1 ); } - + MESSAGE("default version="<< defaultVersion); QStringList filters; QMap::const_iterator it = aFilterMap.begin(); QString aDefaultFilter = it.key(); for ( ; it != aFilterMap.end(); ++it ) { filters.push_back( it.key() ); - if (it.value() == 0) // explicit default for MED = current MED version + if (it.value() == defaultVersion) // explicit default for MED = current MED version aDefaultFilter = it.key(); } QStringList checkBoxes; @@ -819,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 540211542..26fcc1e97 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -3079,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) @@ -3090,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(); @@ -3262,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(); } @@ -3280,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; } @@ -3309,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 786bfc9bd..41bbce48b 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -239,7 +239,7 @@ public: 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); @@ -259,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,