Salome HOME
Issue 1303 Re-ordering of Sketcher menus: using menu mechanizm to group SALOME actions.
authornds <nds@opencascade.com>
Thu, 14 Apr 2016 07:22:01 +0000 (10:22 +0300)
committernds <nds@opencascade.com>
Thu, 14 Apr 2016 07:22:26 +0000 (10:22 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/SHAPERGUI/SHAPERGUI.cpp
src/SHAPERGUI/SHAPERGUI.h
src/XGUI/XGUI_MenuGroup.cpp
src/XGUI/XGUI_MenuGroup.h
src/XGUI/XGUI_MenuMgr.cpp
src/XGUI/XGUI_MenuMgr.h
src/XGUI/XGUI_SalomeConnector.h
src/XGUI/XGUI_Workshop.cpp

index 269c115683bafe6cba17bc69b23380bd4673e768..a89671c2fb37ad38dee7ba3916e2c80bab5e222a 100755 (executable)
@@ -327,8 +327,8 @@ protected slots:
   /// Called on selection changed event\r
   virtual void onSelectionChanged() {}\r
 \r
- protected:\r
 /// Register validators for this module\r
+protected:\r
+ /// Register validators for this module\r
   virtual void registerValidators() {}\r
 \r
   /// Register selection filters for this module\r
index a85c0d9a0e0991e00faca8634461c8e29b6973c4..8af02ae2d3729c459dde3c3deddcacd31c2ea321 100644 (file)
@@ -12,6 +12,7 @@
 #include <XGUI_ObjectsBrowser.h>
 #include <XGUI_OperationMgr.h>
 #include <XGUI_Displayer.h>
+#include <XGUI_MenuMgr.h>
 
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_Preferences.h>
@@ -373,7 +374,9 @@ CAM_DataModel* SHAPERGUI::createDataModel()
   return new SHAPERGUI_DataModel(this);
 }
 
-QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo)
+QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
+                               const bool isAddSeparator,
+                               bool isMenuAction, bool isToolAction)
 {
   return addFeature(theWBName,
                     theInfo.id,
@@ -381,14 +384,16 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theIn
                     theInfo.toolTip,
                     theInfo.icon,
                     theInfo.shortcut,
-                    theInfo.checkable);
+                    theInfo.checkable,
+                    isAddSeparator, isMenuAction, isToolAction);
 }
 
 //******************************************************
 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId,
-                                    const QString& theTitle, const QString& theTip,
-                                    const QIcon& theIcon, const QKeySequence& theKeys,
-                                    bool isCheckable)
+                               const QString& theTitle, const QString& theTip,
+                               const QIcon& theIcon, const QKeySequence& theKeys,
+                               bool isCheckable, const bool isAddSeparator,
+                               bool isMenuAction, bool isToolAction)
 {
   static QString aLastTool = "";
   static int aNb = 0;
@@ -403,9 +408,6 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId,
   }
   aNb++;
 
-  int aMenu = createMenu(theWBName, -1, -1, 50);
-  int aTool = createTool(theWBName, theWBName);
-
   int aId = myActionsList.size();
   myActionsList.append(theId);
   SUIT_Desktop* aDesk = application()->desktop();
@@ -415,9 +417,19 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId,
   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);
 
+  if (isMenuAction) {
+    int aWBMenu = createMenu(theWBName, -1, -1, 50/*10-Window, 1000 - Help*/);
+    int aItemId = createMenu(aId, aWBMenu);
+    if (isAddSeparator)
+      createMenu(separator(), aWBMenu);
+  }
+  if (isToolAction) {
+    int aWBTool = createTool(theWBName, theWBName);
+    int aToolId = createTool(aId, aWBTool);
+    if (isAddSeparator)
+      createTool(separator(), aWBTool);
+  }
   return aAction;
 }
 
@@ -427,12 +439,10 @@ bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
 }
 
 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
