+
+
+//!
+void XGUI_ActionsMgr::setNestedCommandsEnabled(bool theEnabled, const QString& theParent)
+{
+ 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::setNestedStackEnabled(ModuleBase_Operation* theOperation)
+{
+ ModuleBase_OperationFeature* anOperation =
+ dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if(!anOperation || !anOperation->feature())
+ return;
+ FeaturePtr aFeature = anOperation->feature();
+ QString aFeatureId = QString::fromStdString(aFeature->getKind());
+ //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)) {
+ QAction* anAction = myActions[theId];
+ if (anAction->isCheckable()) {
+ anAction->setChecked(theChecked);
+ }
+ }
+}
+
+void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
+{
+ if (myActions.contains(theId)) {
+ 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);
+ }
+}
+
+/*
+ * 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);
+ XGUI_Workshop* aWorkshop = static_cast<XGUI_Workshop*>(parent());
+ foreach(QAction* eachAction, myActions.values()) {
+ QString aCmdDocKind;
+#ifdef HAVE_SALOME
+ QString aId = eachAction->data().toString();
+ if (!aId.isEmpty()) {
+ aCmdDocKind = QString::fromStdString(
+ aWorkshop->salomeConnector()->featureInfo(aId)->documentKind());
+ }
+#else
+ AppElements_Command* aCmd = dynamic_cast<AppElements_Command*>(eachAction);
+ aCmdDocKind = QString::fromStdString(aCmd->featureMessage()->documentKind());
+#endif
+ if(!aCmdDocKind.isEmpty() && aCmdDocKind != aDocKind) {
+ eachAction->setEnabled(false);
+ }
+ }
+}
+
+void XGUI_ActionsMgr::updateByPlugins(FeaturePtr anActiveFeature)
+{
+ static Events_ID aStateRequestEventId = Events_Loop::loop()->eventByName(
+ EVENT_FEATURE_STATE_REQUEST);
+ std::shared_ptr<ModelAPI_FeatureStateMessage> aMsg(
+ new ModelAPI_FeatureStateMessage(aStateRequestEventId, this));
+ aMsg->setFeature(anActiveFeature);
+ Events_Loop::loop()->send(aMsg, false);
+}