From: Paul RASCLE Date: Wed, 18 Jul 2018 13:51:52 +0000 (+0200) Subject: Merge branch 'master' of https://codev-tuleap.cea.fr/plugins/git/salome/smesh X-Git-Tag: SHAPER_V9_1_0RC1~17 X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=commitdiff_plain;h=e330934ca6f8bb1f67b5367bb65a861868998aeb;hp=b4ddd97db887d6928cf2b5bbad99cc6710266487 Merge branch 'master' of https://codev-tuleap.cea.fr/plugins/git/salome/smesh --- diff --git a/idl/SMESH_Gen.idl b/idl/SMESH_Gen.idl index ec7b9ebba..81e4a48cc 100644 --- a/idl/SMESH_Gen.idl +++ b/idl/SMESH_Gen.idl @@ -422,10 +422,15 @@ module SMESH 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); + /*! + * \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. */ diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index b8cc0b387..46f4a40b7 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -622,6 +622,10 @@ 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. + * 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. * - 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 @@ -630,6 +634,7 @@ module SMESH */ void ExportMED( in string fileName, in boolean auto_groups, + in long minor, in boolean overwrite, in boolean autoDimension) raises (SALOME::SALOME_Exception); @@ -639,6 +644,10 @@ 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. + * 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. * - 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. @@ -654,6 +663,7 @@ module SMESH void ExportPartToMED( in SMESH_IDSource meshPart, in string fileName, in boolean auto_groups, + in long minor, in boolean overwrite, in boolean autoDimension, in GEOM::ListOfFields fields, @@ -665,6 +675,11 @@ module SMESH */ void ExportSAUV( in string file, in boolean auto_groups ) raises (SALOME::SALOME_Exception); + + /*! + * Return string representation of a MED file version comprising nbDigits + */ + string GetVersionString(in long minor, in short nbDigits); /*! * Export Mesh to different Formats diff --git a/src/DriverMED/CMakeLists.txt b/src/DriverMED/CMakeLists.txt index af3e0f22d..797f0ed4a 100644 --- a/src/DriverMED/CMakeLists.txt +++ b/src/DriverMED/CMakeLists.txt @@ -20,6 +20,7 @@ # --- options --- # additional include directories INCLUDE_DIRECTORIES( + ${MEDFILE_INCLUDE_DIRS} ${HDF5_INCLUDE_DIRS} ${KERNEL_INCLUDE_DIRS} ${OpenCASCADE_INCLUDE_DIR} diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx index 6ac446156..a1902daac 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx @@ -35,6 +35,8 @@ #include "SMDS_SetIterator.hxx" #include "SMESHDS_Mesh.hxx" +#include + #include #include #include @@ -62,11 +64,41 @@ DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh(): myDoAllInGroups(false) {} -void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName) +void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theMinor) { + myMinor = theMinor; Driver_SMESHDS_Mesh::SetFile(theFileName); } +/*! + * 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) +{ + TInt majeur, mineur, release; + majeur=MED_MAJOR_NUM; + mineur=MED_MINOR_NUM; + release=MED_RELEASE_NUM; + TInt imposedMineur = mineur; + + if (theVersion < 0) + imposedMineur = mineur; + else if (theVersion > MED_MINOR_NUM) + imposedMineur = mineur; + else + imposedMineur = theVersion; + + ostringstream name; + if ( theNbDigits > 0 ) + name << majeur; + if ( theNbDigits > 1 ) + name << "." << imposedMineur; + if ( theNbDigits > 2 ) + name << "." << release; + return name.str(); +} + void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup) { myGroups.push_back(theGroup); @@ -425,7 +457,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() } } - MED::PWrapper myMed = CrWrapperW(myFile); + MED::PWrapper myMed = CrWrapperW(myFile, myMinor); 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 4b63d3cc6..60261dd62 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h @@ -48,9 +48,11 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh DriverMED_W_SMESHDS_Mesh(); - void SetFile(const std::string& theFileName); + void SetFile(const std::string& theFileName, int theMinor=-1); void SetAutoDimension(bool toFindOutDimension) { myAutoDimension = toFindOutDimension; } + static std::string GetVersionString(int theVersion, int theNbDigits=2); + void AddGroupOfNodes(); void AddGroupOfEdges(); void AddGroupOfFaces(); @@ -87,6 +89,7 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh bool myAutoDimension; bool myAddODOnVertices; bool myDoAllInGroups; + int myMinor; }; #endif diff --git a/src/MEDWrapper/MED_Factory.cxx b/src/MEDWrapper/MED_Factory.cxx index 02b7e866e..51fe44ce3 100644 --- a/src/MEDWrapper/MED_Factory.cxx +++ b/src/MEDWrapper/MED_Factory.cxx @@ -35,6 +35,7 @@ extern "C" #include #endif } +#include namespace MED { @@ -47,22 +48,24 @@ namespace MED #endif } - bool CheckCompatibility(const std::string& fileName) + bool CheckCompatibility(const std::string& fileName, bool isForAppend) { bool ok = false; // check that file is accessible if ( exists(fileName) ) { // check HDF5 && MED compatibility med_bool hdfok, medok; - MEDfileCompatibility(fileName.c_str(), &hdfok, &medok); - if ( hdfok && medok ) { + med_err r0 = MEDfileCompatibility(fileName.c_str(), &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); if (ret >= 0) { - int version = 100*major + minor; - if (version >= 202) + bool isReadOnly = !isForAppend; + if ( isReadOnly || ((major == MED_MAJOR_NUM) && (minor == MED_MINOR_NUM))) ok = true; } } @@ -111,10 +114,10 @@ namespace MED return new MED::TWrapper(fileName); } - PWrapper CrWrapperW(const std::string& fileName) + PWrapper CrWrapperW(const std::string& fileName, int theMinor) { - if (!CheckCompatibility(fileName)) + if (!CheckCompatibility(fileName, true)) remove(fileName.c_str()); - return new MED::TWrapper(fileName); + return new MED::TWrapper(fileName, theMinor); } } diff --git a/src/MEDWrapper/MED_Factory.hxx b/src/MEDWrapper/MED_Factory.hxx index 3dea6247b..fe5e0032c 100644 --- a/src/MEDWrapper/MED_Factory.hxx +++ b/src/MEDWrapper/MED_Factory.hxx @@ -37,13 +37,13 @@ namespace MED bool GetMEDVersion( const std::string&, int&, int&, int& ); MEDWRAPPER_EXPORT - bool CheckCompatibility( const std::string& ); + bool CheckCompatibility( const std::string& , bool isForAppend=false); MEDWRAPPER_EXPORT PWrapper CrWrapperR( const std::string& ); MEDWRAPPER_EXPORT - PWrapper CrWrapperW( const std::string& ); + PWrapper CrWrapperW( const std::string&, int theMinor=-1 ); } #endif // MED_Factory_HeaderFile diff --git a/src/MEDWrapper/MED_Wrapper.cxx b/src/MEDWrapper/MED_Wrapper.cxx index dbabc2a2d..cc0e21b63 100644 --- a/src/MEDWrapper/MED_Wrapper.cxx +++ b/src/MEDWrapper/MED_Wrapper.cxx @@ -26,6 +26,7 @@ #include #include +#include #include @@ -77,11 +78,14 @@ namespace MED TFile(const TFile&); public: - TFile(const std::string& theFileName): + TFile(const std::string& theFileName, TInt theMinor=-1): myCount(0), myFid(0), - myFileName(theFileName) - {} + myFileName(theFileName), + myMinor(theMinor) + { + if ((myMinor < 0) || (myMinor > MED_MINOR_NUM)) myMinor = MED_MINOR_NUM; + } ~TFile() { @@ -94,12 +98,12 @@ namespace MED { if (myCount++ == 0) { const char* aFileName = myFileName.c_str(); - myFid = MEDfileOpen(aFileName, med_access_mode(theMode)); + myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), MED_MAJOR_NUM, myMinor, MED_RELEASE_NUM); } if (theErr) *theErr = TErr(myFid); else if (myFid < 0) - EXCEPTION(std::runtime_error, "TFile - MEDfileOpen('"<Open(theMode, theErr); } @@ -178,8 +187,9 @@ namespace MED //--------------------------------------------------------------- TWrapper - ::TWrapper(const std::string& theFileName): - myFile(new TFile(theFileName)) + ::TWrapper(const std::string& theFileName, TInt theMinor): + myMinor(theMinor), + myFile(new TFile(theFileName, theMinor)) { TErr aRet; myFile->Open(eLECTURE_ECRITURE, &aRet); @@ -208,7 +218,7 @@ namespace MED TWrapper ::GetNbMeshes(TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return -1; @@ -223,7 +233,7 @@ namespace MED MED::TMeshInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -284,7 +294,7 @@ namespace MED EModeAcces theMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -368,7 +378,7 @@ namespace MED ::GetNbFamilies(const MED::TMeshInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return -1; @@ -385,7 +395,7 @@ namespace MED const MED::TMeshInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return -1; @@ -404,7 +414,7 @@ namespace MED const MED::TMeshInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return -1; @@ -423,7 +433,7 @@ namespace MED MED::TFamilyInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -481,7 +491,7 @@ namespace MED EModeAcces theMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -603,7 +613,7 @@ namespace MED EGeometrieElement theGeom, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -652,7 +662,7 @@ namespace MED EGeometrieElement theGeom, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -694,7 +704,7 @@ namespace MED EGeometrieElement theGeom, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -743,7 +753,7 @@ namespace MED EGeometrieElement theGeom, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -785,7 +795,7 @@ namespace MED EGeometrieElement theGeom, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -843,7 +853,7 @@ namespace MED EGeometrieElement theGeom, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -890,7 +900,7 @@ namespace MED ETable theTable, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return -1; @@ -918,7 +928,7 @@ namespace MED ::GetNodeInfo(MED::TNodeInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -1009,7 +1019,7 @@ namespace MED EModeAcces theMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -1320,7 +1330,7 @@ namespace MED EConnectivite theConnMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return 0; @@ -1353,7 +1363,7 @@ namespace MED ::GetPolygoneInfo(MED::TPolygoneInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -1412,7 +1422,7 @@ namespace MED EModeAcces theMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -1564,7 +1574,7 @@ namespace MED EConnectivite theConnMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) EXCEPTION(std::runtime_error, "GetPolyedreConnSize - (...)"); @@ -1610,7 +1620,7 @@ namespace MED ::GetPolyedreInfo(TPolyedreInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -1673,7 +1683,7 @@ namespace MED EModeAcces theMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -1869,7 +1879,7 @@ namespace MED { TEntityInfo anInfo; - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return anInfo; @@ -1981,7 +1991,7 @@ namespace MED EConnectivite theConnMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return -1; @@ -2030,7 +2040,7 @@ namespace MED ::GetCellInfo(MED::TCellInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -2097,7 +2107,7 @@ namespace MED EModeAcces theMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -2275,7 +2285,8 @@ namespace MED TWrapper ::GetBallGeom(const TMeshInfo& theMeshInfo) { - TFileWrapper aFileWrapper(myFile, eLECTURE); + TErr anError; + TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor); // read med_geometry_type of "MED_BALL" element char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME; @@ -2287,7 +2298,8 @@ namespace MED TWrapper ::GetNbBalls(const TMeshInfo& theMeshInfo) { - TFileWrapper aFileWrapper(myFile, eLECTURE); + TErr anError; + TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor); EGeometrieElement ballType = GetBallGeom(theMeshInfo); if (ballType < 0) @@ -2302,7 +2314,7 @@ namespace MED ::GetBallInfo(TBallInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); // check geometry of MED_BALL if (theInfo.myGeom == eBALL) @@ -2352,7 +2364,7 @@ namespace MED EModeAcces theMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); TErr ret; char ballsupportname[MED_NAME_SIZE+1] = "BALL_SUPPORT_MESH"; @@ -2480,7 +2492,7 @@ namespace MED TWrapper ::GetNbFields(TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return -1; @@ -2494,7 +2506,7 @@ namespace MED ::GetNbComp(TInt theFieldId, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return -1; @@ -2509,7 +2521,7 @@ namespace MED MED::TFieldInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -2574,7 +2586,7 @@ namespace MED EModeAcces theMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -2661,7 +2673,7 @@ namespace MED TWrapper ::GetNbGauss(TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return -1; @@ -2675,7 +2687,7 @@ namespace MED ::GetGaussPreInfo(TInt theId, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return TGaussInfo::TInfo(TGaussInfo::TKey(ePOINT1, ""), 0); @@ -2715,7 +2727,7 @@ namespace MED TGaussInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -2761,7 +2773,7 @@ namespace MED TErr* theErr) { theEntity = EEntiteMaillage(-1); - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr) { if (theEntityInfo.empty()) @@ -2884,7 +2896,7 @@ namespace MED MED::TTimeStampInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); const TGeom2Size& aGeom2Size = theInfo.myGeom2Size; @@ -3037,7 +3049,7 @@ namespace MED TWrapper ::GetNbProfiles(TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return -1; @@ -3051,7 +3063,7 @@ namespace MED ::GetProfilePreInfo(TInt theId, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return TProfileInfo::TInfo(); @@ -3079,7 +3091,7 @@ namespace MED TProfileInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -3124,7 +3136,7 @@ namespace MED EModeAcces theMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -3177,7 +3189,7 @@ namespace MED const TKey2Gauss& theKey2Gauss, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -3361,7 +3373,7 @@ namespace MED EModeAcces theMode, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -3698,7 +3710,7 @@ namespace MED ::GetGrilleInfo(TGrilleInfo& theInfo, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -3868,7 +3880,7 @@ namespace MED { if (theInfo.myMeshInfo->myType != eSTRUCTURE) return; - TFileWrapper aFileWrapper(myFile, theMode, theErr); + TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor); if (theErr && *theErr < 0) return; @@ -4003,7 +4015,7 @@ namespace MED EGrilleType& theGridType, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) EXCEPTION(std::runtime_error, " GetGrilleType - aFileWrapper (...)"); @@ -4029,7 +4041,7 @@ namespace MED TIntVector& theStruct, TErr* theErr) { - TFileWrapper aFileWrapper(myFile, eLECTURE, theErr); + TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor); if (theErr && *theErr < 0) return; diff --git a/src/MEDWrapper/MED_Wrapper.hxx b/src/MEDWrapper/MED_Wrapper.hxx index 841eb4eca..05b0496c2 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); + TWrapper(const std::string& theFileName, TInt theMinor=-1); virtual ~TWrapper(); @@ -939,6 +939,7 @@ namespace MED protected: PFile myFile; + TInt myMinor; }; //---------------------------------------------------------------------------- diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index afefed35a..3f16ab7dd 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -1402,6 +1402,10 @@ bool SMESH_Mesh::HasDuplicatedGroupNamesMED() * \param [in] theAutoGroups - boolean parameter for creating/not creating * the groups Group_On_All_Nodes, Group_On_All_Faces, ... ; * the typical use is auto_groups=false. + * \param [in] theMinor - define the minor version (y, where version is x.y.z) of MED file format. + * The theMinor must be between 0 and the current minor version of MED file library. + * If theMinor is equal to -1, the minor version is not changed (default). + * The major version (x, where version is x.y.z) cannot be changed. * \param [in] meshPart - mesh data to export * \param [in] theAutoDimension - if \c true, a space dimension of a MED mesh can be either * - 1D if all mesh nodes lie on OX coordinate axis, or @@ -1417,6 +1421,7 @@ bool SMESH_Mesh::HasDuplicatedGroupNamesMED() void SMESH_Mesh::ExportMED(const char * file, const char* theMeshName, bool theAutoGroups, + int theMinor, const SMESHDS_Mesh* meshPart, bool theAutoDimension, bool theAddODOnVertices, @@ -1427,7 +1432,7 @@ void SMESH_Mesh::ExportMED(const char * file, SMESH_TRY; DriverMED_W_SMESHDS_Mesh myWriter; - myWriter.SetFile ( file ); + myWriter.SetFile ( file , theMinor); 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 57c26d63a..c52b5ef2e 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -254,6 +254,7 @@ class SMESH_EXPORT SMESH_Mesh void ExportMED(const char * theFile, const char* theMeshName = NULL, bool theAutoGroups = true, + int TheMinor = -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 259b5d8b1..c1b913cb5 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -655,6 +655,9 @@ namespace // Get parameters of export operation QString aFilename; + 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 bool aIsASCII_STL = true; bool toCreateGroups = false; @@ -706,7 +709,7 @@ namespace if ( fd->exec() ) aFilename = fd->selectedFile(); - toOverwrite = fv->isOverwrite(); + toOverwrite = fv->isOverwrite(aFilename); toCreateGroups = fd->IsChecked(0); SMESHGUI::resourceMgr()->setValue("SMESH", theByTypeResource, toCreateGroups ); @@ -741,14 +744,40 @@ namespace } else if ( isMED || isSAUV ) // Export to MED or SAUV { - QStringList filters; + QMap aFilterMap; if ( isMED ) { - filters << QObject::tr( "MED_FILES_FILTER" ) + " (*.med)"; + //filters << QObject::tr( "MED_FILES_FILTER" ) + " (*.med)"; + 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; iiGetVersionString(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); + } } else { // isSAUV - filters << QObject::tr( "SAUV_FILES_FILTER" ) + " (*.sauv *.sauve)"; + aFilterMap.insert("All files (*)", -1 ); + aFilterMap.insert("SAUV files (*.sauv)", -1 ); + aFilterMap.insert("SAUV files (*.sauve)", -1 ); } + QStringList filters; + QString aDefaultFilter; + QMap::const_iterator it = aFilterMap.begin(); + for ( ; it != aFilterMap.end(); ++it ) { + filters.push_back( it.key() ); + if (it.key() == 0) + aDefaultFilter = it.key(); + } QStringList checkBoxes; checkBoxes << QObject::tr("SMESH_AUTO_GROUPS") << QObject::tr("SMESH_AUTO_DIM"); @@ -782,18 +811,22 @@ namespace bool is_ok = false; while (!is_ok) { + //MESSAGE("******* Loop on file dialog ***********"); + isOkToWrite =true; if ( fd->exec() ) aFilename = fd->selectedFile(); else { aFilename = QString::null; break; } - toOverwrite = fv->isOverwrite(); + aFormat = aFilterMap[fd->selectedNameFilter()]; + //MESSAGE("selected minor: " << aFormat << " file: " << aFilename.toUtf8().constData()); + toOverwrite = fv->isOverwrite(aFilename); is_ok = true; if ( !aFilename.isEmpty() ) { if( !toOverwrite ) { // 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 ) { int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"), @@ -801,11 +834,17 @@ namespace QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 0, 1); if (aRet == 0) - toOverwrite = true; + { + toOverwrite = true; + MESSAGE("incompatible MED file version for add, overwrite accepted"); + } else - is_ok = false; + { + isOkToWrite = false; + is_ok = false; + MESSAGE("incompatible MED file version for add, overwrite refused"); + } } - QStringList aMeshNamesCollisionList; SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toUtf8().constData() ); for( int i = 0, n = aMeshNames->length(); i < n; i++ ) { @@ -818,7 +857,8 @@ namespace } } } - if( !aMeshNamesCollisionList.isEmpty() ) { + if( !aMeshNamesCollisionList.isEmpty() ) { + isOkToWrite = false; QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " ); int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"), @@ -826,14 +866,18 @@ namespace QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), QObject::tr("SMESH_BUT_CANCEL"), 0, 2); - if (aRet == 0) + //MESSAGE("answer collision name " << aRet); + if (aRet == 0) { toOverwrite = true; + isOkToWrite = true; + } else if (aRet == 2) is_ok = false; } } } } + //MESSAGE(" ****** end of file dialog loop") toCreateGroups = fd->IsChecked(0); toFindOutDim = fd->IsChecked(1); fieldSelWdg->GetSelectedFields(); @@ -868,8 +912,9 @@ namespace // if ( SMESHGUI::automaticUpdate() ) // SMESH::UpdateView(); // } - if ( isMED ) + if ( isMED && isOkToWrite) { + //MESSAGE("OK to write MED file "<< aFilename.toUtf8().constData()); aMeshIter = aMeshList.begin(); for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ ) { @@ -879,10 +924,10 @@ namespace const QString& geoAssFields = aFieldList[ aMeshIndex ].second; const bool hasFields = ( fields.length() || !geoAssFields.isEmpty() ); if ( !hasFields && aMeshOrGroup->_is_equivalent( aMeshItem )) - aMeshItem->ExportMED( aFilename.toUtf8().data(), toCreateGroups, + aMeshItem->ExportMED( aFilename.toUtf8().data(), toCreateGroups, aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim ); else - aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups, + aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups, aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim, fields, geoAssFields.toLatin1().data() ); } diff --git a/src/SMESHGUI/SMESHGUI_FileValidator.cxx b/src/SMESHGUI/SMESHGUI_FileValidator.cxx index cf17da474..3583310ce 100755 --- a/src/SMESHGUI/SMESHGUI_FileValidator.cxx +++ b/src/SMESHGUI/SMESHGUI_FileValidator.cxx @@ -72,3 +72,10 @@ bool SMESHGUI_FileValidator::canSave( const QString& fileName, bool checkPermiss } return true; } + +bool SMESHGUI_FileValidator::isOverwrite( const QString& fileName) const +{ + if ( QFile::exists( fileName ) ) + return myIsOverwrite; + return true; +} diff --git a/src/SMESHGUI/SMESHGUI_FileValidator.h b/src/SMESHGUI/SMESHGUI_FileValidator.h index f80e8c5df..764a221bf 100755 --- a/src/SMESHGUI/SMESHGUI_FileValidator.h +++ b/src/SMESHGUI/SMESHGUI_FileValidator.h @@ -37,7 +37,7 @@ public: virtual bool canSave( const QString&, bool = true ); - bool isOverwrite() const { return myIsOverwrite; } + bool isOverwrite( const QString& fileName) const; private: bool myIsOverwrite; diff --git a/src/SMESHGUI/SMESH_msg_en.ts b/src/SMESHGUI/SMESH_msg_en.ts index 8af2e2d7c..af3988660 100644 --- a/src/SMESHGUI/SMESH_msg_en.ts +++ b/src/SMESHGUI/SMESH_msg_en.ts @@ -27,6 +27,10 @@ TEXT_FILES_FILTER TXT files + + MED_VX_FILES_FILTER + MED %1 files + STL_FILES_FILTER STL files diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index f01646e74..8258f4cea 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -2959,7 +2959,7 @@ char* SMESH_Gen_i::GetMEDVersion(const char* theFileName) /*! * 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) @@ -2967,6 +2967,18 @@ CORBA::Boolean SMESH_Gen_i::CheckCompatibility(const char* 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 @@ -2976,10 +2988,12 @@ CORBA::Boolean SMESH_Gen_i::CheckCompatibility(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(); MED::PWrapper aMed = MED::CrWrapperR( theFileName ); MED::TErr anErr; MED::TInt aNbMeshes = aMed->GetNbMeshes( &anErr ); + //MESSAGE("---" << aNbMeshes); if( anErr >= 0 ) { aResult->length( aNbMeshes ); for( MED::TInt i = 0; i < aNbMeshes; i++ ) { diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index dc0f27f95..2360fd4d1 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -348,9 +348,12 @@ public: // Get MED version of the file by its name 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); + // 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 SMESH::string_array* GetMeshNames(const char* theFileName); diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index c7c3f54eb..10bfa8d8e 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -448,6 +448,19 @@ SMESH::DriverMED_ReadStatus SMESH_Mesh_i::ImportCGNSFile( const char* theFileNa return ConvertDriverMEDReadStatus(status); } +//================================================================================ +/*! + * \brief Return string representation of a MED file version comprising nbDigits + */ +//================================================================================ + +char* SMESH_Mesh_i::GetVersionString(CORBA::Long minor, CORBA::Short nbDigits) +{ + string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(minor, + nbDigits); + return CORBA::string_dup( ver.c_str() ); +} + //============================================================================= /*! * ImportUNVFile @@ -2987,22 +3000,26 @@ string SMESH_Mesh_i::prepareMeshNameAndGroups(const char* file, void SMESH_Mesh_i::ExportMED(const char* file, CORBA::Boolean auto_groups, + CORBA::Long minor, CORBA::Boolean overwrite, CORBA::Boolean autoDimension) throw(SALOME::SALOME_Exception) { - //MESSAGE("SMESH::MED_VERSION:"<< theVersion); + //MESSAGE("MED minor version: "<< minor); SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); string aMeshName = prepareMeshNameAndGroups(file, overwrite); - _impl->ExportMED( file, aMeshName.c_str(), auto_groups, 0, autoDimension ); + _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, 0, autoDimension ); TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportMED( r'" - << file << "', " << auto_groups << ", " - << overwrite << ", " - << autoDimension << " )"; + << file << "', " + << "auto_groups=" <FullLoadFromFile(); @@ -3164,7 +3183,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, + _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, 0, autoDimension, /*addODOnVertices=*/have0dField); meshDS = _impl->GetMeshDS(); } @@ -3182,7 +3201,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, + _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, partDS, autoDimension, /*addODOnVertices=*/have0dField); meshDS = tmpDSDeleter._obj = partDS; } @@ -3207,11 +3226,15 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart, GEOM::GEOM_BaseObject_var gbo = GEOM::GEOM_BaseObject::_narrow( fields[i] ); goList[i] = gbo; } - TPythonDump() << _this() << ".ExportPartToMED( " - << meshPart << ", r'" << file << "', " - << auto_groups << ", " << overwrite << ", " - << autoDimension << ", " << goList - << ", '" << ( geomAssocFields ? geomAssocFields : "" ) << "'" << " )"; + TPythonDump() << _this() << ".ExportPartToMED( r'" + << file << "', " + << "auto_groups=" << auto_groups << ", " + << "minor=" << minor << ", " + << "overwrite=" << overwrite << ", " + << "meshPart=" << meshPart << ", " + << "autoDimension=" << autoDimension << ", " + << "fields=" << goList << ", geomAssocFields='" + << ( geomAssocFields ? geomAssocFields : "" ) << "'" << " )"; SMESH_CATCH( SMESH::throwCorbaException ); } diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 9fdde438c..ece281760 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -225,9 +225,14 @@ 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); void ExportMED( const char* file, CORBA::Boolean auto_groups, + CORBA::Long minor, CORBA::Boolean overwrite, CORBA::Boolean autoDimension = true) throw (SALOME::SALOME_Exception); @@ -247,6 +252,7 @@ public: void ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart, const char* file, CORBA::Boolean auto_groups, + CORBA::Long minor, CORBA::Boolean overwrite, CORBA::Boolean autoDim, const GEOM::ListOfFields& fields, diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index f64b1e533..8b62ca6d2 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -24,9 +24,19 @@ import salome from salome.geom import geomBuilder import SMESH # This is necessary for back compatibility -import omniORB # back compatibility -SMESH.MED_V2_1 = omniORB.EnumItem("MED_V2_1", 0) # back compatibility -SMESH.MED_V2_2 = omniORB.EnumItem("MED_V2_2", 1) # back compatibility +import omniORB # back compatibility +SMESH.MED_V2_1 = 11 #omniORB.EnumItem("MED_V2_1", 11) # back compatibility: use number > MED minor version +SMESH.MED_V2_2 = 12 #omniORB.EnumItem("MED_V2_2", 12) # back compatibility: latest minor will be used +SMESH.MED_MINOR_0 = 20 # back compatibility +SMESH.MED_MINOR_1 = 21 # back compatibility +SMESH.MED_MINOR_2 = 22 # back compatibility +SMESH.MED_MINOR_3 = 23 # back compatibility +SMESH.MED_MINOR_4 = 24 # back compatibility +SMESH.MED_MINOR_5 = 25 # back compatibility +SMESH.MED_MINOR_6 = 26 # back compatibility +SMESH.MED_MINOR_7 = 27 # back compatibility +SMESH.MED_MINOR_8 = 28 # back compatibility +SMESH.MED_MINOR_9 = 29 # back compatibility from SMESH import * from salome.smesh.smesh_algorithm import Mesh_Algorithm @@ -2157,6 +2167,10 @@ class Mesh(metaclass = MeshMeta): auto_groups (boolean): parameter for creating/not creating the groups Group_On_All_Nodes, Group_On_All_Faces, ... ; the typical use is auto_groups=False. + minor (int): define the minor version (y, where version is x.y.z) of MED file format. + 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. overwrite (boolean): parameter for overwriting/not overwriting the file meshPart: a part of mesh (:class:`sub-mesh, group or filter `) to export instead of the mesh autoDimension: if *True* (default), a space dimension of a MED mesh can be either @@ -2175,16 +2189,18 @@ class Mesh(metaclass = MeshMeta): - 's' stands for "_solids _" field. """ # process positional arguments - args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility + #args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility fileName = args[0] auto_groups = args[1] if len(args) > 1 else False - overwrite = args[2] if len(args) > 2 else True - meshPart = args[3] if len(args) > 3 else None - autoDimension = args[4] if len(args) > 4 else True - fields = args[5] if len(args) > 5 else [] - geomAssocFields = args[6] if len(args) > 6 else '' + minor = args[2] if len(args) > 2 else -1 + overwrite = args[3] if len(args) > 3 else True + meshPart = args[4] if len(args) > 4 else None + autoDimension = args[5] if len(args) > 5 else True + fields = args[6] if len(args) > 6 else [] + geomAssocFields = args[7] if len(args) > 7 else '' # process keywords arguments auto_groups = kwargs.get("auto_groups", auto_groups) + minor = kwargs.get("minor", minor) overwrite = kwargs.get("overwrite", overwrite) meshPart = kwargs.get("meshPart", meshPart) autoDimension = kwargs.get("autoDimension", autoDimension) @@ -2196,10 +2212,10 @@ class Mesh(metaclass = MeshMeta): if isinstance( meshPart, list ): meshPart = self.GetIDSource( meshPart, SMESH.ALL ) unRegister.set( meshPart ) - self.mesh.ExportPartToMED( meshPart, fileName, auto_groups, overwrite, autoDimension, + self.mesh.ExportPartToMED( meshPart, fileName, auto_groups, minor, overwrite, autoDimension, fields, geomAssocFields) else: - self.mesh.ExportMED(fileName, auto_groups, overwrite, autoDimension) + self.mesh.ExportMED(fileName, auto_groups, minor, overwrite, autoDimension) def ExportSAUV(self, f, auto_groups=0): """ @@ -2336,7 +2352,7 @@ class Mesh(metaclass = MeshMeta): print("WARNING: ExportToMED() is deprecated, use ExportMED() instead") # process positional arguments - args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility + #args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility fileName = args[0] auto_groups = args[1] if len(args) > 1 else False overwrite = args[2] if len(args) > 2 else True @@ -2346,8 +2362,9 @@ class Mesh(metaclass = MeshMeta): auto_groups = kwargs.get("auto_groups", auto_groups) # new keyword name overwrite = kwargs.get("overwrite", overwrite) autoDimension = kwargs.get("autoDimension", autoDimension) + minor = -1 # invoke engine's function - self.mesh.ExportMED(fileName, auto_groups, overwrite, autoDimension) + self.mesh.ExportMED(fileName, auto_groups, minor, overwrite, autoDimension) def ExportToMEDX(self, *args, **kwargs): """ @@ -2370,7 +2387,7 @@ class Mesh(metaclass = MeshMeta): print("WARNING: ExportToMEDX() is deprecated, use ExportMED() instead") # process positional arguments - args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility + #args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] # backward compatibility fileName = args[0] auto_groups = args[1] if len(args) > 1 else False overwrite = args[2] if len(args) > 2 else True @@ -2379,8 +2396,9 @@ class Mesh(metaclass = MeshMeta): auto_groups = kwargs.get("auto_groups", auto_groups) overwrite = kwargs.get("overwrite", overwrite) autoDimension = kwargs.get("autoDimension", autoDimension) + minor = -1 # invoke engine's function - self.mesh.ExportMED(fileName, auto_groups, overwrite, autoDimension) + self.mesh.ExportMED(fileName, auto_groups, minor, overwrite, autoDimension) # Operations with groups: # ---------------------- @@ -6842,19 +6860,19 @@ class meshProxy(SMESH._objref_SMESH_Mesh): return SMESH._objref_SMESH_Mesh.CreateDimGroup(self, *args) def ExportToMEDX(self, *args): # function removed print("WARNING: ExportToMEDX() is deprecated, use ExportMED() instead") - args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] + #args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] SMESH._objref_SMESH_Mesh.ExportMED(self, *args) def ExportToMED(self, *args): # function removed print("WARNING: ExportToMED() is deprecated, use ExportMED() instead") - args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] + #args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] while len(args) < 4: # !!!! nb of parameters for ExportToMED IDL's method args.append(True) SMESH._objref_SMESH_Mesh.ExportMED(self, *args) def ExportPartToMED(self, *args): # 'version' parameter removed - args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] + #args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] SMESH._objref_SMESH_Mesh.ExportPartToMED(self, *args) def ExportMED(self, *args): # signature of method changed - args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] + #args = [i for i in args if i not in [SMESH.MED_V2_1, SMESH.MED_V2_2]] while len(args) < 4: # !!!! nb of parameters for ExportToMED IDL's method args.append(True) SMESH._objref_SMESH_Mesh.ExportMED(self, *args)