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>
31 #include <ModelAPI_ResultField.h>
33 #include <Config_DataModelReader.h>
35 #include <ModuleBase_IModule.h>
36 #include <ModuleBase_Tools.h>
37 #include <ModuleBase_OperationAction.h>
38 #include <ModuleBase_ViewerPrs.h>
41 #include <QActionGroup>
42 #include <QContextMenuEvent>
45 #include <QMainWindow>
46 #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);
155 aAction = ModuleBase_Tools::createAction(QIcon(), tr("Debug Visualization"), aDesktop);
156 addAction("VINSPECTOR_VIEW", aAction);
159 aAction = ModuleBase_Tools::createAction(QIcon(), tr("DFBrowser"), aDesktop);
160 addAction("DFBROWSER_VIEW", aAction);
163 buildObjBrowserMenu();
167 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
169 if (myActions.contains(theId))
170 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
171 theAction->setData(theId);
172 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
173 myActions[theId] = theAction;
176 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
178 if (myActions.contains(theId))
179 return myActions[theId];
183 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
185 foreach(QAction* eachAction, myActions) {
186 if (eachAction->text() == theName) {
193 QStringList XGUI_ContextMenuMgr::actionIds() const
195 return myActions.keys();
198 void XGUI_ContextMenuMgr::onAction(bool isChecked)
200 QAction* aAction = static_cast<QAction*>(sender());
201 emit actionTriggered(aAction->data().toString(), isChecked);
204 void XGUI_ContextMenuMgr::updateCommandsStatus()
208 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
210 QMenu* aMenu = new QMenu();
211 if (sender() == myWorkshop->objectBrowser()) {
212 updateObjectBrowserMenu();
213 addObjBrowserMenu(aMenu);
214 } else if (sender() == myWorkshop->viewer()) {
216 addViewerMenu(aMenu);
219 if (aMenu && (aMenu->actions().size() > 0)) {
220 // it is possible that some objects should do something before and after the popup menu exec
221 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
223 emit beforeContextMenu();
224 aMenu->exec(theEvent->globalPos());
225 emit afterContextMenu();
230 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
232 foreach(QAction* aAction, myActions)
233 aAction->setEnabled(false);
235 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
236 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
237 int aSelected = aObjects.size();
239 SessionPtr aMgr = ModelAPI_Session::get();
240 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
241 bool hasResult = false;
242 bool hasFeature = false;
243 bool hasParameter = false;
244 bool hasCompositeOwner = false;
245 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
248 if (aSelected == 1) {
249 ObjectPtr aObject = aObjects.first();
251 if (hasResult && myWorkshop->canBeShaded(aObject)) {
252 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
253 if (aMode != XGUI_Displayer::NoMode) {
254 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
255 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
257 action("WIREFRAME_CMD")->setEnabled(true);
258 action("SHADING_CMD")->setEnabled(true);
262 bool aHasSubResults = ModelAPI_Tools::hasSubResults(
263 std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
264 if (aHasSubResults) {
265 action("HIDE_CMD")->setEnabled(true);
266 action("SHOW_CMD")->setEnabled(true);
269 if (aObject->isDisplayed()) {
270 action("HIDE_CMD")->setEnabled(true);
271 } else if (hasResult && (!hasParameter)) {
272 action("SHOW_CMD")->setEnabled(true);
275 if (!(hasParameter || hasFeature))
276 action("SHOW_ONLY_CMD")->setEnabled(true);
278 else if (hasFeature && myWorkshop->canMoveFeature())
279 action("MOVE_CMD")->setEnabled(true);
281 if( aMgr->activeDocument() == aObject->document() )
283 action("RENAME_CMD")->setEnabled(true);
284 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
285 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
286 (hasFeature || hasParameter));
290 // parameter is commented because the actions are not in the list of result parameter actions
291 if (hasResult /*&& (!hasParameter)*/) {
292 action("SHOW_CMD")->setEnabled(true);
293 action("HIDE_CMD")->setEnabled(true);
294 action("SHOW_ONLY_CMD")->setEnabled(true);
295 action("SHADING_CMD")->setEnabled(true);
296 action("WIREFRAME_CMD")->setEnabled(true);
299 bool allActive = true;
300 foreach( ObjectPtr aObject, aObjects )
301 if( aMgr->activeDocument() != aObject->document() ) {
305 if (!hasCompositeOwner && allActive ) {
306 if (hasFeature || hasParameter)
307 action("DELETE_CMD")->setEnabled(true);
309 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
310 action("CLEAN_HISTORY_CMD")->setEnabled(true);
312 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
313 action("SHOW_FEATURE_CMD")->setEnabled(hasResult);
316 // Show/Hide command has to be disabled for objects from non active document
317 bool aDeactivate = false;
318 foreach (ObjectPtr aObj, aObjects) {
319 if (!aObj->document()->isActive()) {
320 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
321 aObj->groupName() == ModelAPI_ResultPart::group()) {
328 // If at leas a one objec can not be edited then Show/Hide has to be disabled
329 action("SHOW_CMD")->setEnabled(false);
330 action("HIDE_CMD")->setEnabled(false);
331 action("SHOW_ONLY_CMD")->setEnabled(false);
334 if (myWorkshop->canChangeColor())
335 action("COLOR_CMD")->setEnabled(true);
337 if (myWorkshop->canChangeDeflection())
338 action("DEFLECTION_CMD")->setEnabled(true);
342 action("VINSPECTOR_VIEW")->setEnabled(true);
345 action("DFBROWSER_VIEW")->setEnabled(true);
350 ModuleBase_IModule* aModule = myWorkshop->module();
352 aModule->updateObjectBrowserMenu(myActions);
355 void XGUI_ContextMenuMgr::updateViewerMenu()
357 foreach(QAction* aAction, myActions)
358 aAction->setEnabled(false);
360 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
361 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
362 QList<ModuleBase_ViewerPrsPtr> aPrsList =
363 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
364 if (aPrsList.size() > 0) {
365 bool isVisible = false;
366 bool isShading = false;
367 bool canBeShaded = false;
369 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
370 aObject = aPrs->object();
371 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
372 if (aRes && aRes->isDisplayed()) {
374 canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
376 (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
382 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
383 if (aMode != XGUI_Displayer::NoMode) {
384 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
385 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
387 action("WIREFRAME_CMD")->setEnabled(true);
388 action("SHADING_CMD")->setEnabled(true);
391 action("SHOW_ONLY_CMD")->setEnabled(true);
392 action("HIDE_CMD")->setEnabled(true);
394 action("SHOW_CMD")->setEnabled(true);
396 if (myWorkshop->displayer()->objectsCount() > 0)
397 action("HIDEALL_CMD")->setEnabled(true);
399 // Update selection menu
400 QIntList aModes = aDisplayer->activeSelectionModes();
401 action("SELECT_VERTEX_CMD")->setEnabled(true);
402 action("SELECT_EDGE_CMD")->setEnabled(true);
403 action("SELECT_FACE_CMD")->setEnabled(true);
404 action("SELECT_RESULT_CMD")->setEnabled(true);
406 action("SELECT_RESULT_CMD")->setChecked(false);
407 action("SELECT_VERTEX_CMD")->setChecked(false);
408 action("SELECT_EDGE_CMD")->setChecked(false);
409 action("SELECT_FACE_CMD")->setChecked(false);
410 action("SELECT_RESULT_CMD")->setChecked(false);
411 if (aModes.count() == 0) {
412 action("SELECT_RESULT_CMD")->setChecked(true);
414 foreach(int aMode, aModes) {
417 action("SELECT_VERTEX_CMD")->setChecked(true);
420 action("SELECT_EDGE_CMD")->setChecked(true);
423 action("SELECT_FACE_CMD")->setChecked(true);
426 action("SELECT_RESULT_CMD")->setChecked(true);
431 ModuleBase_IModule* aModule = myWorkshop->module();
433 aModule->updateViewerMenu(myActions);
435 if (myWorkshop->canChangeColor())
436 action("COLOR_CMD")->setEnabled(true);
438 if (myWorkshop->canChangeDeflection())
439 action("DEFLECTION_CMD")->setEnabled(true);
441 action("DELETE_CMD")->setEnabled(true);
444 void XGUI_ContextMenuMgr::connectObjectBrowser()
446 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
447 SLOT(onContextMenuRequest(QContextMenuEvent*)));
450 void XGUI_ContextMenuMgr::connectViewer()
452 connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
453 SLOT(onContextMenuRequest(QContextMenuEvent*)));
457 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
459 QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
460 aSeparator->setSeparator(true);
464 // Result construction menu
465 aList.append(action("SHOW_CMD"));
466 aList.append(action("HIDE_CMD"));
467 aList.append(action("SHOW_ONLY_CMD"));
468 aList.append(mySeparator);
469 aList.append(action("RENAME_CMD"));
470 aList.append(action("COLOR_CMD"));
471 aList.append(action("DEFLECTION_CMD"));
472 aList.append(action("SHOW_FEATURE_CMD"));
473 myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
475 //-------------------------------------
478 aList.append(action("WIREFRAME_CMD"));
479 aList.append(action("SHADING_CMD"));
480 aList.append(mySeparator); // this separator is not shown as this action is added after show only
481 // qt list container contains only one instance of the same action
482 aList.append(action("SHOW_CMD"));
483 aList.append(action("HIDE_CMD"));
484 aList.append(action("SHOW_ONLY_CMD"));
485 aList.append(mySeparator);
486 aList.append(action("RENAME_CMD"));
487 aList.append(action("COLOR_CMD"));
488 aList.append(action("DEFLECTION_CMD"));
489 aList.append(action("SHOW_FEATURE_CMD"));
490 myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
492 myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
493 myObjBrowserMenus[ModelAPI_ResultField::group()] = aList;
495 myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
496 //-------------------------------------
499 aList.append(action("RENAME_CMD"));
500 aList.append(action("SHOW_RESULTS_CMD"));
501 aList.append(action("MOVE_CMD"));
502 aList.append(mySeparator);
503 aList.append(action("CLEAN_HISTORY_CMD"));
504 aList.append(action("DELETE_CMD"));
505 myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
508 aList.append(action("RENAME_CMD"));
509 aList.append(mySeparator);
510 aList.append(action("CLEAN_HISTORY_CMD"));
511 aList.append(action("DELETE_CMD"));
512 myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
513 //-------------------------------------
516 void XGUI_ContextMenuMgr::buildViewerMenu()
519 // Result construction menu
520 aList.append(action("HIDE_CMD"));
521 aList.append(action("SHOW_ONLY_CMD"));
522 aList.append(mySeparator);
523 aList.append(action("COLOR_CMD"));
524 aList.append(action("DEFLECTION_CMD"));
525 myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
527 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
528 //-------------------------------------
531 aList.append(action("WIREFRAME_CMD"));
532 aList.append(action("SHADING_CMD"));
533 aList.append(mySeparator);
534 aList.append(action("HIDE_CMD"));
535 aList.append(action("SHOW_ONLY_CMD"));
536 aList.append(mySeparator);
537 aList.append(action("COLOR_CMD"));
538 aList.append(action("DEFLECTION_CMD"));
539 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
541 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
542 myViewerMenu[ModelAPI_ResultField::group()] = aList;
543 //-------------------------------------
547 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
549 ModuleBase_IModule* aModule = myWorkshop->module();
551 theMenu->addSeparator();
552 aModule->addObjectBrowserMenu(theMenu);
555 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
556 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
557 int aSelected = aObjects.size();
558 QActionsList aActions;
559 if (aSelected == 1) {
560 ObjectPtr aObject = aObjects.first();
561 std::string aName = aObject->groupName();
562 if (myObjBrowserMenus.contains(aName))
563 aActions = myObjBrowserMenus[aName];
564 } else if (aSelected > 1) {
565 aActions.append(action("WIREFRAME_CMD"));
566 aActions.append(action("SHADING_CMD"));
567 aActions.append(mySeparator);
568 aActions.append(action("SHOW_CMD"));
569 aActions.append(action("HIDE_CMD"));
570 aActions.append(action("SHOW_ONLY_CMD"));
571 aActions.append(mySeparator);
572 //aActions.append(action("MOVE_CMD"));
573 aActions.append(action("COLOR_CMD"));
574 aActions.append(action("DEFLECTION_CMD"));
576 aActions.append(action("CLEAN_HISTORY_CMD"));
577 aActions.append(action("DELETE_CMD"));
580 if (aSelected == 0) {
582 aActions.append(action("VINSPECTOR_VIEW"));
585 aActions.append(action("DFBROWSER_VIEW"));
589 theMenu->addActions(aActions);
590 addFeatures(theMenu);
592 // It is commented out because Object Browser does not have actions
593 //theMenu->addSeparator();
594 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
597 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
599 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
600 QList<ModuleBase_ViewerPrsPtr> aPrsList =
601 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
602 int aSelected = aPrsList.size();
603 QActionsList aActions;
605 // Create selection menu
606 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
608 myWorkshop->module()->activeSelectionModes(aModes);
609 if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
610 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
611 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
612 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
613 aSelMenu->addAction(action("SELECT_FACE_CMD"));
614 //IMP: an attempt to use result selection with other selection modes
615 //aSelMenu->addSeparator();
616 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
617 theMenu->addMenu(aSelMenu);
618 theMenu->addSeparator();
620 if (aSelected == 1) {
621 ObjectPtr aObject = aPrsList.first()->object();
622 if (aObject.get() != NULL) {
623 std::string aName = aObject->groupName();
624 if (myViewerMenu.contains(aName))
625 aActions = myViewerMenu[aName];
627 } else if (aSelected > 1) {
628 aActions.append(action("HIDE_CMD"));
630 // hide all is shown always even if selection in the viewer is empty
631 aActions.append(action("HIDEALL_CMD"));
632 aActions.append(action("COLOR_CMD"));
633 aActions.append(action("DEFLECTION_CMD"));
635 theMenu->addActions(aActions);
637 QMap<int, QAction*> aMenuActions;
638 ModuleBase_IModule* aModule = myWorkshop->module();
640 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
641 theMenu->addSeparator();
644 // insert the module menu items on specific positions in the popup menu: some actions should be
645 // in the begin of the list, Delete action should be the last by #1343 issue
646 QList<QAction*> anActions = theMenu->actions();
647 int anActionsSize = anActions.size();
648 QAction* aFirstAction = anActions[0];
649 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
650 for (; anIt != aLast; anIt++) {
651 if (anIt.key() > anActionsSize)
652 theMenu->addAction(anIt.value());
654 theMenu->insertAction(aFirstAction, *anIt);
658 theMenu->addSeparator();
659 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
660 if (aMDI->actions().size() > 0) {
661 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
662 aSubMenu->addActions(aMDI->actions());
667 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
671 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
672 aLast = myObjBrowserMenus.end();
673 for (; anIt != aLast; anIt++) {
674 QString aGroupName(anIt.key().c_str());
675 if (aGroups.contains(aGroupName))
677 QActionsList anActions = anIt.value();
678 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
680 for (; anAIt != anALast && !aFound; anAIt++)
681 aFound = (*anAIt)->data().toString() == theName;
683 aGroups.append(aGroupName);
688 void XGUI_ContextMenuMgr::onRename()
690 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
691 if (!myWorkshop->abortAllOperations())
693 // restore selection in case if dialog box was shown
694 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
695 myWorkshop->objectBrowser()->onEditItem();
698 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
700 SessionPtr aMgr = ModelAPI_Session::get();
701 DocumentPtr aActiveDoc = aMgr->activeDocument();
703 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
704 XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
705 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
706 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
710 bool aIsRoot = false;
711 foreach(QModelIndex aIdx, aSelectedIndexes) {
712 // Process only first column
713 if (aIdx.column() == 0) {
714 aIsRoot = !aIdx.parent().isValid();
715 // Exit if the selected index belongs to non active document
716 if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
718 if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
721 // Get name of the selected index
722 aName = aIdx.data().toString();
723 aLen = aName.indexOf('(');
725 aName = aName.left(--aLen);
727 std::string aFeaturesStr = aIsRoot?
728 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
729 aDataModelXML->subFolderFeatures(aName.toStdString());
730 if (aFeaturesStr.length() > 0) {
731 QStringList aFeturesList =
732 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
733 foreach(QString aFea, aFeturesList) {
734 QAction* aAction = aActionMgr->action(aFea);
736 theMenu->addAction(aAction);
743 #define UNCHECK_ACTION(NAME) \
744 { QAction* aAction = action(NAME); \
745 bool isBlock = aAction->signalsBlocked(); \
746 aAction->blockSignals(true); \
747 aAction->setChecked(false); \
748 aAction->blockSignals(isBlock); }
751 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
753 UNCHECK_ACTION("SELECT_VERTEX_CMD");
754 UNCHECK_ACTION("SELECT_EDGE_CMD");
755 UNCHECK_ACTION("SELECT_FACE_CMD");
758 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
760 UNCHECK_ACTION("SHOW_RESULTS_CMD");