Salome HOME
Copyright update 2020
[modules/smesh.git] / src / MEDWrapper / MED_Wrapper.cxx
index 2f12e7cc81131fa60bc5004a4f013cdb9171825d..7a7e968a89b6ef5d5ef3bbb31b68de52f52dc508 100644 (file)
@@ -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
@@ -78,13 +78,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 +100,7 @@ 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);
+        myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), myMajor, myMinor, MED_RELEASE_NUM);
       }
       if (theErr)
         *theErr = TErr(myFid);
@@ -125,6 +127,7 @@ namespace MED
     TInt myCount;
     TIdt myFid;
     std::string myFileName;
+    TInt myMajor;
     TInt myMinor;
   };
 
@@ -187,23 +190,21 @@ namespace MED
 
   //---------------------------------------------------------------
   TWrapper
-  ::TWrapper(const std::string& theFileName, TInt theMinor):
-    myMinor(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;
-    myFile->Open(eLECTURE_ECRITURE, &aRet);
-    // if (aRet < 0)
-    //   myFile->Close();
-    //   myFile->Open(eLECTURE_AJOUT, &aRet);
-    // }
-    if (aRet < 0) {
-      myFile->Close();
-      myFile->Open(eLECTURE, &aRet);
+    if ( write ) {
+      myFile->Open(eLECTURE_ECRITURE, &aRet);
+      if (aRet < 0) {
+        myFile->Close();
+        myFile->Open(eCREATION, &aRet);
+      }
     }
-    if (aRet < 0) {
-      myFile->Close();
-      myFile->Open(eCREATION, &aRet);
+    else {
+      myFile->Open(eLECTURE, &aRet);
     }
   }
 
@@ -2061,6 +2062,24 @@ namespace MED
     TValueHolder<EConnectivite, med_connectivity_mode> 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,
@@ -2083,11 +2102,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);
+    }
 
   }