Salome HOME
ab42829e1e6b568bd127dbe01424c725555bd61e
[modules/shaper.git] / src / XGUI / XGUI_ContextMenuMgr.cpp
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "XGUI_ContextMenuMgr.h"
21 #include "XGUI_Workshop.h"
22 #include "XGUI_ObjectsBrowser.h"
23 #include "XGUI_SelectionMgr.h"
24 #include "XGUI_Displayer.h"
25 #include "XGUI_ViewerProxy.h"
26 #include "XGUI_SalomeConnector.h"
27 #include "XGUI_Selection.h"
28 #include "XGUI_SelectionActivate.h"
29 #include "XGUI_DataModel.h"
30 #include "XGUI_OperationMgr.h"
31 #include "XGUI_Tools.h"
32 #include "XGUI_ActionsMgr.h"
33
34 #ifndef HAVE_SALOME
35 #include <AppElements_MainWindow.h>
36 #endif
37
38 //#include "PartSetPlugin_Part.h"
39
40 #include <ModelAPI_Data.h>
41 #include <ModelAPI_AttributeDocRef.h>
42 #include <ModelAPI_Object.h>
43 #include <ModelAPI_Session.h>
44 #include <ModelAPI_ResultGroup.h>
45 #include <ModelAPI_ResultParameter.h>
46 #include <ModelAPI_ResultConstruction.h>
47 #include <ModelAPI_ResultBody.h>
48 #include <ModelAPI_Tools.h>
49 #include <ModelAPI_ResultField.h>
50 #include <ModelAPI_Folder.h>
51 #include <ModelAPI_AttributeReference.h>
52 #include <ModelAPI_ResultField.h>
53
54 #include <Config_DataModelReader.h>
55
56 #include <ModuleBase_IModule.h>
57 #include <ModuleBase_Tools.h>
58 #include <ModuleBase_Operation.h>
59 #include <ModuleBase_ViewerPrs.h>
60
61 #include <QAction>
62 #include <QActionGroup>
63 #include <QContextMenuEvent>
64 #include <QMenu>
65 #include <QMdiArea>
66 #include <QMainWindow>
67 #include <QModelIndex>
68
69 #ifdef WIN32
70 #pragma warning(disable : 4456) // for nested foreach
71 #endif
72
73 XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
74     : QObject(theParent),
75       myWorkshop(theParent),
76       mySeparator1(0), mySeparator2(0), mySeparator3(0)
77 {
78 }
79
80 XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr()
81 {
82 }
83
84 void XGUI_ContextMenuMgr::createActions()
85 {
86 #ifdef HAVE_SALOME
87   QMainWindow* aDesktop = myWorkshop->salomeConnector()->desktop();
88 #else
89   QMainWindow* aDesktop = myWorkshop->mainWindow();
90 #endif
91
92   QAction* anAction = ModuleBase_Tools::createAction(QIcon(":pictures/delete.png"), tr("Delete"),
93                                                     aDesktop);
94   aDesktop->addAction(anAction);
95
96   addAction("DELETE_CMD", anAction);
97   anAction->setShortcutContext(Qt::ApplicationShortcut);
98
99   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/rename_edit.png"), tr("Rename"),
100                                            aDesktop, this, SLOT(onRename()));
101   anAction->setShortcut(Qt::Key_F2);
102   addAction("RENAME_CMD", anAction);
103
104 #ifdef HAVE_SALOME
105   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_to_end.png"),
106                                            XGUI_Workshop::MOVE_TO_END_COMMAND, this);
107   addAction("MOVE_CMD", anAction);
108
109   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_to_end_split.png"),
110     XGUI_Workshop::MOVE_TO_END_SPLIT_COMMAND, this);
111   addAction("MOVE_SPLIT_CMD", anAction);
112 #endif
113
114   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/recover.png"),
115     tr("Recover"), this);
116   addAction("RECOVER_CMD", anAction);
117
118   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/clean_history.png"),
119                                            tr("Clean history"), aDesktop);
120   addAction("CLEAN_HISTORY_CMD", anAction);
121
122   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop);
123   addAction("COLOR_CMD", anAction);
124
125   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/autocolor.png"),
126                                                   tr("Auto color"), aDesktop);
127   addAction("AUTOCOLOR_CMD", anAction);
128
129   anAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
130   addAction("DEFLECTION_CMD", anAction);
131
132   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/transparency.png"),
133                                            tr("Transparency..."), aDesktop);
134   addAction("TRANSPARENCY_CMD", anAction);
135
136   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"),
137                                                   tr("Show"), aDesktop);
138   addAction("SHOW_CMD", anAction);
139
140   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"),
141                                             tr("Show only"), aDesktop);
142   addAction("SHOW_ONLY_CMD", anAction);
143
144   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"),
145                                            aDesktop);
146   addAction("HIDE_CMD", anAction);
147
148   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"),
149                                             tr("Hide all"), aDesktop);
150   addAction("HIDEALL_CMD", anAction);
151
152   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"),
153                                             tr("Shading"), aDesktop);
154   addAction("SHADING_CMD", anAction);
155
156   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"),
157                                            aDesktop);
158   addAction("WIREFRAME_CMD", anAction);
159
160   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/edges_dir.png"), tr("Show edges direction"),
161                                            aDesktop);
162   anAction->setCheckable(true);
163   addAction("SHOW_EDGES_DIRECTION_CMD", anAction);
164
165   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/iso_lines.png"), tr("Define Isos..."),
166                                            aDesktop);
167   addAction("ISOLINES_CMD", anAction);
168
169   anAction = ModuleBase_Tools::createAction(QIcon(), tr("Show Isos"), aDesktop);
170   anAction->setCheckable(true);
171   addAction("SHOW_ISOLINES_CMD", anAction);
172
173   anAction = ModuleBase_Tools::createAction(QIcon(), tr("Bring To Front"), aDesktop);
174   anAction->setCheckable(true);
175   addAction("BRING_TO_FRONT_CMD", anAction);
176
177   mySeparator1 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
178   mySeparator1->setSeparator(true);
179
180   mySeparator2 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
181   mySeparator2->setSeparator(true);
182
183   mySeparator3 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
184   mySeparator3->setSeparator(true);
185
186   mySeparator4 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
187   mySeparator4->setSeparator(true);
188
189   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
190                                            this, SLOT(onShapeSelection(bool)));
191   anAction->setCheckable(true);
192   addAction("SELECT_VERTEX_CMD", anAction);
193
194   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
195                                            this, SLOT(onShapeSelection(bool)));
196   anAction->setCheckable(true);
197   addAction("SELECT_EDGE_CMD", anAction);
198
199   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
200                                            this, SLOT(onShapeSelection(bool)));
201   anAction->setCheckable(true);
202   addAction("SELECT_FACE_CMD", anAction);
203
204   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop,
205                                            this, SLOT(onResultSelection(bool)));
206   anAction->setCheckable(true);
207   addAction("SELECT_RESULT_CMD", anAction);
208
209   anAction->setChecked(true);
210
211   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
212                                            tr("Select results"), aDesktop);
213   addAction("SHOW_RESULTS_CMD", anAction);
214
215   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
216                                            tr("Select parent feature"), aDesktop);
217   addAction("SHOW_FEATURE_CMD", anAction);
218
219 #ifdef TINSPECTOR
220   anAction = ModuleBase_Tools::createAction(QIcon(), tr("TInspector"), aDesktop);
221   addAction("TINSPECTOR_VIEW", anAction);
222 #endif
223
224   // Features folders actions
225   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/create_folder.png"),
226                                            tr("Insert a folder before"), aDesktop);
227   addAction("INSERT_FOLDER_CMD", anAction);
228
229   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/insert_folder_before.png"),
230                                            tr("Move into the previous folder"), aDesktop);
231   addAction("ADD_TO_FOLDER_BEFORE_CMD", anAction);
232
233   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/insert_folder_after.png"),
234                                            tr("Move into the next folder"), aDesktop);
235   addAction("ADD_TO_FOLDER_AFTER_CMD", anAction);
236
237   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_out_before.png"),
238                                            tr("Move out before the folder"), aDesktop);
239   addAction("ADD_OUT_FOLDER_BEFORE_CMD", anAction);
240
241   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_out_after.png"),
242                                            tr("Move out after the folder"), aDesktop);
243   addAction("ADD_OUT_FOLDER_AFTER_CMD", anAction);
244
245   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/normal-view-inversed.png"),
246                                            tr("Set view by inverted normal to face"), aDesktop);
247   addAction("SET_VIEW_INVERTEDNORMAL_CMD", anAction);
248
249   anAction = ModuleBase_Tools::createAction(QIcon(":pictures/normal-view.png"),
250                                            tr("Set view by normal to face"), aDesktop);
251   addAction("SET_VIEW_NORMAL_CMD", anAction);
252
253   buildObjBrowserMenu();
254   buildViewerMenu();
255 }
256
257 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
258 {
259   if (myActions.contains(theId))
260     qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
261   theAction->setData(theId);
262   connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
263   myActions[theId] = theAction;
264 }
265
266 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
267 {
268   if (myActions.contains(theId))
269     return myActions[theId];
270   return 0;
271 }
272
273 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
274 {
275   foreach(QAction* eachAction, myActions) {
276     if (eachAction->text() == theName) {
277       return eachAction;
278     }
279   }
280   return NULL;
281 }
282
283 QStringList XGUI_ContextMenuMgr::actionIds() const
284 {
285   return myActions.keys();
286 }
287
288 void XGUI_ContextMenuMgr::onAction(bool isChecked)
289 {
290   QAction* anAction = static_cast<QAction*>(sender());
291   emit actionTriggered(anAction->data().toString(), isChecked);
292 }
293
294 void XGUI_ContextMenuMgr::updateCommandsStatus()
295 {
296 }
297
298 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
299 {
300   QMenu* aMenu = new QMenu();
301   if (sender() == myWorkshop->objectBrowser()) {
302     updateObjectBrowserMenu();
303     addObjBrowserMenu(aMenu);
304   } else if (sender() == myWorkshop->viewer()) {
305     updateViewerMenu();
306     addViewerMenu(aMenu);
307   }
308
309   if (aMenu && (aMenu->actions().size() > 0)) {
310     // it is possible that some objects should do something before and after the popup menu exec
311     // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
312     // a created entity
313     emit beforeContextMenu();
314     aMenu->exec(theEvent->globalPos());
315     emit afterContextMenu();
316     delete aMenu;
317   }
318 }
319
320 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
321 {
322   foreach(QAction* anAction, myActions)
323     anAction->setEnabled(false);
324
325   XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
326   QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
327   int aSelected = aObjects.size();
328   if (aSelected > 0) {
329     SessionPtr aMgr = ModelAPI_Session::get();
330     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
331     bool hasResult = false;
332     bool hasFeature = false;
333     bool hasParameter = false;
334     bool hasCompositeOwner = false;
335     bool hasResultInHistory = false;
336     bool hasFolder = false;
337     bool hasGroupsOnly = false;
338     ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
339                                    hasCompositeOwner, hasResultInHistory, hasFolder, hasGroupsOnly);
340     //Process Feature
341     if (aSelected == 1) { // single selection
342       ObjectPtr aObject = aObjects.first();
343       ResultPtr aResult;
344       if (hasResult)
345         aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
346       if (aObject) {
347         if (hasResult && myWorkshop->canBeShaded(aObject)) {
348           XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
349           if (aMode != XGUI_Displayer::NoMode) {
350             action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
351             action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
352           } else {
353             action("WIREFRAME_CMD")->setEnabled(true);
354             action("SHADING_CMD")->setEnabled(true);
355           }
356           action("SHOW_EDGES_DIRECTION_CMD")->setEnabled(true);
357           action("SHOW_EDGES_DIRECTION_CMD")->setChecked(ModelAPI_Tools::isShowEdgesDirection(aResult));
358
359           action("BRING_TO_FRONT_CMD")->setEnabled(hasGroupsOnly);
360           action("BRING_TO_FRONT_CMD")->setChecked(ModelAPI_Tools::isBringToFront(aResult));
361
362           action("SHOW_ISOLINES_CMD")->setEnabled(true);
363           action("SHOW_ISOLINES_CMD")->setChecked(ModelAPI_Tools::isShownIsoLines(aResult));
364           action("ISOLINES_CMD")->setEnabled(true);
365         }
366         if (!hasFeature) {
367           bool aHasSubResults = ModelAPI_Tools::hasSubResults(aResult);
368           if (aHasSubResults) {
369             action("HIDE_CMD")->setEnabled(true);
370             action("SHOW_CMD")->setEnabled(true);
371           }
372           else {
373             if (aObject->isDisplayed()) {
374               action("HIDE_CMD")->setEnabled(true);
375             } else if (hasResult && (!hasParameter)) {
376               action("SHOW_CMD")->setEnabled(true);
377             }
378           }
379           if (!(hasParameter || hasFeature))
380             action("SHOW_ONLY_CMD")->setEnabled(true);
381         }
382 #ifdef HAVE_SALOME
383         else if (hasFeature && myWorkshop->canMoveFeature()) {
384           action("MOVE_CMD")->setEnabled(true);
385           action("MOVE_SPLIT_CMD")->setEnabled(true);
386         }
387 #endif
388         if (hasFeature && aObject->document() != aMgr->moduleDocument() &&
389             aObject->document() == aMgr->activeDocument())
390         {
391           XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
392           if (!anOperationMgr->hasOperation()) {
393             FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
394             std::list<std::shared_ptr<ModelAPI_Result> > aResults;
395             ModelAPI_Tools::getConcealedResults(aFeature, aResults);
396             if (!aResults.empty()) // check the feature conceals at least one result
397               action("RECOVER_CMD")->setEnabled(true);
398           }
399         }
400
401         if( aMgr->activeDocument() == aObject->document() )
402         {
403           action("RENAME_CMD")->setEnabled(true);
404           action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
405           action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
406                                                   (hasFeature || hasParameter));
407         }
408       }
409       // end single selection
410     } else { // multi-selection
411       // parameter is commented because the actions are not in the list of result parameter actions
412       if (hasResult /*&& (!hasParameter)*/) {
413         action("SHOW_CMD")->setEnabled(true);
414         action("HIDE_CMD")->setEnabled(true);
415         action("SHOW_ONLY_CMD")->setEnabled(true);
416         action("SHADING_CMD")->setEnabled(true);
417         action("WIREFRAME_CMD")->setEnabled(true);
418         action("SHOW_EDGES_DIRECTION_CMD")->setEnabled(true);
419         action("BRING_TO_FRONT_CMD")->setEnabled(hasGroupsOnly);
420         action("SHOW_ISOLINES_CMD")->setEnabled(true);
421         action("ISOLINES_CMD")->setEnabled(true);
422       }
423       if (hasFeature && myWorkshop->canMoveFeature()) {
424         action("MOVE_CMD")->setEnabled(true);
425         action("MOVE_SPLIT_CMD")->setEnabled(true);
426       }
427     } // end multi-selection
428
429     // Check folder management commands state if only features are selected
430     if ((!hasResult) && hasFeature && (!hasParameter) && (!hasCompositeOwner) &&
431       (!hasResultInHistory) && (!hasFolder)) {
432       std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
433       if (aFeatures.size() > 0) { // Check that features do not include Parts
434         QModelIndexList aIndexes = aSelMgr->selection()->selectedIndexes();
435         QModelIndex aFirstIdx = aIndexes.first();
436         QModelIndex aLastIdx = aIndexes.last();
437         QModelIndex aParentIdx = aFirstIdx.parent();
438
439         // if all selected are from the same level
440         bool isSameParent = true;
441         foreach(QModelIndex aIdx, aIndexes) {
442           if (aIdx.parent() != aParentIdx) {
443             isSameParent = false;
444             break;
445           }
446         }
447         if (isSameParent) {
448           // Check is selection continuous
449           XGUI_DataModel* aModel = myWorkshop->objectBrowser()->dataModel();
450           DocumentPtr aDoc = aMgr->activeDocument();
451
452           bool isContinuos = true;
453           if (aSelected > 1) {
454             int aId = -1;
455             foreach(FeaturePtr aF, aFeatures) {
456               if (aId == -1)
457                 aId = aDoc->index(aF);
458               else {
459                 aId++;
460                 if (aId != aDoc->index(aF)) {
461                   isContinuos = false;
462                   break;
463                 }
464               }
465             }
466           }
467           if (isContinuos) {
468             ObjectPtr aDataObj = aModel->object(aParentIdx);
469
470             ObjectPtr aPrevObj;
471             if (aFirstIdx.row() > 0) {
472               QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0);
473               aPrevObj = aModel->object(aPrevIdx);
474             }
475
476             ObjectPtr aNextObj;
477             if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
478               QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
479               aNextObj = aModel->object(aNextIdx);
480             }
481
482             bool isPrevFolder = (aPrevObj.get() &&
483               (aPrevObj->groupName() == ModelAPI_Folder::group()));
484             bool isNextFolder = (aNextObj.get() &&
485               (aNextObj->groupName() == ModelAPI_Folder::group()));
486             bool isInFolder = (aDataObj.get() &&
487               (aDataObj->groupName() == ModelAPI_Folder::group()));
488             bool isOutsideFolder = !isInFolder;
489
490             bool hasFirst = false;
491             bool hasLast = false;
492             if (isInFolder) {
493               FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aDataObj);
494               FeaturePtr aFirstFeatureInFolder;
495               AttributeReferencePtr aFirstFeatAttr =
496                   aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
497               if (aFirstFeatAttr)
498                 aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
499               hasFirst = (aFirstFeatureInFolder == aFeatures.front());
500
501               FeaturePtr aLastFeatureInFolder;
502               AttributeReferencePtr aLastFeatAttr =
503                   aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
504               if (aLastFeatAttr)
505                 aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
506               hasLast = (aLastFeatureInFolder == aFeatures.back());
507             }
508             action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
509             action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
510             action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
511             action("ADD_OUT_FOLDER_BEFORE_CMD")->setEnabled(isInFolder && hasFirst);
512             action("ADD_OUT_FOLDER_AFTER_CMD")->setEnabled(isInFolder && hasLast);
513           }
514         }
515       }
516     } // end folder management commands
517
518     bool allActive = true;
519     foreach( ObjectPtr aObject, aObjects )
520       if( aMgr->activeDocument() != aObject->document() )  {
521         allActive = false;
522         break;
523       }
524     if (!hasCompositeOwner && allActive ) {
525       if (hasResult || hasFeature || hasParameter) // #2924 results can be erased
526         action("DELETE_CMD")->setEnabled(true);
527     }
528     if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
529       action("CLEAN_HISTORY_CMD")->setEnabled(true);
530
531     action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
532     action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory);
533   } // end selection processing
534
535   // Show/Hide command has to be disabled for objects from non active document
536   bool aDeactivate = false;
537   foreach (ObjectPtr aObj, aObjects) {
538     if (!aObj->document()->isActive()) {
539       if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
540            aObj->groupName() == ModelAPI_ResultPart::group()) {
541         aDeactivate = true;
542         break;
543       }
544     }
545   }
546   if (aDeactivate) {
547     // If at leas a one object can not be edited then Show/Hide has to be disabled
548     action("SHOW_CMD")->setEnabled(false);
549     action("HIDE_CMD")->setEnabled(false);
550     action("SHOW_ONLY_CMD")->setEnabled(false);
551   }
552
553   action("COLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("COLOR_CMD"));
554   action("DEFLECTION_CMD")->setEnabled(myWorkshop->canChangeProperty("DEFLECTION_CMD"));
555   action("TRANSPARENCY_CMD")->setEnabled(myWorkshop->canChangeProperty("TRANSPARENCY_CMD"));
556   action("AUTOCOLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("AUTOCOLOR_CMD"));
557
558   #ifdef _DEBUG
559     #ifdef TINSPECTOR
560       action("TINSPECTOR_VIEW")->setEnabled(true);
561     #endif
562   #endif
563
564
565   ModuleBase_IModule* aModule = myWorkshop->module();
566   if (aModule)
567     aModule->updateObjectBrowserMenu(myActions);
568 }
569
570 void XGUI_ContextMenuMgr::updateViewerMenu()
571 {
572   foreach(QAction* anAction, myActions)
573     anAction->setEnabled(false);
574
575   XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
576   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
577   QList<ModuleBase_ViewerPrsPtr> aPrsList =
578     aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
579   if (aPrsList.size() > 0) {
580     bool isVisible = false;
581     bool canBeShaded = false;
582     bool hasPlanar = false;
583     ObjectPtr aObject;
584     foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
585       aObject = aPrs->object();
586       if (!aObject.get())
587         continue;
588       GeomShapePtr aShape = aPrs->shape();
589       if (aObject->isDisplayed()) {
590         isVisible = true;
591         canBeShaded = aDisplayer->canBeShaded(aObject);
592       }
593       if (aShape.get()) {
594         hasPlanar = (aShape->isFace() && aShape->isPlanar());
595       }
596     }
597     if (isVisible) {
598       if (canBeShaded) {
599         XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
600         if (aMode != XGUI_Displayer::NoMode) {
601           action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
602           action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
603         } else {
604           action("WIREFRAME_CMD")->setEnabled(true);
605           action("SHADING_CMD")->setEnabled(true);
606         }
607         action("ISOLINES_CMD")->setEnabled(true);
608
609         if (aPrsList.size() == 1) {
610           ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
611           if (aResult.get()) {
612             action("SHOW_ISOLINES_CMD")->setEnabled(true);
613             action("SHOW_ISOLINES_CMD")->setChecked(ModelAPI_Tools::isShownIsoLines(aResult));
614
615             action("SHOW_EDGES_DIRECTION_CMD")->setEnabled(true);
616             action("SHOW_EDGES_DIRECTION_CMD")->setChecked(
617               ModelAPI_Tools::isShowEdgesDirection(aResult));
618
619             // Only enable the "Bring To Front" command for Groups
620             ResultGroupPtr aGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(aResult);
621             action("BRING_TO_FRONT_CMD")->setEnabled(aGroup.get() != NULL);
622             action("BRING_TO_FRONT_CMD")->setChecked(ModelAPI_Tools::isBringToFront(aResult));
623           }
624         }
625       }
626       action("SHOW_ONLY_CMD")->setEnabled(true);
627       action("HIDE_CMD")->setEnabled(true);
628     } else
629       action("SHOW_CMD")->setEnabled(true);
630
631     action("SET_VIEW_NORMAL_CMD")->setEnabled(hasPlanar);
632     action("SET_VIEW_INVERTEDNORMAL_CMD")->setEnabled(hasPlanar);
633   }
634   //issue #2159 Hide all incomplete behavior
635 #ifdef HAVE_SALOME
636     action("HIDEALL_CMD")->setEnabled(true);
637 #else
638   if (myWorkshop->displayer()->objectsCount() > 0)
639     action("HIDEALL_CMD")->setEnabled(true);
640 #endif
641
642   // Update selection menu
643   QIntList aModes = myWorkshop->selectionActivate()->activeSelectionModes();
644   action("SELECT_VERTEX_CMD")->setEnabled(true);
645   action("SELECT_EDGE_CMD")->setEnabled(true);
646   action("SELECT_FACE_CMD")->setEnabled(true);
647   action("SELECT_RESULT_CMD")->setEnabled(true);
648
649   action("SELECT_RESULT_CMD")->setChecked(false);
650   action("SELECT_VERTEX_CMD")->setChecked(false);
651   action("SELECT_EDGE_CMD")->setChecked(false);
652   action("SELECT_FACE_CMD")->setChecked(false);
653   action("SELECT_RESULT_CMD")->setChecked(false);
654   if (aModes.count() == 0) {
655     action("SELECT_RESULT_CMD")->setChecked(true);
656   } else {
657     foreach(int aMode, aModes) {
658       switch (aMode) {
659       case TopAbs_VERTEX:
660         action("SELECT_VERTEX_CMD")->setChecked(true);
661         break;
662       case TopAbs_EDGE:
663         action("SELECT_EDGE_CMD")->setChecked(true);
664         break;
665       case TopAbs_FACE:
666         action("SELECT_FACE_CMD")->setChecked(true);
667         break;
668       default:
669         action("SELECT_RESULT_CMD")->setChecked(true);
670       }
671     }
672   }
673
674   ModuleBase_IModule* aModule = myWorkshop->module();
675   if (aModule)
676     aModule->updateViewerMenu(myActions);
677
678   if (myWorkshop->canChangeProperty("COLOR_CMD"))
679     action("COLOR_CMD")->setEnabled(true);
680
681   if (myWorkshop->canChangeProperty("DEFLECTION_CMD"))
682     action("DEFLECTION_CMD")->setEnabled(true);
683
684   if (myWorkshop->canChangeProperty("TRANSPARENCY_CMD"))
685     action("TRANSPARENCY_CMD")->setEnabled(true);
686
687   action("DELETE_CMD")->setEnabled(true);
688 }
689
690 void XGUI_ContextMenuMgr::connectObjectBrowser()
691 {
692   connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
693           SLOT(onContextMenuRequest(QContextMenuEvent*)));
694 }
695
696 void XGUI_ContextMenuMgr::connectViewer()
697 {
698   connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
699           SLOT(onContextMenuRequest(QContextMenuEvent*)));
700 }
701
702
703 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
704 {
705   QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
706   aSeparator->setSeparator(true);
707
708   QActionsList aList;
709
710   //-------------------------------------
711   // Result construction menu
712   aList.append(action("SHOW_CMD"));
713   aList.append(action("HIDE_CMD"));
714   aList.append(action("SHOW_ONLY_CMD"));
715   aList.append(mySeparator1);
716   aList.append(action("RENAME_CMD"));
717   aList.append(action("COLOR_CMD"));
718   aList.append(action("DEFLECTION_CMD"));
719   aList.append(action("TRANSPARENCY_CMD"));
720   aList.append(action("SHOW_FEATURE_CMD"));
721   aList.append(mySeparator2);
722   aList.append(action("DELETE_CMD"));
723   myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
724
725   //-------------------------------------
726   // Result body/field/part menu
727   aList.clear();
728   aList.append(action("WIREFRAME_CMD"));
729   aList.append(action("SHADING_CMD"));
730   aList.append(action("SHOW_EDGES_DIRECTION_CMD"));
731   aList.append(mySeparator1); // this separator is not shown as this action is added after show only
732   // qt list container contains only one instance of the same action
733   aList.append(action("SHOW_CMD"));
734   aList.append(action("HIDE_CMD"));
735   aList.append(action("SHOW_ONLY_CMD"));
736   aList.append(mySeparator2);
737   aList.append(action("RENAME_CMD"));
738   aList.append(action("COLOR_CMD"));
739   aList.append(action("DEFLECTION_CMD"));
740   aList.append(action("TRANSPARENCY_CMD"));
741   aList.append(action("SHOW_ISOLINES_CMD"));
742   aList.append(action("ISOLINES_CMD"));
743   aList.append(action("SHOW_FEATURE_CMD"));
744   aList.append(mySeparator3);
745   aList.append(action("DELETE_CMD"));
746   // Result body menu
747   myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
748   // Field menu
749   myObjBrowserMenus[ModelAPI_ResultField::group()] = aList;
750   // Result part menu
751   myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
752
753   //-------------------------------------
754   // Group menu
755   aList.clear();
756   aList.append(action("WIREFRAME_CMD"));
757   aList.append(action("SHADING_CMD"));
758   aList.append(action("SHOW_EDGES_DIRECTION_CMD"));
759   aList.append(mySeparator1);
760   aList.append(action("BRING_TO_FRONT_CMD"));
761   aList.append(mySeparator2);
762   aList.append(action("SHOW_CMD"));
763   aList.append(action("HIDE_CMD"));
764   aList.append(action("SHOW_ONLY_CMD"));
765   aList.append(mySeparator3);
766   aList.append(action("AUTOCOLOR_CMD"));
767   aList.append(action("RENAME_CMD"));
768   aList.append(action("COLOR_CMD"));
769   aList.append(action("DEFLECTION_CMD"));
770   aList.append(action("TRANSPARENCY_CMD"));
771   aList.append(action("SHOW_ISOLINES_CMD"));
772   aList.append(action("ISOLINES_CMD"));
773   aList.append(action("SHOW_FEATURE_CMD"));
774   aList.append(mySeparator4);
775   aList.append(action("DELETE_CMD"));
776   myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
777
778   //-------------------------------------
779   // Feature menu
780   aList.clear();
781   aList.append(action("RENAME_CMD"));
782   aList.append(action("SHOW_RESULTS_CMD"));
783   aList.append(action("MOVE_CMD"));
784   aList.append(action("MOVE_SPLIT_CMD"));
785   aList.append(action("RECOVER_CMD"));
786   aList.append(mySeparator1);
787   aList.append(action("INSERT_FOLDER_CMD"));
788   aList.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
789   aList.append(action("ADD_TO_FOLDER_AFTER_CMD"));
790   aList.append(mySeparator2);
791   aList.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
792   aList.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
793   aList.append(mySeparator3);
794   aList.append(action("CLEAN_HISTORY_CMD"));
795   aList.append(action("DELETE_CMD"));
796   myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
797
798   //-------------------------------------
799   // Parameter menu
800   aList.clear();
801   aList.append(action("RENAME_CMD"));
802   aList.append(mySeparator1);
803   aList.append(action("CLEAN_HISTORY_CMD"));
804   aList.append(action("DELETE_CMD"));
805   myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
806
807   //-------------------------------------
808   // Folder menu
809   aList.clear();
810   aList.append(action("RENAME_CMD"));
811   aList.append(action("DELETE_CMD"));
812   myObjBrowserMenus[ModelAPI_Folder::group()] = aList;
813
814   //---------------------------------------
815   // Step objects menu
816   aList.clear();
817   aList.append(action("SHOW_CMD"));
818   aList.append(action("HIDE_CMD"));
819   aList.append(action("SHOW_ONLY_CMD"));
820   myObjBrowserMenus[ModelAPI_ResultField::ModelAPI_FieldStep::group()] = aList;
821 }
822
823 void XGUI_ContextMenuMgr::buildViewerMenu()
824 {
825   QActionsList aList;
826   // Result construction/part menu
827   aList.append(action("COLOR_CMD"));
828   aList.append(action("DEFLECTION_CMD"));
829   aList.append(action("TRANSPARENCY_CMD"));
830   aList.append(mySeparator3);
831   aList.append(action("SET_VIEW_NORMAL_CMD"));
832   aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD"));
833   aList.append(mySeparator1);
834   aList.append(action("SHOW_ONLY_CMD"));
835   aList.append(action("HIDE_CMD"));
836   myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
837   myViewerMenu[ModelAPI_ResultPart::group()] = aList;
838
839   //-------------------------------------
840   // Result body menu
841   aList.clear();
842   aList.append(action("WIREFRAME_CMD"));
843   aList.append(action("SHADING_CMD"));
844   aList.append(action("SHOW_EDGES_DIRECTION_CMD"));
845   aList.append(mySeparator2);
846   aList.append(action("COLOR_CMD"));
847   aList.append(action("DEFLECTION_CMD"));
848   aList.append(action("TRANSPARENCY_CMD"));
849   aList.append(action("SHOW_ISOLINES_CMD"));
850   aList.append(action("ISOLINES_CMD"));
851   aList.append(mySeparator3);
852   aList.append(action("SET_VIEW_NORMAL_CMD"));
853   aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD"));
854   aList.append(mySeparator1);
855   aList.append(action("SHOW_ONLY_CMD"));
856   aList.append(action("HIDE_CMD"));
857   myViewerMenu[ModelAPI_ResultBody::group()] = aList;
858   myViewerMenu[ModelAPI_ResultField::group()] = aList;
859
860   //-------------------------------------
861   // Group menu
862   aList.clear();
863   aList.append(action("WIREFRAME_CMD"));
864   aList.append(action("SHADING_CMD"));
865   aList.append(action("SHOW_EDGES_DIRECTION_CMD"));
866   aList.append(mySeparator1);
867   aList.append(action("BRING_TO_FRONT_CMD"));
868   aList.append(mySeparator2);
869   aList.append(action("COLOR_CMD"));
870   aList.append(action("DEFLECTION_CMD"));
871   aList.append(action("TRANSPARENCY_CMD"));
872   aList.append(action("SHOW_ISOLINES_CMD"));
873   aList.append(action("ISOLINES_CMD"));
874   aList.append(mySeparator3);
875   aList.append(action("SET_VIEW_NORMAL_CMD"));
876   aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD"));
877   aList.append(mySeparator4);
878   aList.append(action("SHOW_ONLY_CMD"));
879   aList.append(action("HIDE_CMD"));
880   myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
881
882   //-------------------------------------
883   // Step objects menu
884   aList.clear();
885   aList.append(action("HIDE_CMD"));
886   myViewerMenu[ModelAPI_ResultField::ModelAPI_FieldStep::group()] = aList;
887 }
888
889
890 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
891 {
892   ModuleBase_IModule* aModule = myWorkshop->module();
893   if (aModule) {
894     theMenu->addSeparator();
895     aModule->addObjectBrowserMenu(theMenu);
896   }
897
898   XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
899   QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
900   int aSelected = aObjects.size();
901   QActionsList anActions;
902   if (aSelected == 1) {
903     ObjectPtr aObject = aObjects.first();
904     std::string aName = aObject->groupName();
905     if (myObjBrowserMenus.contains(aName))
906       anActions = myObjBrowserMenus[aName];
907   } else if (aSelected > 1) {
908       anActions.append(action("WIREFRAME_CMD"));
909       anActions.append(action("SHADING_CMD"));
910       anActions.append(action("SHOW_EDGES_DIRECTION_CMD"));
911       anActions.append(mySeparator1);
912       anActions.append(action("BRING_TO_FRONT_CMD"));
913       anActions.append(mySeparator2);
914       anActions.append(action("SHOW_CMD"));
915       anActions.append(action("HIDE_CMD"));
916       anActions.append(action("SHOW_ONLY_CMD"));
917       anActions.append(mySeparator3);
918       anActions.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
919       anActions.append(action("ADD_TO_FOLDER_AFTER_CMD"));
920       anActions.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
921       anActions.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
922       anActions.append(mySeparator4);
923       anActions.append(action("MOVE_CMD"));
924       anActions.append(action("MOVE_SPLIT_CMD"));
925       anActions.append(action("COLOR_CMD"));
926       anActions.append(action("DEFLECTION_CMD"));
927       anActions.append(action("TRANSPARENCY_CMD"));
928       anActions.append(action("SHOW_ISOLINES_CMD"));
929       anActions.append(action("ISOLINES_CMD"));
930       anActions.append(action("CLEAN_HISTORY_CMD"));
931       anActions.append(action("DELETE_CMD"));
932   }
933 #ifdef _DEBUG
934   if (aSelected == 0) {
935     #ifdef TINSPECTOR
936     anActions.append(action("TINSPECTOR_VIEW"));
937     #endif
938   }
939 #endif
940   theMenu->addActions(anActions);
941   addFeatures(theMenu);
942
943   // It is commented out because Object Browser does not have actions
944   //theMenu->addSeparator();
945   //theMenu->addActions(myWorkshop->objectBrowser()->actions());
946 }
947
948 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
949 {
950   XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
951   QList<ModuleBase_ViewerPrsPtr> aPrsList =
952     aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
953   int aSelected = aPrsList.size();
954   QActionsList anActions;
955
956   // Create selection menu
957   XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
958   if (!aOpMgr->hasOperation() &&
959       myWorkshop->selectionActivate()->activeSelectionPlace() == XGUI_SelectionActivate::Workshop) {
960     QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
961     aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
962     aSelMenu->addAction(action("SELECT_EDGE_CMD"));
963     aSelMenu->addAction(action("SELECT_FACE_CMD"));
964     //IMP: an attempt to use result selection with other selection modes
965     //aSelMenu->addSeparator();
966     aSelMenu->addAction(action("SELECT_RESULT_CMD"));
967     theMenu->addMenu(aSelMenu);
968     theMenu->addSeparator();
969   }
970   if (aSelected == 1) {
971     ObjectPtr aObject = aPrsList.first()->object();
972     if (aObject.get() != NULL) {
973       std::string aName = aObject->groupName();
974       if (myViewerMenu.contains(aName))
975         anActions = myViewerMenu[aName];
976     }
977   } else if (aSelected > 1) {
978     anActions.append(action("COLOR_CMD"));
979     anActions.append(action("DEFLECTION_CMD"));
980     anActions.append(action("TRANSPARENCY_CMD"));
981     anActions.append(mySeparator1);
982     anActions.append(action("SHOW_ONLY_CMD"));
983     anActions.append(action("HIDE_CMD"));
984   }
985   // hide all is shown always even if selection in the viewer is empty
986   anActions.append(action("HIDEALL_CMD"));
987   theMenu->addActions(anActions);
988
989   QMap<int, QAction*> aMenuActions;
990   ModuleBase_IModule* aModule = myWorkshop->module();
991   if (aModule) {
992     if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
993       theMenu->addSeparator();
994   }
995
996   // insert the module menu items on specific positions in the popup menu: some actions should be
997   // in the begin of the list, Delete action should be the last by #1343 issue
998   QList<QAction*> anActionsList = theMenu->actions();
999   int anActionsListSize = anActionsList.size();
1000   QAction* aFirstAction = anActionsList[0];
1001   QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
1002   for (; anIt != aLast; anIt++) {
1003     if (anIt.key() > anActionsListSize)
1004       theMenu->addAction(anIt.value());
1005     else
1006       theMenu->insertAction(aFirstAction, *anIt);
1007   }
1008
1009 #ifndef HAVE_SALOME
1010   theMenu->addSeparator();
1011   QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
1012   if (aMDI->actions().size() > 0) {
1013     QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
1014     aSubMenu->addActions(aMDI->actions());
1015   }
1016 #endif
1017 }
1018
1019 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
1020 {
1021   QStringList aGroups;
1022
1023   QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
1024                                                   aLast = myObjBrowserMenus.end();
1025   for (; anIt != aLast; anIt++) {
1026     QString aGroupName(anIt.key().c_str());
1027     if (aGroups.contains(aGroupName))
1028       continue;
1029     QActionsList anActions = anIt.value();
1030     QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
1031     bool aFound = false;
1032     for (; anAIt != anALast && !aFound; anAIt++)
1033       aFound = (*anAIt)->data().toString() == theName;
1034     if (aFound)
1035       aGroups.append(aGroupName);
1036   }
1037   return aGroups;
1038 }
1039
1040 void XGUI_ContextMenuMgr::onRename()
1041 {
1042   QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
1043   if (!myWorkshop->abortAllOperations())
1044     return;
1045   // restore selection in case if dialog box was shown
1046   myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
1047   myWorkshop->objectBrowser()->onEditItem();
1048 }
1049
1050 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
1051 {
1052   SessionPtr aMgr = ModelAPI_Session::get();
1053   DocumentPtr anActiveDoc = aMgr->activeDocument();
1054
1055   XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
1056   XGUI_ActionsMgr* anActionMgr = myWorkshop->actionsMgr();
1057   const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
1058   QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
1059
1060   QString aName;
1061   int aLen = 0;
1062   bool aIsRoot = false;
1063   foreach(QModelIndex aIdx, aSelectedIndexes) {
1064     // Process only first column
1065     if (aIdx.column() == 1) {
1066       aIsRoot = !aIdx.parent().isValid();
1067       // Exit if the selected index belongs to non active document
1068       if (aIsRoot && (anActiveDoc != aMgr->moduleDocument()))
1069         return;
1070
1071       // Get name of the selected index
1072       aName = aIdx.data().toString();
1073       aLen = aName.indexOf('(');
1074       if (aLen != -1) {
1075         aName = aName.left(--aLen);
1076       }
1077       std::string aFeaturesStr = aIsRoot?
1078         aDataModelXML->rootFolderFeatures(aName.toStdString()) :
1079         aDataModelXML->subFolderFeatures(aName.toStdString());
1080         if (aFeaturesStr.length() > 0) {
1081           QStringList aFeturesList =
1082             QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
1083           foreach(QString aFea, aFeturesList) {
1084             QAction* anAction = anActionMgr->action(aFea);
1085             if (anAction)
1086               theMenu->addAction(anAction);
1087           }
1088         }
1089     }
1090   }
1091 }
1092
1093 #define UNCHECK_ACTION(NAME) \
1094 { QAction* anAction = action(NAME); \
1095 bool isBlock = anAction->signalsBlocked(); \
1096 anAction->blockSignals(true); \
1097 anAction->setChecked(false); \
1098   anAction->blockSignals(isBlock); }
1099
1100
1101 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
1102 {
1103   UNCHECK_ACTION("SELECT_VERTEX_CMD");
1104   UNCHECK_ACTION("SELECT_EDGE_CMD");
1105   UNCHECK_ACTION("SELECT_FACE_CMD");
1106 }
1107
1108 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
1109 {
1110   UNCHECK_ACTION("SHOW_RESULTS_CMD");
1111 }