Salome HOME
MED write/append with a lower major version of MED file format: second step
authorPaul RASCLE <paul.rascle@edf.fr>
Tue, 9 Oct 2018 13:06:17 +0000 (15:06 +0200)
committerPaul RASCLE <paul.rascle@edf.fr>
Tue, 9 Oct 2018 13:06:17 +0000 (15:06 +0200)
src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx
src/DriverMED/DriverMED_W_SMESHDS_Mesh.h
src/MEDWrapper/MED_Factory.cxx
src/MEDWrapper/MED_Factory.hxx
src/MEDWrapper/MED_Wrapper.hxx
src/SMESH/SMESH_Mesh.cxx
src/SMESH/SMESH_Mesh.hxx
src/SMESHGUI/SMESHGUI.cxx
src/SMESH_I/SMESH_Mesh_i.cxx
src/SMESH_I/SMESH_Mesh_i.hxx

index a1902daac8aafe9f4cfc43d9c83906a2e769242f..63c69c992ee921e3a18351a076439b76abd0d968 100644 (file)
@@ -61,12 +61,13 @@ DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
   myDoGroupOfBalls(false),
   myAutoDimension(false),
   myAddODOnVertices(false),
-  myDoAllInGroups(false)
+  myDoAllInGroups(false),
+  myVersion(-1)
 {}
 
-void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theMinor)
+void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theVersion)
 {
-  myMinor = theMinor;
+  myVersion = theVersion;
   Driver_SMESHDS_Mesh::SetFile(theFileName);
 }
 
@@ -74,7 +75,7 @@ void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theMi
  * 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)
+string DriverMED_W_SMESHDS_Mesh::GetVersionString(int theMinor, int theNbDigits)
 {
   TInt majeur, mineur, release;
   majeur=MED_MAJOR_NUM;
@@ -82,12 +83,12 @@ string DriverMED_W_SMESHDS_Mesh::GetVersionString(int theVersion, int theNbDigit
   release=MED_RELEASE_NUM;
   TInt imposedMineur = mineur;
 
-  if (theVersion < 0)
+  if (theMinor < 0)
     imposedMineur = mineur;
-  else if (theVersion > MED_MINOR_NUM)
+  else if (theMinor > MED_MINOR_NUM)
     imposedMineur = mineur;
   else
-    imposedMineur = theVersion;
+    imposedMineur = theMinor;
 
   ostringstream name;
   if ( theNbDigits > 0 )
@@ -457,7 +458,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
       }
     }
 
-    MED::PWrapper myMed = CrWrapperW(myFile, myMinor);
+    MED::PWrapper myMed = CrWrapperW(myFile, myVersion);
     PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
     //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
     myMed->SetMeshInfo(aMeshInfo);
index 60261dd628f79d2643c32e797fd884b84e5e965c..2b04c05f9fa3326aea7bbf91a6a9b355d5eaf7e4 100644 (file)
@@ -48,10 +48,10 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh
 
   DriverMED_W_SMESHDS_Mesh();
 
-  void SetFile(const std::string& theFileName, int theMinor=-1);
+  void SetFile(const std::string& theFileName, int theVersion=-1);
   void SetAutoDimension(bool toFindOutDimension) { myAutoDimension = toFindOutDimension; }
 
-  static std::string GetVersionString(int theVersion, int theNbDigits=2);
+  static std::string GetVersionString(int theMinor, int theNbDigits=2);
 
   void AddGroupOfNodes();
   void AddGroupOfEdges();
@@ -89,7 +89,7 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh
   bool myAutoDimension;
   bool myAddODOnVertices;
   bool myDoAllInGroups;
-  int myMinor;
+  int myVersion;
 };
 
 #endif
index 5ae8e43de77f39a2d62d29cbe1486682309e8fca..2ffcfe69fe4694f8e34d42c73c230dc881d722f3 100644 (file)
@@ -164,10 +164,45 @@ namespace MED
     return new MED::TWrapper(fileName);
   }
 
-  PWrapper CrWrapperW(const std::string& fileName, int theMinor)
+  PWrapper CrWrapperW(const std::string& fileName, int theVersion)
   {
+    bool isCreated = false;
     if (!CheckCompatibility(fileName, true))
-      remove(fileName.c_str());
-    return new MED::TWrapper(fileName, theMinor);
+      {
+        remove(fileName.c_str());
+        isCreated = true;
+      }
+    int minor = -1;
+    if (isCreated)
+      {
+        med_int wantedMajor = MED_MAJOR_NUM;
+        med_int wantedMinor = MED_MINOR_NUM;
+        if (theVersion > 0)
+          {
+            wantedMajor = theVersion/10;
+            wantedMinor = theVersion%10;
+          }
+        if (wantedMajor == MED_MAJOR_NUM) // the med file will be actually created
+          {
+            if (wantedMinor < MED_MINOR_NUM)
+              minor = wantedMinor;
+          }
+        else                            // an empty existing med file of the right version will be used for append
+          {
+            int medVersionsOK[] = MED_VERSIONS_APPEND_COMPATIBLE;
+            bool isVersionOK = false;
+            for (int ii=0; ii < sizeof(medVersionsOK)/sizeof(int); ii++)
+              if (medVersionsOK[ii] == theVersion)
+                {
+                  isVersionOK =true;
+                  break;
+                }
+            if (isVersionOK)           // copy an empty existing med file of the right version, for append
+              {
+                MESSAGE("copy an empty existing med file of the right version, for append" << theVersion);
+              }
+          }
+      }
+    return new MED::TWrapper(fileName, minor);
   }
 }
