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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "XGUI_ContextMenuMgr.h"
22 #include "XGUI_Workshop.h"
23 #include "XGUI_ObjectsBrowser.h"
24 #include "XGUI_SelectionMgr.h"
25 #include "XGUI_Displayer.h"
26 #include "XGUI_ViewerProxy.h"
27 #include "XGUI_Selection.h"
28 #include "XGUI_SalomeConnector.h"
29 #include "XGUI_DataModel.h"
30 #include "XGUI_OperationMgr.h"
31 #include "XGUI_Tools.h"
32 #include "XGUI_ActionsMgr.h"
35 #include <AppElements_MainWindow.h>
38 //#include "PartSetPlugin_Part.h"
40 #include <ModelAPI_Data.h>
41 #include <ModelAPI_AttributeDocRef.h>
42 #include <ModelAPI_Object.h>
43 #include <ModelAPI_Session.h>
44 #include <ModelAPI_ResultGroup.h>
45 #include <ModelAPI_ResultParameter.h>
46 #include <ModelAPI_ResultConstruction.h>
47 #include <ModelAPI_ResultBody.h>
48 #include <ModelAPI_Tools.h>
49 #include <ModelAPI_ResultField.h>
51 #include <Config_DataModelReader.h>
53 #include <ModuleBase_IModule.h>
54 #include <ModuleBase_Tools.h>
55 #include <ModuleBase_OperationAction.h>
56 #include <ModuleBase_ViewerPrs.h>
59 #include <QActionGroup>
60 #include <QContextMenuEvent>
63 #include <QMainWindow>
64 #include <QModelIndex>
66 XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
68 myWorkshop(theParent),
73 XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr()
77 void XGUI_ContextMenuMgr::createActions()
80 QMainWindow* aDesktop = myWorkshop->salomeConnector()->desktop();
82 QMainWindow* aDesktop = myWorkshop->mainWindow();
85 QAction* aAction = ModuleBase_Tools::createAction(QIcon(":pictures/delete.png"), tr("Delete"),
87 aDesktop->addAction(aAction);
89 addAction("DELETE_CMD", aAction);
90 aAction->setShortcutContext(Qt::ApplicationShortcut);
92 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/rename_edit.png"), tr("Rename"),
93 aDesktop, this, SLOT(onRename()));
94 addAction("RENAME_CMD", aAction);
96 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move.png"),
97 XGUI_Workshop::MOVE_TO_END_COMMAND, this);
98 addAction("MOVE_CMD", aAction);
100 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/clean_history.png"),
101 tr("Clean history"), aDesktop);
102 addAction("CLEAN_HISTORY_CMD", aAction);
104 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop);
105 addAction("COLOR_CMD", aAction);
107 aAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
108 addAction("DEFLECTION_CMD", aAction);
110 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
111 addAction("SHOW_CMD", aAction);
113 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show only"),
115 addAction("SHOW_ONLY_CMD", aAction);
117 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"),
119 addAction("HIDE_CMD", aAction);
121 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide all"),
123 addAction("HIDEALL_CMD", aAction);
125 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"), tr("Shading"), aDesktop);
126 addAction("SHADING_CMD", aAction);
128 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"),
130 addAction("WIREFRAME_CMD", aAction);
132 mySeparator = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
133 mySeparator->setSeparator(true);
135 //mySelectActions = new QActionGroup(this);
136 //mySelectActions->setExclusive(true);
138 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
139 this, SLOT(onShapeSelection(bool)));
140 aAction->setCheckable(true);
141 addAction("SELECT_VERTEX_CMD", aAction);
142 //mySelectActions->addAction(aAction);
144 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
145 this, SLOT(onShapeSelection(bool)));
146 aAction->setCheckable(true);
147 addAction("SELECT_EDGE_CMD", aAction);
148 //mySelectActions->addAction(aAction);
150 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
151 this, SLOT(onShapeSelection(bool)));
152 aAction->setCheckable(true);
153 addAction("SELECT_FACE_CMD", aAction);
154 //mySelectActions->addAction(aAction);
156 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop,
157 this, SLOT(onResultSelection(bool)));
158 aAction->setCheckable(true);
159 addAction("SELECT_RESULT_CMD", aAction);
160 //mySelectActions->addAction(aAction);
162 aAction->setChecked(true);
164 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
165 tr("Select results"), aDesktop);
166 addAction("SHOW_RESULTS_CMD", aAction);
168 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
169 tr("Select parent feature"), aDesktop);
170 addAction("SHOW_FEATURE_CMD", aAction);
173 aAction = ModuleBase_Tools::createAction(QIcon(), tr("TInspector"), aDesktop);
174 addAction("TINSPECTOR_VIEW", aAction);
177 buildObjBrowserMenu();
181 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
183 if (myActions.contains(theId))
184 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
185 theAction->setData(theId);
186 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
187 myActions[theId] = theAction;
190 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
192 if (myActions.contains(theId))
193 return myActions[theId];
197 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
199 foreach(QAction* eachAction, myActions) {
200 if (eachAction->text() == theName) {
207 QStringList XGUI_ContextMenuMgr::actionIds() const
209 return myActions.keys();
212 void XGUI_ContextMenuMgr::onAction(bool isChecked)
214 QAction* aAction = static_cast<QAction*>(sender());
215 emit actionTriggered(aAction->data().toString(), isChecked);
218 void XGUI_ContextMenuMgr::updateCommandsStatus()
222 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
224 QMenu* aMenu = new QMenu();
225 if (sender() == myWorkshop->objectBrowser()) {
226 updateObjectBrowserMenu();
227 addObjBrowserMenu(aMenu);
228 } else if (sender() == myWorkshop->viewer()) {
230 addViewerMenu(aMenu);
233 if (aMenu && (aMenu->actions().size() > 0)) {
234 // it is possible that some objects should do something before and after the popup menu exec
235 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
237 emit beforeContextMenu();
238 aMenu->exec(theEvent->globalPos());
239 emit afterContextMenu();
244 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
246 foreach(QAction* aAction, myActions)
247 aAction->setEnabled(false);
249 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
250 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
251 int aSelected = aObjects.size();
253 SessionPtr aMgr = ModelAPI_Session::get();
254 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
255 bool hasResult = false;
256 bool hasFeature = false;
257 bool hasParameter = false;
258 bool hasCompositeOwner = false;
259 bool hasResultInHistory = false;
260 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
261 hasCompositeOwner, hasResultInHistory);
263 if (aSelected == 1) {
264 ObjectPtr aObject = aObjects.first();
266 if (hasResult && myWorkshop->canBeShaded(aObject)) {
267 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
268 if (aMode != XGUI_Displayer::NoMode) {
269 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
270 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
272 action("WIREFRAME_CMD")->setEnabled(true);
273 action("SHADING_CMD")->setEnabled(true);
277 bool aHasSubResults = ModelAPI_Tools::hasSubResults(
278 std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
279 if (aHasSubResults) {
280 action("HIDE_CMD")->setEnabled(true);
281 action("SHOW_CMD")->setEnabled(true);
284 if (aObject->isDisplayed()) {
285 action("HIDE_CMD")->setEnabled(true);
286 } else if (hasResult && (!hasParameter)) {
287 action("SHOW_CMD")->setEnabled(true);
290 if (!(hasParameter || hasFeature))
291 action("SHOW_ONLY_CMD")->setEnabled(true);
293 else if (hasFeature && myWorkshop->canMoveFeature())
294 action("MOVE_CMD")->setEnabled(true);
296 if( aMgr->activeDocument() == aObject->document() )
298 action("RENAME_CMD")->setEnabled(true);
299 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
300 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
301 (hasFeature || hasParameter));
305 // parameter is commented because the actions are not in the list of result parameter actions
306 if (hasResult /*&& (!hasParameter)*/) {
307 action("SHOW_CMD")->setEnabled(true);
308 action("HIDE_CMD")->setEnabled(true);
309 action("SHOW_ONLY_CMD")->setEnabled(true);
310 action("SHADING_CMD")->setEnabled(true);
311 action("WIREFRAME_CMD")->setEnabled(true);
314 bool allActive = true;
315 foreach( ObjectPtr aObject, aObjects )
316 if( aMgr->activeDocument() != aObject->document() ) {
320 if (!hasCompositeOwner && allActive ) {
321 if (hasFeature || hasParameter)
322 action("DELETE_CMD")->setEnabled(true);
324 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
325 action("CLEAN_HISTORY_CMD")->setEnabled(true);
327 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
328 action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory);
331 // Show/Hide command has to be disabled for objects from non active document
332 bool aDeactivate = false;
333 foreach (ObjectPtr aObj, aObjects) {
334 if (!aObj->document()->isActive()) {
335 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
336 aObj->groupName() == ModelAPI_ResultPart::group()) {
343 // If at leas a one objec can not be edited then Show/Hide has to be disabled
344 action("SHOW_CMD")->setEnabled(false);
345 action("HIDE_CMD")->setEnabled(false);
346 action("SHOW_ONLY_CMD")->setEnabled(false);
349 if (myWorkshop->canChangeColor())
350 action("COLOR_CMD")->setEnabled(true);
352 if (myWorkshop->canChangeDeflection())
353 action("DEFLECTION_CMD")->setEnabled(true);
357 action("TINSPECTOR_VIEW")->setEnabled(true);
362 ModuleBase_IModule* aModule = myWorkshop->module();
364 aModule->updateObjectBrowserMenu(myActions);
367 void XGUI_ContextMenuMgr::updateViewerMenu()
369 foreach(QAction* aAction, myActions)
370 aAction->setEnabled(false);
372 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
373 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
374 QList<ModuleBase_ViewerPrsPtr> aPrsList =
375 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
376 if (aPrsList.size() > 0) {
377 bool isVisible = false;
378 bool isShading = false;
379 bool canBeShaded = false;
381 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
382 aObject = aPrs->object();
383 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
384 if (aRes && aRes->isDisplayed()) {
386 canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
388 (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
394 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
395 if (aMode != XGUI_Displayer::NoMode) {
396 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
397 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
399 action("WIREFRAME_CMD")->setEnabled(true);
400 action("SHADING_CMD")->setEnabled(true);
403 action("SHOW_ONLY_CMD")->setEnabled(true);
404 action("HIDE_CMD")->setEnabled(true);
406 action("SHOW_CMD")->setEnabled(true);
408 //issue #2159 Hide all incomplete behavior
410 action("HIDEALL_CMD")->setEnabled(true);
412 if (myWorkshop->displayer()->objectsCount() > 0)
413 action("HIDEALL_CMD")->setEnabled(true);
416 // Update selection menu
417 QIntList aModes = aDisplayer->activeSelectionModes();
418 action("SELECT_VERTEX_CMD")->setEnabled(true);
419 action("SELECT_EDGE_CMD")->setEnabled(true);
420 action("SELECT_FACE_CMD")->setEnabled(true);
421 action("SELECT_RESULT_CMD")->setEnabled(true);
423 action("SELECT_RESULT_CMD")->setChecked(false);
424 action("SELECT_VERTEX_CMD")->setChecked(false);
425 action("SELECT_EDGE_CMD")->setChecked(false);
426 action("SELECT_FACE_CMD")->setChecked(false);
427 action("SELECT_RESULT_CMD")->setChecked(false);
428 if (aModes.count() == 0) {
429 action("SELECT_RESULT_CMD")->setChecked(true);
431 foreach(int aMode, aModes) {
434 action("SELECT_VERTEX_CMD")->setChecked(true);
437 action("SELECT_EDGE_CMD")->setChecked(true);
440 action("SELECT_FACE_CMD")->setChecked(true);
443 action("SELECT_RESULT_CMD")->setChecked(true);
448 ModuleBase_IModule* aModule = myWorkshop->module();
450 aModule->updateViewerMenu(myActions);
452 if (myWorkshop->canChangeColor())
453 action("COLOR_CMD")->setEnabled(true);
455 if (myWorkshop->canChangeDeflection())
456 action("DEFLECTION_CMD")->setEnabled(true);
458 action("DELETE_CMD")->setEnabled(true);
461 void XGUI_ContextMenuMgr::connectObjectBrowser()
463 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
464 SLOT(onContextMenuRequest(QContextMenuEvent*)));
467 void XGUI_ContextMenuMgr::connectViewer()
469 connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
470 SLOT(onContextMenuRequest(QContextMenuEvent*)));
474 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
476 QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
477 aSeparator->setSeparator(true);
481 // Result construction menu
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_ResultConstruction::group()] = aList;
492 //-------------------------------------
495 aList.append(action("WIREFRAME_CMD"));
496 aList.append(action("SHADING_CMD"));
497 aList.append(mySeparator); // this separator is not shown as this action is added after show only
498 // qt list container contains only one instance of the same action
499 aList.append(action("SHOW_CMD"));
500 aList.append(action("HIDE_CMD"));
501 aList.append(action("SHOW_ONLY_CMD"));
502 aList.append(mySeparator);
503 aList.append(action("RENAME_CMD"));
504 aList.append(action("COLOR_CMD"));
505 aList.append(action("DEFLECTION_CMD"));
506 aList.append(action("SHOW_FEATURE_CMD"));
507 myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
509 myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
510 myObjBrowserMenus[ModelAPI_ResultField::group()] = aList;
512 myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
513 //-------------------------------------
516 aList.append(action("RENAME_CMD"));
517 aList.append(action("SHOW_RESULTS_CMD"));
518 aList.append(action("MOVE_CMD"));
519 aList.append(mySeparator);
520 aList.append(action("CLEAN_HISTORY_CMD"));
521 aList.append(action("DELETE_CMD"));
522 myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
525 aList.append(action("RENAME_CMD"));
526 aList.append(mySeparator);
527 aList.append(action("CLEAN_HISTORY_CMD"));
528 aList.append(action("DELETE_CMD"));
529 myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
530 //-------------------------------------
533 void XGUI_ContextMenuMgr::buildViewerMenu()
536 // Result construction menu
537 aList.append(action("HIDE_CMD"));
538 aList.append(action("SHOW_ONLY_CMD"));
539 aList.append(mySeparator);
540 aList.append(action("COLOR_CMD"));
541 aList.append(action("DEFLECTION_CMD"));
542 myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
544 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
545 //-------------------------------------
548 aList.append(action("WIREFRAME_CMD"));
549 aList.append(action("SHADING_CMD"));
550 aList.append(mySeparator);
551 aList.append(action("HIDE_CMD"));
552 aList.append(action("SHOW_ONLY_CMD"));
553 aList.append(mySeparator);
554 aList.append(action("COLOR_CMD"));
555 aList.append(action("DEFLECTION_CMD"));
556 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
558 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
559 myViewerMenu[ModelAPI_ResultField::group()] = aList;
560 //-------------------------------------
564 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
566 ModuleBase_IModule* aModule = myWorkshop->module();
568 theMenu->addSeparator();
569 aModule->addObjectBrowserMenu(theMenu);
572 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
573 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
574 int aSelected = aObjects.size();
575 QActionsList aActions;
576 if (aSelected == 1) {
577 ObjectPtr aObject = aObjects.first();
578 std::string aName = aObject->groupName();
579 if (myObjBrowserMenus.contains(aName))
580 aActions = myObjBrowserMenus[aName];
581 } else if (aSelected > 1) {
582 aActions.append(action("WIREFRAME_CMD"));
583 aActions.append(action("SHADING_CMD"));
584 aActions.append(mySeparator);
585 aActions.append(action("SHOW_CMD"));
586 aActions.append(action("HIDE_CMD"));
587 aActions.append(action("SHOW_ONLY_CMD"));
588 aActions.append(mySeparator);
589 //aActions.append(action("MOVE_CMD"));
590 aActions.append(action("COLOR_CMD"));
591 aActions.append(action("DEFLECTION_CMD"));
593 aActions.append(action("CLEAN_HISTORY_CMD"));
594 aActions.append(action("DELETE_CMD"));
597 if (aSelected == 0) {
599 aActions.append(action("TINSPECTOR_VIEW"));
603 theMenu->addActions(aActions);
604 addFeatures(theMenu);
606 // It is commented out because Object Browser does not have actions
607 //theMenu->addSeparator();
608 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
611 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
613 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
614 QList<ModuleBase_ViewerPrsPtr> aPrsList =
615 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
616 int aSelected = aPrsList.size();
617 QActionsList aActions;
619 // Create selection menu
620 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
622 myWorkshop->module()->activeSelectionModes(aModes);
623 if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
624 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
625 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
626 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
627 aSelMenu->addAction(action("SELECT_FACE_CMD"));
628 //IMP: an attempt to use result selection with other selection modes
629 //aSelMenu->addSeparator();
630 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
631 theMenu->addMenu(aSelMenu);
632 theMenu->addSeparator();
634 if (aSelected == 1) {
635 ObjectPtr aObject = aPrsList.first()->object();
636 if (aObject.get() != NULL) {
637 std::string aName = aObject->groupName();
638 if (myViewerMenu.contains(aName))
639 aActions = myViewerMenu[aName];
641 } else if (aSelected > 1) {
642 aActions.append(action("HIDE_CMD"));
644 // hide all is shown always even if selection in the viewer is empty
645 aActions.append(action("HIDEALL_CMD"));
646 aActions.append(action("COLOR_CMD"));
647 aActions.append(action("DEFLECTION_CMD"));
649 theMenu->addActions(aActions);
651 QMap<int, QAction*> aMenuActions;
652 ModuleBase_IModule* aModule = myWorkshop->module();
654 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
655 theMenu->addSeparator();
658 // insert the module menu items on specific positions in the popup menu: some actions should be
659 // in the begin of the list, Delete action should be the last by #1343 issue
660 QList<QAction*> anActions = theMenu->actions();
661 int anActionsSize = anActions.size();
662 QAction* aFirstAction = anActions[0];
663 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
664 for (; anIt != aLast; anIt++) {
665 if (anIt.key() > anActionsSize)
666 theMenu->addAction(anIt.value());
668 theMenu->insertAction(aFirstAction, *anIt);
672 theMenu->addSeparator();
673 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
674 if (aMDI->actions().size() > 0) {
675 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
676 aSubMenu->addActions(aMDI->actions());
681 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
685 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
686 aLast = myObjBrowserMenus.end();
687 for (; anIt != aLast; anIt++) {
688 QString aGroupName(anIt.key().c_str());
689 if (aGroups.contains(aGroupName))
691 QActionsList anActions = anIt.value();
692 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
694 for (; anAIt != anALast && !aFound; anAIt++)
695 aFound = (*anAIt)->data().toString() == theName;
697 aGroups.append(aGroupName);
702 void XGUI_ContextMenuMgr::onRename()
704 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
705 if (!myWorkshop->abortAllOperations())
707 // restore selection in case if dialog box was shown
708 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
709 myWorkshop->objectBrowser()->onEditItem();
712 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
714 SessionPtr aMgr = ModelAPI_Session::get();
715 DocumentPtr aActiveDoc = aMgr->activeDocument();
717 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
718 XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
719 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
720 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
724 bool aIsRoot = false;
725 foreach(QModelIndex aIdx, aSelectedIndexes) {
726 // Process only first column
727 if (aIdx.column() == 0) {
728 aIsRoot = !aIdx.parent().isValid();
729 // Exit if the selected index belongs to non active document
730 if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
732 if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
735 // Get name of the selected index
736 aName = aIdx.data().toString();
737 aLen = aName.indexOf('(');
739 aName = aName.left(--aLen);
741 std::string aFeaturesStr = aIsRoot?
742 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
743 aDataModelXML->subFolderFeatures(aName.toStdString());
744 if (aFeaturesStr.length() > 0) {
745 QStringList aFeturesList =
746 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
747 foreach(QString aFea, aFeturesList) {
748 QAction* aAction = aActionMgr->action(aFea);
750 theMenu->addAction(aAction);
757 #define UNCHECK_ACTION(NAME) \
758 { QAction* aAction = action(NAME); \
759 bool isBlock = aAction->signalsBlocked(); \
760 aAction->blockSignals(true); \
761 aAction->setChecked(false); \
762 aAction->blockSignals(isBlock); }
765 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
767 UNCHECK_ACTION("SELECT_VERTEX_CMD");
768 UNCHECK_ACTION("SELECT_EDGE_CMD");
769 UNCHECK_ACTION("SELECT_FACE_CMD");
772 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
774 UNCHECK_ACTION("SHOW_RESULTS_CMD");