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_SalomeConnector.h"
28 #include "XGUI_Selection.h"
29 #include "XGUI_SelectionActivate.h"
30 #include "XGUI_DataModel.h"
31 #include "XGUI_OperationMgr.h"
32 #include "XGUI_Tools.h"
33 #include "XGUI_ActionsMgr.h"
36 #include <AppElements_MainWindow.h>
39 //#include "PartSetPlugin_Part.h"
41 #include <ModelAPI_Data.h>
42 #include <ModelAPI_AttributeDocRef.h>
43 #include <ModelAPI_Object.h>
44 #include <ModelAPI_Session.h>
45 #include <ModelAPI_ResultGroup.h>
46 #include <ModelAPI_ResultParameter.h>
47 #include <ModelAPI_ResultConstruction.h>
48 #include <ModelAPI_ResultBody.h>
49 #include <ModelAPI_Tools.h>
50 #include <ModelAPI_ResultField.h>
51 #include <ModelAPI_Folder.h>
52 #include <ModelAPI_AttributeReference.h>
54 #include <Config_DataModelReader.h>
56 #include <ModuleBase_IModule.h>
57 #include <ModuleBase_Tools.h>
58 #include <ModuleBase_OperationAction.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.png"),
100 XGUI_Workshop::MOVE_TO_END_COMMAND, this);
101 addAction("MOVE_CMD", aAction);
103 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/clean_history.png"),
104 tr("Clean history"), aDesktop);
105 addAction("CLEAN_HISTORY_CMD", aAction);
107 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop);
108 addAction("COLOR_CMD", aAction);
110 aAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
111 addAction("DEFLECTION_CMD", aAction);
113 #ifdef USE_TRANSPARENCY
114 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/transparency.png"),
115 tr("Transparency..."), aDesktop);
116 addAction("TRANSPARENCY_CMD", aAction);
119 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
120 addAction("SHOW_CMD", aAction);
122 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show only"),
124 addAction("SHOW_ONLY_CMD", aAction);
126 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"),
128 addAction("HIDE_CMD", aAction);
130 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide all"),
132 addAction("HIDEALL_CMD", aAction);
134 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"), tr("Shading"), aDesktop);
135 addAction("SHADING_CMD", aAction);
137 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"),
139 addAction("WIREFRAME_CMD", aAction);
141 mySeparator1 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
142 mySeparator1->setSeparator(true);
144 mySeparator2 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
145 mySeparator2->setSeparator(true);
147 mySeparator3 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
148 mySeparator3->setSeparator(true);
150 //mySelectActions = new QActionGroup(this);
151 //mySelectActions->setExclusive(true);
153 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
154 this, SLOT(onShapeSelection(bool)));
155 aAction->setCheckable(true);
156 addAction("SELECT_VERTEX_CMD", aAction);
157 //mySelectActions->addAction(aAction);
159 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
160 this, SLOT(onShapeSelection(bool)));
161 aAction->setCheckable(true);
162 addAction("SELECT_EDGE_CMD", aAction);
163 //mySelectActions->addAction(aAction);
165 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
166 this, SLOT(onShapeSelection(bool)));
167 aAction->setCheckable(true);
168 addAction("SELECT_FACE_CMD", aAction);
169 //mySelectActions->addAction(aAction);
171 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop,
172 this, SLOT(onResultSelection(bool)));
173 aAction->setCheckable(true);
174 addAction("SELECT_RESULT_CMD", aAction);
175 //mySelectActions->addAction(aAction);
177 aAction->setChecked(true);
179 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
180 tr("Select results"), aDesktop);
181 addAction("SHOW_RESULTS_CMD", aAction);
183 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
184 tr("Select parent feature"), aDesktop);
185 addAction("SHOW_FEATURE_CMD", aAction);
188 aAction = ModuleBase_Tools::createAction(QIcon(), tr("TInspector"), aDesktop);
189 addAction("TINSPECTOR_VIEW", aAction);
192 // Features folders actions
193 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/create_folder.png"),
194 tr("Insert a folder before"), aDesktop);
195 addAction("INSERT_FOLDER_CMD", aAction);
197 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/insert_folder_before.png"),
198 tr("Move into the previous folder"), aDesktop);
199 addAction("ADD_TO_FOLDER_BEFORE_CMD", aAction);
201 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/insert_folder_after.png"),
202 tr("Move into the next folder"), aDesktop);
203 addAction("ADD_TO_FOLDER_AFTER_CMD", aAction);
205 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_out_before.png"),
206 tr("Move out before the folder"), aDesktop);
207 addAction("ADD_OUT_FOLDER_BEFORE_CMD", aAction);
209 aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_out_after.png"),
210 tr("Move out after the folder"), aDesktop);
211 addAction("ADD_OUT_FOLDER_AFTER_CMD", aAction);
213 buildObjBrowserMenu();
217 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
219 if (myActions.contains(theId))
220 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
221 theAction->setData(theId);
222 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
223 myActions[theId] = theAction;
226 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
228 if (myActions.contains(theId))
229 return myActions[theId];
233 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
235 foreach(QAction* eachAction, myActions) {
236 if (eachAction->text() == theName) {
243 QStringList XGUI_ContextMenuMgr::actionIds() const
245 return myActions.keys();
248 void XGUI_ContextMenuMgr::onAction(bool isChecked)
250 QAction* aAction = static_cast<QAction*>(sender());
251 emit actionTriggered(aAction->data().toString(), isChecked);
254 void XGUI_ContextMenuMgr::updateCommandsStatus()
258 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
260 QMenu* aMenu = new QMenu();
261 if (sender() == myWorkshop->objectBrowser()) {
262 updateObjectBrowserMenu();
263 addObjBrowserMenu(aMenu);
264 } else if (sender() == myWorkshop->viewer()) {
266 addViewerMenu(aMenu);
269 if (aMenu && (aMenu->actions().size() > 0)) {
270 // it is possible that some objects should do something before and after the popup menu exec
271 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
273 emit beforeContextMenu();
274 aMenu->exec(theEvent->globalPos());
275 emit afterContextMenu();
280 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
282 foreach(QAction* aAction, myActions)
283 aAction->setEnabled(false);
285 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
286 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
287 int aSelected = aObjects.size();
289 SessionPtr aMgr = ModelAPI_Session::get();
290 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
291 bool hasResult = false;
292 bool hasFeature = false;
293 bool hasParameter = false;
294 bool hasCompositeOwner = false;
295 bool hasResultInHistory = false;
296 bool hasFolder = false;
297 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
298 hasCompositeOwner, hasResultInHistory, hasFolder);
300 if (aSelected == 1) { // single selection
301 ObjectPtr aObject = aObjects.first();
303 if (hasResult && myWorkshop->canBeShaded(aObject)) {
304 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
305 if (aMode != XGUI_Displayer::NoMode) {
306 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
307 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
309 action("WIREFRAME_CMD")->setEnabled(true);
310 action("SHADING_CMD")->setEnabled(true);
314 bool aHasSubResults = ModelAPI_Tools::hasSubResults(
315 std::dynamic_pointer_cast<ModelAPI_Result>(aObject));
316 if (aHasSubResults) {
317 action("HIDE_CMD")->setEnabled(true);
318 action("SHOW_CMD")->setEnabled(true);
321 if (aObject->isDisplayed()) {
322 action("HIDE_CMD")->setEnabled(true);
323 } else if (hasResult && (!hasParameter)) {
324 action("SHOW_CMD")->setEnabled(true);
327 if (!(hasParameter || hasFeature))
328 action("SHOW_ONLY_CMD")->setEnabled(true);
330 else if (hasFeature && myWorkshop->canMoveFeature())
331 action("MOVE_CMD")->setEnabled(true);
333 if( aMgr->activeDocument() == aObject->document() )
335 action("RENAME_CMD")->setEnabled(true);
336 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
337 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
338 (hasFeature || hasParameter));
341 // end single selection
342 } else { // multiselection
343 // parameter is commented because the actions are not in the list of result parameter actions
344 if (hasResult /*&& (!hasParameter)*/) {
345 action("SHOW_CMD")->setEnabled(true);
346 action("HIDE_CMD")->setEnabled(true);
347 action("SHOW_ONLY_CMD")->setEnabled(true);
348 action("SHADING_CMD")->setEnabled(true);
349 action("WIREFRAME_CMD")->setEnabled(true);
351 } // end multiselection
353 // Check folder management commands state if only features are selected
354 if ((!hasResult) && hasFeature && (!hasParameter) && (!hasCompositeOwner) &&
355 (!hasResultInHistory) && (!hasFolder)) {
356 std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
357 if (aFeatures.size() > 0) { // Check that features do not include Parts
358 QModelIndexList aIndexes = aSelMgr->selection()->selectedIndexes();
359 QModelIndex aFirstIdx = aIndexes.first();
360 QModelIndex aLastIdx = aIndexes.last();
361 QModelIndex aParentIdx = aFirstIdx.parent();
363 // if all selected are from the same level
364 bool isSameParent = true;
365 foreach(QModelIndex aIdx, aIndexes) {
366 if (aIdx.parent() != aParentIdx) {
367 isSameParent = false;
372 // Check is selection continuous
373 XGUI_DataModel* aModel = myWorkshop->objectBrowser()->dataModel();
374 DocumentPtr aDoc = aMgr->activeDocument();
375 std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
377 bool isContinuos = true;
380 foreach(FeaturePtr aF, aFeatures) {
382 aId = aDoc->index(aF);
385 if (aId != aDoc->index(aF)) {
393 ObjectPtr aDataObj = aModel->object(aParentIdx);
396 if (aFirstIdx.row() > 0) {
397 QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0);
398 aPrevObj = aModel->object(aPrevIdx);
402 if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
403 QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
404 aNextObj = aModel->object(aNextIdx);
407 bool isPrevFolder = (aPrevObj.get() &&
408 (aPrevObj->groupName() == ModelAPI_Folder::group()));
409 bool isNextFolder = (aNextObj.get() &&
410 (aNextObj->groupName() == ModelAPI_Folder::group()));
411 bool isInFolder = (aDataObj.get() &&
412 (aDataObj->groupName() == ModelAPI_Folder::group()));
413 bool isOutsideFolder = !isInFolder;
415 bool hasFirst = false;
416 bool hasLast = false;
418 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aDataObj);
419 FeaturePtr aFirstFeatureInFolder;
420 AttributeReferencePtr aFirstFeatAttr =
421 aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
423 aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
424 hasFirst = (aFirstFeatureInFolder == aFeatures.front());
426 FeaturePtr aLastFeatureInFolder;
427 AttributeReferencePtr aLastFeatAttr =
428 aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
430 aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
431 hasLast = (aLastFeatureInFolder == aFeatures.back());
433 action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
434 action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
435 action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
436 action("ADD_OUT_FOLDER_BEFORE_CMD")->setEnabled(isInFolder && hasFirst);
437 action("ADD_OUT_FOLDER_AFTER_CMD")->setEnabled(isInFolder && hasLast);
441 } // end folder management commands
443 bool allActive = true;
444 foreach( ObjectPtr aObject, aObjects )
445 if( aMgr->activeDocument() != aObject->document() ) {
449 if (!hasCompositeOwner && allActive ) {
450 if (hasFeature || hasParameter)
451 action("DELETE_CMD")->setEnabled(true);
453 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
454 action("CLEAN_HISTORY_CMD")->setEnabled(true);
456 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
457 action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory);
458 } // end selection processing
460 // Show/Hide command has to be disabled for objects from non active document
461 bool aDeactivate = false;
462 foreach (ObjectPtr aObj, aObjects) {
463 if (!aObj->document()->isActive()) {
464 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
465 aObj->groupName() == ModelAPI_ResultPart::group()) {
472 // If at leas a one objec can not be edited then Show/Hide has to be disabled
473 action("SHOW_CMD")->setEnabled(false);
474 action("HIDE_CMD")->setEnabled(false);
475 action("SHOW_ONLY_CMD")->setEnabled(false);
478 action("COLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("COLOR_CMD"));
479 action("DEFLECTION_CMD")->setEnabled(myWorkshop->canChangeProperty("DEFLECTION_CMD"));
480 #ifdef USE_TRANSPARENCY
481 action("TRANSPARENCY_CMD")->setEnabled(myWorkshop->canChangeProperty("TRANSPARENCY_CMD"));
485 action("TINSPECTOR_VIEW")->setEnabled(true);
490 ModuleBase_IModule* aModule = myWorkshop->module();
492 aModule->updateObjectBrowserMenu(myActions);
495 void XGUI_ContextMenuMgr::updateViewerMenu()
497 foreach(QAction* aAction, myActions)
498 aAction->setEnabled(false);
500 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
501 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
502 QList<ModuleBase_ViewerPrsPtr> aPrsList =
503 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
504 if (aPrsList.size() > 0) {
505 bool isVisible = false;
506 bool isShading = false;
507 bool canBeShaded = false;
509 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
510 aObject = aPrs->object();
511 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
512 if (aRes && aRes->isDisplayed()) {
514 canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
516 (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
522 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
523 if (aMode != XGUI_Displayer::NoMode) {
524 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
525 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
527 action("WIREFRAME_CMD")->setEnabled(true);
528 action("SHADING_CMD")->setEnabled(true);
531 action("SHOW_ONLY_CMD")->setEnabled(true);
532 action("HIDE_CMD")->setEnabled(true);
534 action("SHOW_CMD")->setEnabled(true);
536 //issue #2159 Hide all incomplete behavior
538 action("HIDEALL_CMD")->setEnabled(true);
540 if (myWorkshop->displayer()->objectsCount() > 0)
541 action("HIDEALL_CMD")->setEnabled(true);
544 // Update selection menu
545 QIntList aModes = myWorkshop->selectionActivate()->activeSelectionModes();
546 action("SELECT_VERTEX_CMD")->setEnabled(true);
547 action("SELECT_EDGE_CMD")->setEnabled(true);
548 action("SELECT_FACE_CMD")->setEnabled(true);
549 action("SELECT_RESULT_CMD")->setEnabled(true);
551 action("SELECT_RESULT_CMD")->setChecked(false);
552 action("SELECT_VERTEX_CMD")->setChecked(false);
553 action("SELECT_EDGE_CMD")->setChecked(false);
554 action("SELECT_FACE_CMD")->setChecked(false);
555 action("SELECT_RESULT_CMD")->setChecked(false);
556 if (aModes.count() == 0) {
557 action("SELECT_RESULT_CMD")->setChecked(true);
559 foreach(int aMode, aModes) {
562 action("SELECT_VERTEX_CMD")->setChecked(true);
565 action("SELECT_EDGE_CMD")->setChecked(true);
568 action("SELECT_FACE_CMD")->setChecked(true);
571 action("SELECT_RESULT_CMD")->setChecked(true);
576 ModuleBase_IModule* aModule = myWorkshop->module();
578 aModule->updateViewerMenu(myActions);
580 if (myWorkshop->canChangeProperty("COLOR_CMD"))
581 action("COLOR_CMD")->setEnabled(true);
583 if (myWorkshop->canChangeProperty("DEFLECTION_CMD"))
584 action("DEFLECTION_CMD")->setEnabled(true);
586 #ifdef USE_TRANSPARENCY
587 if (myWorkshop->canChangeProperty("TRANSPARENCY_CMD"))
588 action("TRANSPARENCY_CMD")->setEnabled(true);
591 action("DELETE_CMD")->setEnabled(true);
594 void XGUI_ContextMenuMgr::connectObjectBrowser()
596 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
597 SLOT(onContextMenuRequest(QContextMenuEvent*)));
600 void XGUI_ContextMenuMgr::connectViewer()
602 connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
603 SLOT(onContextMenuRequest(QContextMenuEvent*)));
607 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
609 QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
610 aSeparator->setSeparator(true);
614 // Result construction menu
615 aList.append(action("SHOW_CMD"));
616 aList.append(action("HIDE_CMD"));
617 aList.append(action("SHOW_ONLY_CMD"));
618 aList.append(mySeparator1);
619 aList.append(action("RENAME_CMD"));
620 aList.append(action("COLOR_CMD"));
621 aList.append(action("DEFLECTION_CMD"));
622 #ifdef USE_TRANSPARENCY
623 aList.append(action("TRANSPARENCY_CMD"));
625 aList.append(action("SHOW_FEATURE_CMD"));
626 myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
628 //-------------------------------------
631 aList.append(action("WIREFRAME_CMD"));
632 aList.append(action("SHADING_CMD"));
633 aList.append(mySeparator1); // this separator is not shown as this action is added after show only
634 // qt list container contains only one instance of the same action
635 aList.append(action("SHOW_CMD"));
636 aList.append(action("HIDE_CMD"));
637 aList.append(action("SHOW_ONLY_CMD"));
638 aList.append(mySeparator2);
639 aList.append(action("RENAME_CMD"));
640 aList.append(action("COLOR_CMD"));
641 aList.append(action("DEFLECTION_CMD"));
642 #ifdef USE_TRANSPARENCY
643 aList.append(action("TRANSPARENCY_CMD"));
645 aList.append(action("SHOW_FEATURE_CMD"));
646 myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
648 myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
649 myObjBrowserMenus[ModelAPI_ResultField::group()] = aList;
651 myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
652 //-------------------------------------
655 aList.append(action("RENAME_CMD"));
656 aList.append(action("SHOW_RESULTS_CMD"));
657 aList.append(action("MOVE_CMD"));
658 aList.append(mySeparator1);
659 aList.append(action("INSERT_FOLDER_CMD"));
660 aList.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
661 aList.append(action("ADD_TO_FOLDER_AFTER_CMD"));
662 aList.append(mySeparator2);
663 aList.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
664 aList.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
665 aList.append(mySeparator3);
666 aList.append(action("CLEAN_HISTORY_CMD"));
667 aList.append(action("DELETE_CMD"));
668 myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
671 aList.append(action("RENAME_CMD"));
672 aList.append(mySeparator1);
673 aList.append(action("CLEAN_HISTORY_CMD"));
674 aList.append(action("DELETE_CMD"));
675 myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
676 //-------------------------------------
679 aList.append(action("RENAME_CMD"));
680 aList.append(action("DELETE_CMD"));
681 myObjBrowserMenus[ModelAPI_Folder::group()] = aList;
685 void XGUI_ContextMenuMgr::buildViewerMenu()
688 // Result construction menu
689 aList.append(action("HIDE_CMD"));
690 aList.append(action("SHOW_ONLY_CMD"));
691 aList.append(mySeparator1);
692 aList.append(action("COLOR_CMD"));
693 aList.append(action("DEFLECTION_CMD"));
694 #ifdef USE_TRANSPARENCY
695 aList.append(action("TRANSPARENCY_CMD"));
697 myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
699 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
700 //-------------------------------------
703 aList.append(action("WIREFRAME_CMD"));
704 aList.append(action("SHADING_CMD"));
705 aList.append(mySeparator1);
706 aList.append(action("HIDE_CMD"));
707 aList.append(action("SHOW_ONLY_CMD"));
708 aList.append(mySeparator2);
709 aList.append(action("COLOR_CMD"));
710 aList.append(action("DEFLECTION_CMD"));
711 #ifdef USE_TRANSPARENCY
712 aList.append(action("TRANSPARENCY_CMD"));
714 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
716 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
717 myViewerMenu[ModelAPI_ResultField::group()] = aList;
718 //-------------------------------------
722 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
724 ModuleBase_IModule* aModule = myWorkshop->module();
726 theMenu->addSeparator();
727 aModule->addObjectBrowserMenu(theMenu);
730 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
731 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
732 int aSelected = aObjects.size();
733 QActionsList aActions;
734 if (aSelected == 1) {
735 ObjectPtr aObject = aObjects.first();
736 std::string aName = aObject->groupName();
737 if (myObjBrowserMenus.contains(aName))
738 aActions = myObjBrowserMenus[aName];
739 } else if (aSelected > 1) {
740 aActions.append(action("WIREFRAME_CMD"));
741 aActions.append(action("SHADING_CMD"));
742 aActions.append(mySeparator1);
743 aActions.append(action("SHOW_CMD"));
744 aActions.append(action("HIDE_CMD"));
745 aActions.append(action("SHOW_ONLY_CMD"));
746 aActions.append(mySeparator2);
747 aActions.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
748 aActions.append(action("ADD_TO_FOLDER_AFTER_CMD"));
749 aActions.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
750 aActions.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
751 aActions.append(mySeparator3);
752 //aActions.append(action("MOVE_CMD"));
753 aActions.append(action("COLOR_CMD"));
754 aActions.append(action("DEFLECTION_CMD"));
755 #ifdef USE_TRANSPARENCY
756 aActions.append(action("TRANSPARENCY_CMD"));
758 aActions.append(action("CLEAN_HISTORY_CMD"));
759 aActions.append(action("DELETE_CMD"));
762 if (aSelected == 0) {
764 aActions.append(action("TINSPECTOR_VIEW"));
768 theMenu->addActions(aActions);
769 addFeatures(theMenu);
771 // It is commented out because Object Browser does not have actions
772 //theMenu->addSeparator();
773 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
776 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
778 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
779 QList<ModuleBase_ViewerPrsPtr> aPrsList =
780 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
781 int aSelected = aPrsList.size();
782 QActionsList aActions;
784 // Create selection menu
785 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
786 if (!aOpMgr->hasOperation() &&
787 myWorkshop->selectionActivate()->activeSelectionPlace() == XGUI_SelectionActivate::Workshop) {
788 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
789 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
790 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
791 aSelMenu->addAction(action("SELECT_FACE_CMD"));
792 //IMP: an attempt to use result selection with other selection modes
793 //aSelMenu->addSeparator();
794 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
795 theMenu->addMenu(aSelMenu);
796 theMenu->addSeparator();
798 if (aSelected == 1) {
799 ObjectPtr aObject = aPrsList.first()->object();
800 if (aObject.get() != NULL) {
801 std::string aName = aObject->groupName();
802 if (myViewerMenu.contains(aName))
803 aActions = myViewerMenu[aName];
805 } else if (aSelected > 1) {
806 aActions.append(action("HIDE_CMD"));
808 // hide all is shown always even if selection in the viewer is empty
809 aActions.append(action("HIDEALL_CMD"));
810 aActions.append(action("COLOR_CMD"));
811 aActions.append(action("DEFLECTION_CMD"));
812 #ifdef USE_TRANSPARENCY
813 aActions.append(action("TRANSPARENCY_CMD"));
815 theMenu->addActions(aActions);
817 QMap<int, QAction*> aMenuActions;
818 ModuleBase_IModule* aModule = myWorkshop->module();
820 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
821 theMenu->addSeparator();
824 // insert the module menu items on specific positions in the popup menu: some actions should be
825 // in the begin of the list, Delete action should be the last by #1343 issue
826 QList<QAction*> anActions = theMenu->actions();
827 int anActionsSize = anActions.size();
828 QAction* aFirstAction = anActions[0];
829 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
830 for (; anIt != aLast; anIt++) {
831 if (anIt.key() > anActionsSize)
832 theMenu->addAction(anIt.value());
834 theMenu->insertAction(aFirstAction, *anIt);
838 theMenu->addSeparator();
839 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
840 if (aMDI->actions().size() > 0) {
841 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
842 aSubMenu->addActions(aMDI->actions());
847 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
851 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
852 aLast = myObjBrowserMenus.end();
853 for (; anIt != aLast; anIt++) {
854 QString aGroupName(anIt.key().c_str());
855 if (aGroups.contains(aGroupName))
857 QActionsList anActions = anIt.value();
858 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
860 for (; anAIt != anALast && !aFound; anAIt++)
861 aFound = (*anAIt)->data().toString() == theName;
863 aGroups.append(aGroupName);
868 void XGUI_ContextMenuMgr::onRename()
870 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
871 if (!myWorkshop->abortAllOperations())
873 // restore selection in case if dialog box was shown
874 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
875 myWorkshop->objectBrowser()->onEditItem();
878 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
880 SessionPtr aMgr = ModelAPI_Session::get();
881 DocumentPtr aActiveDoc = aMgr->activeDocument();
883 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
884 XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
885 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
886 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
890 bool aIsRoot = false;
891 foreach(QModelIndex aIdx, aSelectedIndexes) {
892 // Process only first column
893 if (aIdx.column() == 1) {
894 aIsRoot = !aIdx.parent().isValid();
895 // Exit if the selected index belongs to non active document
896 if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
898 if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
901 // Get name of the selected index
902 aName = aIdx.data().toString();
903 aLen = aName.indexOf('(');
905 aName = aName.left(--aLen);
907 std::string aFeaturesStr = aIsRoot?
908 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
909 aDataModelXML->subFolderFeatures(aName.toStdString());
910 if (aFeaturesStr.length() > 0) {
911 QStringList aFeturesList =
912 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
913 foreach(QString aFea, aFeturesList) {
914 QAction* aAction = aActionMgr->action(aFea);
916 theMenu->addAction(aAction);
923 #define UNCHECK_ACTION(NAME) \
924 { QAction* aAction = action(NAME); \
925 bool isBlock = aAction->signalsBlocked(); \
926 aAction->blockSignals(true); \
927 aAction->setChecked(false); \
928 aAction->blockSignals(isBlock); }
931 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
933 UNCHECK_ACTION("SELECT_VERTEX_CMD");
934 UNCHECK_ACTION("SELECT_EDGE_CMD");
935 UNCHECK_ACTION("SELECT_FACE_CMD");
938 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
940 UNCHECK_ACTION("SHOW_RESULTS_CMD");