Salome HOME
Issue 0020514: EDF 1110 SMESH : Export many meshes in one Med File
authorouv <ouv@opencascade.com>
Mon, 11 Jan 2010 07:17:11 +0000 (07:17 +0000)
committerouv <ouv@opencascade.com>
Mon, 11 Jan 2010 07:17:11 +0000 (07:17 +0000)
13 files changed:
idl/SMESH_Gen.idl
idl/SMESH_Mesh.idl
src/SMESHGUI/Makefile.am
src/SMESHGUI/SMESHGUI.cxx
src/SMESHGUI/SMESHGUI_FileValidator.cxx [new file with mode: 0755]
src/SMESHGUI/SMESHGUI_FileValidator.h [new file with mode: 0755]
src/SMESHGUI/SMESH_msg_en.ts
src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_I/SMESH_Gen_i.hxx
src/SMESH_I/SMESH_Mesh_i.cxx
src/SMESH_I/SMESH_Mesh_i.hxx
src/SMESH_SWIG/smeshDC.py

index 9173c3f86dd382bb15a999987e0e8ae954e01126..4bec6e9d868310c0055bf966a6e8c14597e65c06 100644 (file)
@@ -339,6 +339,16 @@ module SMESH
      * Can be used to check if the object was created in the same container, as this engine.
      */
     long GetObjectId(in Object theObject);
+
+    /*!
+     * \brief Get MED version of the file by its name.
+     */
+    boolean GetMEDVersion(in string theFileName, out MED_VERSION theVersion);
+
+    /*!
+     * \brief Get names of meshes defined in file with the specified name.
+     */
+    string_array GetMeshNames(in string theFileName);
   };
 
 };
index c58b7fa31665501769d0bc0b28506f74f9ccfa9b..8d55cd0db319d0809240bdede538c15ef9488fb7 100644 (file)
@@ -532,13 +532,23 @@ module SMESH
      *   the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
      *   the typical use is auto_groups=false.
      * - theVersion : define the version of format of MED file, that will be created
+     * - overwrite : boolean parameter for overwriting/not overwriting the file, if it exists
+     */
+    void ExportToMEDX( in string file, in boolean auto_groups, in MED_VERSION theVersion, in boolean overwrite )
+      raises (SALOME::SALOME_Exception);
+
+    /*!
+     * Export Mesh to different MED Formats
+     * Works, just the same as ExportToMEDX, with overwrite parameter equal to true.
+     * The method is kept in order to support old functionality
      */
     void ExportToMED( in string file, in boolean auto_groups, in MED_VERSION theVersion )
       raises (SALOME::SALOME_Exception);
 
     /*!
      * Export Mesh to MED_V2_1 MED format
-     * Works, just the same as ExportToMED, with MED_VERSION parameter equal to MED_V2_1.
+     * Works, just the same as ExportToMEDX with MED_VERSION parameter equal to MED_V2_1
+     * and overwrite parameter equal to true
      * The method is kept in order to support old functionality
      */
     void ExportMED( in string file, in boolean auto_groups )
index 394a318641cea2d2fb5233ea3ee34ec7f6ab28d6..c9f9be98e6d913fc99c2ca40aa3d0392aef3aa75 100644 (file)
@@ -95,6 +95,7 @@ salomeinclude_HEADERS = \
        SMESHGUI_FindElemByPointDlg.h \
        SMESHGUI_MeshOrderDlg.h \
        SMESHGUI_MeshOrderOp.h \
+       SMESHGUI_FileValidator.h \
        SMESH_SMESHGUI.hxx
 
 # Libraries targets
@@ -166,7 +167,8 @@ dist_libSMESH_la_SOURCES = \
        SMESHGUI_MeshInfosBox.cxx \
        SMESHGUI_Make2DFrom3DOp.cxx \
        SMESHGUI_MeshOrderDlg.cxx \
-       SMESHGUI_MeshOrderOp.cxx
+       SMESHGUI_MeshOrderOp.cxx \
+       SMESHGUI_FileValidator.cxx
 
 MOC_FILES = \
        SMESHGUI_moc.cxx \
index 1b84f9acfd4b72b0cf97856adc4f73b1d4b8b09a..74b9d16736be29afce32df22f2f2618b9c2ef1f0 100644 (file)
@@ -38,6 +38,7 @@
 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
 #include "SMESHGUI_ExtrusionDlg.h"
 #include "SMESHGUI_FileInfoDlg.h"