-                                            const ActionInfo& theInfo,
-                                            const QList<QAction*>& theNestedActions)
+                                       const ActionInfo& theInfo,
+                                       const QList<QAction*>& theNestedActions,
+                                       bool isMenuAction, bool isToolAction)
 {
-  int aMenu = createMenu(theWBName, -1, -1, 50);
-  int aTool = createTool(theWBName, theWBName);
-
   int aId = myActionsList.size();
   myActionsList.append(theInfo.id);
   SUIT_Desktop* aDesk = application()->desktop();
@@ -448,9 +458,14 @@ QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
   anAction->setShortcut(theInfo.shortcut);
   anAction->setFont(theInfo.font);
 
-  //int aItemId = createMenu(aId, aMenu, -1, 10);
-  int aToolId = createTool(anAction, aTool, aId);
-
+  if (isMenuAction) {
+    int aWBMenu = createMenu(theWBName, -1, -1, 50);
+    int aItemId = createMenu(anAction, aWBMenu);
+  }
+  if (isToolAction) {
+    int aWBTool = createTool(theWBName, theWBName);
+    int aToolId = createTool(anAction, aWBTool);
+  }
   return anAction;
 }
 
@@ -651,3 +666,8 @@ bool SHAPERGUI::abortAllOperations()
 {
   return workshop()->operationMgr()->abortAllOperations();
 }
+
+void SHAPERGUI::createFeatureActions()
+{
+  myWorkshop->menuMgr()->createFeatureActions();
+}
index 7e1c1435e0de388a9010df5765b4b8c7fb25fc92..7e1ff0b1ef7a547574876a2b0472a37f6bbe09b4 100644 (file)
@@ -52,11 +52,13 @@ Q_OBJECT
   virtual QAction* addFeature(const QString& theWBName, const QString& theId,
                               const QString& theTitle, const QString& theTip, const QIcon& theIcon,
                               const QKeySequence& theKeys = QKeySequence(),
-                              bool isCheckable = false);
+                              bool isCheckable = false, const bool isAddSeparator = false,
+                              bool isMenuAction = true, bool isToolAction = true);
 
   //! Add feature (QAction) in the \a theWBName toolbar with given \a theInfo about action
   virtual QAction* addFeature(const QString& theWBName,
-                              const ActionInfo& theInfo);
+                              const ActionInfo& theInfo, const bool isAddSeparator,
+                              bool isMenuAction = true, bool isToolAction = true);
 
   /// Add a nested feature
   /// \param theWBName a workbench name
@@ -64,7 +66,8 @@ Q_OBJECT
   /// \param theNestedActions a list of nested actions
   virtual QAction* addFeatureOfNested(const QString& theWBName,
                                     const ActionInfo& theInfo,
-                                    const QList<QAction*>& theNestedActions);
+                                    const QList<QAction*>& theNestedActions,
+                                    bool isMenuAction = true, bool isToolAction = true);
 
   //! Returns true if the feature action is a nested action, in other words,
   //! it is created by addNestedFeature().
@@ -85,7 +88,10 @@ Q_OBJECT
   /// \param theAction an ation to add
   /// \param theToolBarTitle a name of tool bar
   virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle );
-    
+
+  /// Creates menu/tool bar actions for loaded features stored in the menu manager
+  virtual void createFeatureActions();
+
   virtual QMainWindow* desktop() const;
 
   virtual QString commandId(const QAction* theCmd) const;
index c2ce5b20f938efb1e42031ca3e110f31b9a8d4af..26407a0e913db0dc3ef76dad098cd3893d35c05b 100755 (executable)
@@ -16,7 +16,7 @@ void XGUI_MenuGroup::setFeatureInfo(const std::shared_ptr<Config_FeatureMessage>
   myFeatureInfo.push_back(theMessage);
 }
 
-const std::list<std::shared_ptr<Config_FeatureMessage> >& XGUI_MenuGroup::featureInfo() const
+const std::list<std::shared_ptr<Config_FeatureMessage> >& XGUI_MenuGroup::featuresInfo() const
 {
   return myFeatureInfo;
 }
