X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FMEDWrapper%2FMED_Wrapper.cxx;h=79dc1996b22bc375040d5f9fa6756a1a7efa4f63;hp=157f9834285bc7cb20ace11d84957ed797257e68;hb=0a37d49f45028285190bc58d74921ecc0f2a1ad0;hpb=10f507591e7a98c697b4c0ec34ca8c9d7abfe545 diff --git a/src/MEDWrapper/MED_Wrapper.cxx b/src/MEDWrapper/MED_Wrapper.cxx index 157f98342..79dc1996b 100644 --- a/src/MEDWrapper/MED_Wrapper.cxx +++ b/src/MEDWrapper/MED_Wrapper.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -28,6 +28,10 @@ #include #include +#ifdef WIN32 +#include +#endif + #include #ifdef _DEBUG_ @@ -78,13 +82,15 @@ namespace MED TFile(const TFile&); public: - TFile(const std::string& theFileName, TInt theMinor=-1): + TFile(const std::string& theFileName, TInt theMajor=-1, TInt theMinor=-1): myCount(0), myFid(0), myFileName(theFileName), + myMajor(theMajor), myMinor(theMinor) { - if ((myMinor < 0) || (myMinor > MED_MINOR_NUM)) myMinor = MED_MINOR_NUM; + if ((myMajor < 0) || (myMajor > MED_MAJOR_NUM)) myMajor = MED_MAJOR_NUM; + if ((myMinor < 0) || (myMajor == MED_MAJOR_NUM && myMinor > MED_MINOR_NUM)) myMinor = MED_MINOR_NUM; } ~TFile() @@ -98,7 +104,24 @@ namespace MED { if (myCount++ == 0) { const char* aFileName = myFileName.c_str(); - myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), MED_MAJOR_NUM, myMinor, MED_RELEASE_NUM); +#ifdef WIN32 + if (med_access_mode(theMode) == MED_ACC_RDWR) { + // Force removing readonly attribute from a file under Windows, because of a bug in the HDF5 + std::string aReadOlnyRmCmd = "attrib -r \"" + myFileName + "\"> nul 2>&1"; +#ifdef UNICODE + const char* to_decode = aReadOlnyRmCmd.c_str(); + int size_needed = MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), NULL, 0); + wchar_t* awReadOlnyRmCmd = new wchar_t[size_needed + 1]; + MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), awReadOlnyRmCmd, size_needed); + awReadOlnyRmCmd[size_needed] = '\0'; + _wsystem(awReadOlnyRmCmd); + delete[] awReadOlnyRmCmd; +#else + system(aReadOlnyRmCmd.c_str()); +#endif + } +#endif + myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), myMajor, myMinor, MED_RELEASE_NUM); } if (theErr) *theErr = TErr(myFid); @@ -125,6 +148,7 @@ namespace MED TInt myCount; TIdt myFid; std::string myFileName; + TInt myMajor; TInt myMinor; }; @@ -187,16 +211,17 @@ namespace MED //--------------------------------------------------------------- TWrapper - ::TWrapper(const std::string& theFileName, bool write, TInt theMinor): - myFile(new TFile(theFileName, theMinor)), + ::TWrapper(const std::string& theFileName, bool write, TInt theMajor, TInt theMinor): + myFile(new TFile(theFileName, theMajor, theMinor)), + myMajor(theMajor), myMinor(theMinor) { TErr aRet; if ( write ) { myFile->Open(eLECTURE_ECRITURE, &aRet); if (aRet < 0) { - myFile->Close(); - myFile->Open(eCREATION, &aRet); + myFile->Close(); + myFile->Open(eCREATION, &aRet); } } else { @@ -2058,6 +2083,24 @@ namespace MED TValueHolder aConnMode (theInfo.myConnMode); TErr aRet; + med_bool dummy; + aRet = MEDmeshnEntity(myFile->Id(), + &aMeshName, + MED_NO_DT, + MED_NO_IT, + anEntity, + aGeom, + MED_NAME, + aConnMode, + &dummy, &dummy); + if ( aRet > 0 ) + { + // names are present in the file, they will be read in spite of theInfo.myIsElemNames + theInfo.myIsElemNames = eVRAI; + theInfo.myElemNames.reset( new TString( theInfo.myNbElem * GetPNOMLength() + 1 )); + anElemNames.myRepresentation = & ((TString&) theInfo.myElemNames )[0]; + } + aRet = MEDmeshElementRd(myFile->Id(), &aMeshName, MED_NO_DT, @@ -2080,11 +2123,11 @@ namespace MED EXCEPTION(std::runtime_error, "GetCellInfo - MEDmeshElementRd(...)"); if (anIsFamNum == MED_FALSE) - { - int mySize = (int) theInfo.myFamNum->size(); - theInfo.myFamNum->clear(); - theInfo.myFamNum->resize(mySize, 0); - } + { + int mySize = (int) theInfo.myFamNum->size(); + theInfo.myFamNum->clear(); + theInfo.myFamNum->resize(mySize, 0); + } } @@ -2421,7 +2464,7 @@ namespace MED // write node ids SetCellInfo(theInfo, theMode, theErr); - if (theErr && theErr < 0) + if (theErr && *theErr < 0) return; // write diameter