]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Adapt action manager for working in SALOME (issue #31)
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 29 Apr 2014 14:07:07 +0000 (18:07 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 29 Apr 2014 14:07:07 +0000 (18:07 +0400)
src/NewGeom/NewGeom_Module.cpp
src/NewGeom/NewGeom_Module.h
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_ActionsMgr.h
src/XGUI/XGUI_SalomeConnector.h
src/XGUI/XGUI_Workshop.cpp

index f56deda0dc3b8c266e7c2c855fa32c01099e1913..8d1b9624646b31d0c800b0b3a199c4ed6b607518 100644 (file)
@@ -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
 {
index be58a360224af956e984836c986e300de5c4b421..65e048e40cdb64240d0ea09a0d4547f0efd56589 100644 (file)
@@ -9,6 +9,7 @@
 #include <XGUI_SalomeConnector.h>
 
 #include <QStringList>
+#include <QMap>
 
 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<QString, QStringList> myNestedActions;
 };
 
 #endif
index 8cc05c494a8a75a01b8c96e38c0ecfd844f3d32e..51efba53326095db0507afe8f7aebfbe6e6242db 100644 (file)
@@ -2,15 +2,18 @@
  * XGUI_ActionsMgr.cpp
  */
 
-#include <XGUI_ActionsMgr.h>
-#include <XGUI_Command.h>
+#include "XGUI_ActionsMgr.h"
+#include "XGUI_Command.h"
+#include "XGUI_Workshop.h"
+#include "XGUI_SalomeConnector.h"
+
 #include <QAction>
 
 
-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<XGUI_Command*>(sender());
-  QString aSkippedId = aToggledFeature->id();
+
+  QString aSkippedId;
+  if (myWorkshop->isSalomeMode()) {
+    QAction* aToggledFeature = dynamic_cast<QAction*>(sender());
+    aSkippedId = myWorkshop->salomeConnector()->commandId(aToggledFeature);
+  } else {
+    XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(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<XGUI_Command*>(sender());
+    myNestedActions = aToggledFeature->unblockableCommands();
+  }
 }
 
 void XGUI_ActionsMgr::saveCommandsState()
index d6c55d833ca7b87720107404be8267a1afd434c3..194412ec13b29edea9ec74b04c306a91b843f331 100644 (file)
@@ -10,6 +10,7 @@
 #include <QStringList>
 
 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<QString, QAction*> myActions;
   QMap<QString, bool> myActionsState;
+
+  XGUI_Workshop* myWorkshop;
 };
 
 #endif /* XGUI_ACTIONSMGR_H_ */
index 6418cdf463f7038189628161aad31cc9c271eca6..f6e89cf17fe5da5f3639a29771eaff0a0fc2f7df 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <AIS_InteractiveContext.hxx>
 #include <QString>
+#include <QStringList>
 
 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;
 };
index 60bad111dbc77e1b051e2f6df8c41965a11821cc..90cb04fc3f3a21adf8f1e2e8bfdfbf5ad0d22ca1 100644 (file)
@@ -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);