index 8b471639028776f04b559c7437ac53203495b123..c265608a4749bc5059876ce1952ebc4cae6ef2f8 100755 (executable)
@@ -38,7 +38,7 @@ class XGUI_EXPORT XGUI_MenuGroup
 
   /// Returns container of existing features
   /// \returns list
-  const std::list<std::shared_ptr<Config_FeatureMessage> >& featureInfo() const;
+  const std::list<std::shared_ptr<Config_FeatureMessage> >& featuresInfo() const;
 
 private:
   std::string myName; /// a name of the workbench
index 8dff16c1f295fbd9ce53bd3039a810b6608eaa7e..6cbf91c1a97cb65be16c0d91be470d8b25af1414 100755 (executable)
@@ -60,16 +60,11 @@ void XGUI_MenuMgr::addFeature(const std::shared_ptr<Config_FeatureMessage>& theM
 #endif
     return;
   }
-  {
-    std::string aWchName = theMessage->workbenchId();
-    std::shared_ptr<XGUI_MenuWorkbench> aWorkbench = findWorkbench(aWchName);
-
-    std::string aGroupName = theMessage->groupId();
-    std::shared_ptr<XGUI_MenuGroup> aGroup = aWorkbench->findGroup(aGroupName);
-
-    aGroup->setFeatureInfo(theMessage);
-  }
-
+#ifdef HAVE_SALOME
+  std::shared_ptr<XGUI_MenuWorkbench> aWorkbench = findWorkbench(theMessage->workbenchId());
+  std::shared_ptr<XGUI_MenuGroup> aGroup = aWorkbench->findGroup(theMessage->groupId());
+  aGroup->setFeatureInfo(theMessage);
+#else
   ActionInfo aFeatureInfo;
   aFeatureInfo.initFrom(theMessage);
 
@@ -94,21 +89,6 @@ void XGUI_MenuMgr::addFeature(const std::shared_ptr<Config_FeatureMessage>& theM
     }
   }
 
-#ifdef HAVE_SALOME
-  XGUI_SalomeConnector* aSalomeConnector = myWorkshop->salomeConnector();
-  QAction* aAction;
-  if (isColumnButton) {
-    aAction = aSalomeConnector->addFeatureOfNested(aWchName, aFeatureInfo, aNestedActList);
-  } else {
-    //Issue #650: in the SALOME mode the tooltip should be same as text
-    aFeatureInfo.toolTip = aFeatureInfo.text;
-    aAction = aSalomeConnector->addFeature(aWchName, aFeatureInfo);
-  }
-  aSalomeConnector->setFeatureInfo(aFeatureInfo.id, theMessage);
-
-  myWorkshop->actionsMgr()->addCommand(aAction);
-  myWorkshop->module()->actionCreated(aAction);
-#else 
   //Find or create Workbench
   AppElements_MainMenu* aMenuBar = myWorkshop->mainWindow()->menuObject();
   AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
@@ -138,7 +118,7 @@ void XGUI_MenuMgr::addFeature(const std::shared_ptr<Config_FeatureMessage>& theM
 #endif
 }
 
-std::shared_ptr<XGUI_MenuWorkbench> XGUI_MenuMgr::findWorkbench(std::string& theWorkbenchName)
+std::shared_ptr<XGUI_MenuWorkbench> XGUI_MenuMgr::findWorkbench(const std::string& theWorkbenchName)
 {
   std::list< std::shared_ptr<XGUI_MenuWorkbench> >::const_iterator anIt = myWorkbenches.begin(),
                                                                    aLast = myWorkbenches.end();
@@ -154,3 +134,78 @@ std::shared_ptr<XGUI_MenuWorkbench> XGUI_MenuMgr::findWorkbench(std::string& the
   }
   return aResultWorkbench;
 }
