1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "XGUI_ContextMenuMgr.h"
21 #include "XGUI_Workshop.h"
22 #include "XGUI_ObjectsBrowser.h"
23 #include "XGUI_SelectionMgr.h"
24 #include "XGUI_Displayer.h"
25 #include "XGUI_ViewerProxy.h"
26 #include "XGUI_Selection.h"
27 #include "XGUI_SalomeConnector.h"
28 #include "XGUI_DataModel.h"
29 #include "XGUI_OperationMgr.h"
30 #include "XGUI_Tools.h"
31 #include "XGUI_ActionsMgr.h"
34 #include <AppElements_MainWindow.h>
37 //#include "PartSetPlugin_Part.h"
39 #include <ModelAPI_Data.h>
40 #include <ModelAPI_AttributeDocRef.h>
41 #include <ModelAPI_Object.h>
42 #include <ModelAPI_Session.h>
43 #include <ModelAPI_ResultGroup.h>
44 #include <ModelAPI_ResultParameter.h>
45 #include <ModelAPI_ResultConstruction.h>
46 #include <ModelAPI_ResultBody.h>
47 #include <ModelAPI_Tools.h>
48 #include <ModelAPI_ResultField.h>
50 #include <Config_DataModelReader.h>
52 #include <ModuleBase_IModule.h>
53 #include <ModuleBase_Tools.h>
54 #include <ModuleBase_OperationAction.h>
55 #include <ModuleBase_ViewerPrs.h>
58 #include <QActionGroup>
59 #include <QContextMenuEvent>
62 #include <QMainWindow>
63 #include <QModelIndex>
65 XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
67 myWorkshop(theParent),
72 XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr()
76 void XGUI_ContextMenuMgr::createActions()
79 QMainWindow* aDesktop = myWorkshop->salomeConnector()->desktop();
81 QMainWindow* aDesktop = myWorkshop->mainWindow();
84 QAction* aAction = ModuleBase_Tools::createAction(QIcon(":pictures/delete.png"), tr("Delete"),
86 aDesktop->addAction(aAction);
88 addAction("DELETE_CMD", aAction);
89 aAction->setShortcutContext(Qt::ApplicationShortcut);
91 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/rename_edit.png"), tr("Rename"),
92 aDesktop, this, SLOT(onRename()));
93 addAction("RENAME_CMD", aAction);
95 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move.png"),
96 XGUI_Workshop::MOVE_TO_END_COMMAND, this);
97 addAction("MOVE_CMD", aAction);
99 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/clean_history.png"),
100 tr("Clean history"), aDesktop);
101 addAction("CLEAN_HISTORY_CMD", aAction);
103 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop);
104 addAction("COLOR_CMD", aAction);
106 aAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
107 addAction("DEFLECTION_CMD", aAction);
109 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
110 addAction("SHOW_CMD", aAction);
112 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show only"),
114 addAction("SHOW_ONLY_CMD", aAction);
116 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"),
118 addAction("HIDE_CMD", aAction);
120 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide all"),
122 addAction("HIDEALL_CMD", aAction);
124 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"), tr("Shading"), aDesktop);
125 addAction("SHADING_CMD", aAction);
127 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"),
129 addAction("WIREFRAME_CMD", aAction);
131 mySeparator = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
132 mySeparator->setSeparator(true);
134 //mySelectActions = new QActionGroup(this);
135 //mySelectActions->setExclusive(true);
137 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
138 this, SLOT(onShapeSelection(bool)));
139 aAction->setCheckable(true);
140 addAction("SELECT_VERTEX_CMD", aAction);
141 //mySelectActions->addAction(aAction);
143 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
144 this, SLOT(onShapeSelection(bool)));
145 aAction->setCheckable(true);
146 addAction("SELECT_EDGE_CMD", aAction);
147 //mySelectActions->addAction(aAction);
149 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
150 this, SLOT(onShapeSelection(bool)));
151 aAction->setCheckable(true);
152 addAction("SELECT_FACE_CMD", aAction);
153 //mySelectActions->addAction(aAction);
155 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop,
156 this, SLOT(onResultSelection(bool)));
157 aAction->setCheckable(true);
158 addAction("SELECT_RESULT_CMD", aAction);
159 //mySelectActions->addAction(aAction);
161 aAction->setChecked(true);
163 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
164 tr("Select results"), aDesktop);
165 addAction("SHOW_RESULTS_CMD", aAction);
167 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
168 tr("Select parent feature"), aDesktop);
169 addAction("SHOW_FEATURE_CMD", aAction);
172 aAction = ModuleBase_Tools::createAction(QIcon(), tr("TInspector"), aDesktop);
173 addAction("TINSPECTOR_VIEW", aAction);
176 buildObjBrowserMenu();
180 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
182 if (myActions.contains(theId))
183 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
184 theAction->setData(theId);
185 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
186 myActions[theId] = theAction;
189 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
191 if (myActions.contains(theId))
192 return myActions[theId];
196 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
198 foreach(QAction* eachAction, myActions) {
199 if (eachAction->text() == theName) {
206 QStringList XGUI_ContextMenuMgr::actionIds() const
208 return myActions.keys();
211 void XGUI_ContextMenuMgr::onAction(bool isChecked)
213 QAction* aAction = static_cast<QAction*>(sender());
214 emit actionTriggered(aAction->data().toString(), isChecked);
217 void XGUI_ContextMenuMgr::updateCommandsStatus()
221 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
223 QMenu* aMenu = new QMenu();
224 if (sender() == myWorkshop->objectBrowser()) {
225 updateObjectBrowserMenu();
226 addObjBrowserMenu(aMenu);
227 } else if (sender() == myWorkshop->viewer()) {
229 addViewerMenu(aMenu);
232 if (aMenu && (aMenu->actions().size() > 0)) {
233 // it is possible that some objects should do something before and after the popup menu exec
234 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
236 emit beforeContextMenu();
237 aMenu->exec(theEvent->globalPos());
238 emit afterContextMenu();
243 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
245 foreach(QAction* aAction, myActions)
246 aAction->setEnabled(false);
248 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
249 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
250 int aSelected = aObjects.size();
252 SessionPtr aMgr = ModelAPI_Session::get();
253 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
254 bool hasResult = false;
255 bool hasFeature = false;
256 bool hasParameter = false;
257 bool hasCompositeOwner = false;
258 bool hasResultInHistory = false;
259 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
260 hasCompositeOwner, hasResultInHistory);
262 if (aSelected == 1) {
263 ObjectPtr aObject = aObjects.first();
265 if (hasResult && myWorkshop->canBeShaded(aObject)) {
266 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
267 if (aMode != XGUI_Displayer::NoMode) {
268 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
269 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
271 action("WIREFRAME_CMD")->setEnabled(true);
272 action("SHADING_CMD")->setEnabled(true);
276 bool aHasSubResults = ModelAPI_Tools::hasSubResults(
277 std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
278 if (aHasSubResults) {
279 action("HIDE_CMD")->setEnabled(true);
280 action("SHOW_CMD")->setEnabled(true);
283 if (aObject->isDisplayed()) {
284 action("HIDE_CMD")->setEnabled(true);
285 } else if (hasResult && (!hasParameter)) {
286 action("SHOW_CMD")->setEnabled(true);
289 if (!(hasParameter || hasFeature))
290 action("SHOW_ONLY_CMD")->setEnabled(true);
292 else if (hasFeature && myWorkshop->canMoveFeature())
293 action("MOVE_CMD")->setEnabled(true);
295 if( aMgr->activeDocument() == aObject->document() )
297 action("RENAME_CMD")->setEnabled(true);
298 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
299 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
300 (hasFeature || hasParameter));
304 // parameter is commented because the actions are not in the list of result parameter actions
305 if (hasResult /*&& (!hasParameter)*/) {
306 action("SHOW_CMD")->setEnabled(true);
307 action("HIDE_CMD")->setEnabled(true);
308 action("SHOW_ONLY_CMD")->setEnabled(true);
309 action("SHADING_CMD")->setEnabled(true);
310 action("WIREFRAME_CMD")->setEnabled(true);
313 bool allActive = true;
314 foreach( ObjectPtr aObject, aObjects )
315 if( aMgr->activeDocument() != aObject->document() ) {
319 if (!hasCompositeOwner && allActive ) {
320 if (hasFeature || hasParameter)
321 action("DELETE_CMD")->setEnabled(true);
323 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
324 action("CLEAN_HISTORY_CMD")->setEnabled(true);
326 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
327 action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory);
330 // Show/Hide command has to be disabled for objects from non active document
331 bool aDeactivate = false;
332 foreach (ObjectPtr aObj, aObjects) {
333 if (!aObj->document()->isActive()) {
334 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
335 aObj->groupName() == ModelAPI_ResultPart::group()) {
342 // If at leas a one objec can not be edited then Show/Hide has to be disabled
343 action("SHOW_CMD")->setEnabled(false);
344 action("HIDE_CMD")->setEnabled(false);
345 action("SHOW_ONLY_CMD")->setEnabled(false);
348 if (myWorkshop->canChangeColor())
349 action("COLOR_CMD")->setEnabled(true);
351 if (myWorkshop->canChangeDeflection())
352 action("DEFLECTION_CMD")->setEnabled(true);
356 action("TINSPECTOR_VIEW")->setEnabled(true);
361 ModuleBase_IModule* aModule = myWorkshop->module();
363 aModule->updateObjectBrowserMenu(myActions);
366 void XGUI_ContextMenuMgr::updateViewerMenu()
368 foreach(QAction* aAction, myActions)
369 aAction->setEnabled(false);
371 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
372 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
373 QList<ModuleBase_ViewerPrsPtr> aPrsList =
374 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
375 if (aPrsList.size() > 0) {
376 bool isVisible = false;
377 bool isShading = false;
378 bool canBeShaded = false;
380 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
381 aObject = aPrs->object();
382 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
383 if (aRes && aRes->isDisplayed()) {
385 canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
387 (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
393 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
394 if (aMode != XGUI_Displayer::NoMode) {
395 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
396 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
398 action("WIREFRAME_CMD")->setEnabled(true);
399 action("SHADING_CMD")->setEnabled(true);
402 action("SHOW_ONLY_CMD")->setEnabled(true);
403 action("HIDE_CMD")->setEnabled(true);
405 action("SHOW_CMD")->setEnabled(true);
407 //issue #2159 Hide all incomplete behavior
409 action("HIDEALL_CMD")->setEnabled(true);
411 if (myWorkshop->displayer()->objectsCount() > 0)
412 action("HIDEALL_CMD")->setEnabled(true);
415 // Update selection menu
416 QIntList aModes = aDisplayer->activeSelectionModes();
417 action("SELECT_VERTEX_CMD")->setEnabled(true);
418 action("SELECT_EDGE_CMD")->setEnabled(true);
419 action("SELECT_FACE_CMD")->setEnabled(true);
420 action("SELECT_RESULT_CMD")->setEnabled(true);
422 action("SELECT_RESULT_CMD")->setChecked(false);
423 action("SELECT_VERTEX_CMD")->setChecked(false);
424 action("SELECT_EDGE_CMD")->setChecked(false);
425 action("SELECT_FACE_CMD")->setChecked(false);
426 action("SELECT_RESULT_CMD")->setChecked(false);
427 if (aModes.count() == 0) {
428 action("SELECT_RESULT_CMD")->setChecked(true);
430 foreach(int aMode, aModes) {
433 action("SELECT_VERTEX_CMD")->setChecked(true);
436 action("SELECT_EDGE_CMD")->setChecked(true);
439 action("SELECT_FACE_CMD")->setChecked(true);
442 action("SELECT_RESULT_CMD")->setChecked(true);
447 ModuleBase_IModule* aModule = myWorkshop->module();
449 aModule->updateViewerMenu(myActions);
451 if (myWorkshop->canChangeColor())
452 action("COLOR_CMD")->setEnabled(true);
454 if (myWorkshop->canChangeDeflection())
455 action("DEFLECTION_CMD")->setEnabled(true);
457 action("DELETE_CMD")->setEnabled(true);
460 void XGUI_ContextMenuMgr::connectObjectBrowser()
462 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
463 SLOT(onContextMenuRequest(QContextMenuEvent*)));
466 void XGUI_ContextMenuMgr::connectViewer()
468 connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
469 SLOT(onContextMenuRequest(QContextMenuEvent*)));
473 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
475 QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
476 aSeparator->setSeparator(true);
480 // Result construction menu
481 aList.append(action("SHOW_CMD"));
482 aList.append(action("HIDE_CMD"));
483 aList.append(action("SHOW_ONLY_CMD"));
484 aList.append(mySeparator);
485 aList.append(action("RENAME_CMD"));
486 aList.append(action("COLOR_CMD"));
487 aList.append(action("DEFLECTION_CMD"));
488 aList.append(action("SHOW_FEATURE_CMD"));
489 myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
491 //-------------------------------------
494 aList.append(action("WIREFRAME_CMD"));
495 aList.append(action("SHADING_CMD"));
496 aList.append(mySeparator); // this separator is not shown as this action is added after show only
497 // qt list container contains only one instance of the same action
498 aList.append(action("SHOW_CMD"));
499 aList.append(action("HIDE_CMD"));
500 aList.append(action("SHOW_ONLY_CMD"));
501 aList.append(mySeparator);
502 aList.append(action("RENAME_CMD"));
503 aList.append(action("COLOR_CMD"));
504 aList.append(action("DEFLECTION_CMD"));
505 aList.append(action("SHOW_FEATURE_CMD"));
506 myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
508 myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
509 myObjBrowserMenus[ModelAPI_ResultField::group()] = aList;
511 myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
512 //-------------------------------------
515 aList.append(action("RENAME_CMD"));
516 aList.append(action("SHOW_RESULTS_CMD"));
517 aList.append(action("MOVE_CMD"));
518 aList.append(mySeparator);
519 aList.append(action("CLEAN_HISTORY_CMD"));
520 aList.append(action("DELETE_CMD"));
521 myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
524 aList.append(action("RENAME_CMD"));
525 aList.append(mySeparator);
526 aList.append(action("CLEAN_HISTORY_CMD"));
527 aList.append(action("DELETE_CMD"));
528 myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
529 //-------------------------------------
532 void XGUI_ContextMenuMgr::buildViewerMenu()
535 // Result construction menu
536 aList.append(action("HIDE_CMD"));
537 aList.append(action("SHOW_ONLY_CMD"));
538 aList.append(mySeparator);
539 aList.append(action("COLOR_CMD"));
540 aList.append(action("DEFLECTION_CMD"));
541 myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
543 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
544 //-------------------------------------
547 aList.append(action("WIREFRAME_CMD"));
548 aList.append(action("SHADING_CMD"));
549 aList.append(mySeparator);
550 aList.append(action("HIDE_CMD"));
551 aList.append(action("SHOW_ONLY_CMD"));
552 aList.append(mySeparator);
553 aList.append(action("COLOR_CMD"));
554 aList.append(action("DEFLECTION_CMD"));
555 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
557 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
558 myViewerMenu[ModelAPI_ResultField::group()] = aList;
559 //-------------------------------------
563 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
565 ModuleBase_IModule* aModule = myWorkshop->module();
567 theMenu->addSeparator();
568 aModule->addObjectBrowserMenu(theMenu);
571 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
572 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
573 int aSelected = aObjects.size();
574 QActionsList aActions;
575 if (aSelected == 1) {
576 ObjectPtr aObject = aObjects.first();
577 std::string aName = aObject->groupName();
578 if (myObjBrowserMenus.contains(aName))
579 aActions = myObjBrowserMenus[aName];
580 } else if (aSelected > 1) {
581 aActions.append(action("WIREFRAME_CMD"));
582 aActions.append(action("SHADING_CMD"));
583 aActions.append(mySeparator);
584 aActions.append(action("SHOW_CMD"));
585 aActions.append(action("HIDE_CMD"));
586 aActions.append(action("SHOW_ONLY_CMD"));
587 aActions.append(mySeparator);
588 //aActions.append(action("MOVE_CMD"));
589 aActions.append(action("COLOR_CMD"));
590 aActions.append(action("DEFLECTION_CMD"));
592 aActions.append(action("CLEAN_HISTORY_CMD"));
593 aActions.append(action("DELETE_CMD"));
596 if (aSelected == 0) {
598 aActions.append(action("TINSPECTOR_VIEW"));
602 theMenu->addActions(aActions);
603 addFeatures(theMenu);
605 // It is commented out because Object Browser does not have actions
606 //theMenu->addSeparator();
607 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
610 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
612 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
613 QList<ModuleBase_ViewerPrsPtr> aPrsList =
614 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
615 int aSelected = aPrsList.size();
616 QActionsList aActions;
618 // Create selection menu
619 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
621 myWorkshop->module()->activeSelectionModes(aModes);
622 if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
623 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
624 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
625 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
626 aSelMenu->addAction(action("SELECT_FACE_CMD"));
627 //IMP: an attempt to use result selection with other selection modes
628 //aSelMenu->addSeparator();
629 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
630 theMenu->addMenu(aSelMenu);
631 theMenu->addSeparator();
633 if (aSelected == 1) {
634 ObjectPtr aObject = aPrsList.first()->object();
635 if (aObject.get() != NULL) {
636 std::string aName = aObject->groupName();
637 if (myViewerMenu.contains(aName))
638 aActions = myViewerMenu[aName];
640 } else if (aSelected > 1) {
641 aActions.append(action("HIDE_CMD"));
643 // hide all is shown always even if selection in the viewer is empty
644 aActions.append(action("HIDEALL_CMD"));
645 aActions.append(action("COLOR_CMD"));
646 aActions.append(action("DEFLECTION_CMD"));
648 theMenu->addActions(aActions);
650 QMap<int, QAction*> aMenuActions;
651 ModuleBase_IModule* aModule = myWorkshop->module();
653 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
654 theMenu->addSeparator();
657 // insert the module menu items on specific positions in the popup menu: some actions should be
658 // in the begin of the list, Delete action should be the last by #1343 issue
659 QList<QAction*> anActions = theMenu->actions();
660 int anActionsSize = anActions.size();
661 QAction* aFirstAction = anActions[0];
662 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
663 for (; anIt != aLast; anIt++) {
664 if (anIt.key() > anActionsSize)
665 theMenu->addAction(anIt.value());
667 theMenu->insertAction(aFirstAction, *anIt);
671 theMenu->addSeparator();
672 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
673 if (aMDI->actions().size() > 0) {
674 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
675 aSubMenu->addActions(aMDI->actions());
680 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
684 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
685 aLast = myObjBrowserMenus.end();
686 for (; anIt != aLast; anIt++) {
687 QString aGroupName(anIt.key().c_str());
688 if (aGroups.contains(aGroupName))
690 QActionsList anActions = anIt.value();
691 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
693 for (; anAIt != anALast && !aFound; anAIt++)
694 aFound = (*anAIt)->data().toString() == theName;
696 aGroups.append(aGroupName);
701 void XGUI_ContextMenuMgr::onRename()
703 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
704 if (!myWorkshop->abortAllOperations())
706 // restore selection in case if dialog box was shown
707 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
708 myWorkshop->objectBrowser()->onEditItem();
711 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
713 SessionPtr aMgr = ModelAPI_Session::get();
714 DocumentPtr aActiveDoc = aMgr->activeDocument();
716 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
717 XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
718 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
719 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
723 bool aIsRoot = false;
724 foreach(QModelIndex aIdx, aSelectedIndexes) {
725 // Process only first column
726 if (aIdx.column() == 0) {
727 aIsRoot = !aIdx.parent().isValid();
728 // Exit if the selected index belongs to non active document
729 if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
731 if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
734 // Get name of the selected index
735 aName = aIdx.data().toString();
736 aLen = aName.indexOf('(');
738 aName = aName.left(--aLen);
740 std::string aFeaturesStr = aIsRoot?
741 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
742 aDataModelXML->subFolderFeatures(aName.toStdString());
743 if (aFeaturesStr.length() > 0) {
744 QStringList aFeturesList =
745 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
746 foreach(QString aFea, aFeturesList) {
747 QAction* aAction = aActionMgr->action(aFea);
749 theMenu->addAction(aAction);
756 #define UNCHECK_ACTION(NAME) \
757 { QAction* aAction = action(NAME); \
758 bool isBlock = aAction->signalsBlocked(); \
759 aAction->blockSignals(true); \
760 aAction->setChecked(false); \
761 aAction->blockSignals(isBlock); }
764 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
766 UNCHECK_ACTION("SELECT_VERTEX_CMD");
767 UNCHECK_ACTION("SELECT_EDGE_CMD");
768 UNCHECK_ACTION("SELECT_FACE_CMD");
771 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
773 UNCHECK_ACTION("SHOW_RESULTS_CMD");