Salome HOME
Initial iteration for storage the back references and making concealment only on...
[modules/shaper.git] / src / XGUI / XGUI_ActionsMgr.cpp
index 165d0457ece943c650770e30952c222a4eed4288..c3a35fe7cbc534739d8db3a16a52ed3ed00ccef4 100644 (file)
@@ -8,6 +8,8 @@
 #include "XGUI_OperationMgr.h"
 #include "XGUI_SalomeConnector.h"
 
+#include <ModelAPI_Session.h>
+
 #include <ModuleBase_Operation.h>
 #include <Events_Error.h>
 
@@ -59,17 +61,19 @@ void XGUI_ActionsMgr::addNestedCommands(const QString& theId, const QStringList&
 void XGUI_ActionsMgr::update()
 {
   if (myOperationMgr->hasOperation()) {
-    setAllEnabled(false);
     ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
     FeaturePtr aFeature = anOperation->feature();
-    QString anOperationId = QString::fromStdString(aFeature->getKind()); //anOperation->id();
-    setActionEnabled(anOperationId, true);
-    bool isNestedEnabled = anOperation->isNestedOperationsEnabled();
-    setNestedCommandsEnabled(isNestedEnabled, anOperationId);
+    if(aFeature) {
+      setAllEnabled(false);
+      QString aFeatureId = QString::fromStdString(aFeature->getKind());
+      setActionEnabled(aFeatureId, true);
+      setNestedStackEnabled(anOperation);
+    }
   } else {
     setAllEnabled(true);
     setNestedCommandsEnabled(false);
   }
+  updateByDocumentKind();
   updateCheckState();
 }
 
@@ -81,6 +85,18 @@ void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
   }
 }
 
+void XGUI_ActionsMgr::setNestedStackEnabled(ModuleBase_Operation* theOperation)
+{
+  if(!theOperation || !theOperation->feature())
+    return;
+  FeaturePtr aFeature = theOperation->feature();
+  QString aFeatureId = QString::fromStdString(aFeature->getKind());
+  bool isNestedEnabled = theOperation->isNestedOperationsEnabled();
+  setNestedCommandsEnabled(isNestedEnabled, aFeatureId);
+
+  setNestedStackEnabled(myOperationMgr->previousOperation(theOperation));
+}
+
 //!
 void XGUI_ActionsMgr::setNestedCommandsEnabled(bool theEnabled, const QString& theParent)
 {
@@ -105,6 +121,25 @@ void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theCheck
   }
 }
 
+/*
+ * Disables all actions which have the Document Kind different to
+ * the current document's kind
+ */
+void XGUI_ActionsMgr::updateByDocumentKind()
+{
+  std::string aStdDocKind = ModelAPI_Session::get()->activeDocument()->kind();
+  QString aDocKind = QString::fromStdString(aStdDocKind);
+  foreach(QAction* eachAction, myActions.values()) {
+    XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(eachAction);
+    if(aCmd) {
+      QString aCmdDocKind = aCmd->documentKind();
+      if(!aCmdDocKind.isEmpty() && aCmdDocKind != aDocKind) {
+        eachAction->setEnabled(false);
+      }
+    }
+  }
+}
+
 void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
 {
   QAction* anAction = myActions[theId];