1 // Copyright (C) 2014-2020 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>
52 #include <ModelAPI_ResultField.h>
54 #include <Config_DataModelReader.h>
56 #include <ModuleBase_IModule.h>
57 #include <ModuleBase_Tools.h>
58 #include <ModuleBase_Operation.h>
59 #include <ModuleBase_ViewerPrs.h>
62 #include <QActionGroup>
63 #include <QContextMenuEvent>
66 #include <QMainWindow>
67 #include <QModelIndex>
69 XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
71 myWorkshop(theParent),
72 mySeparator1(0), mySeparator2(0), mySeparator3(0)
76 XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr()
80 void XGUI_ContextMenuMgr::createActions()
83 QMainWindow* aDesktop = myWorkshop->salomeConnector()->desktop();
85 QMainWindow* aDesktop = myWorkshop->mainWindow();
88 QAction* aAction = ModuleBase_Tools::createAction(QIcon(":pictures/delete.png"), tr("Delete"),
90 aDesktop->addAction(aAction);
92 addAction("DELETE_CMD", aAction);
93 aAction->setShortcutContext(Qt::ApplicationShortcut);
95 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/rename_edit.png"), tr("Rename"),
96 aDesktop, this, SLOT(onRename()));
97 addAction("RENAME_CMD", aAction);
99 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_to_end.png"),
100 XGUI_Workshop::MOVE_TO_END_COMMAND, this);
101 addAction("MOVE_CMD", aAction);
103 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_to_end_split.png"),
104 XGUI_Workshop::MOVE_TO_END_SPLIT_COMMAND, this);
105 addAction("MOVE_SPLIT_CMD", aAction);
107 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/clean_history.png"),
108 tr("Clean history"), aDesktop);
109 addAction("CLEAN_HISTORY_CMD", aAction);
111 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop);
112 addAction("COLOR_CMD", aAction);
114 aAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
115 addAction("DEFLECTION_CMD", aAction);
117 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/transparency.png"),
118 tr("Transparency..."), aDesktop);
119 addAction("TRANSPARENCY_CMD", aAction);
121 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
122 addAction("SHOW_CMD", aAction);
124 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show only"),
126 addAction("SHOW_ONLY_CMD", aAction);
128 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"),
130 addAction("HIDE_CMD", aAction);
132 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide all"),
134 addAction("HIDEALL_CMD", aAction);
136 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"), tr("Shading"), aDesktop);
137 addAction("SHADING_CMD", aAction);
139 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"),
141 addAction("WIREFRAME_CMD", aAction);
143 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/iso_lines.png"), tr("Define Isos..."),
145 addAction("ISOLINES_CMD", aAction);
147 aAction = ModuleBase_Tools::createAction(QIcon(), tr("Show Isos"), aDesktop);
148 aAction->setCheckable(true);
149 addAction("SHOW_ISOLINES_CMD", aAction);
151 mySeparator1 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
152 mySeparator1->setSeparator(true);
154 mySeparator2 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
155 mySeparator2->setSeparator(true);
157 mySeparator3 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
158 mySeparator3->setSeparator(true);
160 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
161 this, SLOT(onShapeSelection(bool)));
162 aAction->setCheckable(true);
163 addAction("SELECT_VERTEX_CMD", aAction);
165 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
166 this, SLOT(onShapeSelection(bool)));
167 aAction->setCheckable(true);
168 addAction("SELECT_EDGE_CMD", aAction);
170 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
171 this, SLOT(onShapeSelection(bool)));
172 aAction->setCheckable(true);
173 addAction("SELECT_FACE_CMD", aAction);
175 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop,
176 this, SLOT(onResultSelection(bool)));
177 aAction->setCheckable(true);
178 addAction("SELECT_RESULT_CMD", aAction);
180 aAction->setChecked(true);
182 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
183 tr("Select results"), aDesktop);
184 addAction("SHOW_RESULTS_CMD", aAction);
186 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
187 tr("Select parent feature"), aDesktop);
188 addAction("SHOW_FEATURE_CMD", aAction);
191 aAction = ModuleBase_Tools::createAction(QIcon(), tr("TInspector"), aDesktop);
192 addAction("TINSPECTOR_VIEW", aAction);
195 // Features folders actions
196 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/create_folder.png"),
197 tr("Insert a folder before"), aDesktop);
198 addAction("INSERT_FOLDER_CMD", aAction);
200 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/insert_folder_before.png"),
201 tr("Move into the previous folder"), aDesktop);
202 addAction("ADD_TO_FOLDER_BEFORE_CMD", aAction);
204 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/insert_folder_after.png"),
205 tr("Move into the next folder"), aDesktop);
206 addAction("ADD_TO_FOLDER_AFTER_CMD", aAction);
208 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_out_before.png"),
209 tr("Move out before the folder"), aDesktop);
210 addAction("ADD_OUT_FOLDER_BEFORE_CMD", aAction);
212 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_out_after.png"),
213 tr("Move out after the folder"), aDesktop);
214 addAction("ADD_OUT_FOLDER_AFTER_CMD", aAction);
216 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/normal-view-inversed.png"),
217 tr("Set view by inverted normal to face"), aDesktop);
218 addAction("SET_VIEW_INVERTEDNORMAL_CMD", aAction);
220 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/normal-view.png"),
221 tr("Set view by normal to face"), aDesktop);
222 addAction("SET_VIEW_NORMAL_CMD", aAction);
224 buildObjBrowserMenu();
228 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
230 if (myActions.contains(theId))
231 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
232 theAction->setData(theId);
233 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
234 myActions[theId] = theAction;
237 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
239 if (myActions.contains(theId))
240 return myActions[theId];
244 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
246 foreach(QAction* eachAction, myActions) {
247 if (eachAction->text() == theName) {
254 QStringList XGUI_ContextMenuMgr::actionIds() const
256 return myActions.keys();
259 void XGUI_ContextMenuMgr::onAction(bool isChecked)
261 QAction* aAction = static_cast<QAction*>(sender());
262 emit actionTriggered(aAction->data().toString(), isChecked);
265 void XGUI_ContextMenuMgr::updateCommandsStatus()
269 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
271 QMenu* aMenu = new QMenu();
272 if (sender() == myWorkshop->objectBrowser()) {
273 updateObjectBrowserMenu();
274 addObjBrowserMenu(aMenu);
275 } else if (sender() == myWorkshop->viewer()) {
277 addViewerMenu(aMenu);
280 if (aMenu && (aMenu->actions().size() > 0)) {
281 // it is possible that some objects should do something before and after the popup menu exec
282 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
284 emit beforeContextMenu();
285 aMenu->exec(theEvent->globalPos());
286 emit afterContextMenu();
291 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
293 foreach(QAction* aAction, myActions)
294 aAction->setEnabled(false);
296 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
297 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
298 int aSelected = aObjects.size();
300 SessionPtr aMgr = ModelAPI_Session::get();
301 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
302 bool hasResult = false;
303 bool hasFeature = false;
304 bool hasParameter = false;
305 bool hasCompositeOwner = false;
306 bool hasResultInHistory = false;
307 bool hasFolder = false;
308 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
309 hasCompositeOwner, hasResultInHistory, hasFolder);
311 if (aSelected == 1) { // single selection
312 ObjectPtr aObject = aObjects.first();
315 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
317 if (hasResult && myWorkshop->canBeShaded(aObject)) {
318 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
319 if (aMode != XGUI_Displayer::NoMode) {
320 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
321 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
323 action("WIREFRAME_CMD")->setEnabled(true);
324 action("SHADING_CMD")->setEnabled(true);
326 action("SHOW_ISOLINES_CMD")->setEnabled(true);
327 action("SHOW_ISOLINES_CMD")->setChecked(ModelAPI_Tools::isShownIsoLines(aResult));
328 action("ISOLINES_CMD")->setEnabled(true);
331 bool aHasSubResults = ModelAPI_Tools::hasSubResults(aResult);
332 if (aHasSubResults) {
333 action("HIDE_CMD")->setEnabled(true);
334 action("SHOW_CMD")->setEnabled(true);
337 if (aObject->isDisplayed()) {
338 action("HIDE_CMD")->setEnabled(true);
339 } else if (hasResult && (!hasParameter)) {
340 action("SHOW_CMD")->setEnabled(true);
343 if (!(hasParameter || hasFeature))
344 action("SHOW_ONLY_CMD")->setEnabled(true);
346 else if (hasFeature && myWorkshop->canMoveFeature()) {
347 action("MOVE_CMD")->setEnabled(true);
348 action("MOVE_SPLIT_CMD")->setEnabled(true);
351 if( aMgr->activeDocument() == aObject->document() )
353 action("RENAME_CMD")->setEnabled(true);
354 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
355 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
356 (hasFeature || hasParameter));
359 // end single selection
360 } else { // multi-selection
361 // parameter is commented because the actions are not in the list of result parameter actions
362 if (hasResult /*&& (!hasParameter)*/) {
363 action("SHOW_CMD")->setEnabled(true);
364 action("HIDE_CMD")->setEnabled(true);
365 action("SHOW_ONLY_CMD")->setEnabled(true);
366 action("SHADING_CMD")->setEnabled(true);
367 action("WIREFRAME_CMD")->setEnabled(true);
368 action("SHOW_ISOLINES_CMD")->setEnabled(true);
369 action("ISOLINES_CMD")->setEnabled(true);
371 if (hasFeature && myWorkshop->canMoveFeature()) {
372 action("MOVE_CMD")->setEnabled(true);
373 action("MOVE_SPLIT_CMD")->setEnabled(true);
375 } // end multi-selection
377 // Check folder management commands state if only features are selected
378 if ((!hasResult) && hasFeature && (!hasParameter) && (!hasCompositeOwner) &&
379 (!hasResultInHistory) && (!hasFolder)) {
380 std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
381 if (aFeatures.size() > 0) { // Check that features do not include Parts
382 QModelIndexList aIndexes = aSelMgr->selection()->selectedIndexes();
383 QModelIndex aFirstIdx = aIndexes.first();
384 QModelIndex aLastIdx = aIndexes.last();
385 QModelIndex aParentIdx = aFirstIdx.parent();
387 // if all selected are from the same level
388 bool isSameParent = true;
389 foreach(QModelIndex aIdx, aIndexes) {
390 if (aIdx.parent() != aParentIdx) {
391 isSameParent = false;
396 // Check is selection continuous
397 XGUI_DataModel* aModel = myWorkshop->objectBrowser()->dataModel();
398 DocumentPtr aDoc = aMgr->activeDocument();
400 bool isContinuos = true;
403 foreach(FeaturePtr aF, aFeatures) {
405 aId = aDoc->index(aF);
408 if (aId != aDoc->index(aF)) {
416 ObjectPtr aDataObj = aModel->object(aParentIdx);
419 if (aFirstIdx.row() > 0) {
420 QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0);
421 aPrevObj = aModel->object(aPrevIdx);
425 if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
426 QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
427 aNextObj = aModel->object(aNextIdx);
430 bool isPrevFolder = (aPrevObj.get() &&
431 (aPrevObj->groupName() == ModelAPI_Folder::group()));
432 bool isNextFolder = (aNextObj.get() &&
433 (aNextObj->groupName() == ModelAPI_Folder::group()));
434 bool isInFolder = (aDataObj.get() &&
435 (aDataObj->groupName() == ModelAPI_Folder::group()));
436 bool isOutsideFolder = !isInFolder;
438 bool hasFirst = false;
439 bool hasLast = false;
441 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aDataObj);
442 FeaturePtr aFirstFeatureInFolder;
443 AttributeReferencePtr aFirstFeatAttr =
444 aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
446 aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
447 hasFirst = (aFirstFeatureInFolder == aFeatures.front());
449 FeaturePtr aLastFeatureInFolder;
450 AttributeReferencePtr aLastFeatAttr =
451 aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
453 aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
454 hasLast = (aLastFeatureInFolder == aFeatures.back());
456 action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
457 action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
458 action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
459 action("ADD_OUT_FOLDER_BEFORE_CMD")->setEnabled(isInFolder && hasFirst);
460 action("ADD_OUT_FOLDER_AFTER_CMD")->setEnabled(isInFolder && hasLast);
464 } // end folder management commands
466 bool allActive = true;
467 foreach( ObjectPtr aObject, aObjects )
468 if( aMgr->activeDocument() != aObject->document() ) {
472 if (!hasCompositeOwner && allActive ) {
473 if (hasResult || hasFeature || hasParameter) // #2924 results can be erased
474 action("DELETE_CMD")->setEnabled(true);
476 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
477 action("CLEAN_HISTORY_CMD")->setEnabled(true);
479 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
480 action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory);
481 } // end selection processing
483 // Show/Hide command has to be disabled for objects from non active document
484 bool aDeactivate = false;
485 foreach (ObjectPtr aObj, aObjects) {
486 if (!aObj->document()->isActive()) {
487 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
488 aObj->groupName() == ModelAPI_ResultPart::group()) {
495 // If at leas a one object can not be edited then Show/Hide has to be disabled
496 action("SHOW_CMD")->setEnabled(false);
497 action("HIDE_CMD")->setEnabled(false);
498 action("SHOW_ONLY_CMD")->setEnabled(false);
501 action("COLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("COLOR_CMD"));
502 action("DEFLECTION_CMD")->setEnabled(myWorkshop->canChangeProperty("DEFLECTION_CMD"));
503 action("TRANSPARENCY_CMD")->setEnabled(myWorkshop->canChangeProperty("TRANSPARENCY_CMD"));
506 action("TINSPECTOR_VIEW")->setEnabled(true);
511 ModuleBase_IModule* aModule = myWorkshop->module();
513 aModule->updateObjectBrowserMenu(myActions);
516 void XGUI_ContextMenuMgr::updateViewerMenu()
518 foreach(QAction* aAction, myActions)
519 aAction->setEnabled(false);
521 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
522 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
523 QList<ModuleBase_ViewerPrsPtr> aPrsList =
524 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
525 if (aPrsList.size() > 0) {
526 bool isVisible = false;
527 bool canBeShaded = false;
528 bool hasPlanar = false;
530 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
531 aObject = aPrs->object();
534 GeomShapePtr aShape = aPrs->shape();
535 if (aObject->isDisplayed()) {
537 canBeShaded = aDisplayer->canBeShaded(aObject);
540 hasPlanar = (aShape->isFace() && aShape->isPlanar());
545 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
546 if (aMode != XGUI_Displayer::NoMode) {
547 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
548 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
550 action("WIREFRAME_CMD")->setEnabled(true);
551 action("SHADING_CMD")->setEnabled(true);
553 action("ISOLINES_CMD")->setEnabled(true);
555 if (aPrsList.size() == 1) {
556 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
558 action("SHOW_ISOLINES_CMD")->setEnabled(true);
559 action("SHOW_ISOLINES_CMD")->setChecked(ModelAPI_Tools::isShownIsoLines(aResult));
563 action("SHOW_ONLY_CMD")->setEnabled(true);
564 action("HIDE_CMD")->setEnabled(true);
566 action("SHOW_CMD")->setEnabled(true);
568 action("SET_VIEW_NORMAL_CMD")->setEnabled(hasPlanar);
569 action("SET_VIEW_INVERTEDNORMAL_CMD")->setEnabled(hasPlanar);
571 //issue #2159 Hide all incomplete behavior
573 action("HIDEALL_CMD")->setEnabled(true);
575 if (myWorkshop->displayer()->objectsCount() > 0)
576 action("HIDEALL_CMD")->setEnabled(true);
579 // Update selection menu
580 QIntList aModes = myWorkshop->selectionActivate()->activeSelectionModes();
581 action("SELECT_VERTEX_CMD")->setEnabled(true);
582 action("SELECT_EDGE_CMD")->setEnabled(true);
583 action("SELECT_FACE_CMD")->setEnabled(true);
584 action("SELECT_RESULT_CMD")->setEnabled(true);
586 action("SELECT_RESULT_CMD")->setChecked(false);
587 action("SELECT_VERTEX_CMD")->setChecked(false);
588 action("SELECT_EDGE_CMD")->setChecked(false);
589 action("SELECT_FACE_CMD")->setChecked(false);
590 action("SELECT_RESULT_CMD")->setChecked(false);
591 if (aModes.count() == 0) {
592 action("SELECT_RESULT_CMD")->setChecked(true);
594 foreach(int aMode, aModes) {
597 action("SELECT_VERTEX_CMD")->setChecked(true);
600 action("SELECT_EDGE_CMD")->setChecked(true);
603 action("SELECT_FACE_CMD")->setChecked(true);
606 action("SELECT_RESULT_CMD")->setChecked(true);
611 ModuleBase_IModule* aModule = myWorkshop->module();
613 aModule->updateViewerMenu(myActions);
615 if (myWorkshop->canChangeProperty("COLOR_CMD"))
616 action("COLOR_CMD")->setEnabled(true);
618 if (myWorkshop->canChangeProperty("DEFLECTION_CMD"))
619 action("DEFLECTION_CMD")->setEnabled(true);
621 if (myWorkshop->canChangeProperty("TRANSPARENCY_CMD"))
622 action("TRANSPARENCY_CMD")->setEnabled(true);
624 action("DELETE_CMD")->setEnabled(true);
627 void XGUI_ContextMenuMgr::connectObjectBrowser()
629 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
630 SLOT(onContextMenuRequest(QContextMenuEvent*)));
633 void XGUI_ContextMenuMgr::connectViewer()
635 connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
636 SLOT(onContextMenuRequest(QContextMenuEvent*)));
640 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
642 QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
643 aSeparator->setSeparator(true);
647 // Result construction menu
648 aList.append(action("SHOW_CMD"));
649 aList.append(action("HIDE_CMD"));
650 aList.append(action("SHOW_ONLY_CMD"));
651 aList.append(mySeparator1);
652 aList.append(action("RENAME_CMD"));
653 aList.append(action("COLOR_CMD"));
654 aList.append(action("DEFLECTION_CMD"));
655 aList.append(action("TRANSPARENCY_CMD"));
656 aList.append(action("SHOW_FEATURE_CMD"));
657 aList.append(mySeparator2);
658 aList.append(action("DELETE_CMD"));
659 myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
661 //-------------------------------------
664 aList.append(action("WIREFRAME_CMD"));
665 aList.append(action("SHADING_CMD"));
666 aList.append(mySeparator1); // this separator is not shown as this action is added after show only
667 // qt list container contains only one instance of the same action
668 aList.append(action("SHOW_CMD"));
669 aList.append(action("HIDE_CMD"));
670 aList.append(action("SHOW_ONLY_CMD"));
671 aList.append(mySeparator2);
672 aList.append(action("RENAME_CMD"));
673 aList.append(action("COLOR_CMD"));
674 aList.append(action("DEFLECTION_CMD"));
675 aList.append(action("TRANSPARENCY_CMD"));
676 aList.append(action("SHOW_ISOLINES_CMD"));
677 aList.append(action("ISOLINES_CMD"));
678 aList.append(action("SHOW_FEATURE_CMD"));
679 aList.append(mySeparator3);
680 aList.append(action("DELETE_CMD"));
681 myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
683 myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
684 myObjBrowserMenus[ModelAPI_ResultField::group()] = aList;
686 myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
687 //-------------------------------------
690 aList.append(action("RENAME_CMD"));
691 aList.append(action("SHOW_RESULTS_CMD"));
692 aList.append(action("MOVE_CMD"));
693 aList.append(action("MOVE_SPLIT_CMD"));
694 aList.append(mySeparator1);
695 aList.append(action("INSERT_FOLDER_CMD"));
696 aList.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
697 aList.append(action("ADD_TO_FOLDER_AFTER_CMD"));
698 aList.append(mySeparator2);
699 aList.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
700 aList.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
701 aList.append(mySeparator3);
702 aList.append(action("CLEAN_HISTORY_CMD"));
703 aList.append(action("DELETE_CMD"));
704 myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
707 aList.append(action("RENAME_CMD"));
708 aList.append(mySeparator1);
709 aList.append(action("CLEAN_HISTORY_CMD"));
710 aList.append(action("DELETE_CMD"));
711 myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
712 //-------------------------------------
715 aList.append(action("RENAME_CMD"));
716 aList.append(action("DELETE_CMD"));
717 myObjBrowserMenus[ModelAPI_Folder::group()] = aList;
719 //---------------------------------------
722 aList.append(action("SHOW_CMD"));
723 aList.append(action("HIDE_CMD"));
724 aList.append(action("SHOW_ONLY_CMD"));
725 myObjBrowserMenus[ModelAPI_ResultField::ModelAPI_FieldStep::group()] = aList;
728 void XGUI_ContextMenuMgr::buildViewerMenu()
731 // Result construction menu
732 aList.append(action("COLOR_CMD"));
733 aList.append(action("DEFLECTION_CMD"));
734 aList.append(action("TRANSPARENCY_CMD"));
735 aList.append(mySeparator3);
736 aList.append(action("SET_VIEW_NORMAL_CMD"));
737 aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD"));
738 aList.append(mySeparator1);
739 aList.append(action("SHOW_ONLY_CMD"));
740 aList.append(action("HIDE_CMD"));
741 myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
743 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
744 //-------------------------------------
747 aList.append(action("WIREFRAME_CMD"));
748 aList.append(action("SHADING_CMD"));
749 aList.append(mySeparator2);
750 aList.append(action("COLOR_CMD"));
751 aList.append(action("DEFLECTION_CMD"));
752 aList.append(action("TRANSPARENCY_CMD"));
753 aList.append(action("SHOW_ISOLINES_CMD"));
754 aList.append(action("ISOLINES_CMD"));
755 aList.append(mySeparator3);
756 aList.append(action("SET_VIEW_NORMAL_CMD"));
757 aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD"));
758 aList.append(mySeparator1);
759 aList.append(action("SHOW_ONLY_CMD"));
760 aList.append(action("HIDE_CMD"));
761 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
763 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
764 myViewerMenu[ModelAPI_ResultField::group()] = aList;
765 //-------------------------------------
768 aList.append(action("HIDE_CMD"));
769 myViewerMenu[ModelAPI_ResultField::ModelAPI_FieldStep::group()] = aList;
773 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
775 ModuleBase_IModule* aModule = myWorkshop->module();
777 theMenu->addSeparator();
778 aModule->addObjectBrowserMenu(theMenu);
781 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
782 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
783 int aSelected = aObjects.size();
784 QActionsList aActions;
785 if (aSelected == 1) {
786 ObjectPtr aObject = aObjects.first();
787 std::string aName = aObject->groupName();
788 if (myObjBrowserMenus.contains(aName))
789 aActions = myObjBrowserMenus[aName];
790 } else if (aSelected > 1) {
791 aActions.append(action("WIREFRAME_CMD"));
792 aActions.append(action("SHADING_CMD"));
793 aActions.append(mySeparator1);
794 aActions.append(action("SHOW_CMD"));
795 aActions.append(action("HIDE_CMD"));
796 aActions.append(action("SHOW_ONLY_CMD"));
797 aActions.append(mySeparator2);
798 aActions.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
799 aActions.append(action("ADD_TO_FOLDER_AFTER_CMD"));
800 aActions.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
801 aActions.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
802 aActions.append(mySeparator3);
803 aActions.append(action("MOVE_CMD"));
804 aActions.append(action("MOVE_SPLIT_CMD"));
805 aActions.append(action("COLOR_CMD"));
806 aActions.append(action("DEFLECTION_CMD"));
807 aActions.append(action("TRANSPARENCY_CMD"));
808 aActions.append(action("SHOW_ISOLINES_CMD"));
809 aActions.append(action("ISOLINES_CMD"));
810 aActions.append(action("CLEAN_HISTORY_CMD"));
811 aActions.append(action("DELETE_CMD"));
814 if (aSelected == 0) {
816 aActions.append(action("TINSPECTOR_VIEW"));
820 theMenu->addActions(aActions);
821 addFeatures(theMenu);
823 // It is commented out because Object Browser does not have actions
824 //theMenu->addSeparator();
825 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
828 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
830 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
831 QList<ModuleBase_ViewerPrsPtr> aPrsList =
832 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
833 int aSelected = aPrsList.size();
834 QActionsList aActions;
836 // Create selection menu
837 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
838 if (!aOpMgr->hasOperation() &&
839 myWorkshop->selectionActivate()->activeSelectionPlace() == XGUI_SelectionActivate::Workshop) {
840 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
841 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
842 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
843 aSelMenu->addAction(action("SELECT_FACE_CMD"));
844 //IMP: an attempt to use result selection with other selection modes
845 //aSelMenu->addSeparator();
846 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
847 theMenu->addMenu(aSelMenu);
848 theMenu->addSeparator();
850 if (aSelected == 1) {
851 ObjectPtr aObject = aPrsList.first()->object();
852 if (aObject.get() != NULL) {
853 std::string aName = aObject->groupName();
854 if (myViewerMenu.contains(aName))
855 aActions = myViewerMenu[aName];
857 } else if (aSelected > 1) {
858 aActions.append(action("COLOR_CMD"));
859 aActions.append(action("DEFLECTION_CMD"));
860 aActions.append(action("TRANSPARENCY_CMD"));
861 aActions.append(mySeparator1);
862 aActions.append(action("SHOW_ONLY_CMD"));
863 aActions.append(action("HIDE_CMD"));
865 // hide all is shown always even if selection in the viewer is empty
866 aActions.append(action("HIDEALL_CMD"));
867 theMenu->addActions(aActions);
869 QMap<int, QAction*> aMenuActions;
870 ModuleBase_IModule* aModule = myWorkshop->module();
872 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
873 theMenu->addSeparator();
876 // insert the module menu items on specific positions in the popup menu: some actions should be
877 // in the begin of the list, Delete action should be the last by #1343 issue
878 QList<QAction*> anActions = theMenu->actions();
879 int anActionsSize = anActions.size();
880 QAction* aFirstAction = anActions[0];
881 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
882 for (; anIt != aLast; anIt++) {
883 if (anIt.key() > anActionsSize)
884 theMenu->addAction(anIt.value());
886 theMenu->insertAction(aFirstAction, *anIt);
890 theMenu->addSeparator();
891 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
892 if (aMDI->actions().size() > 0) {
893 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
894 aSubMenu->addActions(aMDI->actions());
899 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
903 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
904 aLast = myObjBrowserMenus.end();
905 for (; anIt != aLast; anIt++) {
906 QString aGroupName(anIt.key().c_str());
907 if (aGroups.contains(aGroupName))
909 QActionsList anActions = anIt.value();
910 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
912 for (; anAIt != anALast && !aFound; anAIt++)
913 aFound = (*anAIt)->data().toString() == theName;
915 aGroups.append(aGroupName);
920 void XGUI_ContextMenuMgr::onRename()
922 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
923 if (!myWorkshop->abortAllOperations())
925 // restore selection in case if dialog box was shown
926 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
927 myWorkshop->objectBrowser()->onEditItem();
930 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
932 SessionPtr aMgr = ModelAPI_Session::get();
933 DocumentPtr aActiveDoc = aMgr->activeDocument();
935 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
936 XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
937 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
938 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
942 bool aIsRoot = false;
943 foreach(QModelIndex aIdx, aSelectedIndexes) {
944 // Process only first column
945 if (aIdx.column() == 1) {
946 aIsRoot = !aIdx.parent().isValid();
947 // Exit if the selected index belongs to non active document
948 if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
951 // Get name of the selected index
952 aName = aIdx.data().toString();
953 aLen = aName.indexOf('(');
955 aName = aName.left(--aLen);
957 std::string aFeaturesStr = aIsRoot?
958 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
959 aDataModelXML->subFolderFeatures(aName.toStdString());
960 if (aFeaturesStr.length() > 0) {
961 QStringList aFeturesList =
962 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
963 foreach(QString aFea, aFeturesList) {
964 QAction* aAction = aActionMgr->action(aFea);
966 theMenu->addAction(aAction);
973 #define UNCHECK_ACTION(NAME) \
974 { QAction* aAction = action(NAME); \
975 bool isBlock = aAction->signalsBlocked(); \
976 aAction->blockSignals(true); \
977 aAction->setChecked(false); \
978 aAction->blockSignals(isBlock); }
981 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
983 UNCHECK_ACTION("SELECT_VERTEX_CMD");
984 UNCHECK_ACTION("SELECT_EDGE_CMD");
985 UNCHECK_ACTION("SELECT_FACE_CMD");
988 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
990 UNCHECK_ACTION("SHOW_RESULTS_CMD");