Salome HOME
Fix for bug 0019870(Import/Export should show current directory).
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index 01e535f2d841fbdefdf3a94b3d98368b2aeb6a78..2d89fec36f9186b34e622d060bd4a2a01219e33d 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
@@ -182,8 +183,13 @@ using namespace std;
     }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(),
-                                                QDir::currentDirPath(),
+                                                anInitialPath,
                                                 filter,
                                                 QObject::tr("Import mesh"),
                                                 true);
@@ -207,9 +213,9 @@ using namespace std;
            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"));
+                                     QObject::tr("SMESH_WRN_WARNING"),
+                                     QObject::tr(QString("SMESH_DRS_%1").arg(res)),
+                                     QObject::tr("SMESH_BUT_OK"));
              aMeshes->length( 0 );
              wc.resume();
            }
@@ -233,9 +239,9 @@ using namespace std;
        if ( isEmpty ) {
          wc.suspend();
          SUIT_MessageBox::warn1(SMESHGUI::desktop(),
-                               QObject::tr("SMESH_WRN_WARNING"),
-                               QObject::tr("SMESH_DRS_EMPTY"),
-                               QObject::tr("SMESH_BUT_OK"));
+                                 QObject::tr("SMESH_WRN_WARNING"),
+                                 QObject::tr("SMESH_DRS_EMPTY"),
+                                 QObject::tr("SMESH_BUT_OK"));
          wc.resume();
        }
 
@@ -279,8 +285,8 @@ using namespace std;
                 return;
             }
             // PAL18696
-            QString v21( aMesh->GetVersionString( SMESH::MED_V2_1, 2));
-            QString v22( aMesh->GetVersionString( SMESH::MED_V2_2, 2));
+            QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
+            QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
             aFilterMap.insert( QString("MED ") +  v21 + " (*.med)", SMESH::MED_V2_1 );
             aFilterMap.insert( QString("MED ") +  v22 + " (*.med)", SMESH::MED_V2_2 );
           }
@@ -348,10 +354,12 @@ 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, aFilter, aTitle, false);
        else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
          QStringList filters;
           QMap<QString, int>::const_iterator it = aFilterMapSTL.begin();
@@ -362,6 +370,8 @@ using namespace std;
           fd->setCaption( aTitle );
           fd->setFilters( filters );
           fd->setSelectedFilter( QObject::tr("STL ASCII  (*.stl)") );
+         if ( anInitialPath.isEmpty() )
+           fd->setDir( anInitialPath );
           bool is_ok = false;
           while (!is_ok) {
             fd->exec();
@@ -371,19 +381,26 @@ using namespace std;
          }
           delete fd;
        }
-       else {
+       else { // Export to MED
           QStringList filters;
+          QString aDefaultFilter;
           QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
-          for ( ; it != aFilterMap.end(); ++it )
+          for ( ; it != aFilterMap.end(); ++it ) {
             filters.push_back( it.key() );
+            if (it.data() == SMESH::MED_V2_2)
+              aDefaultFilter = it.key();
+          }
 
           //SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
           SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
             ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS") ,true, true );
           fd->setCaption( aTitle );
           fd->setFilters( filters );
-          fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") );
+          //fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") );
+          fd->setSelectedFilter(aDefaultFilter);
           fd->SetChecked(toCreateGroups);
+         if ( anInitialPath.isEmpty() )
+           fd->setDir( anInitialPath );
           bool is_ok = false;
           while (!is_ok) {
             fd->exec();
@@ -1292,6 +1309,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:
@@ -1503,6 +1538,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       new SMESHGUI_BuildCompoundDlg( this );
     }
     break;
+
   case 407: // DIAGONAL INVERSION
   case 408: // Delete diagonal
     {
@@ -1940,6 +1976,8 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       if( aSel )
         aSel->selectedObjects( selected );
 
+      bool isAny = false; // iss there any appropriate object selected
+
       SALOME_ListIteratorOfListIO It( selected );
       for ( ; It.More(); It.Next() )
       {
@@ -1953,22 +1991,40 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
           {
             aName = anAttr;
             QString newName = QString(aName->Value().c_str());
-            newName = LightApp_NameDlg::getName(desktop(), newName);
-            if ( !newName.isEmpty() )
-            {
-              //old source: aStudy->renameIObject( IObject, newName );
-             aName->SetValue( newName.latin1() );
-
-              // if current object is group update group's name
-             SMESH::SMESH_GroupBase_var aGroup =
-                SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
-              if (!aGroup->_is_nil() )
-                aGroup->SetName( newName.latin1() );
 
-             updateObjBrowser();
+            // check type to prevent renaming of inappropriate objects
+            int aType = SMESHGUI_Selection::type(IObject->getEntry(), aStudy);
+            if (aType == MESH || aType == GROUP ||
+                aType == SUBMESH || aType == SUBMESH_COMPOUND ||
+                aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
+                aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
+                aType == HYPOTHESIS || aType == ALGORITHM)
+            {
+              isAny = true;
+              newName = LightApp_NameDlg::getName(desktop(), newName);
+              if ( !newName.isEmpty() )
+              {
+                //old source: aStudy->renameIObject( IObject, newName );
+                aName->SetValue( newName.latin1() );
+
+                // if current object is group update group's name
+                SMESH::SMESH_GroupBase_var aGroup =
+                  SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
+                if (!aGroup->_is_nil() )
+                  aGroup->SetName( newName.latin1() );
+
+                updateObjBrowser();
+              }
             }
           }
         }
+      } // for
+
+      if (!isAny) {
+        SUIT_MessageBox::warn1(desktop(),
+                               QObject::tr("SMESH_WRN_WARNING"),
+                               QObject::tr("SMESH_WRN_NO_APPROPRIATE_SELECTION"),
+                               QObject::tr("SMESH_BUT_OK"));
       }
       break;
     }
@@ -2113,6 +2169,46 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
        }
       break;
     }
