Salome HOME
Synchronize AcceptAll actions state between Tool bar and property panel.
authornds <nds@opencascade.com>
Tue, 25 Aug 2015 13:32:16 +0000 (16:32 +0300)
committernds <nds@opencascade.com>
Tue, 25 Aug 2015 13:32:43 +0000 (16:32 +0300)
In the new realized version, this button state is updated by commit modification to the document and when the operation is started. In the previous version this state was updated by any modification of the model during operaion.

12 files changed:
src/Config/Config_Keywords.h
src/NewGeom/NewGeom_Module.cpp
src/NewGeom/NewGeom_Module.h
src/NewGeom/NewGeom_NestedButton.h
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_ActionsMgr.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h
src/XGUI/XGUI_SalomeConnector.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_WorkshopListener.cpp
src/XGUI/XGUI_WorkshopListener.h

index b9ee0b4a0045dcde4010581a905dc89a67f45d97..bf10876bfd683e146769e149120e0d802de4cc84 100644 (file)
@@ -55,6 +55,8 @@ const static char* FEATURE_TEXT = "title";
 const static char* FEATURE_KEYSEQUENCE = "keysequence";
 const static char* FEATURE_NESTED = "nested";
 const static char* FEATURE_WHEN_NESTED = "when_nested";
+const static char* FEATURE_WHEN_NESTED_ACCEPT = "accept";
+const static char* FEATURE_WHEN_NESTED_ABORT = "abort";
 const static char* FEATURE_DOC = WORKBENCH_DOC;
 // NODE_VALIDATOR properties, NODE_SELFILTER properties
 const static char* _PARAMETERS = "parameters";
index cb422b659c850801ca655f136328d0d9118a3013..df50886286daa97c9a0f2c9217c74d9c65008989 100644 (file)
@@ -398,6 +398,10 @@ QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& the
   return aAction;
 }
 
+bool NewGeom_Module::isNestedFeature(const QAction* theAction)
+{
+  return dynamic_cast<const NewGeom_NestedButton*>(theAction);
+}
 
 QAction* NewGeom_Module::addNestedFeature(const QString& theWBName,
                                           const ActionInfo& theInfo,
index 7c0aa1a6eab7ca13c31f523361bfcd26bfbf7980..0ba1345b7bc16fde13e07148f6e092c11f3c2494 100644 (file)
@@ -61,6 +61,12 @@ Q_OBJECT
                                     const ActionInfo& theInfo,
                                     const QList<QAction*>& theNestedActions);
 
+  //! Returns true if the feature action is a nested action, in other words,
+  //! it is created by addNestedFeature().
+  //! \param theId - an action of a feature
+  //! returns boolean result
+  virtual bool isNestedFeature(const QAction* theAction);
+
   virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle,
                                      const QString& theTip, const QIcon& theIcon,
                                      const QKeySequence& theKeys, bool isCheckable,
index 7be12d4912539e47678979a453898ff2035ddd7f..bc39376c4c7110e876ccfb9fcb723369a8d91485 100644 (file)
@@ -26,7 +26,7 @@ class NewGeom_NestedButton : public QWidgetAction
   NewGeom_NestedButton(QObject *parent, const QList<QAction*>& theNestedActions);
   virtual ~NewGeom_NestedButton();
 
- public slots:
+ private slots:
   /// Shows/hides the additional buttons widget
   void showAdditionalButtons(bool);
   void actionStateChanged();
index 6dc01fa3dc56900b9ac9b1b60b37e47c669d6605..8cf0c02c12f682e2198c8cb6fdf4ce0f6f2ec64b 100644 (file)
@@ -260,6 +260,15 @@ QAction* XGUI_ActionsMgr::operationStateAction(OperationStateActionId theId, QOb
   return aResult;
 }
 
