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(""), tr("Deflection..."), aDesktop);
90 addAction("DEFLECTION_CMD", aAction);
92 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
93 addAction("SHOW_CMD", aAction);
95 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show only"),
97 addAction("SHOW_ONLY_CMD", aAction);
99 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"),
101 addAction("HIDE_CMD", aAction);
103 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide all"),
105 addAction("HIDEALL_CMD", aAction);
107 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"), tr("Shading"), aDesktop);
108 addAction("SHADING_CMD", aAction);
110 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"),
112 addAction("WIREFRAME_CMD", aAction);
114 mySeparator = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
115 mySeparator->setSeparator(true);
117 //mySelectActions = new QActionGroup(this);
118 //mySelectActions->setExclusive(true);
120 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
121 this, SLOT(onShapeSelection(bool)));
122 aAction->setCheckable(true);
123 addAction("SELECT_VERTEX_CMD", aAction);
124 //mySelectActions->addAction(aAction);
126 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
127 this, SLOT(onShapeSelection(bool)));
128 aAction->setCheckable(true);
129 addAction("SELECT_EDGE_CMD", aAction);
130 //mySelectActions->addAction(aAction);
132 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
133 this, SLOT(onShapeSelection(bool)));
134 aAction->setCheckable(true);
135 addAction("SELECT_FACE_CMD", aAction);
136 //mySelectActions->addAction(aAction);
138 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop,
139 this, SLOT(onResultSelection(bool)));
140 aAction->setCheckable(true);
141 addAction("SELECT_RESULT_CMD", aAction);
142 //mySelectActions->addAction(aAction);
144 aAction->setChecked(true);
146 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
147 tr("Select results"), aDesktop);
148 addAction("SHOW_RESULTS_CMD", aAction);
150 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
151 tr("Select parent feature"), aDesktop);
152 addAction("SHOW_FEATURE_CMD", aAction);
154 buildObjBrowserMenu();
158 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
160 if (myActions.contains(theId))
161 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
162 theAction->setData(theId);
163 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
164 myActions[theId] = theAction;
167 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
169 if (myActions.contains(theId))
170 return myActions[theId];
174 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
176 foreach(QAction* eachAction, myActions) {
177 if (eachAction->text() == theName) {
184 QStringList XGUI_ContextMenuMgr::actionIds() const
186 return myActions.keys();
189 void XGUI_ContextMenuMgr::onAction(bool isChecked)
191 QAction* aAction = static_cast<QAction*>(sender());
192 emit actionTriggered(aAction->data().toString(), isChecked);
195 void XGUI_ContextMenuMgr::updateCommandsStatus()
199 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
201 QMenu* aMenu = new QMenu();
202 if (sender() == myWorkshop->objectBrowser()) {
203 updateObjectBrowserMenu();
204 addObjBrowserMenu(aMenu);
205 } else if (sender() == myWorkshop->viewer()) {
207 addViewerMenu(aMenu);
210 if (aMenu && (aMenu->actions().size() > 0)) {
211 // it is possible that some objects should do something before and after the popup menu exec
212 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
214 emit beforeContextMenu();
215 aMenu->exec(theEvent->globalPos());
216 emit afterContextMenu();
221 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
223 foreach(QAction* aAction, myActions)
224 aAction->setEnabled(false);
226 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
227 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
228 int aSelected = aObjects.size();
230 SessionPtr aMgr = ModelAPI_Session::get();
231 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
232 bool hasResult = false;
233 bool hasFeature = false;
234 bool hasParameter = false;
235 bool hasCompositeOwner = false;
236 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
239 if (aSelected == 1) {
240 ObjectPtr aObject = aObjects.first();
242 if (hasResult && myWorkshop->canBeShaded(aObject)) {
243 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
244 if (aMode != XGUI_Displayer::NoMode) {
245 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
246 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
248 action("WIREFRAME_CMD")->setEnabled(true);
249 action("SHADING_CMD")->setEnabled(true);
253 bool aHasSubResults = ModelAPI_Tools::hasSubResults(
254 std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
255 if (aHasSubResults) {
256 action("HIDE_CMD")->setEnabled(true);
257 action("SHOW_CMD")->setEnabled(true);
260 if (aObject->isDisplayed()) {
261 action("HIDE_CMD")->setEnabled(true);
262 } else if (hasResult && (!hasParameter)) {
263 action("SHOW_CMD")->setEnabled(true);
266 if (!(hasParameter || hasFeature))
267 action("SHOW_ONLY_CMD")->setEnabled(true);
269 else if (hasFeature && myWorkshop->canMoveFeature())
270 action("MOVE_CMD")->setEnabled(true);
272 if( aMgr->activeDocument() == aObject->document() )
274 action("RENAME_CMD")->setEnabled(true);
275 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
276 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
277 (hasFeature || hasParameter));
281 // parameter is commented because the actions are not in the list of result parameter actions
282 if (hasResult /*&& (!hasParameter)*/) {
283 action("SHOW_CMD")->setEnabled(true);
284 action("HIDE_CMD")->setEnabled(true);
285 action("SHOW_ONLY_CMD")->setEnabled(true);
286 action("SHADING_CMD")->setEnabled(true);
287 action("WIREFRAME_CMD")->setEnabled(true);
290 bool allActive = true;
291 foreach( ObjectPtr aObject, aObjects )
292 if( aMgr->activeDocument() != aObject->document() ) {
296 if (!hasCompositeOwner && allActive ) {
297 if (hasFeature || hasParameter)
298 action("DELETE_CMD")->setEnabled(true);
300 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
301 action("CLEAN_HISTORY_CMD")->setEnabled(true);
303 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
304 action("SHOW_FEATURE_CMD")->setEnabled(hasResult);
307 // Show/Hide command has to be disabled for objects from non active document
308 bool aDeactivate = false;
309 foreach (ObjectPtr aObj, aObjects) {
310 if (!aObj->document()->isActive()) {
311 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
312 aObj->groupName() == ModelAPI_ResultPart::group()) {
319 // If at leas a one objec can not be edited then Show/Hide has to be disabled
320 action("SHOW_CMD")->setEnabled(false);
321 action("HIDE_CMD")->setEnabled(false);
322 action("SHOW_ONLY_CMD")->setEnabled(false);
325 if (myWorkshop->canChangeColor())
326 action("COLOR_CMD")->setEnabled(true);
328 if (myWorkshop->canChangeDeflection())
329 action("DEFLECTION_CMD")->setEnabled(true);
331 ModuleBase_IModule* aModule = myWorkshop->module();
333 aModule->updateObjectBrowserMenu(myActions);
336 void XGUI_ContextMenuMgr::updateViewerMenu()
338 foreach(QAction* aAction, myActions)
339 aAction->setEnabled(false);
341 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
342 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
343 QList<ModuleBase_ViewerPrsPtr> aPrsList =
344 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
345 if (aPrsList.size() > 0) {
346 bool isVisible = false;
347 bool isShading = false;
348 bool canBeShaded = false;
350 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
351 aObject = aPrs->object();
352 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
353 if (aRes && aRes->isDisplayed()) {
355 canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
357 (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
363 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
364 if (aMode != XGUI_Displayer::NoMode) {
365 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
366 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
368 action("WIREFRAME_CMD")->setEnabled(true);
369 action("SHADING_CMD")->setEnabled(true);
372 action("SHOW_ONLY_CMD")->setEnabled(true);
373 action("HIDE_CMD")->setEnabled(true);
375 action("SHOW_CMD")->setEnabled(true);
377 if (myWorkshop->displayer()->objectsCount() > 0)
378 action("HIDEALL_CMD")->setEnabled(true);
380 // Update selection menu
381 QIntList aModes = aDisplayer->activeSelectionModes();
382 action("SELECT_VERTEX_CMD")->setEnabled(true);
383 action("SELECT_EDGE_CMD")->setEnabled(true);
384 action("SELECT_FACE_CMD")->setEnabled(true);
385 action("SELECT_RESULT_CMD")->setEnabled(true);
387 action("SELECT_RESULT_CMD")->setChecked(false);
388 action("SELECT_VERTEX_CMD")->setChecked(false);
389 action("SELECT_EDGE_CMD")->setChecked(false);
390 action("SELECT_FACE_CMD")->setChecked(false);
391 action("SELECT_RESULT_CMD")->setChecked(false);
392 if (aModes.count() == 0) {
393 action("SELECT_RESULT_CMD")->setChecked(true);
395 foreach(int aMode, aModes) {
398 action("SELECT_VERTEX_CMD")->setChecked(true);
401 action("SELECT_EDGE_CMD")->setChecked(true);
404 action("SELECT_FACE_CMD")->setChecked(true);
407 action("SELECT_RESULT_CMD")->setChecked(true);
412 ModuleBase_IModule* aModule = myWorkshop->module();
414 aModule->updateViewerMenu(myActions);
416 if (myWorkshop->canChangeColor())
417 action("COLOR_CMD")->setEnabled(true);
419 if (myWorkshop->canChangeDeflection())
420 action("DEFLECTION_CMD")->setEnabled(true);
422 action("DELETE_CMD")->setEnabled(true);
425 void XGUI_ContextMenuMgr::connectObjectBrowser()
427 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
428 SLOT(onContextMenuRequest(QContextMenuEvent*)));
431 void XGUI_ContextMenuMgr::connectViewer()
433 connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
434 SLOT(onContextMenuRequest(QContextMenuEvent*)));
438 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
440 QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
441 aSeparator->setSeparator(true);
445 // Result construction menu
446 aList.append(action("SHOW_CMD"));
447 aList.append(action("HIDE_CMD"));
448 aList.append(action("SHOW_ONLY_CMD"));
449 aList.append(mySeparator);
450 aList.append(action("RENAME_CMD"));
451 aList.append(action("COLOR_CMD"));
452 aList.append(action("DEFLECTION_CMD"));
453 aList.append(action("SHOW_FEATURE_CMD"));
454 myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
456 //-------------------------------------
459 aList.append(action("WIREFRAME_CMD"));
460 aList.append(action("SHADING_CMD"));
461 aList.append(mySeparator); // this separator is not shown as this action is added after show only
462 // qt list container contains only one instance of the same action
463 aList.append(action("SHOW_CMD"));
464 aList.append(action("HIDE_CMD"));
465 aList.append(action("SHOW_ONLY_CMD"));
466 aList.append(mySeparator);
467 aList.append(action("RENAME_CMD"));
468 aList.append(action("COLOR_CMD"));
469 aList.append(action("DEFLECTION_CMD"));
470 aList.append(action("SHOW_FEATURE_CMD"));
471 myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
473 myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
475 myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
476 //-------------------------------------
479 aList.append(action("RENAME_CMD"));
480 aList.append(action("SHOW_RESULTS_CMD"));
481 aList.append(action("MOVE_CMD"));
482 aList.append(mySeparator);
483 aList.append(action("CLEAN_HISTORY_CMD"));
484 aList.append(action("DELETE_CMD"));
485 myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
488 aList.append(action("RENAME_CMD"));
489 aList.append(mySeparator);
490 aList.append(action("CLEAN_HISTORY_CMD"));
491 aList.append(action("DELETE_CMD"));
492 myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
493 //-------------------------------------
496 void XGUI_ContextMenuMgr::buildViewerMenu()
499 // Result construction menu
500 aList.append(action("HIDE_CMD"));
501 aList.append(action("SHOW_ONLY_CMD"));
502 aList.append(mySeparator);
503 aList.append(action("COLOR_CMD"));
504 aList.append(action("DEFLECTION_CMD"));
505 myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
507 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
508 //-------------------------------------
511 aList.append(action("WIREFRAME_CMD"));
512 aList.append(action("SHADING_CMD"));
513 aList.append(mySeparator);
514 aList.append(action("HIDE_CMD"));
515 aList.append(action("SHOW_ONLY_CMD"));
516 aList.append(mySeparator);
517 aList.append(action("COLOR_CMD"));
518 aList.append(action("DEFLECTION_CMD"));
519 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
521 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
522 //-------------------------------------
526 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
528 ModuleBase_IModule* aModule = myWorkshop->module();
530 theMenu->addSeparator();
531 aModule->addObjectBrowserMenu(theMenu);
534 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
535 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
536 int aSelected = aObjects.size();
537 QActionsList aActions;
538 if (aSelected == 1) {
539 ObjectPtr aObject = aObjects.first();
540 std::string aName = aObject->groupName();
541 if (myObjBrowserMenus.contains(aName))
542 aActions = myObjBrowserMenus[aName];
543 } else if (aSelected > 1) {
544 aActions.append(action("WIREFRAME_CMD"));
545 aActions.append(action("SHADING_CMD"));
546 aActions.append(mySeparator);
547 aActions.append(action("SHOW_CMD"));
548 aActions.append(action("HIDE_CMD"));
549 aActions.append(action("SHOW_ONLY_CMD"));
550 aActions.append(mySeparator);
551 //aActions.append(action("MOVE_CMD"));
552 aActions.append(action("COLOR_CMD"));
553 aActions.append(action("DEFLECTION_CMD"));
555 aActions.append(action("CLEAN_HISTORY_CMD"));
556 aActions.append(action("DELETE_CMD"));
558 theMenu->addActions(aActions);
559 addFeatures(theMenu);
561 // It is commented out because Object Browser does not have actions
562 //theMenu->addSeparator();
563 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
566 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
568 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
569 QList<ModuleBase_ViewerPrsPtr> aPrsList =
570 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
571 int aSelected = aPrsList.size();
572 QActionsList aActions;
574 // Create selection menu
575 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
577 myWorkshop->module()->activeSelectionModes(aModes);
578 if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
579 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
580 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
581 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
582 aSelMenu->addAction(action("SELECT_FACE_CMD"));
583 //IMP: an attempt to use result selection with other selection modes
584 //aSelMenu->addSeparator();
585 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
586 theMenu->addMenu(aSelMenu);
587 theMenu->addSeparator();
589 if (aSelected == 1) {
590 ObjectPtr aObject = aPrsList.first()->object();
591 if (aObject.get() != NULL) {
592 std::string aName = aObject->groupName();
593 if (myViewerMenu.contains(aName))
594 aActions = myViewerMenu[aName];
596 } else if (aSelected > 1) {
597 aActions.append(action("HIDE_CMD"));
599 // hide all is shown always even if selection in the viewer is empty
600 aActions.append(action("HIDEALL_CMD"));
601 aActions.append(action("COLOR_CMD"));
602 aActions.append(action("DEFLECTION_CMD"));
604 theMenu->addActions(aActions);
606 QMap<int, QAction*> aMenuActions;
607 ModuleBase_IModule* aModule = myWorkshop->module();
609 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
610 theMenu->addSeparator();
613 // insert the module menu items on specific positions in the popup menu: some actions should be
614 // in the begin of the list, Delete action should be the last by #1343 issue
615 QList<QAction*> anActions = theMenu->actions();
616 int anActionsSize = anActions.size();
617 QAction* aFirstAction = anActions[0];
618 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
619 for (; anIt != aLast; anIt++) {
620 if (anIt.key() > anActionsSize)
621 theMenu->addAction(anIt.value());
623 theMenu->insertAction(aFirstAction, *anIt);
627 theMenu->addSeparator();
628 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
629 if (aMDI->actions().size() > 0) {
630 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
631 aSubMenu->addActions(aMDI->actions());
636 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
640 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
641 aLast = myObjBrowserMenus.end();
642 for (; anIt != aLast; anIt++) {
643 QString aGroupName(anIt.key().c_str());
644 if (aGroups.contains(aGroupName))
646 QActionsList anActions = anIt.value();
647 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
649 for (; anAIt != anALast && !aFound; anAIt++)
650 aFound = (*anAIt)->data().toString() == theName;
652 aGroups.append(aGroupName);
657 void XGUI_ContextMenuMgr::onRename()
659 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
660 if (!myWorkshop->abortAllOperations())
662 // restore selection in case if dialog box was shown
663 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
664 myWorkshop->objectBrowser()->onEditItem();
667 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
669 SessionPtr aMgr = ModelAPI_Session::get();
670 DocumentPtr aActiveDoc = aMgr->activeDocument();
672 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
673 XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
674 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
675 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
679 bool aIsRoot = false;
680 foreach(QModelIndex aIdx, aSelectedIndexes) {
681 // Process only first column
682 if (aIdx.column() == 0) {
683 aIsRoot = !aIdx.parent().isValid();
684 // Exit if the selected index belongs to non active document
685 if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
687 if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
690 // Get name of the selected index
691 aName = aIdx.data().toString();
692 aLen = aName.indexOf('(');
694 aName = aName.left(--aLen);
696 std::string aFeaturesStr = aIsRoot?
697 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
698 aDataModelXML->subFolderFeatures(aName.toStdString());
699 if (aFeaturesStr.length() > 0) {
700 QStringList aFeturesList =
701 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
702 foreach(QString aFea, aFeturesList) {
703 QAction* aAction = aActionMgr->action(aFea);
705 theMenu->addAction(aAction);
712 #define UNCHECK_ACTION(NAME) \
713 { QAction* aAction = action(NAME); \
714 bool isBlock = aAction->signalsBlocked(); \
715 aAction->blockSignals(true); \
716 aAction->setChecked(false); \
717 aAction->blockSignals(isBlock); }
720 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
722 UNCHECK_ACTION("SELECT_VERTEX_CMD");
723 UNCHECK_ACTION("SELECT_EDGE_CMD");
724 UNCHECK_ACTION("SELECT_FACE_CMD");
727 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
729 UNCHECK_ACTION("SHOW_RESULTS_CMD");