index 402f97cb92f99c06612c7544559288e1df96f6ce..84087d138d1a9946de3cdc189ad2be6b0b109be1 100644 (file)
@@ -47,7 +47,7 @@ namespace MED
   PWrapper CrWrapperR( const std::string& );
 
   MEDWRAPPER_EXPORT
-  PWrapper CrWrapperW( const std::string&, int theMinor=-1 );
+  PWrapper CrWrapperW( const std::string&, int theVersion=-1 );
 }
 
 #endif // MED_Factory_HeaderFile
index 05b0496c28554fdf7c23800441fcbca76d69da82..159d4571492d39653f7585b783176976441b3263 100644 (file)
@@ -52,7 +52,7 @@ namespace MED
     TWrapper& operator=(const TWrapper&);
 
   public:
-    TWrapper(const std::string& theFileName, TInt theMinor=-1);
+    TWrapper(const std::string& theFileName, TInt theVersion=-1);
 
     virtual
     ~TWrapper();
index 4ee7e09c02c5d00af265fd5b5a5d9670c2b98056..2a19d6e73e800f2df7803f812ac4fe6a426844be 100644 (file)
@@ -1421,18 +1421,18 @@ bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
 void SMESH_Mesh::ExportMED(const char *        file, 
                            const char*         theMeshName, 
                            bool                theAutoGroups,
-                           int                 theMinor,
+                           int                 theVersion,
                            const SMESHDS_Mesh* meshPart,
                            bool                theAutoDimension,
                            bool                theAddODOnVertices,
                            bool                theAllElemsToGroup)
   throw(SALOME_Exception)
 {
-  //MESSAGE("MED_VERSION:"<< theVersion);
+  MESSAGE("MED_VERSION:"<< theVersion);
   SMESH_TRY;
 
   DriverMED_W_SMESHDS_Mesh myWriter;
-  myWriter.SetFile         ( file , theMinor);
+  myWriter.SetFile         ( file , theVersion);
   myWriter.SetMesh         ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS   );
   myWriter.SetAutoDimension( theAutoDimension );
   myWriter.AddODOnVertices ( theAddODOnVertices );
index dbe14fed8203f849ea94426941ed3f5a530a8d98..59ad490b1e0d7fee4a541bfa925ca38f0f48e9f5 100644 (file)
@@ -254,7 +254,7 @@ class SMESH_EXPORT SMESH_Mesh
   void ExportMED(const char *        theFile, 
                  const char*         theMeshName = NULL, 
                  bool                theAutoGroups = true, 
-                 int                 TheMinor = -1,
+                 int                 theVersion = -1,
                  const SMESHDS_Mesh* theMeshPart = 0,
                  bool                theAutoDimension = false,
                  bool                theAddODOnVertices = false,
index e9a49327cf09c6a2aaeb8494ba57d749b9d1add4..99ae22dd25df1bb819fb14bf39f4c995dfe2ee9d 100644 (file)
@@ -655,7 +655,7 @@ namespace
     // Get parameters of export operation
 
     QString aFilename;
-    int aFormat =-1;         // for MED minor versions
+    int aFormat =-1;         // for MED version used for write
     bool isOkToWrite = true; // to check MED file version compatibility before adding a mesh in an existing file
 
     // Init the parameters with the default values
@@ -744,36 +744,39 @@ namespace
     }
     else if ( isMED || isSAUV ) // Export to MED or SAUV
     {
+      int defaultVersion = 0;
       QMap<QString, int> aFilterMap;
       if ( isMED ) {
         //filters << QObject::tr( "MED_FILES_FILTER" ) + " (*.med)";
         //QString vmed (aMesh->GetVersionString(-1, 2));
         //MESSAGE("MED version: " << vmed.toStdString());
         SMESH::long_array_var mvok = aMesh->GetMEDVersionsCompatibleForAppend();
-        for ( int i = 0; i < mvok->length(); ++i )
+        for ( int i = 0; i < mvok->length(); ++i )  // i=0 must correspond to the current version to set the default filter on it
           {
             int versionInt = mvok[i];
+            if (i == 0)
+              defaultVersion = versionInt;
             std::ostringstream vss;
             vss << versionInt/10;
             vss << ".";
             vss << versionInt%10;
             QString vs = vss.str().c_str();
             MESSAGE("MED version: " << vs.toStdString());
-            aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vs ) + " (*.med)",  i);
+            aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vs ) + " (*.med)",  versionInt);
           }
       }
       else { // isSAUV
         aFilterMap.insert("All files (*)", -1 );
-        aFilterMap.insert("SAUV files (*.sauv)", 0 );
+        aFilterMap.insert("SAUV files (*.sauv)", defaultVersion ); // 0 = default filter (defaultVersion)
         aFilterMap.insert("SAUV files (*.sauve)", -1 );
       }
