From: vsv Date: Tue, 29 Apr 2014 14:07:07 +0000 (+0400) Subject: Adapt action manager for working in SALOME (issue #31) X-Git-Tag: V_0.2~105 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=25b7f8a69048e0fb0cc3840d2bb5f4f887749a53;p=modules%2Fshaper.git Adapt action manager for working in SALOME (issue #31) --- diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index f56deda0d..8d1b96246 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -200,6 +200,20 @@ QAction* NewGeom_Module::command(const QString& theId) const return 0; } +//****************************************************** +void NewGeom_Module::setNestedActions(const QString& theId, const QStringList& theActions) +{ + myNestedActions[theId] = theActions; +} + +//****************************************************** +QStringList NewGeom_Module::nestedActions(const QString& theId) const +{ + if (myNestedActions.contains(theId)) + return myNestedActions[theId]; + return QStringList(); +} + //****************************************************** Handle(AIS_InteractiveContext) NewGeom_Module::AISContext() const { diff --git a/src/NewGeom/NewGeom_Module.h b/src/NewGeom/NewGeom_Module.h index be58a3602..65e048e40 100644 --- a/src/NewGeom/NewGeom_Module.h +++ b/src/NewGeom/NewGeom_Module.h @@ -9,6 +9,7 @@ #include #include +#include class XGUI_Workshop; class NewGeom_OCCSelector; @@ -58,6 +59,14 @@ public: virtual QAction* command(const QString& theId) const; + //! Set nested actions dependent on command Id + //! \param theId - the command ID + //! \param theActions - the list of nested actions + virtual void setNestedActions(const QString& theId, const QStringList& theActions); + + //! Returns list of nested actions according to the given command ID + virtual QStringList nestedActions(const QString& theId) const; + //! Returns AIS_InteractiveContext from current OCCViewer virtual Handle(AIS_InteractiveContext) AISContext() const; @@ -80,6 +89,8 @@ private: XGUI_Workshop* myWorkshop; NewGeom_OCCSelector* mySelector; + + QMap myNestedActions; }; #endif diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp index 8cc05c494..51efba533 100644 --- a/src/XGUI/XGUI_ActionsMgr.cpp +++ b/src/XGUI/XGUI_ActionsMgr.cpp @@ -2,15 +2,18 @@ * XGUI_ActionsMgr.cpp */ -#include -#include +#include "XGUI_ActionsMgr.h" +#include "XGUI_Command.h" +#include "XGUI_Workshop.h" +#include "XGUI_SalomeConnector.h" + #include -XGUI_ActionsMgr::XGUI_ActionsMgr(QObject* theParent) - : QObject(theParent) +XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent) + : QObject(theParent), myWorkshop(theParent) { - + } XGUI_ActionsMgr::~XGUI_ActionsMgr() @@ -18,6 +21,13 @@ XGUI_ActionsMgr::~XGUI_ActionsMgr() } +void XGUI_ActionsMgr::addCommand(QString theId, QAction* theCmd) +{ + myActions.insert(theId,theCmd); + myActionsState.insert(theId, theCmd->isEnabled()); + connect(theCmd, SIGNAL(triggered(bool)), this, SLOT(setActionsDisabled(bool))); +} + void XGUI_ActionsMgr::addCommand(XGUI_Command* theCmd) { myActions.insert(theCmd->id(),theCmd); @@ -35,8 +45,15 @@ void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled) } //Disable all actions, but caller and unblockable (defined in a xml) saveCommandsState(); - XGUI_Command* aToggledFeature = dynamic_cast(sender()); - QString aSkippedId = aToggledFeature->id(); + + QString aSkippedId; + if (myWorkshop->isSalomeMode()) { + QAction* aToggledFeature = dynamic_cast(sender()); + aSkippedId = myWorkshop->salomeConnector()->commandId(aToggledFeature); + } else { + XGUI_Command* aToggledFeature = dynamic_cast(sender()); + aSkippedId = aToggledFeature->id(); + } QStringList anActionIdsList = myActions.keys(); foreach(QString eachKey, anActionIdsList) { if (eachKey == aSkippedId) { @@ -44,7 +61,12 @@ void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled) } myActions[eachKey]->setEnabled(false); } - myNestedActions = aToggledFeature->unblockableCommands(); + if (myWorkshop->isSalomeMode()) { + myNestedActions = myWorkshop->salomeConnector()->nestedActions(aSkippedId); + } else { + XGUI_Command* aToggledFeature = dynamic_cast(sender()); + myNestedActions = aToggledFeature->unblockableCommands(); + } } void XGUI_ActionsMgr::saveCommandsState() diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h index d6c55d833..194412ec1 100644 --- a/src/XGUI/XGUI_ActionsMgr.h +++ b/src/XGUI/XGUI_ActionsMgr.h @@ -10,6 +10,7 @@ #include class XGUI_Command; +class XGUI_Workshop; class QAction; class XGUI_ActionsMgr: public QObject @@ -17,11 +18,17 @@ class XGUI_ActionsMgr: public QObject Q_OBJECT public: - XGUI_ActionsMgr(QObject* theParent); + XGUI_ActionsMgr(XGUI_Workshop* theParent); virtual ~XGUI_ActionsMgr(); void addCommand(XGUI_Command* theCmd); + + /// Register a command in SALOME mode + /// \param theId - string ID of the command + /// \param theCmd - command object + void addCommand(QString theId, QAction* theCmd); + void saveCommandsState(); void restoreCommandState(); @@ -34,6 +41,8 @@ private: QStringList myNestedActions; QMap myActions; QMap myActionsState; + + XGUI_Workshop* myWorkshop; }; #endif /* XGUI_ACTIONSMGR_H_ */ diff --git a/src/XGUI/XGUI_SalomeConnector.h b/src/XGUI/XGUI_SalomeConnector.h index 6418cdf46..f6e89cf17 100644 --- a/src/XGUI/XGUI_SalomeConnector.h +++ b/src/XGUI/XGUI_SalomeConnector.h @@ -5,6 +5,7 @@ #include #include +#include class QMainWindow; @@ -65,6 +66,14 @@ public: //! Returns QAction instance by command string Id virtual QAction* command(const QString& theId) const = 0; + //! Set nested actions dependent on command Id + //! \param theId - the command ID + //! \param theActions - the list of nested actions + virtual void setNestedActions(const QString& theId, const QStringList& theActions) = 0; + + //! Returns list of nested actions according to the given command ID + virtual QStringList nestedActions(const QString& theId) const = 0; + //! Returns AIS_InteractiveContext from current OCCViewer virtual Handle(AIS_InteractiveContext) AISContext() const = 0; }; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 60bad111d..90cb04fc3 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -244,10 +244,7 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) } else { hidePropertyPanel(); updateCommandStatus(); - - if (myMainWindow) { - myActionsMgr->restoreCommandState(); - } + myActionsMgr->restoreCommandState(); } } @@ -264,15 +261,22 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) } //Find or create Workbench QString aWchName = QString::fromStdString(theMessage->workbenchId()); + QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures()); + bool isUsePropPanel = theMessage->isUseInput(); if (isSalomeMode()) { + QString aId = QString::fromStdString(theMessage->id()); salomeConnector()->addFeature(aWchName, QString::fromStdString(theMessage->id()), - QString::fromStdString(theMessage->text()), + aId, QString::fromStdString(theMessage->tooltip()), QIcon(theMessage->icon().c_str()), - false, this, + isUsePropPanel, this, SLOT(onFeatureTriggered()), QKeySequence()); + myActionsMgr->addCommand(aId, salomeConnector()->command(aId)); + salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" ")); + } else { + XGUI_MainMenu* aMenuBar = myMainWindow->menuObject(); XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName); if (!aPage) { @@ -284,14 +288,12 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) if (!aGroup) { aGroup = aPage->addGroup(aGroupName); } - bool isUsePropPanel = theMessage->isUseInput(); //Create feature... XGUI_Command* aCommand = aGroup->addFeature(QString::fromStdString(theMessage->id()), QString::fromStdString(theMessage->text()), QString::fromStdString(theMessage->tooltip()), QIcon(theMessage->icon().c_str()), QKeySequence(), isUsePropPanel); - QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures()); aCommand->setUnblockableCommands(aNestedFeatures.split(" ")); myActionsMgr->addCommand(aCommand); myPartSetModule->featureCreated(aCommand);