//! \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();
// 6. Update sketcher actions
XGUI_ActionsMgr* anActMgr = workshop()->actionsMgr();
- anActMgr->update();
+ myWorkshop->updateCommandStatus();
myWorkshop->viewer()->update();
}
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();
}
void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
{
- foreach(QString eachAction, myActions.keys())
- {
+ foreach(QString eachAction, myActions.keys()) {
setActionEnabled(eachAction, isEnabled);
}
}
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)) {
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);
}
}
/// 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;
XGUI_Workshop* myWorkshop;
XGUI_OperationMgr* myOperationMgr;
+
+ friend class XGUI_Workshop;
};
#endif /* XGUI_ACTIONSMGR_H_ */
{
myWorkshop->operationMgr()->abortOperation(theOperation);
}
+
+void XGUI_ModuleConnector::updateCommandStatus()
+{
+ myWorkshop->updateCommandStatus();
+}
\ No newline at end of file
//! 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; }
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);
connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
- myActionsMgr->update();
+ updateCommandStatus();
// activate visualized objects in the viewer
XGUI_Displayer* aDisplayer = displayer();
aCmd->setEnabled(false);
}
}
- myActionsMgr->update();
+ myActionsMgr->updateCommandsStatus();
emit commandStatusUpdated();
}