From: vsv Date: Tue, 17 Nov 2015 12:02:45 +0000 (+0300) Subject: Issue #1063: Algorithm of commands enabling is updated X-Git-Tag: V_2.0.0~30 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bc7efdfcf099e40175e379201359d2024fb624d4;p=modules%2Fshaper.git Issue #1063: Algorithm of commands enabling is updated --- diff --git a/src/ModuleBase/ModuleBase_IWorkshop.h b/src/ModuleBase/ModuleBase_IWorkshop.h index 77f4cfe3f..caeb3dbbd 100644 --- a/src/ModuleBase/ModuleBase_IWorkshop.h +++ b/src/ModuleBase/ModuleBase_IWorkshop.h @@ -101,6 +101,9 @@ Q_OBJECT //! \param theValues a list of presentations virtual void setSelected(const QList& theValues) = 0; + /// Update of commands status + virtual void updateCommandStatus() = 0; + signals: /// Signal selection changed. void selectionChanged(); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 0c2dc8e88..b167f5a47 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -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(); } diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp index b25a6fb75..c16332fd2 100644 --- a/src/XGUI/XGUI_ActionsMgr.cpp +++ b/src/XGUI/XGUI_ActionsMgr.cpp @@ -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 - (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 + (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(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); } } diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h index 9191021ad..378819773 100644 --- a/src/XGUI/XGUI_ActionsMgr.h +++ b/src/XGUI/XGUI_ActionsMgr.h @@ -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 myActions; @@ -123,6 +132,8 @@ public slots: XGUI_Workshop* myWorkshop; XGUI_OperationMgr* myOperationMgr; + + friend class XGUI_Workshop; }; #endif /* XGUI_ACTIONSMGR_H_ */ diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index ee5f029d8..bc8d74140 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -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 diff --git a/src/XGUI/XGUI_ModuleConnector.h b/src/XGUI/XGUI_ModuleConnector.h index 598c7a22e..4b2ed19f4 100644 --- a/src/XGUI/XGUI_ModuleConnector.h +++ b/src/XGUI/XGUI_ModuleConnector.h @@ -81,6 +81,9 @@ Q_OBJECT //! If the list is empty then selection will be cleared virtual void setSelected(const QList& theValues); + /// Update of commands status + virtual void updateCommandStatus(); + //! Returns workshop XGUI_Workshop* workshop() const { return myWorkshop; } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 2199df248..e8840c1a4 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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(); }