1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #include "XGUI_ContextMenuMgr.h"
4 #include "XGUI_Workshop.h"
5 #include "XGUI_ObjectsBrowser.h"
6 #include "XGUI_SelectionMgr.h"
7 #include "XGUI_Displayer.h"
8 #include "XGUI_ViewerProxy.h"
9 #include "XGUI_Selection.h"
10 #include "XGUI_SalomeConnector.h"
11 #include "XGUI_DataModel.h"
12 #include "XGUI_OperationMgr.h"
13 #include "XGUI_Tools.h"
14 #include "XGUI_ActionsMgr.h"
17 #include <AppElements_MainWindow.h>
20 //#include "PartSetPlugin_Part.h"
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_AttributeDocRef.h>
24 #include <ModelAPI_Object.h>
25 #include <ModelAPI_Session.h>
26 #include <ModelAPI_ResultGroup.h>
27 #include <ModelAPI_ResultParameter.h>
28 #include <ModelAPI_ResultConstruction.h>
29 #include <ModelAPI_ResultBody.h>
30 #include <ModelAPI_Tools.h>
32 #include <Config_DataModelReader.h>
34 #include <ModuleBase_IModule.h>
35 #include <ModuleBase_Tools.h>
36 #include <ModuleBase_OperationAction.h>
37 #include <ModuleBase_ViewerPrs.h>
40 #include <QActionGroup>
41 #include <QContextMenuEvent>
44 #include <QMainWindow>
45 #include <QModelIndex>
48 XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
50 myWorkshop(theParent),
55 XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr()
59 void XGUI_ContextMenuMgr::createActions()
62 QMainWindow* aDesktop = myWorkshop->salomeConnector()->desktop();
64 QMainWindow* aDesktop = myWorkshop->mainWindow();
67 QAction* aAction = ModuleBase_Tools::createAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
68 aDesktop->addAction(aAction);
70 addAction("DELETE_CMD", aAction);
71 aAction->setShortcutContext(Qt::ApplicationShortcut);
73 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/rename_edit.png"), tr("Rename"), this,
74 this, SLOT(onRename()));
75 addAction("RENAME_CMD", aAction);
77 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move.png"),
78 XGUI_Workshop::MOVE_TO_END_COMMAND, this);
79 addAction("MOVE_CMD", aAction);
81 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/clean_history.png"), tr("Clean history"), this);
82 addAction("CLEAN_HISTORY_CMD", aAction);
84 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), this);
85 addAction("COLOR_CMD", aAction);
87 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), this);
88 addAction("SHOW_CMD", aAction);
90 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show only"), this);
91 addAction("SHOW_ONLY_CMD", aAction);
93 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"), this);
94 addAction("HIDE_CMD", aAction);
96 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide all"), this);
97 addAction("HIDEALL_CMD", aAction);
99 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"), tr("Shading"), this);
100 addAction("SHADING_CMD", aAction);
102 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"), this);
103 addAction("WIREFRAME_CMD", aAction);
105 mySeparator = ModuleBase_Tools::createAction(QIcon(), "", this);
106 mySeparator->setSeparator(true);
108 //mySelectActions = new QActionGroup(this);
109 //mySelectActions->setExclusive(true);
111 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), this,
112 this, SLOT(onShapeSelection(bool)));
113 aAction->setCheckable(true);
114 addAction("SELECT_VERTEX_CMD", aAction);
115 //mySelectActions->addAction(aAction);
117 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), this,
118 this, SLOT(onShapeSelection(bool)));
119 aAction->setCheckable(true);
120 addAction("SELECT_EDGE_CMD", aAction);
121 //mySelectActions->addAction(aAction);
123 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), this,
124 this, SLOT(onShapeSelection(bool)));
125 aAction->setCheckable(true);
126 addAction("SELECT_FACE_CMD", aAction);
127 //mySelectActions->addAction(aAction);
129 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Result"), this,
130 this, SLOT(onResultSelection(bool)));
131 aAction->setCheckable(true);
132 addAction("SELECT_RESULT_CMD", aAction);
133 //mySelectActions->addAction(aAction);
135 aAction->setChecked(true);
137 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
138 tr("Select results"), this);
139 addAction("SHOW_RESULTS_CMD", aAction);
141 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
142 tr("Select parent feature"), this);
143 addAction("SHOW_FEATURE_CMD", aAction);
145 buildObjBrowserMenu();
149 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
151 if (myActions.contains(theId))
152 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
153 theAction->setData(theId);
154 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
155 myActions[theId] = theAction;
158 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
160 if (myActions.contains(theId))
161 return myActions[theId];
165 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
167 foreach(QAction* eachAction, myActions) {
168 if (eachAction->text() == theName) {
175 QStringList XGUI_ContextMenuMgr::actionIds() const
177 return myActions.keys();
180 void XGUI_ContextMenuMgr::onAction(bool isChecked)
182 QAction* aAction = static_cast<QAction*>(sender());
183 emit actionTriggered(aAction->data().toString(), isChecked);
186 void XGUI_ContextMenuMgr::updateCommandsStatus()
190 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
192 QMenu* aMenu = new QMenu();
193 if (sender() == myWorkshop->objectBrowser()) {
194 updateObjectBrowserMenu();
195 addObjBrowserMenu(aMenu);
196 } else if (sender() == myWorkshop->viewer()) {
198 addViewerMenu(aMenu);
201 if (aMenu && (aMenu->actions().size() > 0)) {
202 // it is possible that some objects should do something before and after the popup menu exec
203 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
205 emit beforeContextMenu();
206 aMenu->exec(theEvent->globalPos());
207 emit afterContextMenu();
212 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
214 foreach(QAction* aAction, myActions)
215 aAction->setEnabled(false);
217 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
218 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
219 int aSelected = aObjects.size();
221 SessionPtr aMgr = ModelAPI_Session::get();
222 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
223 bool hasResult = false;
224 bool hasFeature = false;
225 bool hasParameter = false;
226 bool hasCompositeOwner = false;
227 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
230 if (aSelected == 1) {
231 ObjectPtr aObject = aObjects.first();
233 if (hasResult && myWorkshop->canBeShaded(aObject)) {
234 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
235 if (aMode != XGUI_Displayer::NoMode) {
236 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
237 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
239 action("WIREFRAME_CMD")->setEnabled(true);
240 action("SHADING_CMD")->setEnabled(true);
244 bool aHasSubResults = ModelAPI_Tools::hasSubResults(
245 std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
246 if (aHasSubResults) {
247 action("HIDE_CMD")->setEnabled(true);
248 action("SHOW_CMD")->setEnabled(true);
251 if (aObject->isDisplayed()) {
252 action("HIDE_CMD")->setEnabled(true);
253 } else if (hasResult && (!hasParameter)) {
254 action("SHOW_CMD")->setEnabled(true);
257 if (!(hasParameter || hasFeature))
258 action("SHOW_ONLY_CMD")->setEnabled(true);
260 else if (hasFeature && myWorkshop->canMoveFeature())
261 action("MOVE_CMD")->setEnabled(true);
263 if( aMgr->activeDocument() == aObject->document() )
265 action("RENAME_CMD")->setEnabled(true);
266 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
267 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
268 (hasFeature || hasParameter));
272 // parameter is commented because the actions are not in the list of result parameter actions
273 if (hasResult /*&& (!hasParameter)*/) {
274 action("SHOW_CMD")->setEnabled(true);
275 action("HIDE_CMD")->setEnabled(true);
276 action("SHOW_ONLY_CMD")->setEnabled(true);
277 action("SHADING_CMD")->setEnabled(true);
278 action("WIREFRAME_CMD")->setEnabled(true);
281 bool allActive = true;
282 foreach( ObjectPtr aObject, aObjects )
283 if( aMgr->activeDocument() != aObject->document() ) {
287 if (!hasCompositeOwner && allActive ) {
288 if (hasFeature || hasParameter)
289 action("DELETE_CMD")->setEnabled(true);
291 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
292 action("CLEAN_HISTORY_CMD")->setEnabled(true);
294 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
295 action("SHOW_FEATURE_CMD")->setEnabled(hasResult);
298 // Show/Hide command has to be disabled for objects from non active document
299 bool aDeactivate = false;
300 foreach (ObjectPtr aObj, aObjects) {
301 if (!aObj->document()->isActive()) {
302 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
303 aObj->groupName() == ModelAPI_ResultPart::group()) {
310 // If at leas a one objec can not be edited then Show/Hide has to be disabled
311 action("SHOW_CMD")->setEnabled(false);
312 action("HIDE_CMD")->setEnabled(false);
313 action("SHOW_ONLY_CMD")->setEnabled(false);
316 if (myWorkshop->canChangeColor())
317 action("COLOR_CMD")->setEnabled(true);
319 ModuleBase_IModule* aModule = myWorkshop->module();
321 aModule->updateObjectBrowserMenu(myActions);
324 void XGUI_ContextMenuMgr::updateViewerMenu()
326 foreach(QAction* aAction, myActions)
327 aAction->setEnabled(false);
329 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
330 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
331 QList<ModuleBase_ViewerPrsPtr> aPrsList = aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
332 if (aPrsList.size() > 0) {
333 bool isVisible = false;
334 bool isShading = false;
335 bool canBeShaded = false;
337 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
338 aObject = aPrs->object();
339 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
340 if (aRes && aRes->isDisplayed()) {
342 canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
343 isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
349 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
350 if (aMode != XGUI_Displayer::NoMode) {
351 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
352 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
354 action("WIREFRAME_CMD")->setEnabled(true);
355 action("SHADING_CMD")->setEnabled(true);
358 action("SHOW_ONLY_CMD")->setEnabled(true);
359 action("HIDE_CMD")->setEnabled(true);
361 action("SHOW_CMD")->setEnabled(true);
363 if (myWorkshop->displayer()->objectsCount() > 0)
364 action("HIDEALL_CMD")->setEnabled(true);
366 // Update selection menu
367 QIntList aModes = aDisplayer->activeSelectionModes();
368 action("SELECT_VERTEX_CMD")->setEnabled(true);
369 action("SELECT_EDGE_CMD")->setEnabled(true);
370 action("SELECT_FACE_CMD")->setEnabled(true);
371 action("SELECT_RESULT_CMD")->setEnabled(true);
373 action("SELECT_RESULT_CMD")->setChecked(false);
374 action("SELECT_VERTEX_CMD")->setChecked(false);
375 action("SELECT_EDGE_CMD")->setChecked(false);
376 action("SELECT_FACE_CMD")->setChecked(false);
377 action("SELECT_RESULT_CMD")->setChecked(false);
378 if (aModes.count() == 0) {
379 action("SELECT_RESULT_CMD")->setChecked(true);
381 foreach(int aMode, aModes) {
384 action("SELECT_VERTEX_CMD")->setChecked(true);
387 action("SELECT_EDGE_CMD")->setChecked(true);
390 action("SELECT_FACE_CMD")->setChecked(true);
393 action("SELECT_RESULT_CMD")->setChecked(true);
398 ModuleBase_IModule* aModule = myWorkshop->module();
400 aModule->updateViewerMenu(myActions);
402 if (myWorkshop->canChangeColor())
403 action("COLOR_CMD")->setEnabled(true);
405 action("DELETE_CMD")->setEnabled(true);
408 void XGUI_ContextMenuMgr::connectObjectBrowser()
410 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
411 SLOT(onContextMenuRequest(QContextMenuEvent*)));
414 void XGUI_ContextMenuMgr::connectViewer()
416 connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
417 SLOT(onContextMenuRequest(QContextMenuEvent*)));
421 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
423 QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", this);
424 aSeparator->setSeparator(true);
428 // Result construction menu
429 aList.append(action("SHOW_CMD"));
430 aList.append(action("HIDE_CMD"));
431 aList.append(action("SHOW_ONLY_CMD"));
432 aList.append(mySeparator);
433 aList.append(action("RENAME_CMD"));
434 aList.append(action("COLOR_CMD"));
435 aList.append(action("SHOW_FEATURE_CMD"));
436 myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
438 //-------------------------------------
441 aList.append(action("WIREFRAME_CMD"));
442 aList.append(action("SHADING_CMD"));
443 aList.append(mySeparator); // this separator is not shown as this action is added after show only
444 // qt list container contains only one instance of the same action
445 aList.append(action("SHOW_CMD"));
446 aList.append(action("HIDE_CMD"));
447 aList.append(action("SHOW_ONLY_CMD"));
448 aList.append(mySeparator);
449 aList.append(action("RENAME_CMD"));
450 aList.append(action("COLOR_CMD"));
451 aList.append(action("SHOW_FEATURE_CMD"));
452 myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
454 myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
456 myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
457 //-------------------------------------
460 aList.append(action("RENAME_CMD"));
461 aList.append(action("SHOW_RESULTS_CMD"));
462 aList.append(action("MOVE_CMD"));
463 aList.append(mySeparator);
464 aList.append(action("CLEAN_HISTORY_CMD"));
465 aList.append(action("DELETE_CMD"));
466 myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
469 aList.append(action("RENAME_CMD"));
470 aList.append(mySeparator);
471 aList.append(action("CLEAN_HISTORY_CMD"));
472 aList.append(action("DELETE_CMD"));
473 myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
474 //-------------------------------------
477 void XGUI_ContextMenuMgr::buildViewerMenu()
480 // Result construction menu
481 aList.append(action("HIDE_CMD"));
482 aList.append(action("SHOW_ONLY_CMD"));
483 aList.append(mySeparator);
484 aList.append(action("COLOR_CMD"));
485 myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
487 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
488 //-------------------------------------
491 aList.append(action("WIREFRAME_CMD"));
492 aList.append(action("SHADING_CMD"));
493 aList.append(mySeparator);
494 aList.append(action("HIDE_CMD"));
495 aList.append(action("SHOW_ONLY_CMD"));
496 aList.append(mySeparator);
497 aList.append(action("COLOR_CMD"));
498 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
500 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
501 //-------------------------------------
505 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
507 ModuleBase_IModule* aModule = myWorkshop->module();
509 theMenu->addSeparator();
510 aModule->addObjectBrowserMenu(theMenu);
513 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
514 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
515 int aSelected = aObjects.size();
516 QActionsList aActions;
517 if (aSelected == 1) {
518 ObjectPtr aObject = aObjects.first();
519 std::string aName = aObject->groupName();
520 if (myObjBrowserMenus.contains(aName))
521 aActions = myObjBrowserMenus[aName];
522 } else if (aSelected > 1) {
523 aActions.append(action("WIREFRAME_CMD"));
524 aActions.append(action("SHADING_CMD"));
525 aActions.append(mySeparator);
526 aActions.append(action("SHOW_CMD"));
527 aActions.append(action("HIDE_CMD"));
528 aActions.append(action("SHOW_ONLY_CMD"));
529 aActions.append(mySeparator);
530 //aActions.append(action("MOVE_CMD"));
531 aActions.append(action("COLOR_CMD"));
532 aActions.append(action("CLEAN_HISTORY_CMD"));
533 aActions.append(action("DELETE_CMD"));
535 theMenu->addActions(aActions);
536 addFeatures(theMenu);
538 // It is commented out because Object Browser does not have actions
539 //theMenu->addSeparator();
540 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
543 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
545 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
546 QList<ModuleBase_ViewerPrsPtr> aPrsList = aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
547 int aSelected = aPrsList.size();
548 QActionsList aActions;
550 // Create selection menu
551 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
553 myWorkshop->module()->activeSelectionModes(aModes);
554 if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
555 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
556 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
557 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
558 aSelMenu->addAction(action("SELECT_FACE_CMD"));
559 aSelMenu->addSeparator();
560 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
561 theMenu->addMenu(aSelMenu);
562 theMenu->addSeparator();
564 if (aSelected == 1) {
565 ObjectPtr aObject = aPrsList.first()->object();
566 if (aObject.get() != NULL) {
567 std::string aName = aObject->groupName();
568 if (myViewerMenu.contains(aName))
569 aActions = myViewerMenu[aName];
571 } else if (aSelected > 1) {
572 aActions.append(action("HIDE_CMD"));
574 // hide all is shown always even if selection in the viewer is empty
575 aActions.append(action("HIDEALL_CMD"));
576 aActions.append(action("COLOR_CMD"));
578 theMenu->addActions(aActions);
580 QMap<int, QAction*> aMenuActions;
581 ModuleBase_IModule* aModule = myWorkshop->module();
583 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
584 theMenu->addSeparator();
587 // insert the module menu items on specific positions in the popup menu: some actions should be
588 // in the begin of the list, Delete action should be the last by #1343 issue
589 QList<QAction*> anActions = theMenu->actions();
590 int anActionsSize = anActions.size();
591 QAction* aFirstAction = anActions[0];
592 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
593 for (; anIt != aLast; anIt++) {
594 if (anIt.key() > anActionsSize)
595 theMenu->addAction(anIt.value());
597 theMenu->insertAction(aFirstAction, *anIt);
601 theMenu->addSeparator();
602 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
603 if (aMDI->actions().size() > 0) {
604 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
605 aSubMenu->addActions(aMDI->actions());
610 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
614 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
615 aLast = myObjBrowserMenus.end();
616 for (; anIt != aLast; anIt++) {
617 QString aGroupName(anIt.key().c_str());
618 if (aGroups.contains(aGroupName))
620 QActionsList anActions = anIt.value();
621 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
623 for (; anAIt != anALast && !aFound; anAIt++)
624 aFound = (*anAIt)->data().toString() == theName;
626 aGroups.append(aGroupName);
631 void XGUI_ContextMenuMgr::onRename()
633 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
634 if (!myWorkshop->abortAllOperations())
636 // restore selection in case if dialog box was shown
637 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
638 myWorkshop->objectBrowser()->onEditItem();
641 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
643 SessionPtr aMgr = ModelAPI_Session::get();
644 DocumentPtr aActiveDoc = aMgr->activeDocument();
646 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
647 XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
648 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
649 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
653 bool aIsRoot = false;
654 foreach(QModelIndex aIdx, aSelectedIndexes) {
655 // Process only first column
656 if (aIdx.column() == 0) {
657 aIsRoot = !aIdx.parent().isValid();
658 // Exit if the selected index belongs to non active document
659 if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
661 if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
664 // Get name of the selected index
665 aName = aIdx.data().toString();
666 aLen = aName.indexOf('(');
668 aName = aName.left(--aLen);
670 std::string aFeaturesStr = aIsRoot?
671 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
672 aDataModelXML->subFolderFeatures(aName.toStdString());
673 if (aFeaturesStr.length() > 0) {
674 QStringList aFeturesList =
675 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
676 foreach(QString aFea, aFeturesList) {
677 QAction* aAction = aActionMgr->action(aFea);
679 theMenu->addAction(aAction);
686 #define UNCHECK_ACTION(NAME) \
687 { QAction* aAction = action(NAME); \
688 bool isBlock = aAction->signalsBlocked(); \
689 aAction->blockSignals(true); \
690 aAction->setChecked(false); \
691 aAction->blockSignals(isBlock); }
694 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
696 UNCHECK_ACTION("SELECT_VERTEX_CMD");
697 UNCHECK_ACTION("SELECT_EDGE_CMD");
698 UNCHECK_ACTION("SELECT_FACE_CMD");
701 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
703 UNCHECK_ACTION("SHOW_RESULTS_CMD");