Salome HOME
NPAL19658: Deletion problem. Invalid actions were called by shortcuts.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index 3e3194dc43a54f4f0753960bee5752543fbba4ea..73d08b61f2050757eb6f3d567b3186de37ba8ae3 100644 (file)
@@ -182,8 +182,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 +212,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 +238,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 +284,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 );
           }
@@ -371,18 +376,23 @@ 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);
           bool is_ok = false;
           while (!is_ok) {
@@ -1940,6 +1950,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 +1965,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;
     }
@@ -3075,6 +3105,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 +3123,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 );
 }
 
@@ -3137,9 +3173,8 @@ void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QStrin
   sel.init( client, selectionMgr() );
   popupMgr()->updatePopup( menu, &sel );
 
-  SalomeApp_Module::contextMenuPopup( client, menu, title );
   SALOME_ListIO lst;
-  getApp()->selectionMgr()->selectedObjects( 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() );