+
+void XGUI_MenuMgr::createFeatureActions()
+{
+#ifdef HAVE_SALOME
+  std::list< std::shared_ptr<XGUI_MenuWorkbench> >::const_iterator anIt = myWorkbenches.begin(),
+                                                                   aLast = myWorkbenches.end();
+  XGUI_SalomeConnector* aSalomeConnector = myWorkshop->salomeConnector();
+  for (; anIt != aLast; anIt++) {
+    std::shared_ptr<XGUI_MenuWorkbench> aWorkbench = *anIt;
+    std::string aWchName = aWorkbench->getName();
+    const std::list<std::shared_ptr<XGUI_MenuGroup> >& aGroups = aWorkbench->groups();
+    std::list<std::shared_ptr<XGUI_MenuGroup> >::const_iterator aGIt = aGroups.begin(),
+                                                                aGLast = aGroups.end();
+    for (; aGIt != aGLast; aGIt++) {
+      const std::shared_ptr<XGUI_MenuGroup> aGroup = *aGIt;
+      std::string aGName = aGroup->getName();
+      const std::list<std::shared_ptr<Config_FeatureMessage> >& aFeaturesInfo = aGroup->featuresInfo();
+      std::list<std::shared_ptr<Config_FeatureMessage> >::const_iterator aFIt = aFeaturesInfo.begin(),
+                                                                               aFLast = aFeaturesInfo.end();
+      int aFSize = aFeaturesInfo.size();
+      for(int i = 0; aFIt != aFLast; aFIt++, i++) {
+        std::shared_ptr<Config_FeatureMessage> aMessage = *aFIt;
+        bool aUseSeparator = i == aFSize-1;
+        QAction* aAction = buildAction(aMessage, aWchName, aUseSeparator);
+
+        aSalomeConnector->setFeatureInfo(QString::fromStdString(aMessage->id()), aMessage);
+        myWorkshop->actionsMgr()->addCommand(aAction);
+        myWorkshop->module()->actionCreated(aAction);
+      }
+    }
+  }
+#endif
+}
+
+QAction* XGUI_MenuMgr::buildAction(const std::shared_ptr<Config_FeatureMessage>& theMessage,
+                                   const std::string& theWchName, const bool aUseSeparator) const
+{
+  QAction* anAction;
+
+#ifdef HAVE_SALOME
+  XGUI_SalomeConnector* aSalomeConnector = myWorkshop->salomeConnector();
+
+  ActionInfo aFeatureInfo;
+  aFeatureInfo.initFrom(theMessage);
+  QStringList aNestedFeatures =
+      QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
+  QList<QAction*> aNestedActList;
+  if (!aNestedFeatures.isEmpty()) {
+    QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
+    XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
+    XGUI_ActionsMgr* anActionsMgr = myWorkshop->actionsMgr();
+    if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) {
+      QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
+      QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations()));
+      aNestedActList << anAction;
+    }
+    if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
+      QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
+      QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
+      aNestedActList << anAction;
+    }
+    anAction = aSalomeConnector->addFeatureOfNested(theWchName.c_str(), aFeatureInfo,
+                                                    aNestedActList, false, true);
+    QAction* aMenuAction = aSalomeConnector->addFeature(theWchName.c_str(), aFeatureInfo,
+                                                    aUseSeparator, true, false);
+    myWorkshop->module()->actionCreated(aMenuAction);
+  }
+  else {
+    //Issue #650: in the SALOME mode the tooltip should be same as text
+    aFeatureInfo.toolTip = aFeatureInfo.text;
+    anAction = aSalomeConnector->addFeature(theWchName.c_str(), aFeatureInfo, aUseSeparator);
+  }
+#endif
+  return anAction;
+}
index 74bf04407e24190d75f761875723414830e04879..ac25c80ecacaf181dabfbdc6eae24676015b6b69 100755 (executable)
@@ -19,6 +19,8 @@ class XGUI_MenuWorkbench;
 class XGUI_Workshop;
 class Config_FeatureMessage;
 
