Salome HOME
IMP 001989: multi selection in "Import" dialog boxes
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index d41fd1d59a6a30d8ebadfcc582a6953519954a51..78f79cd15915d1fbed2ae7d50896a241507a0023 100644 (file)
@@ -68,6 +68,7 @@
 #include "SMESHGUI_MakeNodeAtPointDlg.h"
 #include "SMESHGUI_BuildCompoundDlg.h"
 #include "SMESHGUI_ComputeDlg.h"
+#include "SMESHGUI_FileInfoDlg.h"
 
 #include "SMESHGUI_Utils.h"
 #include "SMESHGUI_GEOMGenUtils.h"
 
 #include "SALOMEconfig.h"
 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
-#include CORBA_SERVER_HEADER(SMESH_MeshEditor)
+#include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
 
 // QT Includes
 #define         INCLUDE_MENUITEM_DEF
@@ -168,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()) {
+    if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
+      anInitialPath = QDir::currentDirPath();
+
+    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();
@@ -353,10 +374,13 @@ using namespace std;
        if ( resMgr )
          toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
 
-       if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141)
-
-         aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), "", aFilter, aTitle, false);
+       QString anInitialPath = "";
+       if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
+         anInitialPath = QDir::currentDirPath();
 
+       if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141)
+         aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + anIObject->getName(),
+                                               aFilter, aTitle, false);
        else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
          QStringList filters;
           QMap<QString, int>::const_iterator it = aFilterMapSTL.begin();
@@ -367,6 +391,9 @@ using namespace std;
           fd->setCaption( aTitle );
           fd->setFilters( filters );
           fd->setSelectedFilter( QObject::tr("STL ASCII  (*.stl)") );
+         if ( !anInitialPath.isEmpty() )
+           fd->setDir( anInitialPath );
+         fd->setSelection(anIObject->getName());
           bool is_ok = false;
           while (!is_ok) {
             fd->exec();
@@ -394,6 +421,9 @@ using namespace std;
           //fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") );
           fd->setSelectedFilter(aDefaultFilter);
           fd->SetChecked(toCreateGroups);
+         if ( !anInitialPath.isEmpty() )
+           fd->setDir( anInitialPath );
+         fd->setSelection(anIObject->getName());
           bool is_ok = false;
           while (!is_ok) {
             fd->exec();
@@ -876,9 +906,23 @@ using namespace std;
     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
     SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
 
+    _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+    _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
+    _PTR(GenericAttribute) anAttr;
+    _PTR(AttributeIOR) anIOR;
+
+    int objectCount = 0;
     QString aParentComponent = QString::null;
     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
     {
+      _PTR(SObject) aSO = aStudy->FindObjectID(anIt.Value()->getEntry());
+      if (aSO) {
+       // check if object is not reference
+       _PTR(SObject) refobj;
+       if ( !aSO->ReferencedObject( refobj ) )
+         objectCount++;
+      }
+
       QString cur = anIt.Value()->getComponentDataType();
       if( aParentComponent.isNull() )
         aParentComponent = cur;
@@ -886,6 +930,9 @@ using namespace std;
         aParentComponent = "";
     }
 
+    if ( objectCount == 0 )
+      return; // No Valid Objects Selected
+
     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
       SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
                              QObject::tr("ERR_ERROR"),
@@ -905,11 +952,6 @@ using namespace std;
     SUIT_ViewManager* vm = anApp->activeViewManager();
     int nbSf = vm->getViewsCount();
 
-    _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-    _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
-    _PTR(GenericAttribute) anAttr;
-    _PTR(AttributeIOR) anIOR;
-
     SALOME_ListIteratorOfListIO It(selected);
 
     aStudyBuilder->NewCommand();  // There is a transaction
@@ -925,6 +967,10 @@ using namespace std;
            continue;
        }
 
+       _PTR(SObject) refobj;
+       if ( aSO && aSO->ReferencedObject( refobj ) )
+         continue; // skip references 
+
         // put the whole hierarchy of sub-objects of the selected SO into a list and
         // then treat them all starting from the deepest objects (at list back)
 
@@ -1302,6 +1348,24 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       break;
     }
 
+  case 150:    //MED FILE INFORMATION
+    {
+      SALOME_ListIO selected;
+      LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
+      if( aSel )
+        aSel->selectedObjects( selected );
+      if( selected.Extent() )
+      {
+        Handle(SALOME_InteractiveObject) anIObject = selected.First();
+        SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
+        if ( !aMesh->_is_nil() )
+        {
+          SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
+          dlg.exec();
+        }
+      }
+      break;
+    }
   case 122:                                    // EXPORT MED
   case 121:
   case 123:
@@ -2532,6 +2596,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction(  125, "EXPORT_MED" );
   createSMESHAction(  126, "EXPORT_UNV" );
   createSMESHAction(  141, "EXPORT_STL" );
+  createSMESHAction(  150, "FILE_INFO" );
   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Key_Delete );
   createSMESHAction( 5105, "SEL_FILTER_LIB" );
   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
@@ -2864,6 +2929,8 @@ void SMESHGUI::initialize( CAM_Application* app )
 
   // popup for object browser
 
+  createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
+  
   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
   createPopupItem( 803, OB, group );                       // EDIT_GROUP