1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "XGUI_ContextMenuMgr.h"
22 #include "XGUI_Workshop.h"
23 #include "XGUI_ObjectsBrowser.h"
24 #include "XGUI_SelectionMgr.h"
25 #include "XGUI_Displayer.h"
26 #include "XGUI_ViewerProxy.h"
27 #include "XGUI_Selection.h"
28 #include "XGUI_SalomeConnector.h"
29 #include "XGUI_DataModel.h"
30 #include "XGUI_OperationMgr.h"
31 #include "XGUI_Tools.h"
32 #include "XGUI_ActionsMgr.h"
35 #include <AppElements_MainWindow.h>
38 //#include "PartSetPlugin_Part.h"
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>
53 #include <Config_DataModelReader.h>
55 #include <ModuleBase_IModule.h>
56 #include <ModuleBase_Tools.h>
57 #include <ModuleBase_OperationAction.h>
58 #include <ModuleBase_ViewerPrs.h>
61 #include <QActionGroup>
62 #include <QContextMenuEvent>
65 #include <QMainWindow>
66 #include <QModelIndex>
68 XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
70 myWorkshop(theParent),
71 mySeparator1(0), mySeparator2(0), mySeparator3(0)
75 XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr()
79 void XGUI_ContextMenuMgr::createActions()
82 QMainWindow* aDesktop = myWorkshop->salomeConnector()->desktop();
84 QMainWindow* aDesktop = myWorkshop->mainWindow();
87 QAction* aAction = ModuleBase_Tools::createAction(QIcon(":pictures/delete.png"), tr("Delete"),
89 aDesktop->addAction(aAction);
91 addAction("DELETE_CMD", aAction);
92 aAction->setShortcutContext(Qt::ApplicationShortcut);
94 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/rename_edit.png"), tr("Rename"),
95 aDesktop, this, SLOT(onRename()));
96 addAction("RENAME_CMD", aAction);
98 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move.png"),
99 XGUI_Workshop::MOVE_TO_END_COMMAND, this);
100 addAction("MOVE_CMD", aAction);
102 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/clean_history.png"),
103 tr("Clean history"), aDesktop);
104 addAction("CLEAN_HISTORY_CMD", aAction);
106 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop);
107 addAction("COLOR_CMD", aAction);
109 aAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
110 addAction("DEFLECTION_CMD", aAction);
112 #ifdef USE_TRANSPARENCY
113 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/transparency.png"),
114 tr("Transparency..."), aDesktop);
115 addAction("TRANSPARENCY_CMD", aAction);
118 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
119 addAction("SHOW_CMD", aAction);
121 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show only"),
123 addAction("SHOW_ONLY_CMD", aAction);
125 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"),
127 addAction("HIDE_CMD", aAction);
129 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide all"),
131 addAction("HIDEALL_CMD", aAction);
133 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"), tr("Shading"), aDesktop);
134 addAction("SHADING_CMD", aAction);
136 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"),
138 addAction("WIREFRAME_CMD", aAction);
140 mySeparator1 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
141 mySeparator1->setSeparator(true);
143 mySeparator2 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
144 mySeparator2->setSeparator(true);
146 mySeparator3 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
147 mySeparator3->setSeparator(true);
149 //mySelectActions = new QActionGroup(this);
150 //mySelectActions->setExclusive(true);
152 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
153 this, SLOT(onShapeSelection(bool)));
154 aAction->setCheckable(true);
155 addAction("SELECT_VERTEX_CMD", aAction);
156 //mySelectActions->addAction(aAction);
158 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
159 this, SLOT(onShapeSelection(bool)));
160 aAction->setCheckable(true);
161 addAction("SELECT_EDGE_CMD", aAction);
162 //mySelectActions->addAction(aAction);
164 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
165 this, SLOT(onShapeSelection(bool)));
166 aAction->setCheckable(true);
167 addAction("SELECT_FACE_CMD", aAction);
168 //mySelectActions->addAction(aAction);
170 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop,
171 this, SLOT(onResultSelection(bool)));
172 aAction->setCheckable(true);
173 addAction("SELECT_RESULT_CMD", aAction);
174 //mySelectActions->addAction(aAction);
176 aAction->setChecked(true);
178 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
179 tr("Select results"), aDesktop);
180 addAction("SHOW_RESULTS_CMD", aAction);
182 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
183 tr("Select parent feature"), aDesktop);
184 addAction("SHOW_FEATURE_CMD", aAction);
187 aAction = ModuleBase_Tools::createAction(QIcon(), tr("TInspector"), aDesktop);
188 addAction("TINSPECTOR_VIEW", aAction);
191 // Features folders actions
192 aAction = ModuleBase_Tools::createAction(QIcon(),
193 tr("Insert a folder before"), aDesktop);
194 addAction("INSERT_FOLDER_CMD", aAction);
196 aAction = ModuleBase_Tools::createAction(QIcon(),
197 tr("Move into the previous folder"), aDesktop);
198 addAction("ADD_TO_FOLDER_BEFORE_CMD", aAction);
200 aAction = ModuleBase_Tools::createAction(QIcon(),
201 tr("Move into the next folder"), aDesktop);
202 addAction("ADD_TO_FOLDER_AFTER_CMD", aAction);
204 aAction = ModuleBase_Tools::createAction(QIcon(),
205 tr("Move out before the folder"), aDesktop);
206 addAction("ADD_OUT_FOLDER_BEFORE_CMD", aAction);
208 aAction = ModuleBase_Tools::createAction(QIcon(),
209 tr("Move out after the folder"), aDesktop);
210 addAction("ADD_OUT_FOLDER_AFTER_CMD", aAction);
212 buildObjBrowserMenu();
216 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
218 if (myActions.contains(theId))
219 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
220 theAction->setData(theId);
221 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
222 myActions[theId] = theAction;
225 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
227 if (myActions.contains(theId))
228 return myActions[theId];
232 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
234 foreach(QAction* eachAction, myActions) {
235 if (eachAction->text() == theName) {
242 QStringList XGUI_ContextMenuMgr::actionIds() const
244 return myActions.keys();
247 void XGUI_ContextMenuMgr::onAction(bool isChecked)
249 QAction* aAction = static_cast<QAction*>(sender());
250 emit actionTriggered(aAction->data().toString(), isChecked);
253 void XGUI_ContextMenuMgr::updateCommandsStatus()
257 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
259 QMenu* aMenu = new QMenu();
260 if (sender() == myWorkshop->objectBrowser()) {
261 updateObjectBrowserMenu();
262 addObjBrowserMenu(aMenu);
263 } else if (sender() == myWorkshop->viewer()) {
265 addViewerMenu(aMenu);
268 if (aMenu && (aMenu->actions().size() > 0)) {
269 // it is possible that some objects should do something before and after the popup menu exec
270 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
272 emit beforeContextMenu();
273 aMenu->exec(theEvent->globalPos());
274 emit afterContextMenu();
279 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
281 foreach(QAction* aAction, myActions)
282 aAction->setEnabled(false);
284 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
285 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
286 int aSelected = aObjects.size();
288 SessionPtr aMgr = ModelAPI_Session::get();
289 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
290 bool hasResult = false;
291 bool hasFeature = false;
292 bool hasParameter = false;
293 bool hasCompositeOwner = false;
294 bool hasResultInHistory = false;
295 bool hasFolder = false;
296 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
297 hasCompositeOwner, hasResultInHistory, hasFolder);
299 if (aSelected == 1) { // single selection
300 ObjectPtr aObject = aObjects.first();
302 if (hasResult && myWorkshop->canBeShaded(aObject)) {
303 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
304 if (aMode != XGUI_Displayer::NoMode) {
305 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
306 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
308 action("WIREFRAME_CMD")->setEnabled(true);
309 action("SHADING_CMD")->setEnabled(true);
313 bool aHasSubResults = ModelAPI_Tools::hasSubResults(
314 std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
315 if (aHasSubResults) {
316 action("HIDE_CMD")->setEnabled(true);
317 action("SHOW_CMD")->setEnabled(true);
320 if (aObject->isDisplayed()) {
321 action("HIDE_CMD")->setEnabled(true);
322 } else if (hasResult && (!hasParameter)) {
323 action("SHOW_CMD")->setEnabled(true);
326 if (!(hasParameter || hasFeature))
327 action("SHOW_ONLY_CMD")->setEnabled(true);
329 else if (hasFeature && myWorkshop->canMoveFeature())
330 action("MOVE_CMD")->setEnabled(true);
332 if( aMgr->activeDocument() == aObject->document() )
334 action("RENAME_CMD")->setEnabled(true);
335 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
336 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
337 (hasFeature || hasParameter));
340 // end single selection
341 } else { // multiselection
342 // parameter is commented because the actions are not in the list of result parameter actions
343 if (hasResult /*&& (!hasParameter)*/) {
344 action("SHOW_CMD")->setEnabled(true);
345 action("HIDE_CMD")->setEnabled(true);
346 action("SHOW_ONLY_CMD")->setEnabled(true);
347 action("SHADING_CMD")->setEnabled(true);
348 action("WIREFRAME_CMD")->setEnabled(true);
350 } // end multiselection
352 // Check folder management commands state if only features are selected
353 if ((!hasResult) && hasFeature && (!hasParameter) && (!hasCompositeOwner) &&
354 (!hasResultInHistory) && (!hasFolder)) {
355 QModelIndexList aIndexes = aSelMgr->selection()->selectedIndexes();
356 QModelIndex aFirstIdx = aIndexes.first();
357 QModelIndex aLastIdx = aIndexes.last();
358 QModelIndex aParentIdx = aFirstIdx.parent();
360 // if all selected are from the same level
361 bool isSameParent = true;
362 foreach(QModelIndex aIdx, aIndexes) {
363 if (aIdx.parent() != aParentIdx) {
364 isSameParent = false;
369 // Check is selection continuous
370 XGUI_DataModel* aModel = myWorkshop->objectBrowser()->dataModel();
371 DocumentPtr aDoc = aMgr->activeDocument();
372 std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
374 bool isContinuos = true;
377 foreach(FeaturePtr aF, aFeatures) {
379 aId = aDoc->index(aF);
382 if (aId != aDoc->index(aF)) {
390 ObjectPtr aDataObj = aModel->object(aParentIdx);
393 if (aFirstIdx.row() > 0) {
394 QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0);
395 aPrevObj = aModel->object(aPrevIdx);
399 if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
400 QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
401 aNextObj = aModel->object(aNextIdx);
404 bool isPrevFolder = (aPrevObj.get() && (aPrevObj->groupName() == ModelAPI_Folder::group()));
405 bool isNextFolder = (aNextObj.get() && (aNextObj->groupName() == ModelAPI_Folder::group()));
406 bool isInFolder = (aDataObj.get() && (aDataObj->groupName() == ModelAPI_Folder::group()));
407 bool isOutsideFolder = !isInFolder;
409 bool hasFirst = false;
410 bool hasLast = false;
412 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aDataObj);
413 FeaturePtr aFirstFeatureInFolder;
414 AttributeReferencePtr aFirstFeatAttr =
415 aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
417 aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
418 hasFirst = (aFirstFeatureInFolder == aFeatures.front());
420 FeaturePtr aLastFeatureInFolder;
421 AttributeReferencePtr aLastFeatAttr =
422 aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
424 aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
425 hasLast = (aLastFeatureInFolder == aFeatures.back());
427 action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
428 action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
429 action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
430 action("ADD_OUT_FOLDER_BEFORE_CMD")->setEnabled(isInFolder && hasFirst);
431 action("ADD_OUT_FOLDER_AFTER_CMD")->setEnabled(isInFolder && hasLast);
434 } // end folder management commands
436 bool allActive = true;
437 foreach( ObjectPtr aObject, aObjects )
438 if( aMgr->activeDocument() != aObject->document() ) {
442 if (!hasCompositeOwner && allActive ) {
443 if (hasFeature || hasParameter)
444 action("DELETE_CMD")->setEnabled(true);
446 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
447 action("CLEAN_HISTORY_CMD")->setEnabled(true);
449 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
450 action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory);
451 } // end selection processing
453 // Show/Hide command has to be disabled for objects from non active document
454 bool aDeactivate = false;
455 foreach (ObjectPtr aObj, aObjects) {
456 if (!aObj->document()->isActive()) {
457 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
458 aObj->groupName() == ModelAPI_ResultPart::group()) {
465 // If at leas a one objec can not be edited then Show/Hide has to be disabled
466 action("SHOW_CMD")->setEnabled(false);
467 action("HIDE_CMD")->setEnabled(false);
468 action("SHOW_ONLY_CMD")->setEnabled(false);
471 action("COLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("COLOR_CMD"));
472 action("DEFLECTION_CMD")->setEnabled(myWorkshop->canChangeProperty("DEFLECTION_CMD"));
473 #ifdef USE_TRANSPARENCY
474 action("TRANSPARENCY_CMD")->setEnabled(myWorkshop->canChangeProperty("TRANSPARENCY_CMD"));
478 action("TINSPECTOR_VIEW")->setEnabled(true);
483 ModuleBase_IModule* aModule = myWorkshop->module();
485 aModule->updateObjectBrowserMenu(myActions);
488 void XGUI_ContextMenuMgr::updateViewerMenu()
490 foreach(QAction* aAction, myActions)
491 aAction->setEnabled(false);
493 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
494 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
495 QList<ModuleBase_ViewerPrsPtr> aPrsList =
496 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
497 if (aPrsList.size() > 0) {
498 bool isVisible = false;
499 bool isShading = false;
500 bool canBeShaded = false;
502 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
503 aObject = aPrs->object();
504 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
505 if (aRes && aRes->isDisplayed()) {
507 canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
509 (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
515 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
516 if (aMode != XGUI_Displayer::NoMode) {
517 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
518 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
520 action("WIREFRAME_CMD")->setEnabled(true);
521 action("SHADING_CMD")->setEnabled(true);
524 action("SHOW_ONLY_CMD")->setEnabled(true);
525 action("HIDE_CMD")->setEnabled(true);
527 action("SHOW_CMD")->setEnabled(true);
529 //issue #2159 Hide all incomplete behavior
531 action("HIDEALL_CMD")->setEnabled(true);
533 if (myWorkshop->displayer()->objectsCount() > 0)
534 action("HIDEALL_CMD")->setEnabled(true);
537 // Update selection menu
538 QIntList aModes = aDisplayer->activeSelectionModes();
539 action("SELECT_VERTEX_CMD")->setEnabled(true);
540 action("SELECT_EDGE_CMD")->setEnabled(true);
541 action("SELECT_FACE_CMD")->setEnabled(true);
542 action("SELECT_RESULT_CMD")->setEnabled(true);
544 action("SELECT_RESULT_CMD")->setChecked(false);
545 action("SELECT_VERTEX_CMD")->setChecked(false);
546 action("SELECT_EDGE_CMD")->setChecked(false);
547 action("SELECT_FACE_CMD")->setChecked(false);
548 action("SELECT_RESULT_CMD")->setChecked(false);
549 if (aModes.count() == 0) {
550 action("SELECT_RESULT_CMD")->setChecked(true);
552 foreach(int aMode, aModes) {
555 action("SELECT_VERTEX_CMD")->setChecked(true);
558 action("SELECT_EDGE_CMD")->setChecked(true);
561 action("SELECT_FACE_CMD")->setChecked(true);
564 action("SELECT_RESULT_CMD")->setChecked(true);
569 ModuleBase_IModule* aModule = myWorkshop->module();
571 aModule->updateViewerMenu(myActions);
573 if (myWorkshop->canChangeProperty("COLOR_CMD"))
574 action("COLOR_CMD")->setEnabled(true);
576 if (myWorkshop->canChangeProperty("DEFLECTION_CMD"))
577 action("DEFLECTION_CMD")->setEnabled(true);
579 #ifdef USE_TRANSPARENCY
580 if (myWorkshop->canChangeProperty("TRANSPARENCY_CMD"))
581 action("TRANSPARENCY_CMD")->setEnabled(true);
584 action("DELETE_CMD")->setEnabled(true);
587 void XGUI_ContextMenuMgr::connectObjectBrowser()
589 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
590 SLOT(onContextMenuRequest(QContextMenuEvent*)));
593 void XGUI_ContextMenuMgr::connectViewer()
595 connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
596 SLOT(onContextMenuRequest(QContextMenuEvent*)));
600 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
602 QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
603 aSeparator->setSeparator(true);
607 // Result construction menu
608 aList.append(action("SHOW_CMD"));
609 aList.append(action("HIDE_CMD"));
610 aList.append(action("SHOW_ONLY_CMD"));
611 aList.append(mySeparator1);
612 aList.append(action("RENAME_CMD"));
613 aList.append(action("COLOR_CMD"));
614 aList.append(action("DEFLECTION_CMD"));
615 #ifdef USE_TRANSPARENCY
616 aList.append(action("TRANSPARENCY_CMD"));
618 aList.append(action("SHOW_FEATURE_CMD"));
619 myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
621 //-------------------------------------
624 aList.append(action("WIREFRAME_CMD"));
625 aList.append(action("SHADING_CMD"));
626 aList.append(mySeparator1); // this separator is not shown as this action is added after show only
627 // qt list container contains only one instance of the same action
628 aList.append(action("SHOW_CMD"));
629 aList.append(action("HIDE_CMD"));
630 aList.append(action("SHOW_ONLY_CMD"));
631 aList.append(mySeparator2);
632 aList.append(action("RENAME_CMD"));
633 aList.append(action("COLOR_CMD"));
634 aList.append(action("DEFLECTION_CMD"));
635 #ifdef USE_TRANSPARENCY
636 aList.append(action("TRANSPARENCY_CMD"));
638 aList.append(action("SHOW_FEATURE_CMD"));
639 myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
641 myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
642 myObjBrowserMenus[ModelAPI_ResultField::group()] = aList;
644 myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
645 //-------------------------------------
648 aList.append(action("RENAME_CMD"));
649 aList.append(action("SHOW_RESULTS_CMD"));
650 aList.append(action("MOVE_CMD"));
651 aList.append(mySeparator1);
652 aList.append(action("INSERT_FOLDER_CMD"));
653 aList.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
654 aList.append(action("ADD_TO_FOLDER_AFTER_CMD"));
655 aList.append(mySeparator2);
656 aList.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
657 aList.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
658 aList.append(mySeparator3);
659 aList.append(action("CLEAN_HISTORY_CMD"));
660 aList.append(action("DELETE_CMD"));
661 myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
664 aList.append(action("RENAME_CMD"));
665 aList.append(mySeparator1);
666 aList.append(action("CLEAN_HISTORY_CMD"));
667 aList.append(action("DELETE_CMD"));
668 myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
669 //-------------------------------------
672 aList.append(action("DELETE_CMD"));
673 myObjBrowserMenus[ModelAPI_Folder::group()] = aList;
677 void XGUI_ContextMenuMgr::buildViewerMenu()
680 // Result construction menu
681 aList.append(action("HIDE_CMD"));
682 aList.append(action("SHOW_ONLY_CMD"));
683 aList.append(mySeparator1);
684 aList.append(action("COLOR_CMD"));
685 aList.append(action("DEFLECTION_CMD"));
686 #ifdef USE_TRANSPARENCY
687 aList.append(action("TRANSPARENCY_CMD"));
689 myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
691 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
692 //-------------------------------------
695 aList.append(action("WIREFRAME_CMD"));
696 aList.append(action("SHADING_CMD"));
697 aList.append(mySeparator1);
698 aList.append(action("HIDE_CMD"));
699 aList.append(action("SHOW_ONLY_CMD"));
700 aList.append(mySeparator2);
701 aList.append(action("COLOR_CMD"));
702 aList.append(action("DEFLECTION_CMD"));
703 #ifdef USE_TRANSPARENCY
704 aList.append(action("TRANSPARENCY_CMD"));
706 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
708 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
709 myViewerMenu[ModelAPI_ResultField::group()] = aList;
710 //-------------------------------------
714 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
716 ModuleBase_IModule* aModule = myWorkshop->module();
718 theMenu->addSeparator();
719 aModule->addObjectBrowserMenu(theMenu);
722 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
723 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
724 int aSelected = aObjects.size();
725 QActionsList aActions;
726 if (aSelected == 1) {
727 ObjectPtr aObject = aObjects.first();
728 std::string aName = aObject->groupName();
729 if (myObjBrowserMenus.contains(aName))
730 aActions = myObjBrowserMenus[aName];
731 } else if (aSelected > 1) {
732 aActions.append(action("WIREFRAME_CMD"));
733 aActions.append(action("SHADING_CMD"));
734 aActions.append(mySeparator1);
735 aActions.append(action("SHOW_CMD"));
736 aActions.append(action("HIDE_CMD"));
737 aActions.append(action("SHOW_ONLY_CMD"));
738 aActions.append(mySeparator2);
739 aActions.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
740 aActions.append(action("ADD_TO_FOLDER_AFTER_CMD"));
741 aActions.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
742 aActions.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
743 aActions.append(mySeparator3);
744 //aActions.append(action("MOVE_CMD"));
745 aActions.append(action("COLOR_CMD"));
746 aActions.append(action("DEFLECTION_CMD"));
747 #ifdef USE_TRANSPARENCY
748 aActions.append(action("TRANSPARENCY_CMD"));
750 aActions.append(action("CLEAN_HISTORY_CMD"));
751 aActions.append(action("DELETE_CMD"));
754 if (aSelected == 0) {
756 aActions.append(action("TINSPECTOR_VIEW"));
760 theMenu->addActions(aActions);
761 addFeatures(theMenu);
763 // It is commented out because Object Browser does not have actions
764 //theMenu->addSeparator();
765 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
768 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
770 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
771 QList<ModuleBase_ViewerPrsPtr> aPrsList =
772 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
773 int aSelected = aPrsList.size();
774 QActionsList aActions;
776 // Create selection menu
777 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
779 myWorkshop->module()->activeSelectionModes(aModes);
780 if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
781 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
782 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
783 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
784 aSelMenu->addAction(action("SELECT_FACE_CMD"));
785 //IMP: an attempt to use result selection with other selection modes
786 //aSelMenu->addSeparator();
787 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
788 theMenu->addMenu(aSelMenu);
789 theMenu->addSeparator();
791 if (aSelected == 1) {
792 ObjectPtr aObject = aPrsList.first()->object();
793 if (aObject.get() != NULL) {
794 std::string aName = aObject->groupName();
795 if (myViewerMenu.contains(aName))
796 aActions = myViewerMenu[aName];
798 } else if (aSelected > 1) {
799 aActions.append(action("HIDE_CMD"));
801 // hide all is shown always even if selection in the viewer is empty
802 aActions.append(action("HIDEALL_CMD"));
803 aActions.append(action("COLOR_CMD"));
804 aActions.append(action("DEFLECTION_CMD"));
805 #ifdef USE_TRANSPARENCY
806 aActions.append(action("TRANSPARENCY_CMD"));
808 theMenu->addActions(aActions);
810 QMap<int, QAction*> aMenuActions;
811 ModuleBase_IModule* aModule = myWorkshop->module();
813 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
814 theMenu->addSeparator();
817 // insert the module menu items on specific positions in the popup menu: some actions should be
818 // in the begin of the list, Delete action should be the last by #1343 issue
819 QList<QAction*> anActions = theMenu->actions();
820 int anActionsSize = anActions.size();
821 QAction* aFirstAction = anActions[0];
822 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
823 for (; anIt != aLast; anIt++) {
824 if (anIt.key() > anActionsSize)
825 theMenu->addAction(anIt.value());
827 theMenu->insertAction(aFirstAction, *anIt);
831 theMenu->addSeparator();
832 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
833 if (aMDI->actions().size() > 0) {
834 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
835 aSubMenu->addActions(aMDI->actions());
840 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
844 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
845 aLast = myObjBrowserMenus.end();
846 for (; anIt != aLast; anIt++) {
847 QString aGroupName(anIt.key().c_str());
848 if (aGroups.contains(aGroupName))
850 QActionsList anActions = anIt.value();
851 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
853 for (; anAIt != anALast && !aFound; anAIt++)
854 aFound = (*anAIt)->data().toString() == theName;
856 aGroups.append(aGroupName);
861 void XGUI_ContextMenuMgr::onRename()
863 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
864 if (!myWorkshop->abortAllOperations())
866 // restore selection in case if dialog box was shown
867 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
868 myWorkshop->objectBrowser()->onEditItem();
871 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
873 SessionPtr aMgr = ModelAPI_Session::get();
874 DocumentPtr aActiveDoc = aMgr->activeDocument();
876 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
877 XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
878 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
879 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
883 bool aIsRoot = false;
884 foreach(QModelIndex aIdx, aSelectedIndexes) {
885 // Process only first column
886 if (aIdx.column() == 1) {
887 aIsRoot = !aIdx.parent().isValid();
888 // Exit if the selected index belongs to non active document
889 if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
891 if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
894 // Get name of the selected index
895 aName = aIdx.data().toString();
896 aLen = aName.indexOf('(');
898 aName = aName.left(--aLen);
900 std::string aFeaturesStr = aIsRoot?
901 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
902 aDataModelXML->subFolderFeatures(aName.toStdString());
903 if (aFeaturesStr.length() > 0) {
904 QStringList aFeturesList =
905 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
906 foreach(QString aFea, aFeturesList) {
907 QAction* aAction = aActionMgr->action(aFea);
909 theMenu->addAction(aAction);
916 #define UNCHECK_ACTION(NAME) \
917 { QAction* aAction = action(NAME); \
918 bool isBlock = aAction->signalsBlocked(); \
919 aAction->blockSignals(true); \
920 aAction->setChecked(false); \
921 aAction->blockSignals(isBlock); }
924 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
926 UNCHECK_ACTION("SELECT_VERTEX_CMD");
927 UNCHECK_ACTION("SELECT_EDGE_CMD");
928 UNCHECK_ACTION("SELECT_FACE_CMD");
931 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
933 UNCHECK_ACTION("SHOW_RESULTS_CMD");