]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ContextMenuMgr.cpp
Salome HOME
Issue #1860: fix end lines with spaces
[modules/shaper.git] / src / XGUI / XGUI_ContextMenuMgr.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
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"
15
16 #ifndef HAVE_SALOME
17 #include <AppElements_MainWindow.h>
18 #endif
19
20 //#include "PartSetPlugin_Part.h"
21
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
32 #include <Config_DataModelReader.h>
33
34 #include <ModuleBase_IModule.h>
35 #include <ModuleBase_Tools.h>
36 #include <ModuleBase_OperationAction.h>
37 #include <ModuleBase_ViewerPrs.h>
38
39 #include <QAction>
40 #include <QActionGroup>
41 #include <QContextMenuEvent>
42 #include <QMenu>
43 #include <QMdiArea>
44 #include <QMainWindow>
45 #include <QModelIndex>
46
47
48 XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
49     : QObject(theParent),
50       myWorkshop(theParent),
51       mySeparator(0)
52 {
53 }
54
55 XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr()
56 {
57 }
58
59 void XGUI_ContextMenuMgr::createActions()
60 {
61 #ifdef HAVE_SALOME
62   QMainWindow* aDesktop = myWorkshop->salomeConnector()->desktop();
63 #else
64   QMainWindow* aDesktop = myWorkshop->mainWindow();
65 #endif
66
67   QAction* aAction = ModuleBase_Tools::createAction(QIcon(":pictures/delete.png"), tr("Delete"),
68                                                     aDesktop);
69   aDesktop->addAction(aAction);
70
71   addAction("DELETE_CMD", aAction);
72   aAction->setShortcutContext(Qt::ApplicationShortcut);
73
74   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/rename_edit.png"), tr("Rename"),
75                                            aDesktop, this, SLOT(onRename()));
76   addAction("RENAME_CMD", aAction);
77
78   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move.png"),
79                                            XGUI_Workshop::MOVE_TO_END_COMMAND, this);
80   addAction("MOVE_CMD", aAction);
81
82   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/clean_history.png"),
83                                            tr("Clean history"), aDesktop);
84   addAction("CLEAN_HISTORY_CMD", aAction);
85
86   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop);
87   addAction("COLOR_CMD", aAction);
88
89   aAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
90   addAction("DEFLECTION_CMD", aAction);
91
92   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
93   addAction("SHOW_CMD", aAction);
94
95   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show only"),
96                                            aDesktop);
97   addAction("SHOW_ONLY_CMD", aAction);
98
99   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"),
100                                            aDesktop);
101   addAction("HIDE_CMD", aAction);
102
103   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide all"),
104                                            aDesktop);
105   addAction("HIDEALL_CMD", aAction);
106
107   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"), tr("Shading"), aDesktop);
108   addAction("SHADING_CMD", aAction);
109
110   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"),
111                                            aDesktop);
112   addAction("WIREFRAME_CMD", aAction);
113
114   mySeparator = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
115   mySeparator->setSeparator(true);
116
117   //mySelectActions = new QActionGroup(this);
118   //mySelectActions->setExclusive(true);
119
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);
125
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);
131
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);
137
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);
143
144   aAction->setChecked(true);
145
146   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
147                                            tr("Select results"), aDesktop);
148   addAction("SHOW_RESULTS_CMD", aAction);
149
150   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
151                                            tr("Select parent feature"), aDesktop);
152   addAction("SHOW_FEATURE_CMD", aAction);
153
154   buildObjBrowserMenu();
155   buildViewerMenu();
156 }
157
158 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
159 {
160   if (myActions.contains(theId))
161     qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
162   theAction->setData(theId);
163   connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
164   myActions[theId] = theAction;
165 }
166
167 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
168 {
169   if (myActions.contains(theId))
170     return myActions[theId];
171   return 0;
172 }
173
174 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
175 {
176   foreach(QAction* eachAction, myActions) {
177     if (eachAction->text() == theName) {
178       return eachAction;
179     }
180   }
181   return NULL;
182 }
183
184 QStringList XGUI_ContextMenuMgr::actionIds() const
185 {
186   return myActions.keys();
187 }
188
189 void XGUI_ContextMenuMgr::onAction(bool isChecked)
190 {
191   QAction* aAction = static_cast<QAction*>(sender());
192   emit actionTriggered(aAction->data().toString(), isChecked);
193 }
194
195 void XGUI_ContextMenuMgr::updateCommandsStatus()
196 {
197 }
198
199 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
200 {
201   QMenu* aMenu = new QMenu();
202   if (sender() == myWorkshop->objectBrowser()) {
203     updateObjectBrowserMenu();
204     addObjBrowserMenu(aMenu);
205   } else if (sender() == myWorkshop->viewer()) {
206     updateViewerMenu();
207     addViewerMenu(aMenu);
208   }
209
210   if (aMenu && (aMenu->actions().size() > 0)) {
211     // it is possible that some objects should do something before and after the popup menu exec
212     // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
213     // a created entity
214     emit beforeContextMenu();
215     aMenu->exec(theEvent->globalPos());
216     emit afterContextMenu();
217     delete aMenu;
218   }
219 }
220
221 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
222 {
223   foreach(QAction* aAction, myActions)
224     aAction->setEnabled(false);
225
226   XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
227   QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
228   int aSelected = aObjects.size();
229   if (aSelected > 0) {
230     SessionPtr aMgr = ModelAPI_Session::get();
231     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
232     bool hasResult = false;
233     bool hasFeature = false;
234     bool hasParameter = false;
235     bool hasCompositeOwner = false;
236     ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
237                                    hasCompositeOwner);
238     //Process Feature
239     if (aSelected == 1) {
240       ObjectPtr aObject = aObjects.first();
241       if (aObject) {
242         if (hasResult && myWorkshop->canBeShaded(aObject)) {
243           XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
244           if (aMode != XGUI_Displayer::NoMode) {
245             action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
246             action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
247           } else {
248             action("WIREFRAME_CMD")->setEnabled(true);
249             action("SHADING_CMD")->setEnabled(true);
250           }
251         }
252         if (!hasFeature) {
253           bool aHasSubResults = ModelAPI_Tools::hasSubResults(
254                                             std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
255           if (aHasSubResults) {
256             action("HIDE_CMD")->setEnabled(true);
257             action("SHOW_CMD")->setEnabled(true);
258           }
259           else {
260             if (aObject->isDisplayed()) {
261               action("HIDE_CMD")->setEnabled(true);
262             } else if (hasResult && (!hasParameter)) {
263               action("SHOW_CMD")->setEnabled(true);
264             }
265           }
266           if (!(hasParameter || hasFeature))
267             action("SHOW_ONLY_CMD")->setEnabled(true);
268         }
269         else if (hasFeature && myWorkshop->canMoveFeature())
270           action("MOVE_CMD")->setEnabled(true);
271
272         if( aMgr->activeDocument() == aObject->document() )
273         {
274           action("RENAME_CMD")->setEnabled(true);
275           action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
276           action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
277                                                   (hasFeature || hasParameter));
278         }
279       }
280     } else {
281       // parameter is commented because the actions are not in the list of result parameter actions
282       if (hasResult /*&& (!hasParameter)*/) {
283         action("SHOW_CMD")->setEnabled(true);
284         action("HIDE_CMD")->setEnabled(true);
285         action("SHOW_ONLY_CMD")->setEnabled(true);
286         action("SHADING_CMD")->setEnabled(true);
287         action("WIREFRAME_CMD")->setEnabled(true);
288       }
289     }
290     bool allActive = true;
291     foreach( ObjectPtr aObject, aObjects )
292       if( aMgr->activeDocument() != aObject->document() )  {
293         allActive = false;
294         break;
295       }
296     if (!hasCompositeOwner && allActive ) {
297       if (hasFeature || hasParameter)
298         action("DELETE_CMD")->setEnabled(true);
299     }
300     if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
301       action("CLEAN_HISTORY_CMD")->setEnabled(true);
302
303     action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
304     action("SHOW_FEATURE_CMD")->setEnabled(hasResult);
305   }
306
307   // Show/Hide command has to be disabled for objects from non active document
308   bool aDeactivate = false;
309   foreach (ObjectPtr aObj, aObjects) {
310     if (!aObj->document()->isActive()) {
311       if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
312            aObj->groupName() == ModelAPI_ResultPart::group()) {
313         aDeactivate = true;
314         break;
315       }
316     }
317   }
318   if (aDeactivate) {
319     // If at leas a one objec can not be edited then Show/Hide has to be disabled
320     action("SHOW_CMD")->setEnabled(false);
321     action("HIDE_CMD")->setEnabled(false);
322     action("SHOW_ONLY_CMD")->setEnabled(false);
323   }
324
325   if (myWorkshop->canChangeColor())
326     action("COLOR_CMD")->setEnabled(true);
327
328   if (myWorkshop->canChangeDeflection())
329     action("DEFLECTION_CMD")->setEnabled(true);
330
331   ModuleBase_IModule* aModule = myWorkshop->module();
332   if (aModule)
333     aModule->updateObjectBrowserMenu(myActions);
334 }
335
336 void XGUI_ContextMenuMgr::updateViewerMenu()
337 {
338   foreach(QAction* aAction, myActions)
339     aAction->setEnabled(false);
340
341   XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
342   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
343   QList<ModuleBase_ViewerPrsPtr> aPrsList =
344     aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
345   if (aPrsList.size() > 0) {
346     bool isVisible = false;
347     bool isShading = false;
348     bool canBeShaded = false;
349     ObjectPtr aObject;
350     foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
351       aObject = aPrs->object();
352       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
353       if (aRes && aRes->isDisplayed()) {
354         isVisible = true;
355         canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
356         isShading =
357           (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
358         break;
359       }
360     }
361     if (isVisible) {
362       if (canBeShaded) {
363         XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
364         if (aMode != XGUI_Displayer::NoMode) {
365           action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
366           action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
367         } else {
368           action("WIREFRAME_CMD")->setEnabled(true);
369           action("SHADING_CMD")->setEnabled(true);
370         }
371       }
372       action("SHOW_ONLY_CMD")->setEnabled(true);
373       action("HIDE_CMD")->setEnabled(true);
374     } else
375       action("SHOW_CMD")->setEnabled(true);
376   }
377   if (myWorkshop->displayer()->objectsCount() > 0)
378     action("HIDEALL_CMD")->setEnabled(true);
379
380   // Update selection menu
381   QIntList aModes = aDisplayer->activeSelectionModes();
382   action("SELECT_VERTEX_CMD")->setEnabled(true);
383   action("SELECT_EDGE_CMD")->setEnabled(true);
384   action("SELECT_FACE_CMD")->setEnabled(true);
385   action("SELECT_RESULT_CMD")->setEnabled(true);
386
387   action("SELECT_RESULT_CMD")->setChecked(false);
388   action("SELECT_VERTEX_CMD")->setChecked(false);
389   action("SELECT_EDGE_CMD")->setChecked(false);
390   action("SELECT_FACE_CMD")->setChecked(false);
391   action("SELECT_RESULT_CMD")->setChecked(false);
392   if (aModes.count() == 0) {
393     action("SELECT_RESULT_CMD")->setChecked(true);
394   } else {
395     foreach(int aMode, aModes) {
396       switch (aMode) {
397       case TopAbs_VERTEX:
398         action("SELECT_VERTEX_CMD")->setChecked(true);
399         break;
400       case TopAbs_EDGE:
401         action("SELECT_EDGE_CMD")->setChecked(true);
402         break;
403       case TopAbs_FACE:
404         action("SELECT_FACE_CMD")->setChecked(true);
405         break;
406       default:
407         action("SELECT_RESULT_CMD")->setChecked(true);
408       }
409     }
410   }
411
412   ModuleBase_IModule* aModule = myWorkshop->module();
413   if (aModule)
414     aModule->updateViewerMenu(myActions);
415
416   if (myWorkshop->canChangeColor())
417     action("COLOR_CMD")->setEnabled(true);
418
419   if (myWorkshop->canChangeDeflection())
420     action("DEFLECTION_CMD")->setEnabled(true);
421
422   action("DELETE_CMD")->setEnabled(true);
423 }
424
425 void XGUI_ContextMenuMgr::connectObjectBrowser()
426 {
427   connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
428           SLOT(onContextMenuRequest(QContextMenuEvent*)));
429 }
430
431 void XGUI_ContextMenuMgr::connectViewer()
432 {
433   connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
434           SLOT(onContextMenuRequest(QContextMenuEvent*)));
435 }
436
437
438 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
439 {
440   QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
441   aSeparator->setSeparator(true);
442
443   QActionsList aList;
444
445   // Result construction menu
446   aList.append(action("SHOW_CMD"));
447   aList.append(action("HIDE_CMD"));
448   aList.append(action("SHOW_ONLY_CMD"));
449   aList.append(mySeparator);
450   aList.append(action("RENAME_CMD"));
451   aList.append(action("COLOR_CMD"));
452   aList.append(action("DEFLECTION_CMD"));
453   aList.append(action("SHOW_FEATURE_CMD"));
454   myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
455
456   //-------------------------------------
457   // Result body menu
458   aList.clear();
459   aList.append(action("WIREFRAME_CMD"));
460   aList.append(action("SHADING_CMD"));
461   aList.append(mySeparator); // this separator is not shown as this action is added after show only
462   // qt list container contains only one instance of the same action
463   aList.append(action("SHOW_CMD"));
464   aList.append(action("HIDE_CMD"));
465   aList.append(action("SHOW_ONLY_CMD"));
466   aList.append(mySeparator);
467   aList.append(action("RENAME_CMD"));
468   aList.append(action("COLOR_CMD"));
469   aList.append(action("DEFLECTION_CMD"));
470   aList.append(action("SHOW_FEATURE_CMD"));
471   myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
472   // Group menu
473   myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
474   // Result part menu
475   myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
476   //-------------------------------------
477   // Feature menu
478   aList.clear();
479   aList.append(action("RENAME_CMD"));
480   aList.append(action("SHOW_RESULTS_CMD"));
481   aList.append(action("MOVE_CMD"));
482   aList.append(mySeparator);
483   aList.append(action("CLEAN_HISTORY_CMD"));
484   aList.append(action("DELETE_CMD"));
485   myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
486
487   aList.clear();
488   aList.append(action("RENAME_CMD"));
489   aList.append(mySeparator);
490   aList.append(action("CLEAN_HISTORY_CMD"));
491   aList.append(action("DELETE_CMD"));
492   myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
493   //-------------------------------------
494 }
495
496 void XGUI_ContextMenuMgr::buildViewerMenu()
497 {
498   QActionsList aList;
499   // Result construction menu
500   aList.append(action("HIDE_CMD"));
501   aList.append(action("SHOW_ONLY_CMD"));
502   aList.append(mySeparator);
503   aList.append(action("COLOR_CMD"));
504   aList.append(action("DEFLECTION_CMD"));
505   myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
506   // Result part menu
507   myViewerMenu[ModelAPI_ResultPart::group()] = aList;
508   //-------------------------------------
509   // Result body menu
510   aList.clear();
511   aList.append(action("WIREFRAME_CMD"));
512   aList.append(action("SHADING_CMD"));
513   aList.append(mySeparator);
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_ResultBody::group()] = aList;
520   // Group menu
521   myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
522   //-------------------------------------
523 }
524
525
526 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
527 {
528   ModuleBase_IModule* aModule = myWorkshop->module();
529   if (aModule) {
530     theMenu->addSeparator();
531     aModule->addObjectBrowserMenu(theMenu);
532   }
533
534   XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
535   QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
536   int aSelected = aObjects.size();
537   QActionsList aActions;
538   if (aSelected == 1) {
539     ObjectPtr aObject = aObjects.first();
540     std::string aName = aObject->groupName();
541     if (myObjBrowserMenus.contains(aName))
542       aActions = myObjBrowserMenus[aName];
543   } else if (aSelected > 1) {
544       aActions.append(action("WIREFRAME_CMD"));
545       aActions.append(action("SHADING_CMD"));
546       aActions.append(mySeparator);
547       aActions.append(action("SHOW_CMD"));
548       aActions.append(action("HIDE_CMD"));
549       aActions.append(action("SHOW_ONLY_CMD"));
550       aActions.append(mySeparator);
551       //aActions.append(action("MOVE_CMD"));
552       aActions.append(action("COLOR_CMD"));
553       aActions.append(action("DEFLECTION_CMD"));
554
555       aActions.append(action("CLEAN_HISTORY_CMD"));
556       aActions.append(action("DELETE_CMD"));
557   }
558   theMenu->addActions(aActions);
559   addFeatures(theMenu);
560
561   // It is commented out because Object Browser does not have actions
562   //theMenu->addSeparator();
563   //theMenu->addActions(myWorkshop->objectBrowser()->actions());
564 }
565
566 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
567 {
568   XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
569   QList<ModuleBase_ViewerPrsPtr> aPrsList =
570     aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
571   int aSelected = aPrsList.size();
572   QActionsList aActions;
573
574   // Create selection menu
575   XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
576   QIntList aModes;
577   myWorkshop->module()->activeSelectionModes(aModes);
578   if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
579     QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
580     aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
581     aSelMenu->addAction(action("SELECT_EDGE_CMD"));
582     aSelMenu->addAction(action("SELECT_FACE_CMD"));
583     //IMP: an attempt to use result selection with other selection modes
584     //aSelMenu->addSeparator();
585     aSelMenu->addAction(action("SELECT_RESULT_CMD"));
586     theMenu->addMenu(aSelMenu);
587     theMenu->addSeparator();
588   }
589   if (aSelected == 1) {
590     ObjectPtr aObject = aPrsList.first()->object();
591     if (aObject.get() != NULL) {
592       std::string aName = aObject->groupName();
593       if (myViewerMenu.contains(aName))
594         aActions = myViewerMenu[aName];
595     }
596   } else if (aSelected > 1) {
597     aActions.append(action("HIDE_CMD"));
598   }
599   // hide all is shown always even if selection in the viewer is empty
600   aActions.append(action("HIDEALL_CMD"));
601   aActions.append(action("COLOR_CMD"));
602   aActions.append(action("DEFLECTION_CMD"));
603
604   theMenu->addActions(aActions);
605
606   QMap<int, QAction*> aMenuActions;
607   ModuleBase_IModule* aModule = myWorkshop->module();
608   if (aModule) {
609     if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
610       theMenu->addSeparator();
611   }
612
613   // insert the module menu items on specific positions in the popup menu: some actions should be
614   // in the begin of the list, Delete action should be the last by #1343 issue
615   QList<QAction*> anActions = theMenu->actions();
616   int anActionsSize = anActions.size();
617   QAction* aFirstAction = anActions[0];
618   QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
619   for (; anIt != aLast; anIt++) {
620     if (anIt.key() > anActionsSize)
621       theMenu->addAction(anIt.value());
622     else
623       theMenu->insertAction(aFirstAction, *anIt);
624   }
625
626 #ifndef HAVE_SALOME
627   theMenu->addSeparator();
628   QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
629   if (aMDI->actions().size() > 0) {
630     QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
631     aSubMenu->addActions(aMDI->actions());
632   }
633 #endif
634 }
635
636 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
637 {
638   QStringList aGroups;
639
640   QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
641                                                   aLast = myObjBrowserMenus.end();
642   for (; anIt != aLast; anIt++) {
643     QString aGroupName(anIt.key().c_str());
644     if (aGroups.contains(aGroupName))
645       continue;
646     QActionsList anActions = anIt.value();
647     QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
648     bool aFound = false;
649     for (; anAIt != anALast && !aFound; anAIt++)
650       aFound = (*anAIt)->data().toString() == theName;
651     if (aFound)
652       aGroups.append(aGroupName);
653   }
654   return aGroups;
655 }
656
657 void XGUI_ContextMenuMgr::onRename()
658 {
659   QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
660   if (!myWorkshop->abortAllOperations())
661     return;
662   // restore selection in case if dialog box was shown
663   myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
664   myWorkshop->objectBrowser()->onEditItem();
665 }
666
667 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
668 {
669   SessionPtr aMgr = ModelAPI_Session::get();
670   DocumentPtr aActiveDoc = aMgr->activeDocument();
671
672   XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
673   XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
674   const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
675   QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
676
677   QString aName;
678   int aLen = 0;
679   bool aIsRoot = false;
680   foreach(QModelIndex aIdx, aSelectedIndexes) {
681     // Process only first column
682     if (aIdx.column() == 0) {
683       aIsRoot = !aIdx.parent().isValid();
684       // Exit if the selected index belongs to non active document
685       if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
686         return;
687       if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
688         return;
689
690       // Get name of the selected index
691       aName = aIdx.data().toString();
692       aLen = aName.indexOf('(');
693       if (aLen != -1) {
694         aName = aName.left(--aLen);
695       }
696       std::string aFeaturesStr = aIsRoot?
697         aDataModelXML->rootFolderFeatures(aName.toStdString()) :
698         aDataModelXML->subFolderFeatures(aName.toStdString());
699         if (aFeaturesStr.length() > 0) {
700           QStringList aFeturesList =
701             QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
702           foreach(QString aFea, aFeturesList) {
703             QAction* aAction = aActionMgr->action(aFea);
704             if (aAction)
705               theMenu->addAction(aAction);
706           }
707         }
708     }
709   }
710 }
711
712 #define UNCHECK_ACTION(NAME) \
713 { QAction* aAction = action(NAME); \
714 bool isBlock = aAction->signalsBlocked(); \
715 aAction->blockSignals(true); \
716 aAction->setChecked(false); \
717   aAction->blockSignals(isBlock); }
718
719
720 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
721 {
722   UNCHECK_ACTION("SELECT_VERTEX_CMD");
723   UNCHECK_ACTION("SELECT_EDGE_CMD");
724   UNCHECK_ACTION("SELECT_FACE_CMD");
725 }
726
727 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
728 {
729   UNCHECK_ACTION("SHOW_RESULTS_CMD");
730 }