-
+      MESSAGE("default version="<< defaultVersion);
       QStringList filters;
       QMap<QString, int>::const_iterator it = aFilterMap.begin();
       QString aDefaultFilter = it.key();
       for ( ; it != aFilterMap.end(); ++it ) {
         filters.push_back( it.key() );
-        if (it.value() == 0) // explicit default for MED = current MED version
+        if (it.value() == defaultVersion) // explicit default for MED = current MED version
           aDefaultFilter = it.key();
       }
       QStringList checkBoxes;
@@ -819,13 +822,13 @@ namespace
           break;
         }
         aFormat = aFilterMap[fd->selectedNameFilter()];
-        MESSAGE("selected minor: " << aFormat << " file: " << aFilename.toUtf8().constData());
+        MESSAGE("selected version: " << aFormat << " file: " << aFilename.toUtf8().constData());
         toOverwrite = fv->isOverwrite(aFilename);
         MESSAGE("toOverwrite:" << toOverwrite);
         is_ok = true;
         if ( !aFilename.isEmpty() ) {
           if( !toOverwrite ) {
-            // can't append to an existing using other format
+            // append is only possible if the existing file format is compatible
             bool isVersionOk = SMESHGUI::GetSMESHGen()->CheckWriteCompatibility( aFilename.toUtf8().constData() );
             MESSAGE("Append check, isVersionOk:" << isVersionOk);
             if ( !isVersionOk ) {
index 540211542cc35aa31e3e95769d6296654a72dd5d..26fcc1e97c84907a03107b53f48f3487c4b4e775 100644 (file)
@@ -3079,7 +3079,7 @@ string SMESH_Mesh_i::prepareMeshNameAndGroups(const char*    file,
 
 void SMESH_Mesh_i::ExportMED(const char*        file,
                              CORBA::Boolean     auto_groups,
-                             CORBA::Long        minor,
+                             CORBA::Long        version,
                              CORBA::Boolean     overwrite,
                              CORBA::Boolean     autoDimension)
   throw(SALOME::SALOME_Exception)
@@ -3090,12 +3090,12 @@ void SMESH_Mesh_i::ExportMED(const char*        file,
     _preMeshInfo->FullLoadFromFile();
 
   string aMeshName = prepareMeshNameAndGroups(file, overwrite);
-  _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, 0, autoDimension );
+  _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, 0, autoDimension );
 
   TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportMED( r'"
                 << file << "', "
                 << "auto_groups=" <<auto_groups << ", "
-                << "minor=" << minor <<  ", "
+                << "minor=" << version <<  ", "
                 << "overwrite=" << overwrite << ", "
                 << "meshPart=None, "
                 << "autoDimension=" << autoDimension << " )";
@@ -3208,14 +3208,14 @@ void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
 void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
                                    const char*               file,
                                    CORBA::Boolean            auto_groups,
-                                   CORBA::Long               minor,
+                                   CORBA::Long               version,
                                    CORBA::Boolean            overwrite,
                                    CORBA::Boolean            autoDimension,
                                    const GEOM::ListOfFields& fields,
                                    const char*               geomAssocFields)
   throw (SALOME::SALOME_Exception)
 {
-  //MESSAGE("MED minor version: "<< minor);
+  MESSAGE("MED version: "<< version);
   SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
@@ -3262,7 +3262,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, minor,
+    _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version,
                       0, autoDimension, /*addODOnVertices=*/have0dField);
     meshDS = _impl->GetMeshDS();
   }
@@ -3280,7 +3280,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, minor,
+    _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version,
                       partDS, autoDimension, /*addODOnVertices=*/have0dField);
     meshDS = tmpDSDeleter._obj = partDS;
   }
@@ -3309,7 +3309,7 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
                 << meshPart << ", r'"
                 << file << "', "
                 << auto_groups << ", "
-                << minor << ", "
+                << version << ", "
                 << overwrite << ", "
                 << autoDimension << ", "
                 << goList << ", '"
index 786bfc9bd712b7e61288bedb0bf0afa63c17fd22..41bbce48b96c2038c4cc1dfa790cd0bd738cfb1c 100644 (file)
@@ -239,7 +239,7 @@ public:
 
   void ExportMED( const char*        file,
                   CORBA::Boolean     auto_groups,
-                  CORBA::Long        minor,
+                  CORBA::Long        version,
                   CORBA::Boolean     overwrite,
                   CORBA::Boolean     autoDimension = true) throw (SALOME::SALOME_Exception);
 
@@ -259,7 +259,7 @@ public:
   void ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
                        const char*               file,
                        CORBA::Boolean            auto_groups,
-                       CORBA::Long               minor,
+                       CORBA::Long               version,
                        CORBA::Boolean            overwrite,
                        CORBA::Boolean            autoDim,
                        const GEOM::ListOfFields& fields,