Salome HOME
According to "operation-widget_factory-property"
[modules/shaper.git] / src / XGUI / XGUI_ActionsMgr.cpp
index 7f0b02d9ae0e668688a24dbaaa15d1a65caf1a19..8722c089649af58c9bd6f1229c8d06ba1e1c8f78 100644 (file)
@@ -5,15 +5,22 @@
 #include "XGUI_ActionsMgr.h"
 #include "XGUI_Command.h"
 #include "XGUI_Workshop.h"
+#include "XGUI_OperationMgr.h"
 #include "XGUI_SalomeConnector.h"
 
+#include <ModuleBase_Operation.h>
+
 #include <QAction>
 
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
 
 XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent)
- : QObject(theParent), myWorkshop(theParent)
+ : QObject(theParent), myOperationMgr(theParent->operationMgr())
 {
-  
+
 }
 
 XGUI_ActionsMgr::~XGUI_ActionsMgr()
@@ -24,79 +31,88 @@ XGUI_ActionsMgr::~XGUI_ActionsMgr()
 void XGUI_ActionsMgr::addCommand(QAction* theCmd)
 {
   QString aId = theCmd->data().toString();
+  if(aId.isEmpty()) {
+    return;
+  }
   myActions.insert(aId, theCmd);
-  myActionsState.insert(aId, theCmd->isEnabled());
-  connect(theCmd, SIGNAL(triggered(bool)), this, SLOT(setActionsDisabled(bool)));
+  XGUI_Command* aXCmd = dynamic_cast<XGUI_Command*>(theCmd);
+  if (aXCmd) {
+    myNestedActions[aId] = aXCmd->nestedCommands();
+  } else {
+    XGUI_Workshop* aWorkshop = static_cast<XGUI_Workshop*>(parent());
+    myNestedActions[aId] = aWorkshop->salomeConnector()->nestedActions(aId);
+  }
 }
 
-void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
+void XGUI_ActionsMgr::addNestedCommands(const QString& theId, const QStringList& theCommands)
 {
-  //Re-enable actions (just restore their state)
-  if (!isDisabled) {
-    myNestedActions.clear();
-    restoreCommandState();
-    return;
-  }
-  //Disable all actions, but caller and unblockable (defined in a xml)
-  saveCommandsState();
-
-  QString aSkippedId;
-  QAction* aToggledFeature = dynamic_cast<QAction*>(sender());
-  aSkippedId = aToggledFeature->data().toString();
+  myNestedActions[theId] = theCommands;
+}
 
-  QStringList anActionIdsList = myActions.keys();
-  foreach(QString eachKey, anActionIdsList) {
-    if (eachKey == aSkippedId) {
-      continue;
-    }
-    myActions[eachKey]->setEnabled(false);
-  }
-  if (myWorkshop->isSalomeMode()) {
-    myNestedActions = myWorkshop->salomeConnector()->nestedActions(aSkippedId);
+void XGUI_ActionsMgr::update()
+{
+  if(myOperationMgr->hasOperation()) {
+    setAllEnabled(false);
+    ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
+    QString anOperationId = anOperation->id();
+    setActionEnabled(anOperationId, true);
+    bool isNestedEnabled = anOperation->isNestedOperationsEnabled();
+    setNestedCommandsEnabled(isNestedEnabled, anOperationId);
   } else {
-    XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
-    myNestedActions = aToggledFeature->unblockableCommands();
+    setAllEnabled(true);
+    setNestedCommandsEnabled(false);
   }
+  updateCheckState();
 }
 
-void XGUI_ActionsMgr::saveCommandsState()
+void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
 {
-  myActionsState.clear();
-  QStringList anActionIdsList = myActions.keys();
-  foreach(QString eachKey, anActionIdsList) {
-    myActionsState.insert(eachKey, myActions[eachKey]->isEnabled());
+  foreach(QString eachAction, myActions.keys()) {
+    setActionEnabled(eachAction, isEnabled);
   }
-
 }
 
-void XGUI_ActionsMgr::restoreCommandState()
+//!
+void XGUI_ActionsMgr::setNestedCommandsEnabled(bool theEnabled, const QString& theParent)
 {
-  QStringList anActionIdsList = myActions.keys();
-  foreach(QString eachKey, anActionIdsList) {
-    myActions[eachKey]->setEnabled(myActionsState[eachKey]);
-    myActions[eachKey]->setChecked(false);
+  QStringList ltNestedActions;
+  if(theParent.isEmpty()) { //Disable ALL nested
+    foreach(QString eachParent, myNestedActions.keys()) {
+      ltNestedActions << myNestedActions[eachParent];
+    }
+  } else {
+    ltNestedActions << myNestedActions[theParent];
+  }
+  foreach(QString eachNested, ltNestedActions) {
+    setActionEnabled(eachNested, theEnabled);
   }
 }
 
 void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
 {
-  if(myActions.contains(theId)) {
-    myActions[theId]->setChecked(theChecked);
+  QAction* anAction = myActions[theId];
+  if(anAction && anAction->isCheckable()) {
+    anAction->setChecked(theChecked);
   }
 }
 
-void XGUI_ActionsMgr::updateAction(const QString& theId)
+
+void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
 {
-  if(myActions.contains(theId)){
-    myActions[theId]->setEnabled(myActionsState[theId]);
-    myActions[theId]->setChecked(false);
+  QAction* anAction = myActions[theId];
+  if(anAction) {
+    anAction->setEnabled(theEnabled);
   }
 }
 
-void XGUI_ActionsMgr::setNestedActionsEnabled(bool isEnabled)
+void XGUI_ActionsMgr::updateCheckState()
 {
-  foreach(QString eachKey, myNestedActions) {
-    if (myActions.contains(eachKey))
-      myActions[eachKey]->setEnabled(isEnabled);
+  QString eachCommand = QString();
+  foreach(eachCommand, myActions.keys()) {
+    setActionChecked(eachCommand, false);
+  }
+  QStringList ltActiveCommands = myOperationMgr->operationList();
+  foreach(eachCommand, ltActiveCommands) {
+    setActionChecked(eachCommand, true);
   }
 }