1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: XGUI_MenuMgr.cpp
4 // Created: 13 Apr 2016
5 // Author: Natalia ERMOLAEVA
7 #include <XGUI_MenuMgr.h>
8 #include <XGUI_Workshop.h>
9 #include <XGUI_ActionsMgr.h>
10 #include <XGUI_OperationMgr.h>
12 #include <Events_Loop.h>
13 #include <Config_FeatureMessage.h>
14 #include <Config_Keywords.h>
17 #include <AppElements_Workbench.h>
18 #include <AppElements_Command.h>
19 #include <AppElements_MainMenu.h>
20 #include <AppElements_MainWindow.h>
21 #include <AppElements_MenuGroupPanel.h>
22 #include <AppElements_Button.h>
25 #include <ModuleBase_IModule.h>
31 XGUI_MenuMgr::XGUI_MenuMgr(XGUI_Workshop* theWorkshop)
32 : myWorkshop(theWorkshop)
34 Events_Loop* aLoop = Events_Loop::loop();
36 aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
39 void XGUI_MenuMgr::processEvent(const std::shared_ptr<Events_Message>& theMessage)
41 //A message to start feature creation received.
42 if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
43 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
44 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
45 if (!aFeatureMsg->isInternal()) {
46 addFeature(aFeatureMsg);
51 void XGUI_MenuMgr::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
55 qDebug() << "XGUI_WorkshopListener::addFeature: NULL message.";
60 ActionInfo aFeatureInfo;
61 aFeatureInfo.initFrom(theMessage);
63 QString aWchName = QString::fromStdString(theMessage->workbenchId());
64 QStringList aNestedFeatures =
65 QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
66 QList<QAction*> aNestedActList;
67 bool isColumnButton = !aNestedFeatures.isEmpty();
69 QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
70 XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
71 XGUI_ActionsMgr* anActionsMgr = myWorkshop->actionsMgr();
72 if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) {
73 QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
74 QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations()));
75 aNestedActList << anAction;
77 if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
78 QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
79 QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
80 aNestedActList << anAction;
85 XGUI_SalomeConnector* aSalomeConnector = myWorkshop->salomeConnector();
88 aAction = aSalomeConnector->addFeatureOfNested(aWchName, aFeatureInfo, aNestedActList);
90 //Issue #650: in the SALOME mode the tooltip should be same as text
91 aFeatureInfo.toolTip = aFeatureInfo.text;
92 aAction = aSalomeConnector->addFeature(aWchName, aFeatureInfo);
94 aSalomeConnector->setFeatureInfo(aFeatureInfo.id, theMessage);
96 myWorkshop->actionsMgr()->addCommand(aAction);
97 myWorkshop->module()->actionCreated(aAction);
99 //Find or create Workbench
100 AppElements_MainMenu* aMenuBar = myWorkshop->mainWindow()->menuObject();
101 AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
103 aPage = myWorkshop->addWorkbench(aWchName);
105 //Find or create Group
106 QString aGroupName = QString::fromStdString(theMessage->groupId());
107 AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
109 aGroup = aPage->addGroup(aGroupName);
111 // Check if hotkey sequence is already defined:
112 XGUI_ActionsMgr* anActionsMgr = myWorkshop->actionsMgr();
113 QKeySequence aHotKey = anActionsMgr->registerShortcut(aFeatureInfo.shortcut);
114 if(aHotKey != aFeatureInfo.shortcut) {
115 aFeatureInfo.shortcut = aHotKey;
117 AppElements_Command* aCommand = aGroup->addFeature(theMessage);
118 // Enrich created button with accept/abort buttons if necessary
119 AppElements_Button* aButton = aCommand->button();
120 if (aButton->isColumnButton()) {
121 aButton->setAdditionalButtons(aNestedActList);
123 myWorkshop->actionsMgr()->addCommand(aCommand);
124 myWorkshop->module()->actionCreated(aCommand);