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"),
69 aDesktop->addAction(aAction);
71 addAction("DELETE_CMD", aAction);
72 aAction->setShortcutContext(Qt::ApplicationShortcut);
74 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/rename_edit.png"), tr("Rename"),
75 aDesktop, this, SLOT(onRename()));
76 addAction("RENAME_CMD", aAction);
78 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move.png"),
79 XGUI_Workshop::MOVE_TO_END_COMMAND, this);
80 addAction("MOVE_CMD", aAction);
82 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/clean_history.png"),
83 tr("Clean history"), aDesktop);
84 addAction("CLEAN_HISTORY_CMD", aAction);
86 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop);
87 addAction("COLOR_CMD", aAction);
89 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
90 addAction("SHOW_CMD", aAction);
92 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show only"),
94 addAction("SHOW_ONLY_CMD", aAction);
96 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"),
98 addAction("HIDE_CMD", aAction);
100 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide all"),
102 addAction("HIDEALL_CMD", aAction);
104 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"), tr("Shading"), aDesktop);
105 addAction("SHADING_CMD", aAction);
107 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"),
109 addAction("WIREFRAME_CMD", aAction);
111 mySeparator = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
112 mySeparator->setSeparator(true);
114 //mySelectActions = new QActionGroup(this);
115 //mySelectActions->setExclusive(true);
117 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
118 this, SLOT(onShapeSelection(bool)));
119 aAction->setCheckable(true);
120 addAction("SELECT_VERTEX_CMD", aAction);
121 //mySelectActions->addAction(aAction);
123 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
124 this, SLOT(onShapeSelection(bool)));
125 aAction->setCheckable(true);
126 addAction("SELECT_EDGE_CMD", aAction);
127 //mySelectActions->addAction(aAction);
129 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
130 this, SLOT(onShapeSelection(bool)));
131 aAction->setCheckable(true);
132 addAction("SELECT_FACE_CMD", aAction);
133 //mySelectActions->addAction(aAction);
135 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Result"), aDesktop,
136 this, SLOT(onResultSelection(bool)));
137 aAction->setCheckable(true);
138 addAction("SELECT_RESULT_CMD", aAction);
139 //mySelectActions->addAction(aAction);
141 aAction->setChecked(true);
143 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
144 tr("Select results"), aDesktop);
145 addAction("SHOW_RESULTS_CMD", aAction);
147 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
148 tr("Select parent feature"), aDesktop);
149 addAction("SHOW_FEATURE_CMD", aAction);
151 buildObjBrowserMenu();
155 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
157 if (myActions.contains(theId))
158 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
159 theAction->setData(theId);
160 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
161 myActions[theId] = theAction;
164 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
166 if (myActions.contains(theId))
167 return myActions[theId];
171 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
173 foreach(QAction* eachAction, myActions) {
174 if (eachAction->text() == theName) {
181 QStringList XGUI_ContextMenuMgr::actionIds() const
183 return myActions.keys();
186 void XGUI_ContextMenuMgr::onAction(bool isChecked)
188 QAction* aAction = static_cast<QAction*>(sender());
189 emit actionTriggered(aAction->data().toString(), isChecked);
192 void XGUI_ContextMenuMgr::updateCommandsStatus()
196 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
198 QMenu* aMenu = new QMenu();
199 if (sender() == myWorkshop->objectBrowser()) {
200 updateObjectBrowserMenu();
201 addObjBrowserMenu(aMenu);
202 } else if (sender() == myWorkshop->viewer()) {
204 addViewerMenu(aMenu);
207 if (aMenu && (aMenu->actions().size() > 0)) {
208 // it is possible that some objects should do something before and after the popup menu exec
209 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
211 emit beforeContextMenu();
212 aMenu->exec(theEvent->globalPos());
213 emit afterContextMenu();
218 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
220 foreach(QAction* aAction, myActions)
221 aAction->setEnabled(false);
223 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
224 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
225 int aSelected = aObjects.size();
227 SessionPtr aMgr = ModelAPI_Session::get();
228 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
229 bool hasResult = false;
230 bool hasFeature = false;
231 bool hasParameter = false;
232 bool hasCompositeOwner = false;
233 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
236 if (aSelected == 1) {
237 ObjectPtr aObject = aObjects.first();
239 if (hasResult && myWorkshop->canBeShaded(aObject)) {
240 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
241 if (aMode != XGUI_Displayer::NoMode) {
242 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
243 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
245 action("WIREFRAME_CMD")->setEnabled(true);
246 action("SHADING_CMD")->setEnabled(true);
250 bool aHasSubResults = ModelAPI_Tools::hasSubResults(
251 std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
252 if (aHasSubResults) {
253 action("HIDE_CMD")->setEnabled(true);
254 action("SHOW_CMD")->setEnabled(true);
257 if (aObject->isDisplayed()) {
258 action("HIDE_CMD")->setEnabled(true);
259 } else if (hasResult && (!hasParameter)) {
260 action("SHOW_CMD")->setEnabled(true);
263 if (!(hasParameter || hasFeature))
264 action("SHOW_ONLY_CMD")->setEnabled(true);
266 else if (hasFeature && myWorkshop->canMoveFeature())
267 action("MOVE_CMD")->setEnabled(true);
269 if( aMgr->activeDocument() == aObject->document() )
271 action("RENAME_CMD")->setEnabled(true);
272 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
273 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
274 (hasFeature || hasParameter));
278 // parameter is commented because the actions are not in the list of result parameter actions
279 if (hasResult /*&& (!hasParameter)*/) {
280 action("SHOW_CMD")->setEnabled(true);
281 action("HIDE_CMD")->setEnabled(true);
282 action("SHOW_ONLY_CMD")->setEnabled(true);
283 action("SHADING_CMD")->setEnabled(true);
284 action("WIREFRAME_CMD")->setEnabled(true);
287 bool allActive = true;
288 foreach( ObjectPtr aObject, aObjects )
289 if( aMgr->activeDocument() != aObject->document() ) {
293 if (!hasCompositeOwner && allActive ) {
294 if (hasFeature || hasParameter)
295 action("DELETE_CMD")->setEnabled(true);
297 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
298 action("CLEAN_HISTORY_CMD")->setEnabled(true);
300 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
301 action("SHOW_FEATURE_CMD")->setEnabled(hasResult);
304 // Show/Hide command has to be disabled for objects from non active document
305 bool aDeactivate = false;
306 foreach (ObjectPtr aObj, aObjects) {
307 if (!aObj->document()->isActive()) {
308 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
309 aObj->groupName() == ModelAPI_ResultPart::group()) {
316 // If at leas a one objec can not be edited then Show/Hide has to be disabled
317 action("SHOW_CMD")->setEnabled(false);
318 action("HIDE_CMD")->setEnabled(false);
319 action("SHOW_ONLY_CMD")->setEnabled(false);
322 if (myWorkshop->canChangeColor())
323 action("COLOR_CMD")->setEnabled(true);
325 ModuleBase_IModule* aModule = myWorkshop->module();
327 aModule->updateObjectBrowserMenu(myActions);
330 void XGUI_ContextMenuMgr::updateViewerMenu()
332 foreach(QAction* aAction, myActions)
333 aAction->setEnabled(false);
335 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
336 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
337 QList<ModuleBase_ViewerPrsPtr> aPrsList = aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
338 if (aPrsList.size() > 0) {
339 bool isVisible = false;
340 bool isShading = false;
341 bool canBeShaded = false;
343 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
344 aObject = aPrs->object();
345 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
346 if (aRes && aRes->isDisplayed()) {
348 canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
349 isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
355 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
356 if (aMode != XGUI_Displayer::NoMode) {
357 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
358 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
360 action("WIREFRAME_CMD")->setEnabled(true);
361 action("SHADING_CMD")->setEnabled(true);
364 action("SHOW_ONLY_CMD")->setEnabled(true);
365 action("HIDE_CMD")->setEnabled(true);
367 action("SHOW_CMD")->setEnabled(true);
369 if (myWorkshop->displayer()->objectsCount() > 0)
370 action("HIDEALL_CMD")->setEnabled(true);
372 // Update selection menu
373 QIntList aModes = aDisplayer->activeSelectionModes();
374 action("SELECT_VERTEX_CMD")->setEnabled(true);
375 action("SELECT_EDGE_CMD")->setEnabled(true);
376 action("SELECT_FACE_CMD")->setEnabled(true);
377 action("SELECT_RESULT_CMD")->setEnabled(true);
379 action("SELECT_RESULT_CMD")->setChecked(false);
380 action("SELECT_VERTEX_CMD")->setChecked(false);
381 action("SELECT_EDGE_CMD")->setChecked(false);
382 action("SELECT_FACE_CMD")->setChecked(false);
383 action("SELECT_RESULT_CMD")->setChecked(false);
384 if (aModes.count() == 0) {
385 action("SELECT_RESULT_CMD")->setChecked(true);
387 foreach(int aMode, aModes) {
390 action("SELECT_VERTEX_CMD")->setChecked(true);
393 action("SELECT_EDGE_CMD")->setChecked(true);
396 action("SELECT_FACE_CMD")->setChecked(true);
399 action("SELECT_RESULT_CMD")->setChecked(true);
404 ModuleBase_IModule* aModule = myWorkshop->module();
406 aModule->updateViewerMenu(myActions);
408 if (myWorkshop->canChangeColor())
409 action("COLOR_CMD")->setEnabled(true);
411 action("DELETE_CMD")->setEnabled(true);
414 void XGUI_ContextMenuMgr::connectObjectBrowser()
416 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
417 SLOT(onContextMenuRequest(QContextMenuEvent*)));
420 void XGUI_ContextMenuMgr::connectViewer()
422 connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
423 SLOT(onContextMenuRequest(QContextMenuEvent*)));
427 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
429 QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
430 aSeparator->setSeparator(true);
434 // Result construction menu
435 aList.append(action("SHOW_CMD"));
436 aList.append(action("HIDE_CMD"));
437 aList.append(action("SHOW_ONLY_CMD"));
438 aList.append(mySeparator);
439 aList.append(action("RENAME_CMD"));
440 aList.append(action("COLOR_CMD"));
441 aList.append(action("SHOW_FEATURE_CMD"));
442 myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
444 //-------------------------------------
447 aList.append(action("WIREFRAME_CMD"));
448 aList.append(action("SHADING_CMD"));
449 aList.append(mySeparator); // this separator is not shown as this action is added after show only
450 // qt list container contains only one instance of the same action
451 aList.append(action("SHOW_CMD"));
452 aList.append(action("HIDE_CMD"));
453 aList.append(action("SHOW_ONLY_CMD"));
454 aList.append(mySeparator);
455 aList.append(action("RENAME_CMD"));
456 aList.append(action("COLOR_CMD"));
457 aList.append(action("SHOW_FEATURE_CMD"));
458 myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
460 myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
462 myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
463 //-------------------------------------
466 aList.append(action("RENAME_CMD"));
467 aList.append(action("SHOW_RESULTS_CMD"));
468 aList.append(action("MOVE_CMD"));
469 aList.append(mySeparator);
470 aList.append(action("CLEAN_HISTORY_CMD"));
471 aList.append(action("DELETE_CMD"));
472 myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
475 aList.append(action("RENAME_CMD"));
476 aList.append(mySeparator);
477 aList.append(action("CLEAN_HISTORY_CMD"));
478 aList.append(action("DELETE_CMD"));
479 myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
480 //-------------------------------------
483 void XGUI_ContextMenuMgr::buildViewerMenu()
486 // Result construction menu
487 aList.append(action("HIDE_CMD"));
488 aList.append(action("SHOW_ONLY_CMD"));
489 aList.append(mySeparator);
490 aList.append(action("COLOR_CMD"));
491 myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
493 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
494 //-------------------------------------
497 aList.append(action("WIREFRAME_CMD"));
498 aList.append(action("SHADING_CMD"));
499 aList.append(mySeparator);
500 aList.append(action("HIDE_CMD"));
501 aList.append(action("SHOW_ONLY_CMD"));
502 aList.append(mySeparator);
503 aList.append(action("COLOR_CMD"));
504 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
506 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
507 //-------------------------------------
511 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
513 ModuleBase_IModule* aModule = myWorkshop->module();
515 theMenu->addSeparator();
516 aModule->addObjectBrowserMenu(theMenu);
519 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
520 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
521 int aSelected = aObjects.size();
522 QActionsList aActions;
523 if (aSelected == 1) {
524 ObjectPtr aObject = aObjects.first();
525 std::string aName = aObject->groupName();
526 if (myObjBrowserMenus.contains(aName))
527 aActions = myObjBrowserMenus[aName];
528 } else if (aSelected > 1) {
529 aActions.append(action("WIREFRAME_CMD"));
530 aActions.append(action("SHADING_CMD"));
531 aActions.append(mySeparator);
532 aActions.append(action("SHOW_CMD"));
533 aActions.append(action("HIDE_CMD"));
534 aActions.append(action("SHOW_ONLY_CMD"));
535 aActions.append(mySeparator);
536 //aActions.append(action("MOVE_CMD"));
537 aActions.append(action("COLOR_CMD"));
538 aActions.append(action("CLEAN_HISTORY_CMD"));
539 aActions.append(action("DELETE_CMD"));
541 theMenu->addActions(aActions);
542 addFeatures(theMenu);
544 // It is commented out because Object Browser does not have actions
545 //theMenu->addSeparator();
546 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
549 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
551 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
552 QList<ModuleBase_ViewerPrsPtr> aPrsList = aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
553 int aSelected = aPrsList.size();
554 QActionsList aActions;
556 // Create selection menu
557 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
559 myWorkshop->module()->activeSelectionModes(aModes);
560 if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
561 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
562 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
563 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
564 aSelMenu->addAction(action("SELECT_FACE_CMD"));
565 aSelMenu->addSeparator();
566 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
567 theMenu->addMenu(aSelMenu);
568 theMenu->addSeparator();
570 if (aSelected == 1) {
571 ObjectPtr aObject = aPrsList.first()->object();
572 if (aObject.get() != NULL) {
573 std::string aName = aObject->groupName();
574 if (myViewerMenu.contains(aName))
575 aActions = myViewerMenu[aName];
577 } else if (aSelected > 1) {
578 aActions.append(action("HIDE_CMD"));
580 // hide all is shown always even if selection in the viewer is empty
581 aActions.append(action("HIDEALL_CMD"));
582 aActions.append(action("COLOR_CMD"));
584 theMenu->addActions(aActions);
586 QMap<int, QAction*> aMenuActions;
587 ModuleBase_IModule* aModule = myWorkshop->module();
589 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
590 theMenu->addSeparator();
593 // insert the module menu items on specific positions in the popup menu: some actions should be
594 // in the begin of the list, Delete action should be the last by #1343 issue
595 QList<QAction*> anActions = theMenu->actions();
596 int anActionsSize = anActions.size();
597 QAction* aFirstAction = anActions[0];
598 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
599 for (; anIt != aLast; anIt++) {
600 if (anIt.key() > anActionsSize)
601 theMenu->addAction(anIt.value());
603 theMenu->insertAction(aFirstAction, *anIt);
607 theMenu->addSeparator();
608 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
609 if (aMDI->actions().size() > 0) {
610 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
611 aSubMenu->addActions(aMDI->actions());
616 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
620 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
621 aLast = myObjBrowserMenus.end();
622 for (; anIt != aLast; anIt++) {
623 QString aGroupName(anIt.key().c_str());
624 if (aGroups.contains(aGroupName))
626 QActionsList anActions = anIt.value();
627 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
629 for (; anAIt != anALast && !aFound; anAIt++)
630 aFound = (*anAIt)->data().toString() == theName;
632 aGroups.append(aGroupName);
637 void XGUI_ContextMenuMgr::onRename()
639 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
640 if (!myWorkshop->abortAllOperations())
642 // restore selection in case if dialog box was shown
643 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
644 myWorkshop->objectBrowser()->onEditItem();
647 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
649 SessionPtr aMgr = ModelAPI_Session::get();
650 DocumentPtr aActiveDoc = aMgr->activeDocument();
652 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
653 XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
654 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
655 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
659 bool aIsRoot = false;
660 foreach(QModelIndex aIdx, aSelectedIndexes) {
661 // Process only first column
662 if (aIdx.column() == 0) {
663 aIsRoot = !aIdx.parent().isValid();
664 // Exit if the selected index belongs to non active document
665 if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
667 if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
670 // Get name of the selected index
671 aName = aIdx.data().toString();
672 aLen = aName.indexOf('(');
674 aName = aName.left(--aLen);
676 std::string aFeaturesStr = aIsRoot?
677 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
678 aDataModelXML->subFolderFeatures(aName.toStdString());
679 if (aFeaturesStr.length() > 0) {
680 QStringList aFeturesList =
681 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
682 foreach(QString aFea, aFeturesList) {
683 QAction* aAction = aActionMgr->action(aFea);
685 theMenu->addAction(aAction);
692 #define UNCHECK_ACTION(NAME) \
693 { QAction* aAction = action(NAME); \
694 bool isBlock = aAction->signalsBlocked(); \
695 aAction->blockSignals(true); \
696 aAction->setChecked(false); \
697 aAction->blockSignals(isBlock); }
700 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
702 UNCHECK_ACTION("SELECT_VERTEX_CMD");
703 UNCHECK_ACTION("SELECT_EDGE_CMD");
704 UNCHECK_ACTION("SELECT_FACE_CMD");
707 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
709 UNCHECK_ACTION("SHOW_RESULTS_CMD");