+class QAction;
+
 /**
 * \ingroup GUI
 * A class for management of menu actions (features). The actions should be arranged like they are
@@ -33,6 +35,8 @@ class XGUI_MenuMgr : public Events_Listener
   XGUI_EXPORT XGUI_MenuMgr(XGUI_Workshop* theWorkshop);
   XGUI_EXPORT virtual ~XGUI_MenuMgr() {}
 
+  XGUI_EXPORT void createFeatureActions();
+
   /// Redefinition of Events_Listener method
   XGUI_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
 
@@ -43,7 +47,15 @@ protected:
   /// Finds or creates a workbench for the given name
   /// \param theWorkbenchName a name defined in XML
   /// \return an instance of workbench
-  std::shared_ptr<XGUI_MenuWorkbench> findWorkbench(std::string& theWorkbenchName);
+  std::shared_ptr<XGUI_MenuWorkbench> findWorkbench(const std::string& theWorkbenchName);
+
+  /// Creates a new action by the message
+  /// \param theMessage an XML information of the feature
+  /// \param theWchName a workbench name, will be used as menu/tool bar name
+  /// \param aUseSeparator boolean value if a separator should be added after the action
+  /// \return an action
+  QAction* buildAction(const std::shared_ptr<Config_FeatureMessage>& theMessage,
+                       const std::string& theWchName, const bool aUseSeparator) const;
 
 private:
   XGUI_Workshop* myWorkshop; /// the current workshop
index 7596878a1de0e6eab8fdc382b59c1a6cb0432538..b607f73277641fb5d01b4a9efb1d0c98affb4076 100644 (file)
@@ -35,24 +35,35 @@ class XGUI_EXPORT XGUI_SalomeConnector
   //! \param theIcon - icon
   //! \param isCheckable - is checkable or not
   //! \param theKeys - hot keys
+  //! \param isAddSeparator boolean flag about adding separator after the action
+  //! \param isMenuAction boolean flag about adding the action to application menu bar
+  //! \param isToolAction boolean flag about adding the action to application tool bar
   //! 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;
+                              const QKeySequence& theKeys, bool isCheckable, const bool isAddSeparator,
+                              bool isMenuAction = true, bool isToolAction = true) = 0;
 
   //! Creates a feature (command) in SALOME desktop
   //! \param theWBName - name of toolbar (workbench)
   //! \param theInfo - information about action (icon, text, etc)
+  //! \param isAddSeparator boolean flag about adding separator after the action
+  //! \param isMenuAction boolean flag about adding the action to application menu bar
+  //! \param isToolAction boolean flag about adding the action to application tool bar
   virtual QAction* addFeature(const QString& theWBName,
-                              const ActionInfo& theInfo) = 0;
+                              const ActionInfo& theInfo, const bool isAddSeparator,
+                              bool isMenuAction = true, bool isToolAction = true) = 0;
 
   //! Creates a feature (command) in SALOME desktop
   //! \param theWBName - name of toolbar (workbench)
   //! \param theInfo - information about action (icon, text, etc)
   //! \param theNestedActions a list of nested actions
+  //! \param isMenuAction boolean flag about adding the action to application menu bar
+  //! \param isToolAction boolean flag about adding the action to application tool bar
   virtual QAction* addFeatureOfNested(const QString& theWBName,
-                                    const ActionInfo& theInfo,
-                                    const QList<QAction*>& theNestedActions) = 0;
+                                      const ActionInfo& theInfo,
+                                      const QList<QAction*>& theNestedActions,
+                                      bool isMenuAction = true, bool isToolAction = true) = 0;
 
   //! Returns true if the feature action is a nested action, in other words,
   //! it is created by addFeatureOfNested().
@@ -85,6 +96,9 @@ class XGUI_EXPORT XGUI_SalomeConnector
   /// \param theToolBarTitle the toolbar name
   virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle ) = 0;
 
+  /// Creates menu/tool bar actions for loaded features stored in the menu manager
+  virtual void createFeatureActions() = 0;
+
   //! Returns desktop window of SALOME
   virtual QMainWindow* desktop() const = 0;
 
index d28a944b2a7a13526d3455314ab70fac1f21fe1c..b4a48cd09d43ee5aa3d0b594f50e891b25acabbd 100755 (executable)
@@ -1002,6 +1002,7 @@ bool XGUI_Workshop::createModule()
   //  myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
 
   myModule->createFeatures();
+  salomeConnector()->createFeatureActions();
   //myActionsMgr->update();
   return true;
 }