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>
24 #include <XGUI_SalomeConnector.h>
27 #include <ModuleBase_IModule.h>
33 XGUI_MenuMgr::XGUI_MenuMgr(XGUI_Workshop* theWorkshop)
34 : myWorkshop(theWorkshop)
36 Events_Loop* aLoop = Events_Loop::loop();
38 aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
41 void XGUI_MenuMgr::processEvent(const std::shared_ptr<Events_Message>& theMessage)
43 //A message to start feature creation received.
44 if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
45 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
46 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
47 if (!aFeatureMsg->isInternal()) {
48 addFeature(aFeatureMsg);
53 void XGUI_MenuMgr::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
57 qDebug() << "XGUI_WorkshopListener::addFeature: NULL message.";
62 ActionInfo aFeatureInfo;
63 aFeatureInfo.initFrom(theMessage);
65 QString aWchName = QString::fromStdString(theMessage->workbenchId());
66 QStringList aNestedFeatures =
67 QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
68 QList<QAction*> aNestedActList;
69 bool isColumnButton = !aNestedFeatures.isEmpty();
71 QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
72 XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
73 XGUI_ActionsMgr* anActionsMgr = myWorkshop->actionsMgr();
74 if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) {
75 QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
76 QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations()));
77 aNestedActList << anAction;
79 if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
80 QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
81 QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
82 aNestedActList << anAction;
87 XGUI_SalomeConnector* aSalomeConnector = myWorkshop->salomeConnector();
90 aAction = aSalomeConnector->addFeatureOfNested(aWchName, aFeatureInfo, aNestedActList);
92 //Issue #650: in the SALOME mode the tooltip should be same as text
93 aFeatureInfo.toolTip = aFeatureInfo.text;
94 aAction = aSalomeConnector->addFeature(aWchName, aFeatureInfo);
96 aSalomeConnector->setFeatureInfo(aFeatureInfo.id, theMessage);
98 myWorkshop->actionsMgr()->addCommand(aAction);
99 myWorkshop->module()->actionCreated(aAction);
101 //Find or create Workbench
102 AppElements_MainMenu* aMenuBar = myWorkshop->mainWindow()->menuObject();
103 AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
105 aPage = myWorkshop->addWorkbench(aWchName);
107 //Find or create Group
108 QString aGroupName = QString::fromStdString(theMessage->groupId());
109 AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
111 aGroup = aPage->addGroup(aGroupName);
113 // Check if hotkey sequence is already defined:
114 XGUI_ActionsMgr* anActionsMgr = myWorkshop->actionsMgr();
115 QKeySequence aHotKey = anActionsMgr->registerShortcut(aFeatureInfo.shortcut);
116 if(aHotKey != aFeatureInfo.shortcut) {
117 aFeatureInfo.shortcut = aHotKey;
119 AppElements_Command* aCommand = aGroup->addFeature(theMessage);
120 // Enrich created button with accept/abort buttons if necessary
121 AppElements_Button* aButton = aCommand->button();
122 if (aButton->isColumnButton()) {
123 aButton->setAdditionalButtons(aNestedActList);
125 myWorkshop->actionsMgr()->addCommand(aCommand);
126 myWorkshop->module()->actionCreated(aCommand);