+#include "SMESHGUI_FileValidator.h"
 #include "SMESHGUI_FilterDlg.h"
 #include "SMESHGUI_FilterLibraryDlg.h"
 #include "SMESHGUI_FindElemByPointDlg.h"
     if( aSel )
       aSel->selectedObjects( selected );
 
-    SMESH::SMESH_Mesh_var aMesh;
-    if(selected.Extent() == 1)
-      aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(selected.First());
-    if ( aMesh->_is_nil() ) {
-      SUIT_MessageBox::warning( SMESHGUI::desktop(),
-                                QObject::tr( "SMESH_WRN_WARNING" ),
-                                QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
+    // actually, the following condition can't be met (added for insurance)
+    if( selected.Extent() == 0 ||
+        selected.Extent() > 1 && theCommandID != 122 && theCommandID != 125 )
       return;
+
+    bool hasDuplicatedMeshNames = false;
+    QList< QPair< SMESH::SMESH_Mesh_var, QString > > aMeshList;
+    QList< QPair< SMESH::SMESH_Mesh_var, QString > >::iterator aMeshIter;
+    SALOME_ListIteratorOfListIO It( selected );
+    for( ; It.More(); It.Next() ) {
+      Handle(SALOME_InteractiveObject) anIObject = It.Value();
+      SMESH::SMESH_Mesh_var aMeshItem = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIObject );
+      if ( aMeshItem->_is_nil() ) {
+        SUIT_MessageBox::warning( SMESHGUI::desktop(),
+                                  QObject::tr( "SMESH_WRN_WARNING" ),
+                                  QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
+        return;
+      }
+
+      QString aMeshName = anIObject->getName();
+
+      // check for duplications
+      for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
+        if( aMeshName == (*aMeshIter).second ) {
+          hasDuplicatedMeshNames = true;
+          break;
+        }
+      }
+
+      aMeshList.append( QPair< SMESH::SMESH_Mesh_var, QString >( aMeshItem, aMeshName ) );
     }
 
-    Handle(SALOME_InteractiveObject) anIObject = selected.First();
+    if( hasDuplicatedMeshNames ) {
+      int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
+                                          QObject::tr("SMESH_WRN_WARNING"),
+                                          QObject::tr("SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES"),
+                                          QObject::tr("SMESH_BUT_YES"),
+                                          QObject::tr("SMESH_BUT_NO"), 0, 1);
+      if (aRet != 0)
+        return;
+    }
+
+    aMeshIter = aMeshList.begin();
+    SMESH::SMESH_Mesh_var aMesh = (*aMeshIter).first;
+    QString aMeshName = (*aMeshIter).second;
+
+    QList<SALOMEDS::Color> aReservedColors;
+
     QString aFilter, aTitle = QObject::tr("Export mesh");
     QMap<QString, SMESH::MED_VERSION> aFilterMap;
     QMap<QString, int> aFilterMapSTL;
     case 125:
     case 122:
       {
-        if (aMesh->HasDuplicatedGroupNamesMED()) {
-          int aRet = SUIT_MessageBox::warning
-            (SMESHGUI::desktop(),
-             QObject::tr("SMESH_WRN_WARNING"),
-             QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg(anIObject->getName()),
-             SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes);
-          if (aRet != SUIT_MessageBox::Yes)
-            return;
+        for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
+          SMESH::SMESH_Mesh_var aMeshItem = (*aMeshIter).first;
+          if (aMeshItem->HasDuplicatedGroupNamesMED()) {
+            int aRet = SUIT_MessageBox::warning
+              (SMESHGUI::desktop(),
+               QObject::tr("SMESH_WRN_WARNING"),
+               QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg((*aMeshIter).second),
+               QObject::tr("SMESH_BUT_YES"),
+               QObject::tr("SMESH_BUT_NO"), 0, 1);
+            if (aRet != 0)
+              return;
+          }
         }
         // PAL18696
         QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
           int aRet = SUIT_MessageBox::warning
             (SMESHGUI::desktop(),
              QObject::tr("SMESH_WRN_WARNING"),
-             QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()),
-             SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes);
-          if (aRet != SUIT_MessageBox::Yes)
+             QObject::tr("SMESH_EXPORT_UNV").arg(aMeshName),
+             QObject::tr("SMESH_BUT_YES"),
+             QObject::tr("SMESH_BUT_NO"), 0, 1);
+          if (aRet != 0)
             return;
         }
         aFilter = QObject::tr("IDEAS files (*.unv)");
           SUIT_MessageBox::warning
             (SMESHGUI::desktop(),
              QObject::tr("SMESH_WRN_WARNING"),
-             QObject::tr("SMESH_EXPORT_STL1").arg(anIObject->getName()));
+             QObject::tr("SMESH_EXPORT_STL1").arg(aMeshName));
           return;
         }
         if (!(aMesh->NbElements() - aMesh->NbTriangles())) {
           int aRet = SUIT_MessageBox::warning
             (SMESHGUI::desktop(),
              QObject::tr("SMESH_WRN_WARNING"),
-             QObject::tr("SMESH_EXPORT_STL2").arg(anIObject->getName()),
-             SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes);
-          if (aRet != SUIT_MessageBox::Yes)
+             QObject::tr("SMESH_EXPORT_STL2").arg(aMeshName),
+             QObject::tr("SMESH_BUT_YES"),
+             QObject::tr("SMESH_BUT_NO"), 0, 1);
+          if (aRet != 0)
             return;
         }
 
     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
     if ( resMgr )
       toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
