Salome HOME
reintroduction of choice of MED minor version when exporting MED files
[modules/smesh.git] / src / MEDWrapper / MED_Wrapper.cxx
index dbabc2a2d5a7c2c8d4114bd5bb06097dc2d7b2bf..cc0e21b636bb5ccd75038762a2b0b110557c5e03 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <med.h>
 #include <med_err.h>
+#include <med_proto.h>
 
 #include <boost/version.hpp>
 
@@ -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('"<<myFileName<<"',"<<theMode<<")");
+        EXCEPTION(std::runtime_error,"TFile - MEDfileVersionOpen('"<<myFileName<<"',"<<theMode<<"',"<< MED_MAJOR_NUM<<"',"<< myMinor<<"',"<< MED_RELEASE_NUM<<")");
     }
 
     const TIdt&
@@ -121,19 +125,24 @@ namespace MED
     TInt myCount;
     TIdt myFid;
     std::string myFileName;
+    TInt myMinor;
   };
 
   //---------------------------------------------------------------
   class TFileWrapper
   {
     PFile myFile;
+    TInt myMinor;
 
   public:
     TFileWrapper(const PFile& theFile,
                  EModeAcces theMode,
-                 TErr* theErr = NULL):
-      myFile(theFile)
+                 TErr* theErr = NULL,
+                 TInt theMinor=-1):
+      myFile(theFile),
+      myMinor(theMinor)
     {
+      if (myMinor < 0) myMinor = MED_MINOR_NUM;
       myFile->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;