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>
50 #include "ModelAPI_Folder.h"
52 #include <Config_DataModelReader.h>
54 #include <ModuleBase_IModule.h>
55 #include <ModuleBase_Tools.h>
56 #include <ModuleBase_OperationAction.h>
57 #include <ModuleBase_ViewerPrs.h>
60 #include <QActionGroup>
61 #include <QContextMenuEvent>
64 #include <QMainWindow>
65 #include <QModelIndex>
67 XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
69 myWorkshop(theParent),
70 mySeparator1(0), mySeparator2(0)
74 XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr()
78 void XGUI_ContextMenuMgr::createActions()
81 QMainWindow* aDesktop = myWorkshop->salomeConnector()->desktop();
83 QMainWindow* aDesktop = myWorkshop->mainWindow();
86 QAction* aAction = ModuleBase_Tools::createAction(QIcon(":pictures/delete.png"), tr("Delete"),
88 aDesktop->addAction(aAction);
90 addAction("DELETE_CMD", aAction);
91 aAction->setShortcutContext(Qt::ApplicationShortcut);
93 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/rename_edit.png"), tr("Rename"),
94 aDesktop, this, SLOT(onRename()));
95 addAction("RENAME_CMD", aAction);
97 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move.png"),
98 XGUI_Workshop::MOVE_TO_END_COMMAND, this);
99 addAction("MOVE_CMD", aAction);
101 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/clean_history.png"),
102 tr("Clean history"), aDesktop);
103 addAction("CLEAN_HISTORY_CMD", aAction);
105 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop);
106 addAction("COLOR_CMD", aAction);
108 aAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
109 addAction("DEFLECTION_CMD", aAction);
111 #ifdef USE_TRANSPARENCY
112 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/transparency.png"),
113 tr("Transparency..."), aDesktop);
114 addAction("TRANSPARENCY_CMD", aAction);
117 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
118 addAction("SHOW_CMD", aAction);
120 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show only"),
122 addAction("SHOW_ONLY_CMD", aAction);
124 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"),
126 addAction("HIDE_CMD", aAction);
128 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide all"),
130 addAction("HIDEALL_CMD", aAction);
132 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"), tr("Shading"), aDesktop);
133 addAction("SHADING_CMD", aAction);
135 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"),
137 addAction("WIREFRAME_CMD", aAction);
139 mySeparator1 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
140 mySeparator1->setSeparator(true);
142 mySeparator2 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
143 mySeparator2->setSeparator(true);
145 //mySelectActions = new QActionGroup(this);
146 //mySelectActions->setExclusive(true);
148 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
149 this, SLOT(onShapeSelection(bool)));
150 aAction->setCheckable(true);
151 addAction("SELECT_VERTEX_CMD", aAction);
152 //mySelectActions->addAction(aAction);
154 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
155 this, SLOT(onShapeSelection(bool)));
156 aAction->setCheckable(true);
157 addAction("SELECT_EDGE_CMD", aAction);
158 //mySelectActions->addAction(aAction);
160 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
161 this, SLOT(onShapeSelection(bool)));
162 aAction->setCheckable(true);
163 addAction("SELECT_FACE_CMD", aAction);
164 //mySelectActions->addAction(aAction);
166 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop,
167 this, SLOT(onResultSelection(bool)));
168 aAction->setCheckable(true);
169 addAction("SELECT_RESULT_CMD", aAction);
170 //mySelectActions->addAction(aAction);
172 aAction->setChecked(true);
174 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
175 tr("Select results"), aDesktop);
176 addAction("SHOW_RESULTS_CMD", aAction);
178 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
179 tr("Select parent feature"), aDesktop);
180 addAction("SHOW_FEATURE_CMD", aAction);
183 aAction = ModuleBase_Tools::createAction(QIcon(), tr("TInspector"), aDesktop);
184 addAction("TINSPECTOR_VIEW", aAction);
187 // Features folders actions
188 aAction = ModuleBase_Tools::createAction(QIcon(),
189 tr("Insert a folder before"), aDesktop);
190 addAction("INSERT_FOLDER_CMD", aAction);
193 buildObjBrowserMenu();
197 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
199 if (myActions.contains(theId))
200 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
201 theAction->setData(theId);
202 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
203 myActions[theId] = theAction;
206 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
208 if (myActions.contains(theId))
209 return myActions[theId];
213 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
215 foreach(QAction* eachAction, myActions) {
216 if (eachAction->text() == theName) {
223 QStringList XGUI_ContextMenuMgr::actionIds() const
225 return myActions.keys();
228 void XGUI_ContextMenuMgr::onAction(bool isChecked)
230 QAction* aAction = static_cast<QAction*>(sender());
231 emit actionTriggered(aAction->data().toString(), isChecked);
234 void XGUI_ContextMenuMgr::updateCommandsStatus()
238 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
240 QMenu* aMenu = new QMenu();
241 if (sender() == myWorkshop->objectBrowser()) {
242 updateObjectBrowserMenu();
243 addObjBrowserMenu(aMenu);
244 } else if (sender() == myWorkshop->viewer()) {
246 addViewerMenu(aMenu);
249 if (aMenu && (aMenu->actions().size() > 0)) {
250 // it is possible that some objects should do something before and after the popup menu exec
251 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
253 emit beforeContextMenu();
254 aMenu->exec(theEvent->globalPos());
255 emit afterContextMenu();
260 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
262 foreach(QAction* aAction, myActions)
263 aAction->setEnabled(false);
265 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
266 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
267 int aSelected = aObjects.size();
269 SessionPtr aMgr = ModelAPI_Session::get();
270 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
271 bool hasResult = false;
272 bool hasFeature = false;
273 bool hasParameter = false;
274 bool hasCompositeOwner = false;
275 bool hasResultInHistory = false;
276 bool hasFolder = false;
277 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
278 hasCompositeOwner, hasResultInHistory, hasFolder);
280 if (aSelected == 1) {
281 ObjectPtr aObject = aObjects.first();
283 if (hasResult && myWorkshop->canBeShaded(aObject)) {
284 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
285 if (aMode != XGUI_Displayer::NoMode) {
286 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
287 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
289 action("WIREFRAME_CMD")->setEnabled(true);
290 action("SHADING_CMD")->setEnabled(true);
294 bool aHasSubResults = ModelAPI_Tools::hasSubResults(
295 std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
296 if (aHasSubResults) {
297 action("HIDE_CMD")->setEnabled(true);
298 action("SHOW_CMD")->setEnabled(true);
301 if (aObject->isDisplayed()) {
302 action("HIDE_CMD")->setEnabled(true);
303 } else if (hasResult && (!hasParameter)) {
304 action("SHOW_CMD")->setEnabled(true);
307 if (!(hasParameter || hasFeature))
308 action("SHOW_ONLY_CMD")->setEnabled(true);
310 else if (hasFeature && myWorkshop->canMoveFeature())
311 action("MOVE_CMD")->setEnabled(true);
313 if( aMgr->activeDocument() == aObject->document() )
315 action("RENAME_CMD")->setEnabled(true);
316 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
317 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
318 (hasFeature || hasParameter));
322 // parameter is commented because the actions are not in the list of result parameter actions
323 if (hasResult /*&& (!hasParameter)*/) {
324 action("SHOW_CMD")->setEnabled(true);
325 action("HIDE_CMD")->setEnabled(true);
326 action("SHOW_ONLY_CMD")->setEnabled(true);
327 action("SHADING_CMD")->setEnabled(true);
328 action("WIREFRAME_CMD")->setEnabled(true);
331 bool allActive = true;
332 foreach( ObjectPtr aObject, aObjects )
333 if( aMgr->activeDocument() != aObject->document() ) {
337 if (!hasCompositeOwner && allActive ) {
338 if (hasFeature || hasParameter)
339 action("DELETE_CMD")->setEnabled(true);
341 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
342 action("CLEAN_HISTORY_CMD")->setEnabled(true);
344 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
345 action("INSERT_FOLDER_CMD")->setEnabled(hasFeature);
346 action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory);
349 // Show/Hide command has to be disabled for objects from non active document
350 bool aDeactivate = false;
351 foreach (ObjectPtr aObj, aObjects) {
352 if (!aObj->document()->isActive()) {
353 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
354 aObj->groupName() == ModelAPI_ResultPart::group()) {
361 // If at leas a one objec can not be edited then Show/Hide has to be disabled
362 action("SHOW_CMD")->setEnabled(false);
363 action("HIDE_CMD")->setEnabled(false);
364 action("SHOW_ONLY_CMD")->setEnabled(false);
367 action("COLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("COLOR_CMD"));
368 action("DEFLECTION_CMD")->setEnabled(myWorkshop->canChangeProperty("DEFLECTION_CMD"));
369 #ifdef USE_TRANSPARENCY
370 action("TRANSPARENCY_CMD")->setEnabled(myWorkshop->canChangeProperty("TRANSPARENCY_CMD"));
374 action("TINSPECTOR_VIEW")->setEnabled(true);
379 ModuleBase_IModule* aModule = myWorkshop->module();
381 aModule->updateObjectBrowserMenu(myActions);
384 void XGUI_ContextMenuMgr::updateViewerMenu()
386 foreach(QAction* aAction, myActions)
387 aAction->setEnabled(false);
389 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
390 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
391 QList<ModuleBase_ViewerPrsPtr> aPrsList =
392 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
393 if (aPrsList.size() > 0) {
394 bool isVisible = false;
395 bool isShading = false;
396 bool canBeShaded = false;
398 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
399 aObject = aPrs->object();
400 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
401 if (aRes && aRes->isDisplayed()) {
403 canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
405 (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
411 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
412 if (aMode != XGUI_Displayer::NoMode) {
413 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
414 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
416 action("WIREFRAME_CMD")->setEnabled(true);
417 action("SHADING_CMD")->setEnabled(true);
420 action("SHOW_ONLY_CMD")->setEnabled(true);
421 action("HIDE_CMD")->setEnabled(true);
423 action("SHOW_CMD")->setEnabled(true);
425 //issue #2159 Hide all incomplete behavior
427 action("HIDEALL_CMD")->setEnabled(true);
429 if (myWorkshop->displayer()->objectsCount() > 0)
430 action("HIDEALL_CMD")->setEnabled(true);
433 // Update selection menu
434 QIntList aModes = aDisplayer->activeSelectionModes();
435 action("SELECT_VERTEX_CMD")->setEnabled(true);
436 action("SELECT_EDGE_CMD")->setEnabled(true);
437 action("SELECT_FACE_CMD")->setEnabled(true);
438 action("SELECT_RESULT_CMD")->setEnabled(true);
440 action("SELECT_RESULT_CMD")->setChecked(false);
441 action("SELECT_VERTEX_CMD")->setChecked(false);
442 action("SELECT_EDGE_CMD")->setChecked(false);
443 action("SELECT_FACE_CMD")->setChecked(false);
444 action("SELECT_RESULT_CMD")->setChecked(false);
445 if (aModes.count() == 0) {
446 action("SELECT_RESULT_CMD")->setChecked(true);
448 foreach(int aMode, aModes) {
451 action("SELECT_VERTEX_CMD")->setChecked(true);
454 action("SELECT_EDGE_CMD")->setChecked(true);
457 action("SELECT_FACE_CMD")->setChecked(true);
460 action("SELECT_RESULT_CMD")->setChecked(true);
465 ModuleBase_IModule* aModule = myWorkshop->module();
467 aModule->updateViewerMenu(myActions);
469 if (myWorkshop->canChangeProperty("COLOR_CMD"))
470 action("COLOR_CMD")->setEnabled(true);
472 if (myWorkshop->canChangeProperty("DEFLECTION_CMD"))
473 action("DEFLECTION_CMD")->setEnabled(true);
475 #ifdef USE_TRANSPARENCY
476 if (myWorkshop->canChangeProperty("TRANSPARENCY_CMD"))
477 action("TRANSPARENCY_CMD")->setEnabled(true);
480 action("DELETE_CMD")->setEnabled(true);
483 void XGUI_ContextMenuMgr::connectObjectBrowser()
485 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
486 SLOT(onContextMenuRequest(QContextMenuEvent*)));
489 void XGUI_ContextMenuMgr::connectViewer()
491 connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
492 SLOT(onContextMenuRequest(QContextMenuEvent*)));
496 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
498 QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
499 aSeparator->setSeparator(true);
503 // Result construction menu
504 aList.append(action("SHOW_CMD"));
505 aList.append(action("HIDE_CMD"));
506 aList.append(action("SHOW_ONLY_CMD"));
507 aList.append(mySeparator1);
508 aList.append(action("RENAME_CMD"));
509 aList.append(action("COLOR_CMD"));
510 aList.append(action("DEFLECTION_CMD"));
511 #ifdef USE_TRANSPARENCY
512 aList.append(action("TRANSPARENCY_CMD"));
514 aList.append(action("SHOW_FEATURE_CMD"));
515 myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
517 //-------------------------------------
520 aList.append(action("WIREFRAME_CMD"));
521 aList.append(action("SHADING_CMD"));
522 aList.append(mySeparator1); // this separator is not shown as this action is added after show only
523 // qt list container contains only one instance of the same action
524 aList.append(action("SHOW_CMD"));
525 aList.append(action("HIDE_CMD"));
526 aList.append(action("SHOW_ONLY_CMD"));
527 aList.append(mySeparator2);
528 aList.append(action("RENAME_CMD"));
529 aList.append(action("COLOR_CMD"));
530 aList.append(action("DEFLECTION_CMD"));
531 #ifdef USE_TRANSPARENCY
532 aList.append(action("TRANSPARENCY_CMD"));
534 aList.append(action("SHOW_FEATURE_CMD"));
535 myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
537 myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
538 myObjBrowserMenus[ModelAPI_ResultField::group()] = aList;
540 myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
541 //-------------------------------------
544 aList.append(action("RENAME_CMD"));
545 aList.append(action("SHOW_RESULTS_CMD"));
546 aList.append(action("MOVE_CMD"));
547 aList.append(mySeparator1);
548 aList.append(action("INSERT_FOLDER_CMD"));
549 aList.append(mySeparator2);
550 aList.append(action("CLEAN_HISTORY_CMD"));
551 aList.append(action("DELETE_CMD"));
552 myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
555 aList.append(action("RENAME_CMD"));
556 aList.append(mySeparator1);
557 aList.append(action("CLEAN_HISTORY_CMD"));
558 aList.append(action("DELETE_CMD"));
559 myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
560 //-------------------------------------
563 aList.append(action("DELETE_CMD"));
564 myObjBrowserMenus[ModelAPI_Folder::group()] = aList;
568 void XGUI_ContextMenuMgr::buildViewerMenu()
571 // Result construction menu
572 aList.append(action("HIDE_CMD"));
573 aList.append(action("SHOW_ONLY_CMD"));
574 aList.append(mySeparator1);
575 aList.append(action("COLOR_CMD"));
576 aList.append(action("DEFLECTION_CMD"));
577 #ifdef USE_TRANSPARENCY
578 aList.append(action("TRANSPARENCY_CMD"));
580 myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
582 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
583 //-------------------------------------
586 aList.append(action("WIREFRAME_CMD"));
587 aList.append(action("SHADING_CMD"));
588 aList.append(mySeparator1);
589 aList.append(action("HIDE_CMD"));
590 aList.append(action("SHOW_ONLY_CMD"));
591 aList.append(mySeparator2);
592 aList.append(action("COLOR_CMD"));
593 aList.append(action("DEFLECTION_CMD"));
594 #ifdef USE_TRANSPARENCY
595 aList.append(action("TRANSPARENCY_CMD"));
597 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
599 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
600 myViewerMenu[ModelAPI_ResultField::group()] = aList;
601 //-------------------------------------
605 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
607 ModuleBase_IModule* aModule = myWorkshop->module();
609 theMenu->addSeparator();
610 aModule->addObjectBrowserMenu(theMenu);
613 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
614 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
615 int aSelected = aObjects.size();
616 QActionsList aActions;
617 if (aSelected == 1) {
618 ObjectPtr aObject = aObjects.first();
619 std::string aName = aObject->groupName();
620 if (myObjBrowserMenus.contains(aName))
621 aActions = myObjBrowserMenus[aName];
622 } else if (aSelected > 1) {
623 aActions.append(action("WIREFRAME_CMD"));
624 aActions.append(action("SHADING_CMD"));
625 aActions.append(mySeparator1);
626 aActions.append(action("SHOW_CMD"));
627 aActions.append(action("HIDE_CMD"));
628 aActions.append(action("SHOW_ONLY_CMD"));
629 aActions.append(mySeparator2);
630 //aActions.append(action("MOVE_CMD"));
631 aActions.append(action("COLOR_CMD"));
632 aActions.append(action("DEFLECTION_CMD"));
633 #ifdef USE_TRANSPARENCY
634 aActions.append(action("TRANSPARENCY_CMD"));
636 aActions.append(action("CLEAN_HISTORY_CMD"));
637 aActions.append(action("DELETE_CMD"));
640 if (aSelected == 0) {
642 aActions.append(action("TINSPECTOR_VIEW"));
646 theMenu->addActions(aActions);
647 addFeatures(theMenu);
649 // It is commented out because Object Browser does not have actions
650 //theMenu->addSeparator();
651 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
654 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
656 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
657 QList<ModuleBase_ViewerPrsPtr> aPrsList =
658 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
659 int aSelected = aPrsList.size();
660 QActionsList aActions;
662 // Create selection menu
663 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
665 myWorkshop->module()->activeSelectionModes(aModes);
666 if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
667 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
668 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
669 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
670 aSelMenu->addAction(action("SELECT_FACE_CMD"));
671 //IMP: an attempt to use result selection with other selection modes
672 //aSelMenu->addSeparator();
673 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
674 theMenu->addMenu(aSelMenu);
675 theMenu->addSeparator();
677 if (aSelected == 1) {
678 ObjectPtr aObject = aPrsList.first()->object();
679 if (aObject.get() != NULL) {
680 std::string aName = aObject->groupName();
681 if (myViewerMenu.contains(aName))
682 aActions = myViewerMenu[aName];
684 } else if (aSelected > 1) {
685 aActions.append(action("HIDE_CMD"));
687 // hide all is shown always even if selection in the viewer is empty
688 aActions.append(action("HIDEALL_CMD"));
689 aActions.append(action("COLOR_CMD"));
690 aActions.append(action("DEFLECTION_CMD"));
691 #ifdef USE_TRANSPARENCY
692 aActions.append(action("TRANSPARENCY_CMD"));
694 theMenu->addActions(aActions);
696 QMap<int, QAction*> aMenuActions;
697 ModuleBase_IModule* aModule = myWorkshop->module();
699 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
700 theMenu->addSeparator();
703 // insert the module menu items on specific positions in the popup menu: some actions should be
704 // in the begin of the list, Delete action should be the last by #1343 issue
705 QList<QAction*> anActions = theMenu->actions();
706 int anActionsSize = anActions.size();
707 QAction* aFirstAction = anActions[0];
708 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
709 for (; anIt != aLast; anIt++) {
710 if (anIt.key() > anActionsSize)
711 theMenu->addAction(anIt.value());
713 theMenu->insertAction(aFirstAction, *anIt);
717 theMenu->addSeparator();
718 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
719 if (aMDI->actions().size() > 0) {
720 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
721 aSubMenu->addActions(aMDI->actions());
726 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
730 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
731 aLast = myObjBrowserMenus.end();
732 for (; anIt != aLast; anIt++) {
733 QString aGroupName(anIt.key().c_str());
734 if (aGroups.contains(aGroupName))
736 QActionsList anActions = anIt.value();
737 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
739 for (; anAIt != anALast && !aFound; anAIt++)
740 aFound = (*anAIt)->data().toString() == theName;
742 aGroups.append(aGroupName);
747 void XGUI_ContextMenuMgr::onRename()
749 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
750 if (!myWorkshop->abortAllOperations())
752 // restore selection in case if dialog box was shown
753 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
754 myWorkshop->objectBrowser()->onEditItem();
757 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
759 SessionPtr aMgr = ModelAPI_Session::get();
760 DocumentPtr aActiveDoc = aMgr->activeDocument();
762 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
763 XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
764 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
765 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
769 bool aIsRoot = false;
770 foreach(QModelIndex aIdx, aSelectedIndexes) {
771 // Process only first column
772 if (aIdx.column() == 1) {
773 aIsRoot = !aIdx.parent().isValid();
774 // Exit if the selected index belongs to non active document
775 if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
777 if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
780 // Get name of the selected index
781 aName = aIdx.data().toString();
782 aLen = aName.indexOf('(');
784 aName = aName.left(--aLen);
786 std::string aFeaturesStr = aIsRoot?
787 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
788 aDataModelXML->subFolderFeatures(aName.toStdString());
789 if (aFeaturesStr.length() > 0) {
790 QStringList aFeturesList =
791 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
792 foreach(QString aFea, aFeturesList) {
793 QAction* aAction = aActionMgr->action(aFea);
795 theMenu->addAction(aAction);
802 #define UNCHECK_ACTION(NAME) \
803 { QAction* aAction = action(NAME); \
804 bool isBlock = aAction->signalsBlocked(); \
805 aAction->blockSignals(true); \
806 aAction->setChecked(false); \
807 aAction->blockSignals(isBlock); }
810 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
812 UNCHECK_ACTION("SELECT_VERTEX_CMD");
813 UNCHECK_ACTION("SELECT_EDGE_CMD");
814 UNCHECK_ACTION("SELECT_FACE_CMD");
817 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
819 UNCHECK_ACTION("SHOW_RESULTS_CMD");