+    bool toOverwrite = true;
 
     QString anInitialPath = "";
     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
 
     if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141) {
       if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
-      aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + anIObject->getName(),
+      aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + aMeshName,
                                             aFilter, aTitle, false);
     }
     else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
       fd->selectFilter( QObject::tr("STL ASCII  (*.stl)") );
       if ( !anInitialPath.isEmpty() )
         fd->setDirectory( anInitialPath );
-      fd->selectFile(anIObject->getName());
+      fd->selectFile(aMeshName);
       bool is_ok = false;
       while (!is_ok) {
         if ( fd->exec() )
       fd->SetChecked(toCreateGroups);
       if ( !anInitialPath.isEmpty() )
         fd->setDirectory( anInitialPath );
-      fd->selectFile(anIObject->getName());
+      fd->selectFile(aMeshName);
+
+      SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
+      fd->setValidator( fv );
+
       bool is_ok = false;
       while (!is_ok) {
         if ( fd->exec() )
           aFilename = fd->selectedFile();
+        else {
+          aFilename = QString::null;
+          break;
+        }
         aFormat = aFilterMap[fd->selectedFilter()];
+        toOverwrite = fv->isOverwrite();
         is_ok = true;
-        if ( !aFilename.isEmpty()
-             && (aMesh->NbPolygons()>0 || aMesh->NbPolyhedrons()>0)
-             && aFormat==SMESH::MED_V2_1) {
-          int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
-                                              QObject::tr("SMESH_WRN_WARNING"),
-                                              QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()),
-                                              SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes);
-          if (aRet != SUIT_MessageBox::Yes) {
-            is_ok = false;
+        if ( !aFilename.isEmpty() ) {
+          for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
+            SMESH::SMESH_Mesh_var aMeshItem = (*aMeshIter).first;
+            if( (aMeshItem->NbPolygons()>0 || aMeshItem->NbPolyhedrons()>0)
+                && aFormat==SMESH::MED_V2_1) {
+              int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
+                                                  QObject::tr("SMESH_WRN_WARNING"),
+                                                  QObject::tr("SMESH_EXPORT_MED_V2_1").arg((*aMeshIter).second),
+                                                  QObject::tr("SMESH_BUT_YES"),
+                                                  QObject::tr("SMESH_BUT_NO"), 0, 1);
+              if (aRet != 0) {
+                is_ok = false;
+                break;
+              }
+            }
+          }
+          if( !toOverwrite ) {
+            SMESH::MED_VERSION aVersion = SMESH::MED_V2_1;
+            bool isVersionOk = SMESHGUI::GetSMESHGen()->GetMEDVersion( aFilename.toLatin1().constData(), aVersion );
+            if( !isVersionOk || aVersion != aFormat ) {
+              int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
+                                                  QObject::tr("SMESH_WRN_WARNING"),
+                                                  QObject::tr("SMESH_EXPORT_MED_VERSION_COLLISION").arg(aFilename),
+                                                  QObject::tr("SMESH_BUT_YES"),
+                                                  QObject::tr("SMESH_BUT_NO"), 0, 1);
+              if (aRet == 0)
+                toOverwrite = true;
+              else
+                is_ok = false;
+            }
+
+            QStringList aMeshNamesCollisionList;
+            SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toLatin1().constData() );
+            for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
+              QString anExistingMeshName( aMeshNames[ i ] );
+              for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
+                QString anExportMeshName = (*aMeshIter).second;
+                if( anExportMeshName == anExistingMeshName ) {
+                  aMeshNamesCollisionList.append( anExportMeshName );
+                  break;
+                }
+              }
+            }
+
+            if( !aMeshNamesCollisionList.isEmpty() ) {
+              QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
+              int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
+                                                  QObject::tr("SMESH_WRN_WARNING"),
+                                                  QObject::tr("SMESH_EXPORT_MED_MESH_NAMES_COLLISION").arg(aMeshNamesCollisionString),
+                                                  QObject::tr("SMESH_BUT_YES"),
+                                                  QObject::tr("SMESH_BUT_NO"),
+                                                  QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
+              if (aRet == 0)
+                toOverwrite = true;
+              else if (aRet == 2)
+                is_ok = false;
+            }
           }
         }
       }
     if ( !aFilename.isEmpty() ) {
       // Check whether the file already exists and delete it if yes
       QFile aFile( aFilename );
-      if ( aFile.exists() )
+      if ( aFile.exists() && toOverwrite )
         aFile.remove();
       SUIT_OverrideCursor wc;
 
         }
         switch ( theCommandID ) {
         case 125:
-        case 122:
-          aMesh->ExportToMED( aFilename.toLatin1().data(), toCreateGroups, aFormat );
+        case 122: {
+            int aMeshIndex = 0;
+            for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ ) {
+              SMESH::SMESH_Mesh_var aMeshItem = (*aMeshIter).first;
+              if( !aMeshItem->_is_nil() )
+                aMeshItem->ExportToMEDX( aFilename.toLatin1().data(), toCreateGroups, aFormat, toOverwrite && aMeshIndex == 0 );
+            }
+          }
           break;
         case 124:
         case 121:
