X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FMEDWrapper%2FMED_Wrapper.cxx;h=4d0f992714aa6140a2198f0178c0de2d824a0363;hp=157f9834285bc7cb20ace11d84957ed797257e68;hb=0a447a3701c9274833f0964516261bcdfe7bbbb5;hpb=58a7aa4445314783449856504f994d259f21d091 diff --git a/src/MEDWrapper/MED_Wrapper.cxx b/src/MEDWrapper/MED_Wrapper.cxx index 157f98342..4d0f99271 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-2021 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 @@ -23,19 +23,25 @@ #include "MED_Wrapper.hxx" #include "MED_TStructures.hxx" #include "MED_Utilities.hxx" +#include "MED_TFile.hxx" +#include "MEDFileUtilities.hxx" #include #include #include +#ifdef WIN32 +#include +#endif + #include #ifdef _DEBUG_ static int MYDEBUG = 0; static int MYVALUEDEBUG = 0; #else -static int MYDEBUG = 0; -static int MYVALUEDEBUG = 0; +// static int MYDEBUG = 0; // unused in release mode +// static int MYVALUEDEBUG = 0; // unused in release mode #endif namespace MED @@ -72,70 +78,75 @@ namespace MED } //--------------------------------------------------------------- - class TFile + const TIdt& MEDIDTHoder::Id() const { - TFile(); - TFile(const TFile&); - - public: - TFile(const std::string& theFileName, TInt theMinor=-1): - myCount(0), - myFid(0), - myFileName(theFileName), - myMinor(theMinor) - { - if ((myMinor < 0) || (myMinor > MED_MINOR_NUM)) myMinor = MED_MINOR_NUM; - } + if (myFid < 0) + EXCEPTION(std::runtime_error, "TFile - GetFid() < 0"); + return myFid; + } - ~TFile() + void TMemFile::Open(EModeAcces theMode, TErr* theErr) + { + if (this->myCount++ == 0) { - Close(); + std::string dftFileName = MEDCoupling::MEDFileWritableStandAlone::GenerateUniqueDftFileNameInMem(); + memfile = MED_MEMFILE_INIT; + memfile.app_image_ptr=0; + memfile.app_image_size=0; + myFid = MEDmemFileOpen(dftFileName.c_str(),&memfile,MED_FALSE,MED_ACC_CREAT); } + if (theErr) + *theErr = TErr(myFid); + else if (myFid < 0) + EXCEPTION(std::runtime_error,"TMemFile - MEDmemFileOpen"); + } - void - Open(EModeAcces theMode, - TErr* theErr = NULL) - { - if (myCount++ == 0) { - const char* aFileName = myFileName.c_str(); - myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), MED_MAJOR_NUM, myMinor, MED_RELEASE_NUM); + TFile::TFile(const std::string& theFileName, TInt theMajor, TInt theMinor): + myFileName(theFileName), + myMajor(theMajor), + myMinor(theMinor) + { + 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; + } + + void TFile::Open(EModeAcces theMode, TErr* theErr) + { + if (myCount++ == 0) { + const char* aFileName = myFileName.c_str(); +#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 } - if (theErr) - *theErr = TErr(myFid); - else if (myFid < 0) - EXCEPTION(std::runtime_error,"TFile - MEDfileVersionOpen('"<Open(eLECTURE_ECRITURE, &aRet); if (aRet < 0) { - myFile->Close(); - myFile->Open(eCREATION, &aRet); + myFile->Close(); + myFile->Open(eCREATION, &aRet); } } else { @@ -605,7 +621,7 @@ namespace MED void TWrapper ::GetNames(TElemInfo& theInfo, - TInt theNb, + TInt /*theNb*/, EEntiteMaillage theEntity, EGeometrieElement theGeom, TErr* theErr) @@ -696,7 +712,7 @@ namespace MED void TWrapper ::GetNumeration(TElemInfo& theInfo, - TInt theNb, + TInt /*theNb*/, EEntiteMaillage theEntity, EGeometrieElement theGeom, TErr* theErr) @@ -787,7 +803,7 @@ namespace MED void TWrapper ::GetFamilies(TElemInfo& theInfo, - TInt theNb, + TInt /*theNb*/, EEntiteMaillage theEntity, EGeometrieElement theGeom, TErr* theErr) @@ -2058,6 +2074,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 +2114,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); + } } @@ -2280,7 +2314,7 @@ namespace MED //---------------------------------------------------------------------------- EGeometrieElement TWrapper - ::GetBallGeom(const TMeshInfo& theMeshInfo) + ::GetBallGeom(const TMeshInfo& /*theMeshInfo*/) { TErr anError; TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor); @@ -2421,7 +2455,7 @@ namespace MED // write node ids SetCellInfo(theInfo, theMode, theErr); - if (theErr && theErr < 0) + if (theErr && *theErr < 0) return; // write diameter @@ -2720,7 +2754,7 @@ namespace MED //---------------------------------------------------------------------------- void TWrapper - ::GetGaussInfo(TInt theId, + ::GetGaussInfo(TInt /*theId*/, TGaussInfo& theInfo, TErr* theErr) { @@ -3084,7 +3118,7 @@ namespace MED //---------------------------------------------------------------------------- void TWrapper - ::GetProfileInfo(TInt theId, + ::GetProfileInfo(TInt /*theId*/, TProfileInfo& theInfo, TErr* theErr) { @@ -3963,7 +3997,7 @@ namespace MED //---------------------------------------------------------------------------- PGrilleInfo TWrapper - ::CrGrilleInfo(const PMeshInfo& theMeshInfo) + ::CrGrilleInfo(const PMeshInfo& /*theMeshInfo*/) { return PGrilleInfo(); // not implemented???? }