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