@@ -3135,8 +3243,9 @@ void SMESHGUI::initialize( CAM_Application* app )
   popupMgr()->insert( separator(), -1, 0 );
 
   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
+  QString multiple_non_empty = QString( " && %1>0 && numberOfNodes>0" ).arg( dc );
 
-  createPopupItem( 125, OB, mesh, only_one_non_empty );   // EXPORT_MED
+  createPopupItem( 125, OB, mesh, multiple_non_empty );   // EXPORT_MED
   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
   //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
diff --git a/src/SMESHGUI/SMESHGUI_FileValidator.cxx b/src/SMESHGUI/SMESHGUI_FileValidator.cxx
new file mode 100755 (executable)
index 0000000..f2aa316
--- /dev/null
@@ -0,0 +1,76 @@
+//  Copyright (C) 2007-2008  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
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// SMESH SMESHGUI : GUI for SMESH component
+// File   : SMESHGUI_FileValidator.cxx
+// Author : Oleg UVAROV
+// SMESH includes
+//
+#include "SMESHGUI_FileValidator.h"
+
+// SALOME GUI includes
+#include <SUIT_MessageBox.h>
+#include <SUIT_Tools.h>
+
+// Qt includes
+#include <QFileInfo>
+
+//=======================================================================
+//function : SMESHGUI_FileValidator
+//purpose  : 
+//=======================================================================
+SMESHGUI_FileValidator::SMESHGUI_FileValidator( QWidget* parent )
+: SUIT_FileValidator( parent ),
+  myIsOverwrite( true )
+{
+}
+  
+//=======================================================================
+//function : canSave
+//purpose  : 
+//=======================================================================
+bool SMESHGUI_FileValidator::canSave( const QString& fileName, bool checkPermission ) 
+{
+  if ( QFile::exists( fileName ) ) {
+    if ( parent() ) {
+      int anAnswer = SUIT_MessageBox::question( parent(), QObject::tr( "SMESH_WRN_WARNING" ),
+                                                QObject::tr( "SMESH_FILE_EXISTS" ).arg( fileName ),
+                                                QObject::tr( "SMESH_BUT_OVERWRITE" ),
+                                                QObject::tr( "SMESH_BUT_ADD" ),
+                                                QObject::tr( "SMESH_BUT_CANCEL" ), 0, 2 );
+      if( anAnswer == 2 )
+        return false;
+      myIsOverwrite = anAnswer == 0;
+    }
+
+    // copied from SUIT_FileValidator
+    if ( checkPermission && !QFileInfo( fileName ).isWritable() ) {
+      if ( parent() ) 
+        SUIT_MessageBox::critical( parent(), QObject::tr( "SMESH_ERROR" ),
+                                   QObject::tr( "NO_PERMISSION" ).arg( fileName ) );
+      return false; 
+    }
+  }
+  else {
+    return SUIT_FileValidator::canSave( fileName, checkPermission );
+  }
+  return true;
+}
diff --git a/src/SMESHGUI/SMESHGUI_FileValidator.h b/src/SMESHGUI/SMESHGUI_FileValidator.h
new file mode 100755 (executable)
index 0000000..ae42667
--- /dev/null
@@ -0,0 +1,48 @@
+//  Copyright (C) 2007-2008  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
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// SMESH SMESHGUI : GUI for SMESH component
+// File   : SMESHGUI_FileValidator.h
+// Author : Oleg UVAROV
+//
+#ifndef SMESHGUI_FILEVALIDATOR_H
+#define SMESHGUI_FILEVALIDATOR_H
+
+// SMESH includes
+#include "SMESH_SMESHGUI.hxx"
+
+// SALOME GUI includes
+#include <SUIT_FileValidator.h>
+
+class SMESHGUI_EXPORT SMESHGUI_FileValidator : public SUIT_FileValidator
+{
+public:
+  SMESHGUI_FileValidator( QWidget* = 0 );
+  
+  virtual bool canSave( const QString&, bool = true );
+
+  bool         isOverwrite() const { return myIsOverwrite; }
+
+private:
+  bool         myIsOverwrite;
+};
+
+#endif // SMESHGUI_FILEVALIDATOR_H
index 5e0e03e4fea37e3046c2b1746bed2823413064d6..6a864d0f5ab95cb2d9aae43cb306bb9f8d6a1d2e 100644 (file)
@@ -969,6 +969,10 @@ Please enter correct values and try again</translation>
             <source>SMESH_BUT_OK</source>
             <translation>&amp;Ok</translation>
         </message>
