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