+QAction* XGUI_ActionsMgr::action(const QString& theId)
+{
+  QAction* anAction;
+  if(myActions.contains(theId)) {
+    anAction = myActions.value(theId);
+  }
+  return anAction;
+}
+
 ActionInfo XGUI_ActionsMgr::actionInfoById(const QString& theId)
 {
   ActionInfo aResult;
index 0acc6a26a98b8254fc501c208b9f57b8b57e9c00..9191021ad42650baaae1df0944df3cea0f5d55ee 100644 (file)
@@ -80,10 +80,13 @@ class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
   //! If there is no such action, it will be created.
   QAction* operationStateAction(OperationStateActionId theId, QObject* theParent = 0);
 
+  /// Return an action by the given id, if it was registered in the manager
+  QAction* action(const QString& theId);
+
   /// Return info (icon, text, etc) about the action by the given id, if it was registered in the manager
   ActionInfo actionInfoById(const QString& theId);
 
- public slots:
+public slots:
   //! Update workbench actions according to OperationMgr state:
   //! No active operations: all actions but nested are available
   //! There is active operation: current operation + it's nested
index 3bab1779f7888e3ae7def969319913c2cb851db5..fe2b72830ae95b4697dcf0850139e3788beb8bdc 100644 (file)
@@ -9,6 +9,7 @@
 #include "ModuleBase_Operation.h"
 #include "ModuleBase_IWorkshop.h"
 #include "ModuleBase_IModule.h"
+#include "ModuleBase_OperationDescription.h"
 
 #include "ModelAPI_CompositeFeature.h"
 #include "ModelAPI_Session.h"
@@ -188,9 +189,19 @@ void XGUI_OperationMgr::setApplyEnabled(const bool theEnabled)
 {
   myIsApplyEnabled = theEnabled;
   emit validationStateChanged(theEnabled);
+}
 
-  bool aParentValid = true;//isParentOperationValid();
-  emit nestedStateChanged(aParentValid);
+void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
+{
+  if (theOperation)
+    emit nestedStateChanged(theOperation->getDescription()->operationId().toStdString(),
+                            theOperation->isValid());
+  else {
+    foreach(ModuleBase_Operation* anOperation, myOperations) {
+      emit nestedStateChanged(anOperation->getDescription()->operationId().toStdString(),
+                              anOperation->isValid());
+    }
+  }
 }
 
 bool XGUI_OperationMgr::isApplyEnabled() const
@@ -301,6 +312,7 @@ void XGUI_OperationMgr::onAbortOperation()
 void XGUI_OperationMgr::onOperationStarted()
 {
   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
+  updateApplyOfOperations(aSenderOperation);
   emit operationStarted(aSenderOperation);
 }
 
@@ -312,6 +324,8 @@ void XGUI_OperationMgr::onOperationAborted()
 
 void XGUI_OperationMgr::onOperationCommitted()
 {
+  updateApplyOfOperations();
+
   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
   emit operationCommitted(aSenderOperation);
 }
index 582dc4ce43f28bfa861923cf5d188516da65a208..7f6e26b931dc4d8b1e37f7340e44044eef46d613 100644 (file)
@@ -138,8 +138,10 @@ signals:
   /// Signal is emitted after the apply enable state changed.
   void validationStateChanged(bool);
 
-  /// Signal is emitted after the apply enable state changed.
-  void nestedStateChanged(bool);
+  /// Signal is emitted after the model is modified. It is emitted for all active operations.
+  /// \param theFeatureKind a feature id
+  /// \param theState validity of the operation with the feature kind
+  void nestedStateChanged(const std::string& theFeatureKind, const bool theState);
 
   /// Signal is emitted after the current operation is filled with existing preselection.
   void operationActivatedByPreselection();
@@ -152,6 +154,10 @@ signals:
   /// \param theEnabled the state value
   void setApplyEnabled(const bool theEnabled);
 
+  /// Emits nestedStateChange for operations with an information about validity of the operation
+  /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent.
+  void updateApplyOfOperations(ModuleBase_Operation* theOperation = 0);
+
   /// Commits the current operatin if it is valid
   bool commitOperation();
 
index 742a6055bb598116e7c5a7081b92d8627d44dd5d..910aaa2495e1d921dc386afbfeb39e6e66673854 100644 (file)
@@ -52,6 +52,12 @@ class XGUI_EXPORT XGUI_SalomeConnector
                                     const ActionInfo& theInfo,
                                     const QList<QAction*>& theNestedActions) = 0;
 