+        <message>
+            <source>SMESH_BUT_OVERWRITE</source>
+            <translation>Over&amp;write</translation>
+        </message>
         <message>
             <source>SMESH_BUT_APPLY_AND_CLOSE</source>
             <translation>A&amp;pply and Close</translation>
@@ -1175,6 +1179,12 @@ Probably, there is not enough space on disk.</translation>
 You can cancel exporting and rename them,
 otherwise some group names in the resulting MED file
 will not match ones in the study.
+Do you want to continue ?</translation>
+        </message>
+        <message>
+            <source>SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES</source>
+            <translation>There are some meshes with the same names in the selection.
+The result file may be incorrect.
 Do you want to continue ?</translation>
         </message>
         <message>
@@ -1183,6 +1193,19 @@ Do you want to continue ?</translation>
 polygons and polyhedrons elements will be missed
 For correct export use MED 2.2
 Are you sure want to export to MED 2.1 ?</translation>
+        </message>
+        <message>
+            <source>SMESH_EXPORT_MED_VERSION_COLLISION</source>
+            <translation>MED version of the file "%1"
+is unknown or doesn't match the selected version.
+Overwrite the file?</translation>
+        </message>
+        <message>
+            <source>SMESH_EXPORT_MED_MESH_NAMES_COLLISION</source>
+            <translation>The selected file already contains
+meshes with the following names: %1
+The result file may be incorrect.
+Overwrite the file?</translation>
         </message>
         <message>
             <source>SMESH_EXPORT_STL1</source>
@@ -1221,6 +1244,12 @@ Are you sure want to export to MED 2.1 ?</translation>
             <source>SMESH_FEATUREEDGES</source>
             <translation>Feature Edges</translation>
         </message>
+        <message>
+            <source>SMESH_FILE_EXISTS</source>
+            <translation>The file "%1" already exists.
+Do you want to overwrite it or
+add the exported data to its contents?</translation>
+        </message>
         <message>
             <source>SMESH_FONT_ARIAL</source>
             <translation>Arial</translation>
index 42358009e60b9a81fc86162554b2156319182337..d21765a8f66904811e1a089e5409be7e47e12078 100644 (file)
@@ -846,7 +846,8 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
     }
   }
   // ----------------------------------------------------------------------
