]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1063: Algorithm of commands enabling is updated
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 17 Nov 2015 12:02:45 +0000 (15:02 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 17 Nov 2015 12:03:04 +0000 (15:03 +0300)
src/ModuleBase/ModuleBase_IWorkshop.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_ActionsMgr.h
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_ModuleConnector.h
src/XGUI/XGUI_Workshop.cpp

index 77f4cfe3f4da25b38949809c33747f643af71399..caeb3dbbd293d16d158c1b59a1298afeff68a876 100644 (file)
@@ -101,6 +101,9 @@ Q_OBJECT
   //! \param theValues a list of presentations
   virtual void setSelected(const QList<ModuleBase_ViewerPrs>& theValues) = 0;
 
+   /// Update of commands status
+  virtual void updateCommandStatus() = 0;
+
 signals:
   /// Signal selection changed.
   void selectionChanged();
index 0c2dc8e8848fcf7731dc860ce092825994584bd3..b167f5a47d31f3afc287d0df3afee39e6442c80b 100644 (file)
@@ -223,7 +223,7 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
 
   // 6. Update sketcher actions
   XGUI_ActionsMgr* anActMgr = workshop()->actionsMgr();
-  anActMgr->update();
+  myWorkshop->updateCommandStatus();
   myWorkshop->viewer()->update();
 }
 
index b25a6fb75ab96ed4e140ea528f1a6bbb6a904a68..c16332fd23ea467142f05f61d98a480ba19b3c49 100644 (file)
@@ -95,31 +95,28 @@ 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();
-    updateByPlugins(anActiveFeature);
-  }
+  } else 
+    setNestedCommandsEnabled(false);
+
+  updateByPlugins(anActiveFeature);
+  updateByDocumentKind();
   updateCheckState();
 }
 
@@ -276,8 +273,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);
   }
 }
@@ -312,6 +308,20 @@ void XGUI_ActionsMgr::setNestedStackEnabled(ModuleBase_Operation* theOperation)
   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 +335,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);
   }
 }
 
index 9191021ad42650baaae1df0944df3cea0f5d55ee..3788197734e5ad3352bb732bd34e9dd2696cb80b 100644 (file)
@@ -86,34 +86,43 @@ class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
   /// 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:
+ private:
   //! 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
   //! are enabled, all the rest is disabled. All active commands is checked.
-  void update();
+  void updateCommandsStatus();
+
   //! Sets all commands checked if it's operation is active.
   void updateCheckState();
+
   //! Updates actions according to current selection in the viewer
   void updateOnViewSelection();
-
- protected:
+  
   //! Sets all actions to isEnabled state.
   void setAllEnabled(bool isEnabled);
+  
   //! Sets all nested actions to isEnabled state for the command with given ID.
   //! If ID is empty - all nested actions will be affected.
   void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
+  
   //! Sets to enabled state all siblings of the given operation and it's parents recursively
   void setNestedStackEnabled(ModuleBase_Operation* theOperation);
+  
   //! Sets the action with theId to theChecked state.
   void setActionChecked(const QString& theId, const bool theChecked);
+  
   //! Sets the action with theId to theEnabled state.
   void setActionEnabled(const QString& theId, const bool theEnabled);
+  
   //! Updates actions according to their "document" tag
   void updateByDocumentKind();
+
   //! Asks plugins about their features state, using the Events system
   void updateByPlugins(FeaturePtr theActiveFeature);
 
+  QStringList allNestedCommands(ModuleBase_Operation* theOperation);
+
  private:
 
   QMap<QString, QAction*> myActions;
@@ -123,6 +132,8 @@ public slots:
 
   XGUI_Workshop* myWorkshop;
   XGUI_OperationMgr* myOperationMgr;
+
+  friend class XGUI_Workshop;
 };
 
 #endif /* XGUI_ACTIONSMGR_H_ */
index ee5f029d8445a4dd698c781be9e7555f00ae9bc0..bc8d74140c16a92a0e5c824875800a9e4aa7c87d 100644 (file)
@@ -132,3 +132,8 @@ void XGUI_ModuleConnector::abortOperation(ModuleBase_Operation* theOperation)
 {
   myWorkshop->operationMgr()->abortOperation(theOperation);
 }
+
+void XGUI_ModuleConnector::updateCommandStatus()
+{
+  myWorkshop->updateCommandStatus();
+}
\ No newline at end of file
index 598c7a22e956a9605ad9855a9c772a90aee39386..4b2ed19f4b8cd6bb2100a6628e2a4108ce1d904f 100644 (file)
@@ -81,6 +81,9 @@ Q_OBJECT
   //! If the list is empty then selection will be cleared
   virtual void setSelected(const QList<ModuleBase_ViewerPrs>& theValues);
 
+   /// Update of commands status
+  virtual void updateCommandStatus();
+
   //! Returns workshop
   XGUI_Workshop* workshop() const { return myWorkshop; }
 
index 2199df248daadf4873e4b07639499cf6650cbc8e..e8840c1a4c3a7ba5fd1f610f743a5ca5373ee0b9 100755 (executable)
@@ -129,7 +129,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   myDisplayer = new XGUI_Displayer(this);
 
   mySelector = new XGUI_SelectionMgr(this);
-  //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
+  connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
 
   myOperationMgr = new XGUI_OperationMgr(this, 0);
   myActionsMgr = new XGUI_ActionsMgr(this);
@@ -227,7 +227,7 @@ void XGUI_Workshop::activateModule()
   connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
     myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
 
-  myActionsMgr->update();
+  updateCommandStatus();
 
   // activate visualized objects in the viewer
   XGUI_Displayer* aDisplayer = displayer();
@@ -991,7 +991,7 @@ void XGUI_Workshop::updateCommandStatus()
         aCmd->setEnabled(false);
     }
   }
-  myActionsMgr->update();
+  myActionsMgr->updateCommandsStatus();
   emit commandStatusUpdated();
 }