+  //! Returns true if the feature action is a nested action, in other words,
+  //! it is created by addNestedFeature().
+  //! \param theId - an action of a feature
+  //! returns boolean result
+  virtual bool isNestedFeature(const QAction* theAction) = 0;
+
   //! Creates a command in Edit menu of SALOME desktop
   //! \param theId - an id of the feature
   //! \param theTitle - a menu item string
index 82fb45c18c3fde147356b7965bb67c3ad05d6429..e08bae76c1f1e8c7bd3a758ceada5fde9bc86812 100644 (file)
@@ -906,10 +906,6 @@ void XGUI_Workshop::createDockWidgets()
           myOperationMgr,  SLOT(onKeyReleased(QKeyEvent*)));
   connect(myOperationMgr,  SIGNAL(validationStateChanged(bool)),
           aOkAct,          SLOT(setEnabled(bool)));
-  QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
-  connect(myOperationMgr,  SIGNAL(nestedStateChanged(bool)),
-          aAcceptAllAct,   SLOT(setEnabled(bool)));
-
 }
 
 //******************************************************
index 2e22c49eda0c6e4b103b2dbe5b41d85c9cd4425f..b55879faef8597bb03611983a10cfa6cb7942ee6 100755 (executable)
@@ -44,6 +44,7 @@
 #include <Config_FeatureMessage.h>
 #include <Config_PointerMessage.h>
 #include <Config_SelectionFilterMessage.h>
+#include <Config_Keywords.h>
 
 #include <QApplication>
 #include <QMainWindow>
@@ -355,6 +356,25 @@ void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_O
   //}
 }
 
+void XGUI_WorkshopListener::onNestedStateChanged(const std::string& theFeatureId, const bool theState)
+{
+  XGUI_Workshop* aWorkshop = workshop();
+
+  //one button is used for all features, which can have nested actions, so it is obtained from
+  // the action manager
+  QAction* anAcceptAllAction = aWorkshop->actionsMgr()->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
+  if (aWorkshop->isSalomeMode()) {
+    XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector();
+    XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
+    if (aSalomeConnector->isNestedFeature(anActionsMgr->action(theFeatureId.c_str())))
+      anAcceptAllAction->setEnabled(theState);
+  } else {
+    AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
+    if (aMenuBar->feature(theFeatureId.c_str())->button()->additionalButtonWidget())
+      anAcceptAllAction->setEnabled(theState);
+  }
+}
+
 bool XGUI_WorkshopListener::event(QEvent * theEvent)
 {
   PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
@@ -389,12 +409,12 @@ void XGUI_WorkshopListener::addFeature(const std::shared_ptr<Config_FeatureMessa
     QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
     XGUI_OperationMgr* anOperationMgr = aWorkshop->operationMgr();
     XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
-    if (aNestedActions.contains("accept")) {
+    if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) {
       QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
       connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations()));
       aNestedActList << anAction;
     }
-    if (aNestedActions.contains("abort")) {
+    if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
       QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
       connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
       aNestedActList << anAction;
@@ -447,6 +467,9 @@ void XGUI_WorkshopListener::addFeature(const std::shared_ptr<Config_FeatureMessa
     aWorkshop->actionsMgr()->addCommand(aCommand);
     aWorkshop->module()->actionCreated(aCommand);
   }
+  XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
+  connect(anOperationMgr, SIGNAL(nestedStateChanged(const std::string&, const bool)),
+          this, SLOT(onNestedStateChanged(const std::string&, const bool)));
 }
 
 
index 71d0a99852c4ce2e572847f8ed6f01d3a74c8206..912fb85dff3455125b620f7c8e9c812de853270f 100755 (executable)
@@ -44,6 +44,12 @@ signals:
   /// Emitted when error in applivation happens
   void errorOccurred(const QString&);
 
+protected slots:
+  /// Updates Apply All button state of the feature to the state if the feature has the button
+  /// \param theFeatureId an index of the feature, the action is searched, which state is to be changed
+  /// \param theState an action enable state
+  void onNestedStateChanged(const std::string& theFeatureId, const bool theState);
+
 protected:
   /// Procedure to process postponed events
   bool event(QEvent * theEvent);