]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Adaptation of the application to SALOME interface (issue #31)
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 20 May 2014 07:24:59 +0000 (11:24 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 20 May 2014 07:24:59 +0000 (11:24 +0400)
13 files changed:
src/NewGeom/CMakeLists.txt
src/NewGeom/NewGeom_Module.cpp
src/NewGeom/NewGeom_Module.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_ActionsMgr.h
src/XGUI/XGUI_Command.cpp
src/XGUI/XGUI_Command.h
src/XGUI/XGUI_MenuGroupPanel.cpp
src/XGUI/XGUI_Module.h
src/XGUI/XGUI_SalomeConnector.h
src/XGUI/XGUI_Workshop.cpp

index 0f41fea7f82c7fd3922340cb876babf2055c1852..4eee4a29489646d15093f9cb1d10080fd7d9b488 100644 (file)
@@ -44,6 +44,7 @@ ADD_DEFINITIONS( -DNewGeom_EXPORTS ${CAS_DEFINITIONS} )
 INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/XGUI
                                        ${PROJECT_SOURCE_DIR}/src/Events
                                        ${PROJECT_SOURCE_DIR}/src/ModuleBase
+                    ${PROJECT_SOURCE_DIR}/src/ModelAPI
                                        ${SALOME_GUI_INCLUDE}
                                        ${SALOME_KERNEL_INCLUDE}
                     ${CAS_INCLUDE_DIRS}
index 2b7e8e5c9ec49ce41af79c52300d840ac1d488fa..549276279f14ece914747ce0b52deb231b7a3dce 100644 (file)
@@ -19,6 +19,7 @@
 #include <QtxActionMenuMgr.h>
 
 #include <QDockWidget>
+#include <QAction>
 
 extern "C" {
   NewGeom_EXPORT CAM_Module* createModule() {
@@ -126,15 +127,13 @@ CAM_DataModel* NewGeom_Module::createDataModel()
 }
 
 //******************************************************
-void NewGeom_Module::addFeature(const QString& theWBName,
-                                const QString& theId, 
-                                const QString& theTitle, 
-                                const QString& theTip,
-                                const QIcon& theIcon, 
-                                bool isCheckable,
-                                QObject* theReciever,
-                                const char* theMember,
-                                const QKeySequence& theKeys)
+QAction* NewGeom_Module::addFeature(const QString& theWBName,
+                                    const QString& theId, 
+                                    const QString& theTitle, 
+                                    const QString& theTip,
+                                    const QIcon& theIcon, 
+                                    const QKeySequence& theKeys,
+                                    bool isCheckable)
 {
   int aMenu = createMenu(theWBName, -1, -1, 50);
   int aTool = createTool(theWBName);
@@ -145,21 +144,21 @@ void NewGeom_Module::addFeature(const QString& theWBName,
   int aKeys = 0;
   for (int i = 0; i < theKeys.count(); i++) 
     aKeys += theKeys[i];
-  createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, 
-               isCheckable, theReciever, theMember);
+  QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, 
+                                  isCheckable);
+  aAction->setData(theId);
   int aItemId = createMenu( aId,  aMenu, -1, 10 );
   int aToolId = createTool( aId, aTool );
+  return aAction;
 }
 
 //******************************************************
-void NewGeom_Module::addEditCommand(const QString& theId,
-                                    const QString& theTitle,
-                                    const QString& theTip,
-                                    const QIcon& theIcon, 
-                                    bool isCheckable,
-                                    QObject* theReciever,
-                                    const char* theMember,
-                                    const QKeySequence& theKeys)
+QAction* NewGeom_Module::addEditCommand(const QString& theId,
+                                        const QString& theTitle,
+                                        const QString& theTip,
+                                        const QIcon& theIcon, 
+                                        const QKeySequence& theKeys,
+                                        bool isCheckable)
 {
   int aMenu = createMenu(tr( "MEN_DESK_EDIT" ), -1, -1);
 
@@ -169,9 +168,11 @@ void NewGeom_Module::addEditCommand(const QString& theId,
   int aKeys = 0;
   for (int i = 0; i < theKeys.count(); i++) 
     aKeys += theKeys[i];
-  createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, 
-               isCheckable, theReciever, theMember);
+  QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, 
+                                  isCheckable);
+  aAction->setData(theId);
   createMenu( aId, aMenu, 10 );
+  return aAction;
 }
 
 //******************************************************
@@ -181,6 +182,21 @@ void NewGeom_Module::addEditMenuSeparator()
   createMenu( separator(), aMenu, -1, 10 );
 }
 
