]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue 1303 Re-ordering of Sketcher menus: separation of the current menu build functi...
authornds <nds@opencascade.com>
Wed, 13 Apr 2016 06:11:00 +0000 (09:11 +0300)
committernds <nds@opencascade.com>
Wed, 13 Apr 2016 06:11:00 +0000 (09:11 +0300)
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_MenuGroup.cpp [new file with mode: 0755]
src/XGUI/XGUI_MenuGroup.h [new file with mode: 0755]
src/XGUI/XGUI_MenuMgr.cpp [new file with mode: 0755]
src/XGUI/XGUI_MenuMgr.h [new file with mode: 0755]
src/XGUI/XGUI_MenuWorkbench.cpp [new file with mode: 0755]
src/XGUI/XGUI_MenuWorkbench.h [new file with mode: 0755]
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h
src/XGUI/XGUI_WorkshopListener.cpp
src/XGUI/XGUI_WorkshopListener.h

index b84f87ca7145ecc9f7a0c38cfc25cf61923a02bf..26ba96f7a11fe1e0ac85c9219dc6541a4d56b177 100644 (file)
@@ -14,6 +14,9 @@ SET(PROJECT_HEADERS
        XGUI_ErrorDialog.h
        XGUI_ErrorMgr.h
        XGUI_HistoryMenu.h
+       XGUI_MenuGroup.h
+       XGUI_MenuMgr.h
+       XGUI_MenuWorkbench.h
        XGUI_ModuleConnector.h
        XGUI_ObjectsBrowser.h
        XGUI_OperationMgr.h
@@ -42,6 +45,9 @@ SET(PROJECT_SOURCES
        XGUI_ErrorDialog.cpp
        XGUI_ErrorMgr.cpp
        XGUI_HistoryMenu.cpp
+       XGUI_MenuGroup.cpp
+       XGUI_MenuMgr.cpp
+       XGUI_MenuWorkbench.cpp
        XGUI_ModuleConnector.cpp
        XGUI_ObjectsBrowser.cpp
        XGUI_OperationMgr.cpp
diff --git a/src/XGUI/XGUI_MenuGroup.cpp b/src/XGUI/XGUI_MenuGroup.cpp
new file mode 100755 (executable)
index 0000000..e0bc02e
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        XGUI_MenuGroup.cpp
+// Created:     13 Apr 2016
+// Author:      Natalia ERMOLAEVA
+
+#include <XGUI_MenuGroup.h>
+
+XGUI_MenuGroup::XGUI_MenuGroup()
+{
+}
diff --git a/src/XGUI/XGUI_MenuGroup.h b/src/XGUI/XGUI_MenuGroup.h
new file mode 100755 (executable)
index 0000000..d4d0832
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        XGUI_MenuGroup.hxx
+// Created:     13 Apr 2016
+// Author:      Natalia ERMOLAEVA
+
+#ifndef XGUI_MENUGROUP_H_
+#define XGUI_MENUGROUP_H_
+
+#include "XGUI.h"
+
+/**
+* \ingroup GUI
+* A class for management of menu actions (features). The actions should be arranged like they are
+* in XML file. It listens the read feature of XML and fills internal structure of menu workbenches
+* and groups of feature. After, it creates menues and tools in the module.
+*/
+class XGUI_EXPORT XGUI_MenuGroup
+{
+ public:
+  /// Constructor
+  XGUI_MenuGroup();
+  virtual ~XGUI_MenuGroup() {}
+};
+
+#endif /* XGUI_MENUGROUP_H_ */
+
diff --git a/src/XGUI/XGUI_MenuMgr.cpp b/src/XGUI/XGUI_MenuMgr.cpp
new file mode 100755 (executable)
index 0000000..085797e
--- /dev/null
@@ -0,0 +1,126 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        XGUI_MenuMgr.cpp
+// Created:     13 Apr 2016
+// Author:      Natalia ERMOLAEVA
+
+#include <XGUI_MenuMgr.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_ActionsMgr.h>
+#include <XGUI_OperationMgr.h>
+
+#include <Events_Loop.h>
+#include <Config_FeatureMessage.h>
+#include <Config_Keywords.h>
+
+#ifndef HAVE_SALOME
+#include <AppElements_Workbench.h>
+#include <AppElements_Command.h>
+#include <AppElements_MainMenu.h>
+#include <AppElements_MainWindow.h>
+#include <AppElements_MenuGroupPanel.h>
+#include <AppElements_Button.h>
+#endif
+
+#include <ModuleBase_IModule.h>
+
+#include <QObject>
+#include <QAction>
+#include <QDebug>
+
+XGUI_MenuMgr::XGUI_MenuMgr(XGUI_Workshop* theWorkshop)
+: myWorkshop(theWorkshop)
+{
+  Events_Loop* aLoop = Events_Loop::loop();
+
+  aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
+}
+
+void XGUI_MenuMgr::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+  //A message to start feature creation received.
+  if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
+    std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
+       std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
+    if (!aFeatureMsg->isInternal()) {
+      addFeature(aFeatureMsg);
+    }
+  }
+}
+
+void XGUI_MenuMgr::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
+{
+  if (!theMessage) {
+#ifdef _DEBUG
+    qDebug() << "XGUI_WorkshopListener::addFeature: NULL message.";
+#endif
+    return;
+  }
+
+  ActionInfo aFeatureInfo;
+  aFeatureInfo.initFrom(theMessage);
+
+  QString aWchName = QString::fromStdString(theMessage->workbenchId());
+  QStringList aNestedFeatures =
+      QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
+  QList<QAction*> aNestedActList;
+  bool isColumnButton = !aNestedFeatures.isEmpty();
+  if (isColumnButton) {
+    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;
+    }
+  }
+
+#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);
+  if (!aPage) {
+    aPage = myWorkshop->addWorkbench(aWchName);
+  }
+  //Find or create Group
+  QString aGroupName = QString::fromStdString(theMessage->groupId());
+  AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
+  if (!aGroup) {
+    aGroup = aPage->addGroup(aGroupName);
+  }
+  // Check if hotkey sequence is already defined:
+  XGUI_ActionsMgr* anActionsMgr = myWorkshop->actionsMgr();
+  QKeySequence aHotKey = anActionsMgr->registerShortcut(aFeatureInfo.shortcut);
+  if(aHotKey != aFeatureInfo.shortcut) {
+    aFeatureInfo.shortcut = aHotKey;
+  }
+  AppElements_Command* aCommand = aGroup->addFeature(theMessage);
+  // Enrich created button with accept/abort buttons if necessary
+  AppElements_Button* aButton = aCommand->button();
+  if (aButton->isColumnButton()) {
+    aButton->setAdditionalButtons(aNestedActList);
+  }
+  myWorkshop->actionsMgr()->addCommand(aCommand);
+  myWorkshop->module()->actionCreated(aCommand);
+#endif
+}
diff --git a/src/XGUI/XGUI_MenuMgr.h b/src/XGUI/XGUI_MenuMgr.h
new file mode 100755 (executable)
index 0000000..dc5ddfb
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        XGUI_MenuMgr.hxx
+// Created:     13 Apr 2016
+// Author:      Natalia ERMOLAEVA
+
+#ifndef XGUI_MENUMGR_H_
+#define XGUI_MENUMGR_H_
+
+#include "XGUI.h"
+
+#include <Events_Listener.h>
+
+class XGUI_Workshop;
+class Config_FeatureMessage;
+
+/**
+* \ingroup GUI
+* A class for management of menu actions (features). The actions should be arranged like they are
+* in XML file. It listens the read feature of XML and fills internal structure of menu workbenches
+* and groups of feature. After, it creates menues and tools in the module.
+*/
+class XGUI_EXPORT XGUI_MenuMgr : public Events_Listener
+{
+ public:
+  /// Constructor
+  /// \param the current workshop
+  XGUI_MenuMgr(XGUI_Workshop* theWorkshop);
+  virtual ~XGUI_MenuMgr() {}
+
+  //! Redefinition of Events_Listener method
+  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+
+protected:
+  /// Process event "Add a feature"
+  void addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage);
+
+private:
+  XGUI_Workshop* myWorkshop; /// the current workshop
+};
+
+#endif /* XGUI_MENUMGR_H_ */
diff --git a/src/XGUI/XGUI_MenuWorkbench.cpp b/src/XGUI/XGUI_MenuWorkbench.cpp
new file mode 100755 (executable)
index 0000000..297d643
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        XGUI_MenuWorkbench.cpp
+// Created:     13 Apr 2016
+// Author:      Natalia ERMOLAEVA
+
+#include <XGUI_MenuWorkbench.h>
+
+XGUI_MenuWorkbench::XGUI_MenuWorkbench()
+{
+}
diff --git a/src/XGUI/XGUI_MenuWorkbench.h b/src/XGUI/XGUI_MenuWorkbench.h
new file mode 100755 (executable)
index 0000000..11597bb
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        XGUI_MenuWorkbench.hxx
+// Created:     13 Apr 2016
+// Author:      Natalia ERMOLAEVA
+
+#ifndef XGUI_MENUWORKBENCH_H_
+#define XGUI_MENUWORKBENCH_H_
+
+#include "XGUI.h"
+
+/**
+* \ingroup GUI
+* A class for management of menu actions (features). The actions should be arranged like they are
+* in XML file. It listens the read feature of XML and fills internal structure of menu workbenches
+* and groups of feature. After, it creates menues and tools in the module.
+*/
+class XGUI_EXPORT XGUI_MenuWorkbench
+{
+ public:
+  /// Constructor
+  XGUI_MenuWorkbench();
+  /// Destructor
+  virtual ~XGUI_MenuWorkbench() {}
+};
+
+#endif /* XGUI_MENUWORKBENCH_H_ */
+
index 77727cacbf8be40d4394644e6eb3adeb9da0d82e..d28a944b2a7a13526d3455314ab70fac1f21fe1c 100755 (executable)
@@ -4,6 +4,7 @@
 #include "XGUI_Workshop.h"
 
 #include "XGUI_ActionsMgr.h"
