Salome HOME
IMP 001989: multi selection in "Import" dialog boxes
authorvsr <vsr@opencascade.com>
Wed, 2 Jul 2008 08:41:03 +0000 (08:41 +0000)
committervsr <vsr@opencascade.com>
Wed, 2 Jul 2008 08:41:03 +0000 (08:41 +0000)
src/SMESHGUI/SMESHGUI.cxx
src/SMESHGUI/SMESH_msg_en.po

index f9ed315776ef4f3bd3f03fb83d6ba53238302777..78f79cd15915d1fbed2ae7d50896a241507a0023 100644 (file)
@@ -169,93 +169,113 @@ using namespace std;
 
   // Definitions
   //=============================================================
-  void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
-                           int theCommandID)
+  void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
+                            int theCommandID )
   {
     QStringList filter;
     string myExtension;
 
-    if(theCommandID == 113){
-      filter.append(QObject::tr("MED files (*.med)"));
-      filter.append(QObject::tr("All files (*)"));
-    }else if (theCommandID == 112){
-      filter.append(QObject::tr("IDEAS files (*.unv)"));
-    }else if (theCommandID == 111){
-      filter.append(QObject::tr("DAT files (*.dat)"));
+    if ( theCommandID == 113 ) {
+      filter.append( QObject::tr( "MED files (*.med)" ) );
+      filter.append( QObject::tr( "All files (*)" ) );
+    }
+    else if ( theCommandID == 112 ) {
+      filter.append( QObject::tr( "IDEAS files (*.unv)" ) );
+    }
+    else if ( theCommandID == 111 ) {
+      filter.append( QObject::tr( "DAT files (*.dat)" ) );
     }
 
     QString anInitialPath = "";
     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
       anInitialPath = QDir::currentDirPath();
 
-    QString filename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
-                                                anInitialPath,
-                                                filter,
-                                                QObject::tr("Import mesh"),
-                                                true);
-    if(!filename.isEmpty()) {
+    QStringList filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
+                                                           anInitialPath,
+                                                           filter,
+                                                           QObject::tr( "SMESH_IMPORT_MESH" ) );
+    if ( filenames.count() > 0 ) {
       SUIT_OverrideCursor wc;
       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
 
-      try {
+      QStringList errors;
+      bool isEmpty = false;
+      for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it ) {
+       QString filename = *it;
        SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
-       switch ( theCommandID ) {
-       case 112:
-         {
-           aMeshes->length( 1 );
-           aMeshes[0] = theComponentMesh->CreateMeshesFromUNV(filename.latin1());
-           break;
-         }
-       case 113:
-         {
-           SMESH::DriverMED_ReadStatus res;
-           aMeshes = theComponentMesh->CreateMeshesFromMED(filename.latin1(),res);
-           if ( res != SMESH::DRS_OK ) {
-             wc.suspend();
-             SUIT_MessageBox::warn1(SMESHGUI::desktop(),
-                                     QObject::tr("SMESH_WRN_WARNING"),
-                                     QObject::tr(QString("SMESH_DRS_%1").arg(res)),
-                                     QObject::tr("SMESH_BUT_OK"));
-             aMeshes->length( 0 );
-             wc.resume();
+       try {
+         switch ( theCommandID ) {
+         case 111:
+           {
+             // DAT format (currently unsupported)
+             errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
+                            arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
+             break;
+           }
+         case 112:
+           {
+             // UNV format
+             aMeshes->length( 1 );
+             aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.latin1() );
+             if ( aMeshes[0]->_is_nil() )
+               errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
+                              arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
+             break;
+           }
+         case 113:
+           {
+             // MED format
+             SMESH::DriverMED_ReadStatus res;
+             aMeshes = theComponentMesh->CreateMeshesFromMED( filename.latin1(), res );
+             if ( res != SMESH::DRS_OK ) {
+               errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
+                              arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ) ) ) );
+             }
+             break;
            }
-           break;
          }
        }
+       catch ( const SALOME::SALOME_Exception& S_ex ) {
+         errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
+                        arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
+       }
 
-       bool isEmpty = false;
        for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
          _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
          if ( aMeshSO ) {
            _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
            _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
-           aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_IMPORTED");
+           aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
            if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
              SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
-         } else
+         }
+         else {
            isEmpty = true;
+         }
        }
+      }
 
-       if ( isEmpty ) {
-         wc.suspend();
-         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
-                                 QObject::tr("SMESH_WRN_WARNING"),
-                                 QObject::tr("SMESH_DRS_EMPTY"),
-                                 QObject::tr("SMESH_BUT_OK"));
-         wc.resume();
-       }
-
-       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
+      // update Object browser
+      SMESHGUI::GetSMESHGUI()->updateObjBrowser();
+      
+      // show Error message box if there were errors
+      if ( errors.count() > 0 ) {
+       SUIT_MessageBox::error1( SMESHGUI::desktop(),
+                                QObject::tr( "SMESH_ERROR" ),
+                                QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ),
+                                QObject::tr( "SMESH_BUT_OK" ) );
       }
-      catch (const SALOME::SALOME_Exception& S_ex){
-       wc.suspend();
-       SalomeApp_Tools::QtCatchCorbaException(S_ex);
-       wc.resume();
+      
+      // show warning message box, if some imported mesh is empty
+      if ( isEmpty ) {
+         SUIT_MessageBox::warn1( SMESHGUI::desktop(),
+                                 QObject::tr( "SMESH_WRN_WARNING" ),
+                                 QObject::tr( "SMESH_DRS_SOME_EMPTY" ),
+                                 QObject::tr( "SMESH_BUT_OK" ) );
       }
     }
   }
 
-
   void ExportMeshToFile( int theCommandID )
   {
     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
index e45227fc9ec3125a83d9f4b922670ee815e84b11..6fb75440811ce9dd01fd2d95e33b022b0b1dcc4c 100644 (file)
@@ -1384,20 +1384,16 @@ msgid "SMESH_DRS_1"
 msgstr "MED file contains no mesh with the given name"
 
 msgid "SMESH_DRS_2"
-msgstr ""
-"MED file has overlapped ranges of element numbers,\n"
-"     the numbers from the file are ignored"
+msgstr "MED file has overlapped ranges of element numbers, the numbers from the file are ignored"
 
 msgid "SMESH_DRS_3"
 msgstr "Some elements were skipped due to incorrect file data"
 
 msgid "SMESH_DRS_4"
-msgstr "    The file is incorrect,\n"
-       "some information will be missed"
+msgstr "The file is incorrect, some data is missed"
 
 msgid "SMESH_DRS_EMPTY"
-msgstr "      The file is empty,\n"
-       "there is nothing to be published"
+msgstr "The file is empty, there is nothing to be published"
 
 msgid "SMESH_EXPORT_UNV"
 msgstr "During export mesh with name - \"%1\" to UNV\n"
@@ -3568,3 +3564,18 @@ msgstr "File size (bytes)"
 
 msgid "SMESHGUI_FileInfoDlg::MED_VERSION"
 msgstr "MED version"
+
+msgid "SMESH_IMPORT_MESH"
+msgstr "Import mesh data from files"
+
+msgid "SMESH_ERR_NOT_SUPPORTED_FORMAT"
+msgstr "Unsupported file format"
+
+msgid "SMESH_ERR_UNKNOWN_IMPORT_ERROR"
+msgstr "Unknown error"
+
+msgid "SMESH_IMPORT_ERRORS"
+msgstr "Import operation has finished with errors:"
+
+msgid "SMESH_DRS_SOME_EMPTY"
+msgstr "One or more mesh files were empty, data has not been published"