+//******************************************************
+QList<QAction*> NewGeom_Module::commandList() const
+{
+  QList<QAction*> aActions;
+  for (int i = 0; i < myActionsList.size(); i++)
+    aActions.append(action(i));
+  return aActions;
+}
+
+//******************************************************
+QStringList NewGeom_Module::commandIdList() const
+{
+  return myActionsList;
+}
+
 //******************************************************
 QMainWindow* NewGeom_Module::desktop() const
 {
index 9b63a18c636955e24e04e6347f39fb6f0151bed5..ef0b4eb4ad28d8f2596b7155a7bc70c35c3f0142 100644 (file)
@@ -34,24 +34,20 @@ public:
   virtual void selectionChanged();
 
   //--- XGUI connector interface -----
-  virtual void addFeature(const QString& theWBName,
-                          const QString& theId, 
-                          const QString& theTitle, 
-                          const QString& theTip,
-                          const QIcon& theIcon, 
-                          bool isCheckable = false,
-                          QObject* reciever = 0,
-                          const char* member = 0,
-                          const QKeySequence& theKeys = QKeySequence());
-
-  virtual void addEditCommand(const QString& theId,
-                              const QString& theTitle,
+  virtual QAction* addFeature(const QString& theWBName,
+                              const QString& theId, 
+                              const QString& theTitle, 
                               const QString& theTip,
                               const QIcon& theIcon, 
-                              bool isCheckable,
-                              QObject* reciever,
-                              const char* member,
-                              const QKeySequence& theKeys);
+                              const QKeySequence& theKeys = QKeySequence(),
+                              bool isCheckable = false);
+
+  virtual QAction* addEditCommand(const QString& theId,
+                                  const QString& theTitle,
+                                  const QString& theTip,
+                                  const QIcon& theIcon, 
+                                  const QKeySequence& theKeys,
+                                  bool isCheckable);
 
   virtual void addEditMenuSeparator();
 
@@ -72,6 +68,12 @@ public:
   //! Returns interface to Salome viewer
   virtual XGUI_SalomeViewer* viewer() const { return myProxyViewer; }
 
+  //! Returns list of defined actions (just by NewGeom module)
+  virtual QList<QAction*> commandList() const;
+
+  //! Returns list of Ids of defined actions (just by NewGeom module)
+  virtual QStringList commandIdList() const;
+
 public slots:
   virtual bool activateModule( SUIT_Study* theStudy);
   virtual bool deactivateModule( SUIT_Study* theStudy);
index 08b5bf2b66300052cd2a920d498e0d3f78ab64ca..99806f4621d20ca6223e8cc7dd6779e1542f9b87 100644 (file)
@@ -80,9 +80,9 @@ void PartSet_Module::createFeatures()
   myFeaturesInFiles = aXMLReader.featuresInFiles();
 }
 
-void PartSet_Module::featureCreated(XGUI_Command* theFeature)
+void PartSet_Module::featureCreated(QAction* theFeature)
 {
-  theFeature->connectTo(this, SLOT(onFeatureTriggered()));
+  connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
 }
 
 QStringList PartSet_Module::nestedFeatures(QString)
@@ -100,11 +100,11 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId)
  */
 void PartSet_Module::onFeatureTriggered()
 {
-  XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
+  QAction* aCmd = dynamic_cast<QAction*>(sender());
   //Do nothing on uncheck
   if(aCmd->isCheckable() && !aCmd->isChecked())
     return;
-  launchOperation(aCmd->id());
+  launchOperation(aCmd->data().toString());
 }
   
 void PartSet_Module::launchOperation(const QString& theCmdId)
index 86c2d95f6b38ed99599461e1907e740b96b9813f..0c9e72a4a44b15d20a5fe6f671868d90061668ca 100644 (file)
@@ -31,7 +31,7 @@ public:
   XGUI_Workshop* workshop() const;
 
   virtual void createFeatures();
-  virtual void featureCreated(XGUI_Command* theFeature);
+  virtual void featureCreated(QAction* theFeature);
   virtual QStringList nestedFeatures(QString theFeature);
   std::string featureFile(const std::string&);
 
