Salome HOME
#1330 Multiply selection when Create fillet using Shift button
[modules/shaper.git] / src / XGUI / XGUI_ActionsMgr.cpp
index 83a388576ba9ef3969c0e449005cbd1f1434cd26..2468786c43859ced97f6586a46310ef28c820908 100644 (file)
@@ -95,32 +95,29 @@ bool XGUI_ActionsMgr::isNested(const QString& theId) const
   return false;
 }
 
-void XGUI_ActionsMgr::update()
+void XGUI_ActionsMgr::updateCommandsStatus()
 {
+  setAllEnabled(true);
   XGUI_Selection* aSelection = myWorkshop->selector()->selection();
-  if (aSelection->getSelected(ModuleBase_ISelection::Viewer).size() > 0) {
+  if (aSelection->getSelected(ModuleBase_ISelection::Viewer).size() > 0)
     updateOnViewSelection();
-  } else {
-    FeaturePtr anActiveFeature = FeaturePtr();
-    ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
-                                                           (myOperationMgr->currentOperation());
-    if (aFOperation) {
-      anActiveFeature = aFOperation->feature();
-      if(anActiveFeature.get()) {
-        setAllEnabled(false);
-        QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
-        setActionEnabled(aFeatureId, true);
-      }
-      setNestedStackEnabled(aFOperation);
-    } else {
-      setAllEnabled(true);
-      setNestedCommandsEnabled(false);
+
+  FeaturePtr anActiveFeature = FeaturePtr();
+  ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+                                                         (myOperationMgr->currentOperation());
+  if (aFOperation) {
+    anActiveFeature = aFOperation->feature();  
+    QStringList aNested = allNestedCommands(aFOperation);
+    foreach(QString aAction, myActions.keys()) {
+      if (!aNested.contains(aAction))
+        setActionEnabled(aAction, false);
     }
-    // TODO(SBH): Get defaults state of actions from XML and remove the following method
-    updateByDocumentKind();
-    updateCheckState();
-    updateByPlugins(anActiveFeature);
-  }
+  } else 
+    setNestedCommandsEnabled(false);
+
+  updateByPlugins(anActiveFeature);
+  updateByDocumentKind();
+  updateCheckState();
 }
 
 void XGUI_ActionsMgr::updateCheckState()
@@ -231,20 +228,25 @@ QAction* XGUI_ActionsMgr::operationStateAction(OperationStateActionId theId, QOb
   } else {
     switch (theId) {
       case Accept:
-      case AcceptAll:
+      case AcceptAll: {
         aResult = new QAction(QIcon(":pictures/button_ok.png"), "", theParent);
-        break;
+        aResult->setToolTip("Apply");
+      }
+      break;
       case Abort:
       case AbortAll: {
         aResult = new QAction(QIcon(":pictures/button_cancel.png"), "", theParent);
-        if(theId == Abort) {
+        aResult->setToolTip("Cancel");
+        if (theId == Abort) {
           aResult->setShortcut(QKeySequence(Qt::Key_Escape));
         }
       }
       break;
-      case Help:
+      case Help: {
         aResult = new QAction(QIcon(":pictures/button_help.png"), "", theParent);
-        break;
+        aResult->setToolTip("Help");
+      }
+      break;
       default:
         break;
     }
@@ -276,8 +278,7 @@ ActionInfo XGUI_ActionsMgr::actionInfoById(const QString& theId)
 
 void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
 {
-  foreach(QString eachAction, myActions.keys())
-  {
+  foreach(QString eachAction, myActions.keys()) {
     setActionEnabled(eachAction, isEnabled);
   }
 }
@@ -306,12 +307,26 @@ void XGUI_ActionsMgr::setNestedStackEnabled(ModuleBase_Operation* theOperation)
     return;
   FeaturePtr aFeature = anOperation->feature();
   QString aFeatureId = QString::fromStdString(aFeature->getKind());
-  setActionEnabled(aFeatureId, true);
+  //setActionEnabled(aFeatureId, true);
   setNestedCommandsEnabled(true, aFeatureId);
 
   setNestedStackEnabled(myOperationMgr->previousOperation(theOperation));
 }
 
+QStringList XGUI_ActionsMgr::allNestedCommands(ModuleBase_Operation* theOperation)
+{
+  QStringList aFeatures;
+  ModuleBase_OperationFeature* anOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+  if(!anOperation || !anOperation->feature())
+    return aFeatures;
+  FeaturePtr aFeature = anOperation->feature();
+  QString aFeatureId = QString::fromStdString(aFeature->getKind());
+
+  aFeatures << myNestedActions[aFeatureId];
+  aFeatures << allNestedCommands(myOperationMgr->previousOperation(theOperation));
+  return aFeatures;
+}
+
 void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
 {
   if (myActions.contains(theId)) {
@@ -325,7 +340,11 @@ void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theCheck
 void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
 {
   if (myActions.contains(theId)) {
-    myActions[theId]->setEnabled(theEnabled);
+    QAction* aAction = myActions[theId];
+    // Initially all actions are enabled
+    // If it was disabled for any reason then we can not enable it
+    if (aAction->isEnabled())
+      aAction->setEnabled(theEnabled);
   }
 }