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