From: nds Date: Wed, 13 Apr 2016 06:11:00 +0000 (+0300) Subject: Issue 1303 Re-ordering of Sketcher menus: separation of the current menu build functi... X-Git-Tag: V_2.3.0~236 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=88e8b404bd38608fe57b1720e94173b677612976;p=modules%2Fshaper.git Issue 1303 Re-ordering of Sketcher menus: separation of the current menu build functionality in XGUI_MenuMgr class. --- diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index b84f87ca7..26ba96f7a 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -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 index 000000000..e0bc02e2d --- /dev/null +++ b/src/XGUI/XGUI_MenuGroup.cpp @@ -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::XGUI_MenuGroup() +{ +} diff --git a/src/XGUI/XGUI_MenuGroup.h b/src/XGUI/XGUI_MenuGroup.h new file mode 100755 index 000000000..d4d08329e --- /dev/null +++ b/src/XGUI/XGUI_MenuGroup.h @@ -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 index 000000000..085797eb0 --- /dev/null +++ b/src/XGUI/XGUI_MenuMgr.cpp @@ -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 +#include +#include +#include + +#include +#include +#include + +#ifndef HAVE_SALOME +#include +#include +#include +#include +#include +#include +#endif + +#include + +#include +#include +#include + +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& theMessage) +{ + //A message to start feature creation received. + if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) { + std::shared_ptr aFeatureMsg = + std::dynamic_pointer_cast(theMessage); + if (!aFeatureMsg->isInternal()) { + addFeature(aFeatureMsg); + } + } +} + +void XGUI_MenuMgr::addFeature(const std::shared_ptr& 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 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 index 000000000..dc5ddfb9c --- /dev/null +++ b/src/XGUI/XGUI_MenuMgr.h @@ -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 + +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& theMessage); + +protected: + /// Process event "Add a feature" + void addFeature(const std::shared_ptr& 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 index 000000000..297d643e6 --- /dev/null +++ b/src/XGUI/XGUI_MenuWorkbench.cpp @@ -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::XGUI_MenuWorkbench() +{ +} diff --git a/src/XGUI/XGUI_MenuWorkbench.h b/src/XGUI/XGUI_MenuWorkbench.h new file mode 100755 index 000000000..11597bb17 --- /dev/null +++ b/src/XGUI/XGUI_MenuWorkbench.h @@ -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_ */ + diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 77727cacb..d28a944b2 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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, diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 2c3946be5..edf22c262 100755 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -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; diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index ff6e73792..e4d13e93b 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -12,12 +12,7 @@ #include "XGUI_QtEvents.h" #ifndef HAVE_SALOME -#include -#include -#include #include -#include -#include #endif #include @@ -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& return; } - //A message to start feature creation received. - if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) { - std::shared_ptr aFeatureMsg = - std::dynamic_pointer_cast(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 aUpdMsg = std::dynamic_pointer_cast(theMessage); onFeatureCreatedMsg(aUpdMsg); @@ -467,85 +453,6 @@ bool XGUI_WorkshopListener::event(QEvent * theEvent) return false; } -void XGUI_WorkshopListener::addFeature(const std::shared_ptr& 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 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) { diff --git a/src/XGUI/XGUI_WorkshopListener.h b/src/XGUI/XGUI_WorkshopListener.h index 49199f225..2567daffb 100755 --- a/src/XGUI/XGUI_WorkshopListener.h +++ b/src/XGUI/XGUI_WorkshopListener.h @@ -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&); - /// Process feature update message void onFeatureUpdatedMsg(const std::shared_ptr& );