-  else if ( method == "ExportToMED" ) { // ExportToMED() --> ExportMED()
+  else if ( method == "ExportToMED" ||   // ExportToMED() --> ExportMED()
+            method == "ExportToMEDX" ) { // ExportToMEDX() --> ExportMED()
     theCommand->SetMethod( "ExportMED" );
   }
   // ----------------------------------------------------------------------
index 58ed9071fb926cf8b2d70b2c491ac4b133f4c7e9..52bf0094880be4c14facda3ff1264f1406ad9980 100644 (file)
@@ -2193,6 +2193,49 @@ SMESH_Gen_i::ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
   return aNewMesh._retn();
 }
 
+//================================================================================
+/*!
+ *  SMESH_Gen_i::GetMEDVersion
+ *
+ *  Get MED version of the file by its name
+ */
+//================================================================================
+CORBA::Boolean SMESH_Gen_i::GetMEDVersion(const char* theFileName,
+                                          SMESH::MED_VERSION& theVersion)
+{
+  theVersion = SMESH::MED_V2_1;
+  MED::EVersion aVersion = MED::GetVersionId( theFileName );
+  switch( aVersion ) {
+    case MED::eV2_1     : theVersion = SMESH::MED_V2_1; return true;
+    case MED::eV2_2     : theVersion = SMESH::MED_V2_2; return true;
+    case MED::eVUnknown : return false;
+  }
+  return false;
+}
+
+//================================================================================
+/*!
+ *  SMESH_Gen_i::GetMeshNames
+ *
+ *  Get names of meshes defined in file with the specified name
+ */
+//================================================================================
+SMESH::string_array* SMESH_Gen_i::GetMeshNames(const char* theFileName)
+{
+  SMESH::string_array_var aResult = new SMESH::string_array();
+  MED::PWrapper aMed = MED::CrWrapper( theFileName );
+  MED::TErr anErr;
+  MED::TInt aNbMeshes = aMed->GetNbMeshes( &anErr );
+  if( anErr >= 0 ) {
+    aResult->length( aNbMeshes );
+    for( MED::TInt i = 0; i < aNbMeshes; i++ ) {
+      MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo( i+1 );
+      aResult[i] = CORBA::string_dup( aMeshInfo->GetName().c_str() );
+    }
+  }
+  return aResult._retn();
+}
+
 //=============================================================================
 /*!
  *  SMESH_Gen_i::Save
index 13bca294ab715d73c53b84258e6d3a3733d1c9c6..174b1b2eb45fddc8e8f3354876d664ddfbc2d6c2 100644 (file)
@@ -320,6 +320,13 @@ public:
                                               CORBA::Double            theMergeTolerance)
     throw ( SALOME::SALOME_Exception );
 
+  // Get MED version of the file by its name
+  CORBA::Boolean GetMEDVersion(const char* theFileName,
+                               SMESH::MED_VERSION& theVersion);
+
+  // Get names of meshes defined in file with the specified name
+  SMESH::string_array* GetMeshNames(const char* theFileName);
+
   // ****************************************************
   // Interface inherited methods (from SALOMEDS::Driver)
   // ****************************************************
index 6e22b0d6a81886cf40a86116cc024b13c92140ae..9c44e29d2e49609bd17c86cd05acf714e4f73258 100644 (file)
@@ -2263,7 +2263,7 @@ CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
   return _impl->HasDuplicatedGroupNamesMED();
 }
 
-void SMESH_Mesh_i::PrepareForWriting (const char* file)
+void SMESH_Mesh_i::PrepareForWriting (const char* file, bool overwrite)
 {
   TCollection_AsciiString aFullName ((char*)file);
   OSD_Path aPath (aFullName);
@@ -2272,8 +2272,10 @@ void SMESH_Mesh_i::PrepareForWriting (const char* file)
     // existing filesystem node
     if (aFile.KindOfFile() == OSD_FILE) {
       if (aFile.IsWriteable()) {
-        aFile.Reset();
-        aFile.Remove();
+        if (overwrite) {
+          aFile.Reset();
+          aFile.Remove();
+        }
         if (aFile.Failed()) {
           TCollection_AsciiString msg ("File ");
           msg += aFullName + " cannot be replaced.";
@@ -2304,15 +2306,16 @@ void SMESH_Mesh_i::PrepareForWriting (const char* file)
   }
 }
 
-void SMESH_Mesh_i::ExportToMED (const char* file,
-                                CORBA::Boolean auto_groups,
-                                SMESH::MED_VERSION theVersion)
+void SMESH_Mesh_i::ExportToMEDX (const char* file,
+                                 CORBA::Boolean auto_groups,
+                                 SMESH::MED_VERSION theVersion,
+                                 CORBA::Boolean overwrite)
   throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
 
   // Perform Export
-  PrepareForWriting(file);
+  PrepareForWriting(file, overwrite);
   const char* aMeshName = "Mesh";
   SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
   if ( !aStudy->_is_nil() ) {
@@ -2344,17 +2347,25 @@ void SMESH_Mesh_i::ExportToMED (const char* file,
   // check names of groups
   checkGroupNames();
 
-  TPythonDump() << _this() << ".ExportToMED( '"
-                << file << "', " << auto_groups << ", " << theVersion << " )";
+  TPythonDump() << _this() << ".ExportToMEDX( '"
+                << file << "', " << auto_groups << ", " << theVersion << ", " << overwrite << " )";
 
   _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
 }
 
+void SMESH_Mesh_i::ExportToMED (const char* file,
+                                CORBA::Boolean auto_groups,
+                                SMESH::MED_VERSION theVersion)
+  throw(SALOME::SALOME_Exception)
+{
+  ExportToMEDX(file,auto_groups,theVersion,true);
+}
+
 void SMESH_Mesh_i::ExportMED (const char* file,
                               CORBA::Boolean auto_groups)
   throw(SALOME::SALOME_Exception)
 {
-  ExportToMED(file,auto_groups,SMESH::MED_V2_1);
+  ExportToMEDX(file,auto_groups,SMESH::MED_V2_1,true);
 }
 
 void SMESH_Mesh_i::ExportDAT (const char *file)
index 99513b047854bb69848317d71077faf3d3dbbb8c..ab8abdabf27dcb2a2a442d9bb0fb37dad983f3d2 100644 (file)
@@ -206,6 +206,8 @@ public:
    */
   char* GetVersionString(SMESH::MED_VERSION version, CORBA::Short nbDigits);
 
+  void ExportToMEDX( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion, CORBA::Boolean overwrite )
+    throw (SALOME::SALOME_Exception);
   void ExportToMED( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion )
     throw (SALOME::SALOME_Exception);
   void ExportMED( const char* file, CORBA::Boolean auto_groups )
@@ -338,7 +340,7 @@ public:
   static SMESH::Hypothesis_Status
   ConvertHypothesisStatus (SMESH_Hypothesis::Hypothesis_Status theStatus);
 
-  static void PrepareForWriting (const char* file);
+  static void PrepareForWriting (const char* file, bool overwrite = true);
 
   //int importMEDFile( const char* theFileName, const char* theMeshName );
 
index 3b0e547caf2ad4231f3114fb5c5aa5e5737f3630..1510a126f4b982326b14df6767f68e76076977c4 100644 (file)
@@ -1328,25 +1328,29 @@ class Mesh:
     def Group(self, grp, name=""):
         return self.GroupOnGeom(grp, name)
 
-    ## Deprecated, used only for compatibility! Please, use ExportMED() method instead.
+    ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
     #  Exports the mesh in a file in MED format and chooses the \a version of MED format
+    ## allowing to overwrite the file if it exists or add the exported data to its contents
     #  @param f the file name
     #  @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
     #  @param opt boolean parameter for creating/not creating
     #  the groups Group_On_All_Nodes, Group_On_All_Faces, ...
+    #  @param overwrite boolean parameter for overwriting/not overwriting the file
     #  @ingroup l2_impexp
-    def ExportToMED(self, f, version, opt=0):
-        self.mesh.ExportToMED(f, opt, version)
+    def ExportToMED(self, f, version, opt=0, overwrite=1):
+        self.mesh.ExportToMEDX(f, opt, version, overwrite)
 
-    ## Exports the mesh in a file in MED format
+    ## Exports the mesh in a file in MED format and chooses the \a version of MED format
+    ## allowing to overwrite the file if it exists or add the exported data to its contents
     #  @param f is the file name
     #  @param auto_groups boolean parameter for creating/not creating
     #  the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
     #  the typical use is auto_groups=false.
     #  @param version MED format version(MED_V2_1 or MED_V2_2)
+    #  @param overwrite boolean parameter for overwriting/not overwriting the file
     #  @ingroup l2_impexp
-    def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
-        self.mesh.ExportToMED(f, auto_groups, version)
+    def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1):
+        self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
 
     ## Exports the mesh in a file in DAT format
     #  @param f the file name