1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
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"
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 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/transparency.png"),
113 tr("Transparency..."), aDesktop);
114 addAction("TRANSPARENCY_CMD", aAction);
116 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
117 addAction("SHOW_CMD", aAction);
119 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show only"),
121 addAction("SHOW_ONLY_CMD", aAction);
123 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"),
125 addAction("HIDE_CMD", aAction);
127 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide all"),
129 addAction("HIDEALL_CMD", aAction);
131 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"), tr("Shading"), aDesktop);
132 addAction("SHADING_CMD", aAction);
134 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"),
136 addAction("WIREFRAME_CMD", aAction);
138 mySeparator1 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
139 mySeparator1->setSeparator(true);
141 mySeparator2 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
142 mySeparator2->setSeparator(true);
144 mySeparator3 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
145 mySeparator3->setSeparator(true);
147 //mySelectActions = new QActionGroup(this);
148 //mySelectActions->setExclusive(true);
150 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
151 this, SLOT(onShapeSelection(bool)));
152 aAction->setCheckable(true);
153 addAction("SELECT_VERTEX_CMD", aAction);
154 //mySelectActions->addAction(aAction);
156 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
157 this, SLOT(onShapeSelection(bool)));
158 aAction->setCheckable(true);
159 addAction("SELECT_EDGE_CMD", aAction);
160 //mySelectActions->addAction(aAction);
162 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
163 this, SLOT(onShapeSelection(bool)));
164 aAction->setCheckable(true);
165 addAction("SELECT_FACE_CMD", aAction);
166 //mySelectActions->addAction(aAction);
168 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop,
169 this, SLOT(onResultSelection(bool)));
170 aAction->setCheckable(true);
171 addAction("SELECT_RESULT_CMD", aAction);
172 //mySelectActions->addAction(aAction);
174 aAction->setChecked(true);
176 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
177 tr("Select results"), aDesktop);
178 addAction("SHOW_RESULTS_CMD", aAction);
180 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
181 tr("Select parent feature"), aDesktop);
182 addAction("SHOW_FEATURE_CMD", aAction);
185 aAction = ModuleBase_Tools::createAction(QIcon(), tr("TInspector"), aDesktop);
186 addAction("TINSPECTOR_VIEW", aAction);
189 // Features folders actions
190 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/create_folder.png"),
191 tr("Insert a folder before"), aDesktop);
192 addAction("INSERT_FOLDER_CMD", aAction);
194 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/insert_folder_before.png"),
195 tr("Move into the previous folder"), aDesktop);
196 addAction("ADD_TO_FOLDER_BEFORE_CMD", aAction);
198 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/insert_folder_after.png"),
199 tr("Move into the next folder"), aDesktop);
200 addAction("ADD_TO_FOLDER_AFTER_CMD", aAction);
202 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_out_before.png"),
203 tr("Move out before the folder"), aDesktop);
204 addAction("ADD_OUT_FOLDER_BEFORE_CMD", aAction);
206 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_out_after.png"),
207 tr("Move out after the folder"), aDesktop);
208 addAction("ADD_OUT_FOLDER_AFTER_CMD", aAction);
210 buildObjBrowserMenu();
214 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
216 if (myActions.contains(theId))
217 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
218 theAction->setData(theId);
219 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
220 myActions[theId] = theAction;
223 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
225 if (myActions.contains(theId))
226 return myActions[theId];
230 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
232 foreach(QAction* eachAction, myActions) {
233 if (eachAction->text() == theName) {
240 QStringList XGUI_ContextMenuMgr::actionIds() const
242 return myActions.keys();
245 void XGUI_ContextMenuMgr::onAction(bool isChecked)
247 QAction* aAction = static_cast<QAction*>(sender());
248 emit actionTriggered(aAction->data().toString(), isChecked);
251 void XGUI_ContextMenuMgr::updateCommandsStatus()
255 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
257 QMenu* aMenu = new QMenu();
258 if (sender() == myWorkshop->objectBrowser()) {
259 updateObjectBrowserMenu();
260 addObjBrowserMenu(aMenu);
261 } else if (sender() == myWorkshop->viewer()) {
263 addViewerMenu(aMenu);
266 if (aMenu && (aMenu->actions().size() > 0)) {
267 // it is possible that some objects should do something before and after the popup menu exec
268 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
270 emit beforeContextMenu();
271 aMenu->exec(theEvent->globalPos());
272 emit afterContextMenu();
277 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
279 foreach(QAction* aAction, myActions)
280 aAction->setEnabled(false);
282 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
283 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
284 int aSelected = aObjects.size();
286 SessionPtr aMgr = ModelAPI_Session::get();
287 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
288 bool hasResult = false;
289 bool hasFeature = false;
290 bool hasParameter = false;
291 bool hasCompositeOwner = false;
292 bool hasResultInHistory = false;
293 bool hasFolder = false;
294 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
295 hasCompositeOwner, hasResultInHistory, hasFolder);
297 if (aSelected == 1) { // single selection
298 ObjectPtr aObject = aObjects.first();
300 if (hasResult && myWorkshop->canBeShaded(aObject)) {
301 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
302 if (aMode != XGUI_Displayer::NoMode) {
303 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
304 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
306 action("WIREFRAME_CMD")->setEnabled(true);
307 action("SHADING_CMD")->setEnabled(true);
311 bool aHasSubResults = ModelAPI_Tools::hasSubResults(
312 std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
313 if (aHasSubResults) {
314 action("HIDE_CMD")->setEnabled(true);
315 action("SHOW_CMD")->setEnabled(true);
318 if (aObject->isDisplayed()) {
319 action("HIDE_CMD")->setEnabled(true);
320 } else if (hasResult && (!hasParameter)) {
321 action("SHOW_CMD")->setEnabled(true);
324 if (!(hasParameter || hasFeature))
325 action("SHOW_ONLY_CMD")->setEnabled(true);
327 else if (hasFeature && myWorkshop->canMoveFeature())
328 action("MOVE_CMD")->setEnabled(true);
330 if( aMgr->activeDocument() == aObject->document() )
332 action("RENAME_CMD")->setEnabled(true);
333 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
334 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
335 (hasFeature || hasParameter));
338 // end single selection
339 } else { // multi-selection
340 // parameter is commented because the actions are not in the list of result parameter actions
341 if (hasResult /*&& (!hasParameter)*/) {
342 action("SHOW_CMD")->setEnabled(true);
343 action("HIDE_CMD")->setEnabled(true);
344 action("SHOW_ONLY_CMD")->setEnabled(true);
345 action("SHADING_CMD")->setEnabled(true);
346 action("WIREFRAME_CMD")->setEnabled(true);
348 } // end multi-selection
350 // Check folder management commands state if only features are selected
351 if ((!hasResult) && hasFeature && (!hasParameter) && (!hasCompositeOwner) &&
352 (!hasResultInHistory) && (!hasFolder)) {
353 std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
354 if (aFeatures.size() > 0) { // Check that features do not include Parts
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() &&
405 (aPrevObj->groupName() == ModelAPI_Folder::group()));
406 bool isNextFolder = (aNextObj.get() &&
407 (aNextObj->groupName() == ModelAPI_Folder::group()));
408 bool isInFolder = (aDataObj.get() &&
409 (aDataObj->groupName() == ModelAPI_Folder::group()));
410 bool isOutsideFolder = !isInFolder;
412 bool hasFirst = false;
413 bool hasLast = false;
415 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aDataObj);
416 FeaturePtr aFirstFeatureInFolder;
417 AttributeReferencePtr aFirstFeatAttr =
418 aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
420 aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
421 hasFirst = (aFirstFeatureInFolder == aFeatures.front());
423 FeaturePtr aLastFeatureInFolder;
424 AttributeReferencePtr aLastFeatAttr =
425 aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
427 aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
428 hasLast = (aLastFeatureInFolder == aFeatures.back());
430 action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
431 action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
432 action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
433 action("ADD_OUT_FOLDER_BEFORE_CMD")->setEnabled(isInFolder && hasFirst);
434 action("ADD_OUT_FOLDER_AFTER_CMD")->setEnabled(isInFolder && hasLast);
438 } // end folder management commands
440 bool allActive = true;
441 foreach( ObjectPtr aObject, aObjects )
442 if( aMgr->activeDocument() != aObject->document() ) {
446 if (!hasCompositeOwner && allActive ) {
447 if (hasResult || hasFeature || hasParameter) // #2924 results can be erased
448 action("DELETE_CMD")->setEnabled(true);
450 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
451 action("CLEAN_HISTORY_CMD")->setEnabled(true);
453 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
454 action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory);
455 } // end selection processing
457 // Show/Hide command has to be disabled for objects from non active document
458 bool aDeactivate = false;
459 foreach (ObjectPtr aObj, aObjects) {
460 if (!aObj->document()->isActive()) {
461 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
462 aObj->groupName() == ModelAPI_ResultPart::group()) {
469 // If at leas a one object can not be edited then Show/Hide has to be disabled
470 action("SHOW_CMD")->setEnabled(false);
471 action("HIDE_CMD")->setEnabled(false);
472 action("SHOW_ONLY_CMD")->setEnabled(false);
475 action("COLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("COLOR_CMD"));
476 action("DEFLECTION_CMD")->setEnabled(myWorkshop->canChangeProperty("DEFLECTION_CMD"));
477 action("TRANSPARENCY_CMD")->setEnabled(myWorkshop->canChangeProperty("TRANSPARENCY_CMD"));
480 action("TINSPECTOR_VIEW")->setEnabled(true);
485 ModuleBase_IModule* aModule = myWorkshop->module();
487 aModule->updateObjectBrowserMenu(myActions);
490 void XGUI_ContextMenuMgr::updateViewerMenu()
492 foreach(QAction* aAction, myActions)
493 aAction->setEnabled(false);
495 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
496 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
497 QList<ModuleBase_ViewerPrsPtr> aPrsList =
498 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
499 if (aPrsList.size() > 0) {
500 bool isVisible = false;
501 bool isShading = false;
502 bool canBeShaded = false;
504 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
505 aObject = aPrs->object();
506 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
507 if (aRes && aRes->isDisplayed()) {
509 canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
511 (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
517 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
518 if (aMode != XGUI_Displayer::NoMode) {
519 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
520 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
522 action("WIREFRAME_CMD")->setEnabled(true);
523 action("SHADING_CMD")->setEnabled(true);
526 action("SHOW_ONLY_CMD")->setEnabled(true);
527 action("HIDE_CMD")->setEnabled(true);
529 action("SHOW_CMD")->setEnabled(true);
531 //issue #2159 Hide all incomplete behavior
533 action("HIDEALL_CMD")->setEnabled(true);
535 if (myWorkshop->displayer()->objectsCount() > 0)
536 action("HIDEALL_CMD")->setEnabled(true);
539 // Update selection menu
540 QIntList aModes = myWorkshop->selectionActivate()->activeSelectionModes();
541 action("SELECT_VERTEX_CMD")->setEnabled(true);
542 action("SELECT_EDGE_CMD")->setEnabled(true);
543 action("SELECT_FACE_CMD")->setEnabled(true);
544 action("SELECT_RESULT_CMD")->setEnabled(true);
546 action("SELECT_RESULT_CMD")->setChecked(false);
547 action("SELECT_VERTEX_CMD")->setChecked(false);
548 action("SELECT_EDGE_CMD")->setChecked(false);
549 action("SELECT_FACE_CMD")->setChecked(false);
550 action("SELECT_RESULT_CMD")->setChecked(false);
551 if (aModes.count() == 0) {
552 action("SELECT_RESULT_CMD")->setChecked(true);
554 foreach(int aMode, aModes) {
557 action("SELECT_VERTEX_CMD")->setChecked(true);
560 action("SELECT_EDGE_CMD")->setChecked(true);
563 action("SELECT_FACE_CMD")->setChecked(true);
566 action("SELECT_RESULT_CMD")->setChecked(true);
571 ModuleBase_IModule* aModule = myWorkshop->module();
573 aModule->updateViewerMenu(myActions);
575 if (myWorkshop->canChangeProperty("COLOR_CMD"))
576 action("COLOR_CMD")->setEnabled(true);
578 if (myWorkshop->canChangeProperty("DEFLECTION_CMD"))
579 action("DEFLECTION_CMD")->setEnabled(true);
581 if (myWorkshop->canChangeProperty("TRANSPARENCY_CMD"))
582 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 aList.append(action("TRANSPARENCY_CMD"));
616 aList.append(action("SHOW_FEATURE_CMD"));
617 aList.append(mySeparator2);
618 aList.append(action("DELETE_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 aList.append(action("TRANSPARENCY_CMD"));
636 aList.append(action("SHOW_FEATURE_CMD"));
637 aList.append(mySeparator3);
638 aList.append(action("DELETE_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("RENAME_CMD"));
673 aList.append(action("DELETE_CMD"));
674 myObjBrowserMenus[ModelAPI_Folder::group()] = aList;
678 void XGUI_ContextMenuMgr::buildViewerMenu()
681 // Result construction menu
682 aList.append(action("HIDE_CMD"));
683 aList.append(action("SHOW_ONLY_CMD"));
684 aList.append(mySeparator1);
685 aList.append(action("COLOR_CMD"));
686 aList.append(action("DEFLECTION_CMD"));
687 aList.append(action("TRANSPARENCY_CMD"));
688 myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
690 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
691 //-------------------------------------
694 aList.append(action("WIREFRAME_CMD"));
695 aList.append(action("SHADING_CMD"));
696 aList.append(mySeparator1);
697 aList.append(action("HIDE_CMD"));
698 aList.append(action("SHOW_ONLY_CMD"));
699 aList.append(mySeparator2);
700 aList.append(action("COLOR_CMD"));
701 aList.append(action("DEFLECTION_CMD"));
702 aList.append(action("TRANSPARENCY_CMD"));
703 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
705 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
706 myViewerMenu[ModelAPI_ResultField::group()] = aList;
707 //-------------------------------------
711 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
713 ModuleBase_IModule* aModule = myWorkshop->module();
715 theMenu->addSeparator();
716 aModule->addObjectBrowserMenu(theMenu);
719 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
720 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
721 int aSelected = aObjects.size();
722 QActionsList aActions;
723 if (aSelected == 1) {
724 ObjectPtr aObject = aObjects.first();
725 std::string aName = aObject->groupName();
726 if (myObjBrowserMenus.contains(aName))
727 aActions = myObjBrowserMenus[aName];
728 } else if (aSelected > 1) {
729 aActions.append(action("WIREFRAME_CMD"));
730 aActions.append(action("SHADING_CMD"));
731 aActions.append(mySeparator1);
732 aActions.append(action("SHOW_CMD"));
733 aActions.append(action("HIDE_CMD"));
734 aActions.append(action("SHOW_ONLY_CMD"));
735 aActions.append(mySeparator2);
736 aActions.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
737 aActions.append(action("ADD_TO_FOLDER_AFTER_CMD"));
738 aActions.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
739 aActions.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
740 aActions.append(mySeparator3);
741 //aActions.append(action("MOVE_CMD"));
742 aActions.append(action("COLOR_CMD"));
743 aActions.append(action("DEFLECTION_CMD"));
744 aActions.append(action("TRANSPARENCY_CMD"));
745 aActions.append(action("CLEAN_HISTORY_CMD"));
746 aActions.append(action("DELETE_CMD"));
749 if (aSelected == 0) {
751 aActions.append(action("TINSPECTOR_VIEW"));
755 theMenu->addActions(aActions);
756 addFeatures(theMenu);
758 // It is commented out because Object Browser does not have actions
759 //theMenu->addSeparator();
760 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
763 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
765 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
766 QList<ModuleBase_ViewerPrsPtr> aPrsList =
767 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
768 int aSelected = aPrsList.size();
769 QActionsList aActions;
771 // Create selection menu
772 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
773 if (!aOpMgr->hasOperation() &&
774 myWorkshop->selectionActivate()->activeSelectionPlace() == XGUI_SelectionActivate::Workshop) {
775 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
776 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
777 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
778 aSelMenu->addAction(action("SELECT_FACE_CMD"));
779 //IMP: an attempt to use result selection with other selection modes
780 //aSelMenu->addSeparator();
781 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
782 theMenu->addMenu(aSelMenu);
783 theMenu->addSeparator();
785 if (aSelected == 1) {
786 ObjectPtr aObject = aPrsList.first()->object();
787 if (aObject.get() != NULL) {
788 std::string aName = aObject->groupName();
789 if (myViewerMenu.contains(aName))
790 aActions = myViewerMenu[aName];
792 } else if (aSelected > 1) {
793 aActions.append(action("SHOW_ONLY_CMD"));
794 aActions.append(action("HIDE_CMD"));
796 // hide all is shown always even if selection in the viewer is empty
797 aActions.append(action("HIDEALL_CMD"));
798 aActions.append(action("COLOR_CMD"));
799 aActions.append(action("DEFLECTION_CMD"));
800 aActions.append(action("TRANSPARENCY_CMD"));
801 theMenu->addActions(aActions);
803 QMap<int, QAction*> aMenuActions;
804 ModuleBase_IModule* aModule = myWorkshop->module();
806 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
807 theMenu->addSeparator();
810 // insert the module menu items on specific positions in the popup menu: some actions should be
811 // in the begin of the list, Delete action should be the last by #1343 issue
812 QList<QAction*> anActions = theMenu->actions();
813 int anActionsSize = anActions.size();
814 QAction* aFirstAction = anActions[0];
815 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
816 for (; anIt != aLast; anIt++) {
817 if (anIt.key() > anActionsSize)
818 theMenu->addAction(anIt.value());
820 theMenu->insertAction(aFirstAction, *anIt);
824 theMenu->addSeparator();
825 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
826 if (aMDI->actions().size() > 0) {
827 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
828 aSubMenu->addActions(aMDI->actions());
833 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
837 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
838 aLast = myObjBrowserMenus.end();
839 for (; anIt != aLast; anIt++) {
840 QString aGroupName(anIt.key().c_str());
841 if (aGroups.contains(aGroupName))
843 QActionsList anActions = anIt.value();
844 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
846 for (; anAIt != anALast && !aFound; anAIt++)
847 aFound = (*anAIt)->data().toString() == theName;
849 aGroups.append(aGroupName);
854 void XGUI_ContextMenuMgr::onRename()
856 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
857 if (!myWorkshop->abortAllOperations())
859 // restore selection in case if dialog box was shown
860 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
861 myWorkshop->objectBrowser()->onEditItem();
864 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
866 SessionPtr aMgr = ModelAPI_Session::get();
867 DocumentPtr aActiveDoc = aMgr->activeDocument();
869 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
870 XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
871 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
872 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
876 bool aIsRoot = false;
877 foreach(QModelIndex aIdx, aSelectedIndexes) {
878 // Process only first column
879 if (aIdx.column() == 1) {
880 aIsRoot = !aIdx.parent().isValid();
881 // Exit if the selected index belongs to non active document
882 if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
884 if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
887 // Get name of the selected index
888 aName = aIdx.data().toString();
889 aLen = aName.indexOf('(');
891 aName = aName.left(--aLen);
893 std::string aFeaturesStr = aIsRoot?
894 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
895 aDataModelXML->subFolderFeatures(aName.toStdString());
896 if (aFeaturesStr.length() > 0) {
897 QStringList aFeturesList =
898 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
899 foreach(QString aFea, aFeturesList) {
900 QAction* aAction = aActionMgr->action(aFea);
902 theMenu->addAction(aAction);
909 #define UNCHECK_ACTION(NAME) \
910 { QAction* aAction = action(NAME); \
911 bool isBlock = aAction->signalsBlocked(); \
912 aAction->blockSignals(true); \
913 aAction->setChecked(false); \
914 aAction->blockSignals(isBlock); }
917 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
919 UNCHECK_ACTION("SELECT_VERTEX_CMD");
920 UNCHECK_ACTION("SELECT_EDGE_CMD");
921 UNCHECK_ACTION("SELECT_FACE_CMD");
924 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
926 UNCHECK_ACTION("SHOW_RESULTS_CMD");