+  case 4043: {                                // CLEAR_MESH
+
+    if(checkLock(aStudy)) break;
+    
+    SALOME_ListIO selected;
+    if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
+      aSel->selectedObjects( selected );
+
+    SUIT_OverrideCursor wc;
+    SALOME_ListIteratorOfListIO It (selected);
+    for ( ; It.More(); It.Next() )
+    {
+      Handle(SALOME_InteractiveObject) IOS = It.Value();
+      SMESH::SMESH_Mesh_var aMesh =
+        SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
+      if ( aMesh->_is_nil()) continue;
+      try {
+        SMESH::UpdateView(SMESH::eErase, IOS->getEntry());
+        aMesh->Clear();
+        _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
+        SMESH::ModifiedMesh( aMeshSObj, false, true);
+        // hide groups and submeshes
+        _PTR(ChildIterator) anIter =
+          SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
+        for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
+        {
+          _PTR(SObject) so = anIter->Value();
+          SMESH::UpdateView(SMESH::eErase, so->GetID().c_str());
+        }
+      }
+      catch (const SALOME::SALOME_Exception& S_ex){
+       wc.suspend();
+       SalomeApp_Tools::QtCatchCorbaException(S_ex);
+       wc.resume();
+      }
+    }
+    SMESH::UpdateView();
+    updateObjBrowser();
+    break;
+  }
   case 4051:                                   // RENUMBERING NODES
     {
       if(checkLock(aStudy)) break;
@@ -2461,6 +2557,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" );
@@ -2503,6 +2600,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
+  createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
@@ -2594,7 +2692,7 @@ void SMESHGUI::initialize( CAM_Application* app )
 
   createMenu( 5105, toolsId, -1 );
 
-  createMenu( 702, meshId, -1 );
+  createMenu( 702, meshId, -1 ); // "Mesh" menu
   createMenu( 703, meshId, -1 );
   createMenu( 704, meshId, -1 );
   createMenu( 710, meshId, -1 );
@@ -2653,6 +2751,7 @@ void SMESHGUI::initialize( CAM_Application* app )
 
   createMenu( 4041, removeId, -1 );
   createMenu( 4042, removeId, -1 );
+  createMenu( 4043, removeId, -1 );
 
   createMenu( 4051, renumId, -1 );
   createMenu( 4052, renumId, -1 );
@@ -2740,6 +2839,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createTool( separator(), addRemTb );
   createTool( 4041, addRemTb );
   createTool( 4042, addRemTb );
+  createTool( 4043, addRemTb );
   createTool( separator(), addRemTb );
   createTool( 4051, addRemTb );
   createTool( 4052, addRemTb );
@@ -2790,6 +2890,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
@@ -2803,12 +2905,16 @@ void SMESHGUI::initialize( CAM_Application* app )
   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
   popupMgr()->insert( separator(), -1, 0 );
-  createPopupItem( 1100, OB, hypo, "" /*"&& $hasReference={false}"*/ );   // EDIT HYPOTHESIS
+  createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
-  createPopupItem( 1101, OB, mesh_group + " " + hyp_alg, "" /*"&& $hasReference={false}"*/ ); // RENAME
+  createPopupItem( 1101, OB, mesh_group + " " + hyp_alg ); // RENAME
+  popupMgr()->insert( separator(), -1, 0 );
+  createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
   popupMgr()->insert( separator(), -1, 0 );
 
-  QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
+  QString         nbSelected = QtxPopupMgr::Selection::defSelCountParam();
+  QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( nbSelected );
+
   createPopupItem( 125, OB, mesh, only_one_non_empty );   // EXPORT_MED
   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
@@ -3075,6 +3181,9 @@ bool SMESHGUI::activateModule( SUIT_Study* study )
   action(112)->setAccel(QKeySequence(CTRL + Key_U)); // Import UNV
   action(113)->setAccel(QKeySequence(CTRL + Key_M)); // Import MED
 
+  action(  33)->setEnabled(true); // Delete: Key_Delete
+  action(1101)->setEnabled(true); // Rename: Key_F2
+
   return res;
 }
 
@@ -3090,6 +3199,9 @@ bool SMESHGUI::deactivateModule( SUIT_Study* study )
   action(112)->setAccel(QKeySequence()); // Import UNV
   action(113)->setAccel(QKeySequence()); // Import MED
 
+  action(  33)->setEnabled(false); // Delete: Key_Delete
+  action(1101)->setEnabled(false); // Rename: Key_F2
+
   return SalomeApp_Module::deactivateModule( study );
 }
 
@@ -3131,11 +3243,26 @@ QString SMESHGUI::engineIOR() const
   return QString( anIOR.in() );
 }
 
-void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
+void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
 {
   SMESHGUI_Selection sel;
   sel.init( client, selectionMgr() );
   popupMgr()->updatePopup( menu, &sel );
+
+  SALOME_ListIO lst;
+  selectionMgr()->selectedObjects( lst );
+  if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
+    Handle(SALOME_InteractiveObject) io = lst.First();
+    SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
+    _PTR(Study) study = appStudy->studyDS();
+    _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
+    if ( obj ) {
+      QString aName = QString( obj->GetName().c_str() );
+      while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
+         aName.remove( (aName.length() - 1), 1 );
+      title = aName;
+    }
+  }
 }
 
 void SMESHGUI::windows( QMap<int, int>& aMap ) const