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("TInspector"), aDesktop);
156 addAction("TINSPECTOR_VIEW", aAction);
159 buildObjBrowserMenu();
163 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
165 if (myActions.contains(theId))
166 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
167 theAction->setData(theId);
168 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
169 myActions[theId] = theAction;
172 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
174 if (myActions.contains(theId))
175 return myActions[theId];
179 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
181 foreach(QAction* eachAction, myActions) {
182 if (eachAction->text() == theName) {
189 QStringList XGUI_ContextMenuMgr::actionIds() const
191 return myActions.keys();
194 void XGUI_ContextMenuMgr::onAction(bool isChecked)
196 QAction* aAction = static_cast<QAction*>(sender());
197 emit actionTriggered(aAction->data().toString(), isChecked);
200 void XGUI_ContextMenuMgr::updateCommandsStatus()
204 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
206 QMenu* aMenu = new QMenu();
207 if (sender() == myWorkshop->objectBrowser()) {
208 updateObjectBrowserMenu();
209 addObjBrowserMenu(aMenu);
210 } else if (sender() == myWorkshop->viewer()) {
212 addViewerMenu(aMenu);
215 if (aMenu && (aMenu->actions().size() > 0)) {
216 // it is possible that some objects should do something before and after the popup menu exec
217 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
219 emit beforeContextMenu();
220 aMenu->exec(theEvent->globalPos());
221 emit afterContextMenu();
226 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
228 foreach(QAction* aAction, myActions)
229 aAction->setEnabled(false);
231 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
232 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
233 int aSelected = aObjects.size();
235 SessionPtr aMgr = ModelAPI_Session::get();
236 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
237 bool hasResult = false;
238 bool hasFeature = false;
239 bool hasParameter = false;
240 bool hasCompositeOwner = false;
241 bool hasResultInHistory = false;
242 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
243 hasCompositeOwner, hasResultInHistory);
245 if (aSelected == 1) {
246 ObjectPtr aObject = aObjects.first();
248 if (hasResult && myWorkshop->canBeShaded(aObject)) {
249 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
250 if (aMode != XGUI_Displayer::NoMode) {
251 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
252 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
254 action("WIREFRAME_CMD")->setEnabled(true);
255 action("SHADING_CMD")->setEnabled(true);
259 bool aHasSubResults = ModelAPI_Tools::hasSubResults(
260 std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
261 if (aHasSubResults) {
262 action("HIDE_CMD")->setEnabled(true);
263 action("SHOW_CMD")->setEnabled(true);
266 if (aObject->isDisplayed()) {
267 action("HIDE_CMD")->setEnabled(true);
268 } else if (hasResult && (!hasParameter)) {
269 action("SHOW_CMD")->setEnabled(true);
272 if (!(hasParameter || hasFeature))
273 action("SHOW_ONLY_CMD")->setEnabled(true);
275 else if (hasFeature && myWorkshop->canMoveFeature())
276 action("MOVE_CMD")->setEnabled(true);
278 if( aMgr->activeDocument() == aObject->document() )
280 action("RENAME_CMD")->setEnabled(true);
281 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
282 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
283 (hasFeature || hasParameter));
287 // parameter is commented because the actions are not in the list of result parameter actions
288 if (hasResult /*&& (!hasParameter)*/) {
289 action("SHOW_CMD")->setEnabled(true);
290 action("HIDE_CMD")->setEnabled(true);
291 action("SHOW_ONLY_CMD")->setEnabled(true);
292 action("SHADING_CMD")->setEnabled(true);
293 action("WIREFRAME_CMD")->setEnabled(true);
296 bool allActive = true;
297 foreach( ObjectPtr aObject, aObjects )
298 if( aMgr->activeDocument() != aObject->document() ) {
302 if (!hasCompositeOwner && allActive ) {
303 if (hasFeature || hasParameter)
304 action("DELETE_CMD")->setEnabled(true);
306 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
307 action("CLEAN_HISTORY_CMD")->setEnabled(true);
309 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
310 action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory);
313 // Show/Hide command has to be disabled for objects from non active document
314 bool aDeactivate = false;
315 foreach (ObjectPtr aObj, aObjects) {
316 if (!aObj->document()->isActive()) {
317 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
318 aObj->groupName() == ModelAPI_ResultPart::group()) {
325 // If at leas a one objec can not be edited then Show/Hide has to be disabled
326 action("SHOW_CMD")->setEnabled(false);
327 action("HIDE_CMD")->setEnabled(false);
328 action("SHOW_ONLY_CMD")->setEnabled(false);
331 if (myWorkshop->canChangeColor())
332 action("COLOR_CMD")->setEnabled(true);
334 if (myWorkshop->canChangeDeflection())
335 action("DEFLECTION_CMD")->setEnabled(true);
339 action("TINSPECTOR_VIEW")->setEnabled(true);
344 ModuleBase_IModule* aModule = myWorkshop->module();
346 aModule->updateObjectBrowserMenu(myActions);
349 void XGUI_ContextMenuMgr::updateViewerMenu()
351 foreach(QAction* aAction, myActions)
352 aAction->setEnabled(false);
354 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
355 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
356 QList<ModuleBase_ViewerPrsPtr> aPrsList =
357 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
358 if (aPrsList.size() > 0) {
359 bool isVisible = false;
360 bool isShading = false;
361 bool canBeShaded = false;
363 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
364 aObject = aPrs->object();
365 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
366 if (aRes && aRes->isDisplayed()) {
368 canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
370 (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
376 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
377 if (aMode != XGUI_Displayer::NoMode) {
378 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
379 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
381 action("WIREFRAME_CMD")->setEnabled(true);
382 action("SHADING_CMD")->setEnabled(true);
385 action("SHOW_ONLY_CMD")->setEnabled(true);
386 action("HIDE_CMD")->setEnabled(true);
388 action("SHOW_CMD")->setEnabled(true);
390 if (myWorkshop->displayer()->objectsCount() > 0)
391 action("HIDEALL_CMD")->setEnabled(true);
393 // Update selection menu
394 QIntList aModes = aDisplayer->activeSelectionModes();
395 action("SELECT_VERTEX_CMD")->setEnabled(true);
396 action("SELECT_EDGE_CMD")->setEnabled(true);
397 action("SELECT_FACE_CMD")->setEnabled(true);
398 action("SELECT_RESULT_CMD")->setEnabled(true);
400 action("SELECT_RESULT_CMD")->setChecked(false);
401 action("SELECT_VERTEX_CMD")->setChecked(false);
402 action("SELECT_EDGE_CMD")->setChecked(false);
403 action("SELECT_FACE_CMD")->setChecked(false);
404 action("SELECT_RESULT_CMD")->setChecked(false);
405 if (aModes.count() == 0) {
406 action("SELECT_RESULT_CMD")->setChecked(true);
408 foreach(int aMode, aModes) {
411 action("SELECT_VERTEX_CMD")->setChecked(true);
414 action("SELECT_EDGE_CMD")->setChecked(true);
417 action("SELECT_FACE_CMD")->setChecked(true);
420 action("SELECT_RESULT_CMD")->setChecked(true);
425 ModuleBase_IModule* aModule = myWorkshop->module();
427 aModule->updateViewerMenu(myActions);
429 if (myWorkshop->canChangeColor())
430 action("COLOR_CMD")->setEnabled(true);
432 if (myWorkshop->canChangeDeflection())
433 action("DEFLECTION_CMD")->setEnabled(true);
435 action("DELETE_CMD")->setEnabled(true);
438 void XGUI_ContextMenuMgr::connectObjectBrowser()
440 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
441 SLOT(onContextMenuRequest(QContextMenuEvent*)));
444 void XGUI_ContextMenuMgr::connectViewer()
446 connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
447 SLOT(onContextMenuRequest(QContextMenuEvent*)));
451 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
453 QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
454 aSeparator->setSeparator(true);
458 // Result construction menu
459 aList.append(action("SHOW_CMD"));
460 aList.append(action("HIDE_CMD"));
461 aList.append(action("SHOW_ONLY_CMD"));
462 aList.append(mySeparator);
463 aList.append(action("RENAME_CMD"));
464 aList.append(action("COLOR_CMD"));
465 aList.append(action("DEFLECTION_CMD"));
466 aList.append(action("SHOW_FEATURE_CMD"));
467 myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
469 //-------------------------------------
472 aList.append(action("WIREFRAME_CMD"));
473 aList.append(action("SHADING_CMD"));
474 aList.append(mySeparator); // this separator is not shown as this action is added after show only
475 // qt list container contains only one instance of the same action
476 aList.append(action("SHOW_CMD"));
477 aList.append(action("HIDE_CMD"));
478 aList.append(action("SHOW_ONLY_CMD"));
479 aList.append(mySeparator);
480 aList.append(action("RENAME_CMD"));
481 aList.append(action("COLOR_CMD"));
482 aList.append(action("DEFLECTION_CMD"));
483 aList.append(action("SHOW_FEATURE_CMD"));
484 myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
486 myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
487 myObjBrowserMenus[ModelAPI_ResultField::group()] = aList;
489 myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
490 //-------------------------------------
493 aList.append(action("RENAME_CMD"));
494 aList.append(action("SHOW_RESULTS_CMD"));
495 aList.append(action("MOVE_CMD"));
496 aList.append(mySeparator);
497 aList.append(action("CLEAN_HISTORY_CMD"));
498 aList.append(action("DELETE_CMD"));
499 myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
502 aList.append(action("RENAME_CMD"));
503 aList.append(mySeparator);
504 aList.append(action("CLEAN_HISTORY_CMD"));
505 aList.append(action("DELETE_CMD"));
506 myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
507 //-------------------------------------
510 void XGUI_ContextMenuMgr::buildViewerMenu()
513 // Result construction menu
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_ResultConstruction::group()] = aList;
521 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
522 //-------------------------------------
525 aList.append(action("WIREFRAME_CMD"));
526 aList.append(action("SHADING_CMD"));
527 aList.append(mySeparator);
528 aList.append(action("HIDE_CMD"));
529 aList.append(action("SHOW_ONLY_CMD"));
530 aList.append(mySeparator);
531 aList.append(action("COLOR_CMD"));
532 aList.append(action("DEFLECTION_CMD"));
533 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
535 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
536 myViewerMenu[ModelAPI_ResultField::group()] = aList;
537 //-------------------------------------
541 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
543 ModuleBase_IModule* aModule = myWorkshop->module();
545 theMenu->addSeparator();
546 aModule->addObjectBrowserMenu(theMenu);
549 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
550 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
551 int aSelected = aObjects.size();
552 QActionsList aActions;
553 if (aSelected == 1) {
554 ObjectPtr aObject = aObjects.first();
555 std::string aName = aObject->groupName();
556 if (myObjBrowserMenus.contains(aName))
557 aActions = myObjBrowserMenus[aName];
558 } else if (aSelected > 1) {
559 aActions.append(action("WIREFRAME_CMD"));
560 aActions.append(action("SHADING_CMD"));
561 aActions.append(mySeparator);
562 aActions.append(action("SHOW_CMD"));
563 aActions.append(action("HIDE_CMD"));
564 aActions.append(action("SHOW_ONLY_CMD"));
565 aActions.append(mySeparator);
566 //aActions.append(action("MOVE_CMD"));
567 aActions.append(action("COLOR_CMD"));
568 aActions.append(action("DEFLECTION_CMD"));
570 aActions.append(action("CLEAN_HISTORY_CMD"));
571 aActions.append(action("DELETE_CMD"));
574 if (aSelected == 0) {
576 aActions.append(action("TINSPECTOR_VIEW"));
580 theMenu->addActions(aActions);
581 addFeatures(theMenu);
583 // It is commented out because Object Browser does not have actions
584 //theMenu->addSeparator();
585 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
588 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
590 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
591 QList<ModuleBase_ViewerPrsPtr> aPrsList =
592 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
593 int aSelected = aPrsList.size();
594 QActionsList aActions;
596 // Create selection menu
597 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
599 myWorkshop->module()->activeSelectionModes(aModes);
600 if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
601 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
602 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
603 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
604 aSelMenu->addAction(action("SELECT_FACE_CMD"));
605 //IMP: an attempt to use result selection with other selection modes
606 //aSelMenu->addSeparator();
607 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
608 theMenu->addMenu(aSelMenu);
609 theMenu->addSeparator();
611 if (aSelected == 1) {
612 ObjectPtr aObject = aPrsList.first()->object();
613 if (aObject.get() != NULL) {
614 std::string aName = aObject->groupName();
615 if (myViewerMenu.contains(aName))
616 aActions = myViewerMenu[aName];
618 } else if (aSelected > 1) {
619 aActions.append(action("HIDE_CMD"));
621 // hide all is shown always even if selection in the viewer is empty
622 aActions.append(action("HIDEALL_CMD"));
623 aActions.append(action("COLOR_CMD"));
624 aActions.append(action("DEFLECTION_CMD"));
626 theMenu->addActions(aActions);
628 QMap<int, QAction*> aMenuActions;
629 ModuleBase_IModule* aModule = myWorkshop->module();
631 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
632 theMenu->addSeparator();
635 // insert the module menu items on specific positions in the popup menu: some actions should be
636 // in the begin of the list, Delete action should be the last by #1343 issue
637 QList<QAction*> anActions = theMenu->actions();
638 int anActionsSize = anActions.size();
639 QAction* aFirstAction = anActions[0];
640 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
641 for (; anIt != aLast; anIt++) {
642 if (anIt.key() > anActionsSize)
643 theMenu->addAction(anIt.value());
645 theMenu->insertAction(aFirstAction, *anIt);
649 theMenu->addSeparator();
650 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
651 if (aMDI->actions().size() > 0) {
652 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
653 aSubMenu->addActions(aMDI->actions());
658 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
662 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
663 aLast = myObjBrowserMenus.end();
664 for (; anIt != aLast; anIt++) {
665 QString aGroupName(anIt.key().c_str());
666 if (aGroups.contains(aGroupName))
668 QActionsList anActions = anIt.value();
669 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
671 for (; anAIt != anALast && !aFound; anAIt++)
672 aFound = (*anAIt)->data().toString() == theName;
674 aGroups.append(aGroupName);
679 void XGUI_ContextMenuMgr::onRename()
681 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
682 if (!myWorkshop->abortAllOperations())
684 // restore selection in case if dialog box was shown
685 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
686 myWorkshop->objectBrowser()->onEditItem();
689 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
691 SessionPtr aMgr = ModelAPI_Session::get();
692 DocumentPtr aActiveDoc = aMgr->activeDocument();
694 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
695 XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
696 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
697 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
701 bool aIsRoot = false;
702 foreach(QModelIndex aIdx, aSelectedIndexes) {
703 // Process only first column
704 if (aIdx.column() == 0) {
705 aIsRoot = !aIdx.parent().isValid();
706 // Exit if the selected index belongs to non active document
707 if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
709 if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
712 // Get name of the selected index
713 aName = aIdx.data().toString();
714 aLen = aName.indexOf('(');
716 aName = aName.left(--aLen);
718 std::string aFeaturesStr = aIsRoot?
719 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
720 aDataModelXML->subFolderFeatures(aName.toStdString());
721 if (aFeaturesStr.length() > 0) {
722 QStringList aFeturesList =
723 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
724 foreach(QString aFea, aFeturesList) {
725 QAction* aAction = aActionMgr->action(aFea);
727 theMenu->addAction(aAction);
734 #define UNCHECK_ACTION(NAME) \
735 { QAction* aAction = action(NAME); \
736 bool isBlock = aAction->signalsBlocked(); \
737 aAction->blockSignals(true); \
738 aAction->setChecked(false); \
739 aAction->blockSignals(isBlock); }
742 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
744 UNCHECK_ACTION("SELECT_VERTEX_CMD");
745 UNCHECK_ACTION("SELECT_EDGE_CMD");
746 UNCHECK_ACTION("SELECT_FACE_CMD");
749 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
751 UNCHECK_ACTION("SHOW_RESULTS_CMD");