+#include "XGUI_MenuMgr.h"
 #include "XGUI_ColorDialog.h"
 #include "XGUI_ContextMenuMgr.h"
 #include "XGUI_Displayer.h"
@@ -141,6 +142,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
 
   myOperationMgr = new XGUI_OperationMgr(this, 0);
   myActionsMgr = new XGUI_ActionsMgr(this);
+  myMenuMgr = new XGUI_MenuMgr(this);
   myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
   myContextMenuMgr = new XGUI_ContextMenuMgr(this);
   connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
index 2c3946be59f2e62b93760f9a7c37a1082ae3f164..edf22c262b2130362ce5034dc673a4397269464a 100755 (executable)
@@ -27,6 +27,7 @@ class XGUI_ContextMenuMgr;
 class XGUI_Displayer;
 class XGUI_ErrorDialog;
 class XGUI_ErrorMgr;
+class XGUI_MenuMgr;
 class XGUI_ModuleConnector;
 class XGUI_ObjectsBrowser;
 class XGUI_OperationMgr;
@@ -112,6 +113,12 @@ Q_OBJECT
     return myActionsMgr;
   }
 
+  //! ! Returns an actions manager
+  XGUI_MenuMgr* menuMgr() const
+  {
+    return myMenuMgr;
+  }
+
   //! Returns property panel widget
   XGUI_PropertyPanel* propertyPanel() const
   {
@@ -514,6 +521,7 @@ private:
   XGUI_Displayer* myDisplayer;
   XGUI_OperationMgr* myOperationMgr;  ///< manager to manipulate through the operations
   XGUI_ActionsMgr* myActionsMgr;
+  XGUI_MenuMgr* myMenuMgr; ///< manager to build menu/tool bar using order defined in XML
   XGUI_SalomeConnector* mySalomeConnector;
   XGUI_ErrorDialog* myErrorDlg;
   XGUI_ViewerProxy* myViewerProxy;
index ff6e7379237f654684276d117f700138130889b1..e4d13e93b7e2fd1fdca47abea431acaff7516706 100755 (executable)
 #include "XGUI_QtEvents.h"
 
 #ifndef HAVE_SALOME
-#include <AppElements_Workbench.h>
-#include <AppElements_Command.h>
-#include <AppElements_MainMenu.h>
 #include <AppElements_MainWindow.h>
-#include <AppElements_MenuGroupPanel.h>
-#include <AppElements_Button.h>
 #endif
 
 #include <ModuleBase_IModule.h>
@@ -88,7 +83,6 @@ void XGUI_WorkshopListener::initializeEventListening()
   //Initialize event listening
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->registerListener(this, Events_Error::errorID());  //!< Listening application errors.
-  aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
@@ -115,16 +109,8 @@ void XGUI_WorkshopListener::processEvent(const std::shared_ptr<Events_Message>&
     return;
   }
 
-  //A message to start feature creation received.
-  if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
-    std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
-       std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
-    if (!aFeatureMsg->isInternal()) {
-      addFeature(aFeatureMsg);
-    }
-  }
   // Process creation of Part