index a496899708f9375fd8fa60fde53a89de2044a6f3..7f0b02d9ae0e668688a24dbaaa15d1a65caf1a19 100644 (file)
@@ -21,20 +21,14 @@ XGUI_ActionsMgr::~XGUI_ActionsMgr()
 }
 
 
-void XGUI_ActionsMgr::addCommand(QString theId, QAction* theCmd)
+void XGUI_ActionsMgr::addCommand(QAction* theCmd)
 {
-  myActions.insert(theId,theCmd);
-  myActionsState.insert(theId, theCmd->isEnabled());
+  QString aId = theCmd->data().toString();
+  myActions.insert(aId, theCmd);
+  myActionsState.insert(aId, theCmd->isEnabled());
   connect(theCmd, SIGNAL(triggered(bool)), this, SLOT(setActionsDisabled(bool)));
 }
 
-void XGUI_ActionsMgr::addCommand(XGUI_Command* theCmd)
-{
-  myActions.insert(theCmd->id(),theCmd);
-  myActionsState.insert(theCmd->id(), theCmd->enabled());
-  theCmd->connectTo(this, SLOT(setActionsDisabled(bool)));
-}
-
 void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
 {
   //Re-enable actions (just restore their state)
@@ -47,13 +41,9 @@ void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
   saveCommandsState();
 
   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();
-  }
+  QAction* aToggledFeature = dynamic_cast<QAction*>(sender());
+  aSkippedId = aToggledFeature->data().toString();
+
   QStringList anActionIdsList = myActions.keys();
   foreach(QString eachKey, anActionIdsList) {
     if (eachKey == aSkippedId) {
index 965f2289f05e884d451e2c32450a68ad7aea7f3d..3390a83f3b87092cf9b0d8879bafc5625fddc007 100644 (file)
@@ -24,12 +24,7 @@ public:
   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 addCommand(QAction* theCmd);
 
   void saveCommandsState();
   void restoreCommandState();
index 9b5dd7b9abfa4ea89a6e5e81f9e2ecbc529a0dab..220e04f474b5007c1b2dabd60722aeca78c5ac1d 100644 (file)
@@ -3,16 +3,18 @@
 #include <QPushButton>
 
 XGUI_Command::XGUI_Command(const QString& theId, QObject * parent, bool isCheckable)
-    : QWidgetAction(parent), myId(theId), myCheckable(isCheckable)
+    : QWidgetAction(parent), myCheckable(isCheckable)
 {
+  setData(theId);
 }
 
 XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text,
                            QObject* parent, bool isCheckable)
-    : QWidgetAction(parent), myId(theId), myCheckable(isCheckable)
+    : QWidgetAction(parent), myCheckable(isCheckable)
 {
   setIcon(icon);
   setText(text);
+  setData(theId);
 }
 
 XGUI_Command::~XGUI_Command()
@@ -46,21 +48,6 @@ QWidget* XGUI_Command::createWidget(QWidget* theParent)
   return QWidgetAction::createWidget(theParent);
 }
 
-bool XGUI_Command::enabled() const
-{
-  return isEnabled();
-}
-
-void XGUI_Command::enable()
-{
-  setEnabled(true);
-}
-
-void XGUI_Command::disable()
-{
-  setEnabled(false);
-}
-
 void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
 {
     connect(this, SIGNAL(triggered(bool)), theResiver, theSlot);
index 380b64ae4b8ce90eb1761995cc724d67dc5f81ca..dbd45b43207d969a93b67916a3768bdffbe04d12 100644 (file)
@@ -19,20 +19,11 @@ public:
   XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, QObject* parent, bool isCheckable = false);
   ~XGUI_Command();
 
-  //! Returns true if the command is enabled
-  virtual bool enabled() const;
-
-  //! Set the command enabled
-  virtual void enable();
-
-  //! Set the command disabled
-  virtual void disable();
-
-  //! Returns Id of the command
-  virtual QString id() const
+  //VSV: Don't use this method for compatibility with SALOME. Use the construction below
+  /*virtual QString id() const
   {
-    return myId;
-  }
+    return data().toString();
+  }*/
 
   const QStringList& unblockableCommands() const;
   void setUnblockableCommands(const QStringList& myUnblockableCommands);
@@ -45,7 +36,6 @@ protected:
   virtual QWidget* createWidget(QWidget* theParent);
 
 private:
-  QString myId;
   bool myCheckable;
   //! List of Ids of commands which WILL NOT be blocked when the command is on.
   QStringList myUnblockableCommands;
index 4f4673470417dad3dcb02a3d1ac5f13080df9201..48a9ce1a87bc81f01734676f6e174917c193a3df 100644 (file)
@@ -76,9 +76,9 @@ XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId, const QStrin
 
 XGUI_Command* XGUI_MenuGroupPanel::feature(const QString& theId) const
 {
-  QList<XGUI_Command*>::const_iterator aIt;
-  for (aIt = myActions.constBegin(); aIt != myActions.constEnd(); ++aIt)
-    if ((*aIt)->id() == theId)
-      return (*aIt);
+  foreach (XGUI_Command* aCmd, myActions) {
+    if (aCmd->data().toString() == theId)
+      return aCmd;
+  }
   return 0;
 }
index 48de0ad69b8a309550d3e2745a6573bba43af839..4df05ea2f5cb02b524457c2284f303c8c026e2af 100644 (file)
@@ -4,13 +4,13 @@
 #include <XGUI_Workshop.h>\r
 #include <QString>\r
 \r
-class XGUI_Command;\r
+class QAction;\r
 \r
 class XGUI_Module\r
 {\r
 public:\r
   virtual void createFeatures() = 0;\r
-  virtual void featureCreated(XGUI_Command*) = 0;\r
+  virtual void featureCreated(QAction*) = 0;\r
   virtual void launchOperation(const QString& theCmdId) = 0;\r
 \r
   virtual ~XGUI_Module() {};\r
index a55398cb15ef6db5ab732f78739dd6ecd0411e4b..48bb6e10f7515f81768dc034740762af94b3d2e5 100644 (file)
@@ -23,18 +23,15 @@ public:
   //! \param theTip - a tooltip string (help)
   //! \param theIcon - icon
   //! \param isCheckable - is checkable or not
-  //! \param reciever - QObject which will react on the command call
-  //! \param member - a method of receiver which will be called on the command
   //! \param theKeys - hot keys
-  virtual void addFeature(const QString& theWBName,
-                          const QString& theId, 
-                          const QString& theTitle, 
-                          const QString& theTip,
-                          const QIcon& theIcon, 
-                          bool isCheckable,
-                          QObject* reciever,
-                          const char* member,
-                          const QKeySequence& theKeys) = 0;
+  //! returns created action
+  virtual QAction* addFeature(const QString& theWBName,
+                              const QString& theId, 
+                              const QString& theTitle, 
+                              const QString& theTip,
+                              const QIcon& theIcon, 
+                              const QKeySequence& theKeys,
+                              bool isCheckable) = 0;
 
   //! Creates a command in Edit menu of SALOME desktop
   //! \param theId - an id of the feature
@@ -42,17 +39,14 @@ public:
   //! \param theTip - a tooltip string (help)
   //! \param theIcon - icon
   //! \param isCheckable - is checkable or not
-  //! \param reciever - QObject which will react on the command call
-  //! \param member - a method of receiver which will be called on the command
   //! \param theKeys - hot keys
-  virtual void addEditCommand(const QString& theId,
-                              const QString& theTitle,
-                              const QString& theTip,
-                              const QIcon& theIcon, 
-                              bool isCheckable,
-                              QObject* reciever,
-                              const char* member,
-                              const QKeySequence& theKeys) = 0;
+  //! returns created action
+  virtual QAction* addEditCommand(const QString& theId,
+                                  const QString& theTitle,
+                                  const QString& theTip,
+                                  const QIcon& theIcon, 
+                                  const QKeySequence& theKeys,
+                                  bool isCheckable) = 0;
 
   //! Insert separator into Edit menu of SALOME desktop
   virtual void addEditMenuSeparator() = 0;
@@ -66,6 +60,12 @@ public:
   //! Returns QAction instance by command string Id
   virtual QAction* command(const QString& theId) const = 0;
 
+  //! Returns list of defined actions (just by NewGeom module)
+  virtual QList<QAction*> commandList() const = 0;
+
+  //! Returns list of Ids of defined actions (just by NewGeom module)
+  virtual QStringList commandIdList() const = 0;
+
   //! Set nested actions dependent on command Id
   //! \param theId - the command ID
   //! \param theActions - the list of nested actions
index 1a11dca832d2f22f545eea46e1305eaef5722ffd..60c7f0b5bf8c56d814ce347479666f046a89dcee 100644 (file)
@@ -129,16 +129,16 @@ void XGUI_Workshop::initMenu()
 {
   if (isSalomeMode()) {
     // Create only Undo, Redo commands
-    salomeConnector()->addEditCommand("UNDO_CMD", 
+    QAction* aAction = salomeConnector()->addEditCommand("UNDO_CMD", 
                                       tr("Undo"), tr("Undo last command"),
                                       QIcon(":pictures/undo.png"), 
-                                      false, this, SLOT(onUndo()),
-                                      QKeySequence::Undo);
-    salomeConnector()->addEditCommand("REDO_CMD", 
+                                      QKeySequence::Undo, false);
+    connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
+    aAction = salomeConnector()->addEditCommand("REDO_CMD", 
                                       tr("Redo"), tr("Redo last command"),
                                       QIcon(":pictures/redo.png"), 
-                                      false, this, SLOT(onRedo()),
-                                      QKeySequence::Redo);
+                                      QKeySequence::Redo, false);
+    connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
     salomeConnector()->addEditMenuSeparator();
     return;
   }
@@ -297,16 +297,15 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
   bool isUsePropPanel = theMessage->isUseInput();
   if (isSalomeMode()) {
     QString aId = QString::fromStdString(theMessage->id());
-    salomeConnector()->addFeature(aWchName,
-                                  QString::fromStdString(theMessage->id()),
-                                  aId,
-                                  QString::fromStdString(theMessage->tooltip()),
-                                  QIcon(theMessage->icon().c_str()),
-                                  isUsePropPanel, this, 
-                                  SLOT(onFeatureTriggered()), QKeySequence());
-    myActionsMgr->addCommand(aId, salomeConnector()->command(aId));
+    QAction* aAction = salomeConnector()->addFeature(aWchName,
+                              aId,
+                              QString::fromStdString(theMessage->text()),
+                              QString::fromStdString(theMessage->tooltip()),
+                              QIcon(theMessage->icon().c_str()),
+                              QKeySequence(), isUsePropPanel);
+    myActionsMgr->addCommand(aAction);
     salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" "));
-
+    myPartSetModule->featureCreated(aAction);
   } else {
 
     XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
@@ -563,36 +562,39 @@ bool XGUI_Workshop::activateModule()
 //******************************************************
 void XGUI_Workshop::updateCommandStatus()
 {
-  if (isSalomeMode()) // TODO: update commands in SALOME
-    return;
-  XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
-
-  QList<XGUI_Command*> aCommands = aMenuBar->features();
-  QList<XGUI_Command*>::const_iterator aIt;
-
+  QList<QAction*> aCommands;
+  if (isSalomeMode()) { // update commands in SALOME mode
+    aCommands = salomeConnector()->commandList();
+  } else {
+    XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
+    foreach (XGUI_Command* aCmd, aMenuBar->features())
+      aCommands.append(aCmd);
+  }
   PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
   if (aMgr->hasRootDocument()) {
-    XGUI_Command* aUndoCmd;
-    XGUI_Command* aRedoCmd;
-    foreach(XGUI_Command* aCmd, aCommands) {
-      if (aCmd->id() == "UNDO_CMD")
+    QAction* aUndoCmd;
+    QAction* aRedoCmd;
+    foreach(QAction* aCmd, aCommands) {
+      QString aId = aCmd->data().toString();
+      if (aId == "UNDO_CMD")
         aUndoCmd = aCmd;
-      else if (aCmd->id() == "REDO_CMD")
+      else if (aId == "REDO_CMD")
         aRedoCmd = aCmd;
       else // Enable all commands
-        aCmd->enable();
+        aCmd->setEnabled(true);
     }
     DocumentPtr aDoc = aMgr->rootDocument();
     aUndoCmd->setEnabled(aDoc->canUndo());
     aRedoCmd->setEnabled(aDoc->canRedo());
   } else {
-    foreach(XGUI_Command* aCmd, aCommands) {
-      if (aCmd->id() == "NEW_CMD")
-        aCmd->enable();
-      else if (aCmd->id() == "EXIT_CMD")
-        aCmd->enable();
+    foreach(QAction* aCmd, aCommands) {
+      QString aId = aCmd->data().toString();
+      if (aId == "NEW_CMD")
+        aCmd->setEnabled(true);
+      else if (aId == "EXIT_CMD")
+        aCmd->setEnabled(true);
       else 
-        aCmd->disable();
+        aCmd->setEnabled(false);
     }
   }
 }