-  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
+  if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
     onFeatureCreatedMsg(aUpdMsg);
@@ -467,85 +453,6 @@ bool XGUI_WorkshopListener::event(QEvent * theEvent)
   return false;
 }
 
-void XGUI_WorkshopListener::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
-{
-  if (!theMessage) {
-#ifdef _DEBUG
-    qDebug() << "XGUI_WorkshopListener::addFeature: NULL message.";
-#endif
-    return;
-  }
-  ActionInfo aFeatureInfo;
-  aFeatureInfo.initFrom(theMessage);
-
-  XGUI_Workshop* aWorkshop = workshop();
-
-  QString aWchName = QString::fromStdString(theMessage->workbenchId());
-  QStringList aNestedFeatures =
-      QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
-  QList<QAction*> aNestedActList;
-  bool isColumnButton = !aNestedFeatures.isEmpty();
-  if (isColumnButton) {
-    QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
-    XGUI_OperationMgr* anOperationMgr = aWorkshop->operationMgr();
-    XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
-    if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) {
-      QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
-      connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations()));
-      aNestedActList << anAction;
-    }
-    if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
-      QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
-      connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
-      aNestedActList << anAction;
-    }
-  }
-
-#ifdef HAVE_SALOME
-  XGUI_SalomeConnector* aSalomeConnector = aWorkshop->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);
-
-  aWorkshop->actionsMgr()->addCommand(aAction);
-  aWorkshop->module()->actionCreated(aAction);
-#else 
-  //Find or create Workbench
-  AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
-  AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
-  if (!aPage) {
-    aPage = aWorkshop->addWorkbench(aWchName);
-  }
-  //Find or create Group
-  QString aGroupName = QString::fromStdString(theMessage->groupId());
-  AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
-  if (!aGroup) {
-    aGroup = aPage->addGroup(aGroupName);
-  }
-  // Check if hotkey sequence is already defined:
-  XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
-  QKeySequence aHotKey = anActionsMgr->registerShortcut(aFeatureInfo.shortcut);
-  if(aHotKey != aFeatureInfo.shortcut) {
-    aFeatureInfo.shortcut = aHotKey;
-  }
-  AppElements_Command* aCommand = aGroup->addFeature(theMessage);
-  // Enrich created button with accept/abort buttons if necessary
-  AppElements_Button* aButton = aCommand->button();
-  if (aButton->isColumnButton()) {
-    aButton->setAdditionalButtons(aNestedActList);
-  }
-  aWorkshop->actionsMgr()->addCommand(aCommand);
-  aWorkshop->module()->actionCreated(aCommand);
-#endif
-}
-
-
 //**************************************************************
 bool XGUI_WorkshopListener::displayObject(ObjectPtr theObj, bool& theFirstVisualizedBody)
 {
index 49199f22512379576bead7d152a36e76f726a0ee..2567daffbd7d60875dbc580926a562a86e97b374 100755 (executable)
@@ -47,9 +47,6 @@ protected:
   /// Procedure to process postponed events
   bool event(QEvent * theEvent);
 
-   /// Process event "Add a feature"
-  void addFeature(const std::shared_ptr<Config_FeatureMessage>&);
-
   /// Process feature update message
   void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );