1 // Copyright (C) 2014-2023 CEA, EDF
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>
70 #pragma warning(disable : 4456) // for nested foreach
73 XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
75 myWorkshop(theParent),
76 mySeparator1(0), mySeparator2(0), mySeparator3(0)
80 XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr()
84 void XGUI_ContextMenuMgr::createActions()
87 QMainWindow* aDesktop = myWorkshop->salomeConnector()->desktop();
89 QMainWindow* aDesktop = myWorkshop->mainWindow();
92 QAction* anAction = ModuleBase_Tools::createAction(QIcon(":pictures/delete.png"), tr("Delete"),
94 aDesktop->addAction(anAction);
96 addAction("DELETE_CMD", anAction);
97 anAction->setShortcutContext(Qt::ApplicationShortcut);
99 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/rename_edit.png"), tr("Rename"),
100 aDesktop, this, SLOT(onRename()));
101 anAction->setShortcut(Qt::Key_F2);
102 addAction("RENAME_CMD", anAction);
105 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_to_end.png"),
106 XGUI_Workshop::MOVE_TO_END_COMMAND, this);
107 addAction("MOVE_CMD", anAction);
109 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_to_end_split.png"),
110 XGUI_Workshop::MOVE_TO_END_SPLIT_COMMAND, this);
111 addAction("MOVE_SPLIT_CMD", anAction);
114 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/recover.png"),
115 tr("Recover"), this);
116 addAction("RECOVER_CMD", anAction);
118 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/clean_history.png"),
119 tr("Clean history"), aDesktop);
120 addAction("CLEAN_HISTORY_CMD", anAction);
122 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop);
123 addAction("COLOR_CMD", anAction);
125 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/autocolor.png"),
126 tr("Auto color"), aDesktop);
127 addAction("AUTOCOLOR_CMD", anAction);
129 anAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
130 addAction("DEFLECTION_CMD", anAction);
132 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/transparency.png"),
133 tr("Transparency..."), aDesktop);
134 addAction("TRANSPARENCY_CMD", anAction);
136 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"),
137 tr("Show"), aDesktop);
138 addAction("SHOW_CMD", anAction);
140 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"),
141 tr("Show only"), aDesktop);
142 addAction("SHOW_ONLY_CMD", anAction);
144 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"),
146 addAction("HIDE_CMD", anAction);
148 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil_closed.png"),
149 tr("Hide all"), aDesktop);
150 addAction("HIDEALL_CMD", anAction);
152 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/shading.png"),
153 tr("Shading"), aDesktop);
154 addAction("SHADING_CMD", anAction);
156 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"),
158 addAction("WIREFRAME_CMD", anAction);
160 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/edges_dir.png"), tr("Show edges direction"),
162 anAction->setCheckable(true);
163 addAction("SHOW_EDGES_DIRECTION_CMD", anAction);
165 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/iso_lines.png"), tr("Define Isos..."),
167 addAction("ISOLINES_CMD", anAction);
169 anAction = ModuleBase_Tools::createAction(QIcon(), tr("Show Isos"), aDesktop);
170 anAction->setCheckable(true);
171 addAction("SHOW_ISOLINES_CMD", anAction);
173 anAction = ModuleBase_Tools::createAction(QIcon(), tr("Bring To Front"), aDesktop);
174 anAction->setCheckable(true);
175 addAction("BRING_TO_FRONT_CMD", anAction);
177 mySeparator1 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
178 mySeparator1->setSeparator(true);
180 mySeparator2 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
181 mySeparator2->setSeparator(true);
183 mySeparator3 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
184 mySeparator3->setSeparator(true);
186 mySeparator4 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
187 mySeparator4->setSeparator(true);
189 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
190 this, SLOT(onShapeSelection(bool)));
191 anAction->setCheckable(true);
192 addAction("SELECT_VERTEX_CMD", anAction);
194 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
195 this, SLOT(onShapeSelection(bool)));
196 anAction->setCheckable(true);
197 addAction("SELECT_EDGE_CMD", anAction);
199 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
200 this, SLOT(onShapeSelection(bool)));
201 anAction->setCheckable(true);
202 addAction("SELECT_FACE_CMD", anAction);
204 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop,
205 this, SLOT(onResultSelection(bool)));
206 anAction->setCheckable(true);
207 addAction("SELECT_RESULT_CMD", anAction);
209 anAction->setChecked(true);
211 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
212 tr("Select results"), aDesktop);
213 addAction("SHOW_RESULTS_CMD", anAction);
215 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/find_result.png"),
216 tr("Select parent feature"), aDesktop);
217 addAction("SHOW_FEATURE_CMD", anAction);
220 anAction = ModuleBase_Tools::createAction(QIcon(), tr("TInspector"), aDesktop);
221 addAction("TINSPECTOR_VIEW", anAction);
224 // Features folders actions
225 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/create_folder.png"),
226 tr("Insert a folder before"), aDesktop);
227 addAction("INSERT_FOLDER_CMD", anAction);
229 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/insert_folder_before.png"),
230 tr("Move into the previous folder"), aDesktop);
231 addAction("ADD_TO_FOLDER_BEFORE_CMD", anAction);
233 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/insert_folder_after.png"),
234 tr("Move into the next folder"), aDesktop);
235 addAction("ADD_TO_FOLDER_AFTER_CMD", anAction);
237 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_out_before.png"),
238 tr("Move out before the folder"), aDesktop);
239 addAction("ADD_OUT_FOLDER_BEFORE_CMD", anAction);
241 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_out_after.png"),
242 tr("Move out after the folder"), aDesktop);
243 addAction("ADD_OUT_FOLDER_AFTER_CMD", anAction);
245 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/normal-view-inversed.png"),
246 tr("Set view by inverted normal to face"), aDesktop);
247 addAction("SET_VIEW_INVERTEDNORMAL_CMD", anAction);
249 anAction = ModuleBase_Tools::createAction(QIcon(":pictures/normal-view.png"),
250 tr("Set view by normal to face"), aDesktop);
251 addAction("SET_VIEW_NORMAL_CMD", anAction);
253 buildObjBrowserMenu();
257 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
259 if (myActions.contains(theId))
260 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
261 theAction->setData(theId);
262 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
263 myActions[theId] = theAction;
266 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
268 if (myActions.contains(theId))
269 return myActions[theId];
273 QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const
275 foreach(QAction* eachAction, myActions) {
276 if (eachAction->text() == theName) {
283 QStringList XGUI_ContextMenuMgr::actionIds() const
285 return myActions.keys();
288 void XGUI_ContextMenuMgr::onAction(bool isChecked)
290 QAction* anAction = static_cast<QAction*>(sender());
291 emit actionTriggered(anAction->data().toString(), isChecked);
294 void XGUI_ContextMenuMgr::updateCommandsStatus()
298 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
300 QMenu* aMenu = new QMenu();
301 if (sender() == myWorkshop->objectBrowser()) {
302 updateObjectBrowserMenu();
303 addObjBrowserMenu(aMenu);
304 } else if (sender() == myWorkshop->viewer()) {
306 addViewerMenu(aMenu);
309 if (aMenu && (aMenu->actions().size() > 0)) {
310 // it is possible that some objects should do something before and after the popup menu exec
311 // e.g. a sketch manager changes an internal flag on this signals in order to do not hide
313 emit beforeContextMenu();
314 aMenu->exec(theEvent->globalPos());
315 emit afterContextMenu();
320 void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
322 foreach(QAction* anAction, myActions)
323 anAction->setEnabled(false);
325 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
326 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
327 int aSelected = aObjects.size();
329 SessionPtr aMgr = ModelAPI_Session::get();
330 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
331 bool hasResult = false;
332 bool hasFeature = false;
333 bool hasParameter = false;
334 bool hasCompositeOwner = false;
335 bool hasResultInHistory = false;
336 bool hasFolder = false;
337 bool hasGroupsOnly = false;
338 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
339 hasCompositeOwner, hasResultInHistory, hasFolder, hasGroupsOnly);
341 if (aSelected == 1) { // single selection
342 ObjectPtr aObject = aObjects.first();
345 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
347 if (hasResult && myWorkshop->canBeShaded(aObject)) {
348 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
349 if (aMode != XGUI_Displayer::NoMode) {
350 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
351 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
353 action("WIREFRAME_CMD")->setEnabled(true);
354 action("SHADING_CMD")->setEnabled(true);
356 action("SHOW_EDGES_DIRECTION_CMD")->setEnabled(true);
357 action("SHOW_EDGES_DIRECTION_CMD")->setChecked(ModelAPI_Tools::isShowEdgesDirection(aResult));
359 action("BRING_TO_FRONT_CMD")->setEnabled(hasGroupsOnly);
360 action("BRING_TO_FRONT_CMD")->setChecked(ModelAPI_Tools::isBringToFront(aResult));
362 action("SHOW_ISOLINES_CMD")->setEnabled(true);
363 action("SHOW_ISOLINES_CMD")->setChecked(ModelAPI_Tools::isShownIsoLines(aResult));
364 action("ISOLINES_CMD")->setEnabled(true);
367 bool aHasSubResults = ModelAPI_Tools::hasSubResults(aResult);
368 if (aHasSubResults) {
369 action("HIDE_CMD")->setEnabled(true);
370 action("SHOW_CMD")->setEnabled(true);
373 if (aObject->isDisplayed()) {
374 action("HIDE_CMD")->setEnabled(true);
375 } else if (hasResult && (!hasParameter)) {
376 action("SHOW_CMD")->setEnabled(true);
379 if (!(hasParameter || hasFeature))
380 action("SHOW_ONLY_CMD")->setEnabled(true);
383 else if (hasFeature && myWorkshop->canMoveFeature()) {
384 action("MOVE_CMD")->setEnabled(true);
385 action("MOVE_SPLIT_CMD")->setEnabled(true);
388 if (hasFeature && aObject->document() != aMgr->moduleDocument() &&
389 aObject->document() == aMgr->activeDocument())
391 XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
392 if (!anOperationMgr->hasOperation()) {
393 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
394 std::list<std::shared_ptr<ModelAPI_Result> > aResults;
395 ModelAPI_Tools::getConcealedResults(aFeature, aResults);
396 if (!aResults.empty()) // check the feature conceals at least one result
397 action("RECOVER_CMD")->setEnabled(true);
401 if( aMgr->activeDocument() == aObject->document() )
403 action("RENAME_CMD")->setEnabled(true);
404 action("DELETE_CMD")->setEnabled(!hasCompositeOwner);
405 action("CLEAN_HISTORY_CMD")->setEnabled(!hasCompositeOwner &&
406 (hasFeature || hasParameter));
409 // end single selection
410 } else { // multi-selection
411 // parameter is commented because the actions are not in the list of result parameter actions
412 if (hasResult /*&& (!hasParameter)*/) {
413 action("SHOW_CMD")->setEnabled(true);
414 action("HIDE_CMD")->setEnabled(true);
415 action("SHOW_ONLY_CMD")->setEnabled(true);
416 action("SHADING_CMD")->setEnabled(true);
417 action("WIREFRAME_CMD")->setEnabled(true);
418 action("SHOW_EDGES_DIRECTION_CMD")->setEnabled(true);
419 action("BRING_TO_FRONT_CMD")->setEnabled(hasGroupsOnly);
420 action("SHOW_ISOLINES_CMD")->setEnabled(true);
421 action("ISOLINES_CMD")->setEnabled(true);
423 if (hasFeature && myWorkshop->canMoveFeature()) {
424 action("MOVE_CMD")->setEnabled(true);
425 action("MOVE_SPLIT_CMD")->setEnabled(true);
427 } // end multi-selection
429 // Check folder management commands state if only features are selected
430 if ((!hasResult) && hasFeature && (!hasParameter) && (!hasCompositeOwner) &&
431 (!hasResultInHistory) && (!hasFolder)) {
432 std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
433 if (aFeatures.size() > 0) { // Check that features do not include Parts
434 QModelIndexList aIndexes = aSelMgr->selection()->selectedIndexes();
435 QModelIndex aFirstIdx = aIndexes.first();
436 QModelIndex aLastIdx = aIndexes.last();
437 QModelIndex aParentIdx = aFirstIdx.parent();
439 // if all selected are from the same level
440 bool isSameParent = true;
441 foreach(QModelIndex aIdx, aIndexes) {
442 if (aIdx.parent() != aParentIdx) {
443 isSameParent = false;
448 // Check is selection continuous
449 XGUI_DataModel* aModel = myWorkshop->objectBrowser()->dataModel();
450 DocumentPtr aDoc = aMgr->activeDocument();
452 bool isContinuos = true;
455 foreach(FeaturePtr aF, aFeatures) {
457 aId = aDoc->index(aF);
460 if (aId != aDoc->index(aF)) {
468 ObjectPtr aDataObj = aModel->object(aParentIdx);
471 if (aFirstIdx.row() > 0) {
472 QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0);
473 aPrevObj = aModel->object(aPrevIdx);
477 if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
478 QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
479 aNextObj = aModel->object(aNextIdx);
482 bool isPrevFolder = (aPrevObj.get() &&
483 (aPrevObj->groupName() == ModelAPI_Folder::group()));
484 bool isNextFolder = (aNextObj.get() &&
485 (aNextObj->groupName() == ModelAPI_Folder::group()));
486 bool isInFolder = (aDataObj.get() &&
487 (aDataObj->groupName() == ModelAPI_Folder::group()));
488 bool isOutsideFolder = !isInFolder;
490 bool hasFirst = false;
491 bool hasLast = false;
493 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aDataObj);
494 FeaturePtr aFirstFeatureInFolder;
495 AttributeReferencePtr aFirstFeatAttr =
496 aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
498 aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
499 hasFirst = (aFirstFeatureInFolder == aFeatures.front());
501 FeaturePtr aLastFeatureInFolder;
502 AttributeReferencePtr aLastFeatAttr =
503 aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
505 aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
506 hasLast = (aLastFeatureInFolder == aFeatures.back());
508 action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
509 action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
510 action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
511 action("ADD_OUT_FOLDER_BEFORE_CMD")->setEnabled(isInFolder && hasFirst);
512 action("ADD_OUT_FOLDER_AFTER_CMD")->setEnabled(isInFolder && hasLast);
516 } // end folder management commands
518 bool allActive = true;
519 foreach( ObjectPtr aObject, aObjects )
520 if( aMgr->activeDocument() != aObject->document() ) {
524 if (!hasCompositeOwner && allActive ) {
525 if (hasResult || hasFeature || hasParameter) // #2924 results can be erased
526 action("DELETE_CMD")->setEnabled(true);
528 if (!hasCompositeOwner && allActive && (hasFeature|| hasParameter))
529 action("CLEAN_HISTORY_CMD")->setEnabled(true);
531 action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
532 action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory);
533 } // end selection processing
535 // Show/Hide command has to be disabled for objects from non active document
536 bool aDeactivate = false;
537 foreach (ObjectPtr aObj, aObjects) {
538 if (!aObj->document()->isActive()) {
539 if ((aObj->document() != ModelAPI_Session::get()->moduleDocument()) ||
540 aObj->groupName() == ModelAPI_ResultPart::group()) {
547 // If at leas a one object can not be edited then Show/Hide has to be disabled
548 action("SHOW_CMD")->setEnabled(false);
549 action("HIDE_CMD")->setEnabled(false);
550 action("SHOW_ONLY_CMD")->setEnabled(false);
553 action("COLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("COLOR_CMD"));
554 action("DEFLECTION_CMD")->setEnabled(myWorkshop->canChangeProperty("DEFLECTION_CMD"));
555 action("TRANSPARENCY_CMD")->setEnabled(myWorkshop->canChangeProperty("TRANSPARENCY_CMD"));
556 action("AUTOCOLOR_CMD")->setEnabled(myWorkshop->canChangeProperty("AUTOCOLOR_CMD"));
560 action("TINSPECTOR_VIEW")->setEnabled(true);
565 ModuleBase_IModule* aModule = myWorkshop->module();
567 aModule->updateObjectBrowserMenu(myActions);
570 void XGUI_ContextMenuMgr::updateViewerMenu()
572 foreach(QAction* anAction, myActions)
573 anAction->setEnabled(false);
575 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
576 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
577 QList<ModuleBase_ViewerPrsPtr> aPrsList =
578 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
579 if (aPrsList.size() > 0) {
580 bool isVisible = false;
581 bool canBeShaded = false;
582 bool hasPlanar = false;
584 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
585 aObject = aPrs->object();
588 GeomShapePtr aShape = aPrs->shape();
589 if (aObject->isDisplayed()) {
591 canBeShaded = aDisplayer->canBeShaded(aObject);
594 hasPlanar = (aShape->isFace() && aShape->isPlanar());
599 XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
600 if (aMode != XGUI_Displayer::NoMode) {
601 action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
602 action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe);
604 action("WIREFRAME_CMD")->setEnabled(true);
605 action("SHADING_CMD")->setEnabled(true);
607 action("ISOLINES_CMD")->setEnabled(true);
609 if (aPrsList.size() == 1) {
610 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
612 action("SHOW_ISOLINES_CMD")->setEnabled(true);
613 action("SHOW_ISOLINES_CMD")->setChecked(ModelAPI_Tools::isShownIsoLines(aResult));
615 action("SHOW_EDGES_DIRECTION_CMD")->setEnabled(true);
616 action("SHOW_EDGES_DIRECTION_CMD")->setChecked(
617 ModelAPI_Tools::isShowEdgesDirection(aResult));
619 // Only enable the "Bring To Front" command for Groups
620 ResultGroupPtr aGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(aResult);
621 action("BRING_TO_FRONT_CMD")->setEnabled(aGroup.get() != NULL);
622 action("BRING_TO_FRONT_CMD")->setChecked(ModelAPI_Tools::isBringToFront(aResult));
626 action("SHOW_ONLY_CMD")->setEnabled(true);
627 action("HIDE_CMD")->setEnabled(true);
629 action("SHOW_CMD")->setEnabled(true);
631 action("SET_VIEW_NORMAL_CMD")->setEnabled(hasPlanar);
632 action("SET_VIEW_INVERTEDNORMAL_CMD")->setEnabled(hasPlanar);
634 //issue #2159 Hide all incomplete behavior
636 action("HIDEALL_CMD")->setEnabled(true);
638 if (myWorkshop->displayer()->objectsCount() > 0)
639 action("HIDEALL_CMD")->setEnabled(true);
642 // Update selection menu
643 QIntList aModes = myWorkshop->selectionActivate()->activeSelectionModes();
644 action("SELECT_VERTEX_CMD")->setEnabled(true);
645 action("SELECT_EDGE_CMD")->setEnabled(true);
646 action("SELECT_FACE_CMD")->setEnabled(true);
647 action("SELECT_RESULT_CMD")->setEnabled(true);
649 action("SELECT_RESULT_CMD")->setChecked(false);
650 action("SELECT_VERTEX_CMD")->setChecked(false);
651 action("SELECT_EDGE_CMD")->setChecked(false);
652 action("SELECT_FACE_CMD")->setChecked(false);
653 action("SELECT_RESULT_CMD")->setChecked(false);
654 if (aModes.count() == 0) {
655 action("SELECT_RESULT_CMD")->setChecked(true);
657 foreach(int aMode, aModes) {
660 action("SELECT_VERTEX_CMD")->setChecked(true);
663 action("SELECT_EDGE_CMD")->setChecked(true);
666 action("SELECT_FACE_CMD")->setChecked(true);
669 action("SELECT_RESULT_CMD")->setChecked(true);
674 ModuleBase_IModule* aModule = myWorkshop->module();
676 aModule->updateViewerMenu(myActions);
678 if (myWorkshop->canChangeProperty("COLOR_CMD"))
679 action("COLOR_CMD")->setEnabled(true);
681 if (myWorkshop->canChangeProperty("DEFLECTION_CMD"))
682 action("DEFLECTION_CMD")->setEnabled(true);
684 if (myWorkshop->canChangeProperty("TRANSPARENCY_CMD"))
685 action("TRANSPARENCY_CMD")->setEnabled(true);
687 action("DELETE_CMD")->setEnabled(true);
690 void XGUI_ContextMenuMgr::connectObjectBrowser()
692 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
693 SLOT(onContextMenuRequest(QContextMenuEvent*)));
696 void XGUI_ContextMenuMgr::connectViewer()
698 connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
699 SLOT(onContextMenuRequest(QContextMenuEvent*)));
703 void XGUI_ContextMenuMgr::buildObjBrowserMenu()
705 QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
706 aSeparator->setSeparator(true);
710 //-------------------------------------
711 // Result construction menu
712 aList.append(action("SHOW_CMD"));
713 aList.append(action("HIDE_CMD"));
714 aList.append(action("SHOW_ONLY_CMD"));
715 aList.append(mySeparator1);
716 aList.append(action("RENAME_CMD"));
717 aList.append(action("COLOR_CMD"));
718 aList.append(action("DEFLECTION_CMD"));
719 aList.append(action("TRANSPARENCY_CMD"));
720 aList.append(action("SHOW_FEATURE_CMD"));
721 aList.append(mySeparator2);
722 aList.append(action("DELETE_CMD"));
723 myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
725 //-------------------------------------
726 // Result body/field/part menu
728 aList.append(action("WIREFRAME_CMD"));
729 aList.append(action("SHADING_CMD"));
730 aList.append(action("SHOW_EDGES_DIRECTION_CMD"));
731 aList.append(mySeparator1); // this separator is not shown as this action is added after show only
732 // qt list container contains only one instance of the same action
733 aList.append(action("SHOW_CMD"));
734 aList.append(action("HIDE_CMD"));
735 aList.append(action("SHOW_ONLY_CMD"));
736 aList.append(mySeparator2);
737 aList.append(action("RENAME_CMD"));
738 aList.append(action("COLOR_CMD"));
739 aList.append(action("DEFLECTION_CMD"));
740 aList.append(action("TRANSPARENCY_CMD"));
741 aList.append(action("SHOW_ISOLINES_CMD"));
742 aList.append(action("ISOLINES_CMD"));
743 aList.append(action("SHOW_FEATURE_CMD"));
744 aList.append(mySeparator3);
745 aList.append(action("DELETE_CMD"));
747 myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
749 myObjBrowserMenus[ModelAPI_ResultField::group()] = aList;
751 myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
753 //-------------------------------------
756 aList.append(action("WIREFRAME_CMD"));
757 aList.append(action("SHADING_CMD"));
758 aList.append(action("SHOW_EDGES_DIRECTION_CMD"));
759 aList.append(mySeparator1);
760 aList.append(action("BRING_TO_FRONT_CMD"));
761 aList.append(mySeparator2);
762 aList.append(action("SHOW_CMD"));
763 aList.append(action("HIDE_CMD"));
764 aList.append(action("SHOW_ONLY_CMD"));
765 aList.append(mySeparator3);
766 aList.append(action("AUTOCOLOR_CMD"));
767 aList.append(action("RENAME_CMD"));
768 aList.append(action("COLOR_CMD"));
769 aList.append(action("DEFLECTION_CMD"));
770 aList.append(action("TRANSPARENCY_CMD"));
771 aList.append(action("SHOW_ISOLINES_CMD"));
772 aList.append(action("ISOLINES_CMD"));
773 aList.append(action("SHOW_FEATURE_CMD"));
774 aList.append(mySeparator4);
775 aList.append(action("DELETE_CMD"));
776 myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
778 //-------------------------------------
781 aList.append(action("RENAME_CMD"));
782 aList.append(action("SHOW_RESULTS_CMD"));
783 aList.append(action("MOVE_CMD"));
784 aList.append(action("MOVE_SPLIT_CMD"));
785 aList.append(action("RECOVER_CMD"));
786 aList.append(mySeparator1);
787 aList.append(action("INSERT_FOLDER_CMD"));
788 aList.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
789 aList.append(action("ADD_TO_FOLDER_AFTER_CMD"));
790 aList.append(mySeparator2);
791 aList.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
792 aList.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
793 aList.append(mySeparator3);
794 aList.append(action("CLEAN_HISTORY_CMD"));
795 aList.append(action("DELETE_CMD"));
796 myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
798 //-------------------------------------
801 aList.append(action("RENAME_CMD"));
802 aList.append(mySeparator1);
803 aList.append(action("CLEAN_HISTORY_CMD"));
804 aList.append(action("DELETE_CMD"));
805 myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
807 //-------------------------------------
810 aList.append(action("RENAME_CMD"));
811 aList.append(action("DELETE_CMD"));
812 myObjBrowserMenus[ModelAPI_Folder::group()] = aList;
814 //---------------------------------------
817 aList.append(action("SHOW_CMD"));
818 aList.append(action("HIDE_CMD"));
819 aList.append(action("SHOW_ONLY_CMD"));
820 myObjBrowserMenus[ModelAPI_ResultField::ModelAPI_FieldStep::group()] = aList;
823 void XGUI_ContextMenuMgr::buildViewerMenu()
826 // Result construction/part menu
827 aList.append(action("COLOR_CMD"));
828 aList.append(action("DEFLECTION_CMD"));
829 aList.append(action("TRANSPARENCY_CMD"));
830 aList.append(mySeparator3);
831 aList.append(action("SET_VIEW_NORMAL_CMD"));
832 aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD"));
833 aList.append(mySeparator1);
834 aList.append(action("SHOW_ONLY_CMD"));
835 aList.append(action("HIDE_CMD"));
836 myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
837 myViewerMenu[ModelAPI_ResultPart::group()] = aList;
839 //-------------------------------------
842 aList.append(action("WIREFRAME_CMD"));
843 aList.append(action("SHADING_CMD"));
844 aList.append(action("SHOW_EDGES_DIRECTION_CMD"));
845 aList.append(mySeparator2);
846 aList.append(action("COLOR_CMD"));
847 aList.append(action("DEFLECTION_CMD"));
848 aList.append(action("TRANSPARENCY_CMD"));
849 aList.append(action("SHOW_ISOLINES_CMD"));
850 aList.append(action("ISOLINES_CMD"));
851 aList.append(mySeparator3);
852 aList.append(action("SET_VIEW_NORMAL_CMD"));
853 aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD"));
854 aList.append(mySeparator1);
855 aList.append(action("SHOW_ONLY_CMD"));
856 aList.append(action("HIDE_CMD"));
857 myViewerMenu[ModelAPI_ResultBody::group()] = aList;
858 myViewerMenu[ModelAPI_ResultField::group()] = aList;
860 //-------------------------------------
863 aList.append(action("WIREFRAME_CMD"));
864 aList.append(action("SHADING_CMD"));
865 aList.append(action("SHOW_EDGES_DIRECTION_CMD"));
866 aList.append(mySeparator1);
867 aList.append(action("BRING_TO_FRONT_CMD"));
868 aList.append(mySeparator2);
869 aList.append(action("COLOR_CMD"));
870 aList.append(action("DEFLECTION_CMD"));
871 aList.append(action("TRANSPARENCY_CMD"));
872 aList.append(action("SHOW_ISOLINES_CMD"));
873 aList.append(action("ISOLINES_CMD"));
874 aList.append(mySeparator3);
875 aList.append(action("SET_VIEW_NORMAL_CMD"));
876 aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD"));
877 aList.append(mySeparator4);
878 aList.append(action("SHOW_ONLY_CMD"));
879 aList.append(action("HIDE_CMD"));
880 myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
882 //-------------------------------------
885 aList.append(action("HIDE_CMD"));
886 myViewerMenu[ModelAPI_ResultField::ModelAPI_FieldStep::group()] = aList;
890 void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
892 ModuleBase_IModule* aModule = myWorkshop->module();
894 theMenu->addSeparator();
895 aModule->addObjectBrowserMenu(theMenu);
898 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
899 QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
900 int aSelected = aObjects.size();
901 QActionsList anActions;
902 if (aSelected == 1) {
903 ObjectPtr aObject = aObjects.first();
904 std::string aName = aObject->groupName();
905 if (myObjBrowserMenus.contains(aName))
906 anActions = myObjBrowserMenus[aName];
907 } else if (aSelected > 1) {
908 anActions.append(action("WIREFRAME_CMD"));
909 anActions.append(action("SHADING_CMD"));
910 anActions.append(action("SHOW_EDGES_DIRECTION_CMD"));
911 anActions.append(mySeparator1);
912 anActions.append(action("BRING_TO_FRONT_CMD"));
913 anActions.append(mySeparator2);
914 anActions.append(action("SHOW_CMD"));
915 anActions.append(action("HIDE_CMD"));
916 anActions.append(action("SHOW_ONLY_CMD"));
917 anActions.append(mySeparator3);
918 anActions.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
919 anActions.append(action("ADD_TO_FOLDER_AFTER_CMD"));
920 anActions.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
921 anActions.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
922 anActions.append(mySeparator4);
923 anActions.append(action("MOVE_CMD"));
924 anActions.append(action("MOVE_SPLIT_CMD"));
925 anActions.append(action("COLOR_CMD"));
926 anActions.append(action("DEFLECTION_CMD"));
927 anActions.append(action("TRANSPARENCY_CMD"));
928 anActions.append(action("SHOW_ISOLINES_CMD"));
929 anActions.append(action("ISOLINES_CMD"));
930 anActions.append(action("CLEAN_HISTORY_CMD"));
931 anActions.append(action("DELETE_CMD"));
934 if (aSelected == 0) {
936 anActions.append(action("TINSPECTOR_VIEW"));
940 theMenu->addActions(anActions);
941 addFeatures(theMenu);
943 // It is commented out because Object Browser does not have actions
944 //theMenu->addSeparator();
945 //theMenu->addActions(myWorkshop->objectBrowser()->actions());
948 void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
950 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
951 QList<ModuleBase_ViewerPrsPtr> aPrsList =
952 aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
953 int aSelected = aPrsList.size();
954 QActionsList anActions;
956 // Create selection menu
957 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
958 if (!aOpMgr->hasOperation() &&
959 myWorkshop->selectionActivate()->activeSelectionPlace() == XGUI_SelectionActivate::Workshop) {
960 QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
961 aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
962 aSelMenu->addAction(action("SELECT_EDGE_CMD"));
963 aSelMenu->addAction(action("SELECT_FACE_CMD"));
964 //IMP: an attempt to use result selection with other selection modes
965 //aSelMenu->addSeparator();
966 aSelMenu->addAction(action("SELECT_RESULT_CMD"));
967 theMenu->addMenu(aSelMenu);
968 theMenu->addSeparator();
970 if (aSelected == 1) {
971 ObjectPtr aObject = aPrsList.first()->object();
972 if (aObject.get() != NULL) {
973 std::string aName = aObject->groupName();
974 if (myViewerMenu.contains(aName))
975 anActions = myViewerMenu[aName];
977 } else if (aSelected > 1) {
978 anActions.append(action("COLOR_CMD"));
979 anActions.append(action("DEFLECTION_CMD"));
980 anActions.append(action("TRANSPARENCY_CMD"));
981 anActions.append(mySeparator1);
982 anActions.append(action("SHOW_ONLY_CMD"));
983 anActions.append(action("HIDE_CMD"));
985 // hide all is shown always even if selection in the viewer is empty
986 anActions.append(action("HIDEALL_CMD"));
987 theMenu->addActions(anActions);
989 QMap<int, QAction*> aMenuActions;
990 ModuleBase_IModule* aModule = myWorkshop->module();
992 if (aModule->addViewerMenu(myActions, theMenu, aMenuActions))
993 theMenu->addSeparator();
996 // insert the module menu items on specific positions in the popup menu: some actions should be
997 // in the begin of the list, Delete action should be the last by #1343 issue
998 QList<QAction*> anActionsList = theMenu->actions();
999 int anActionsListSize = anActionsList.size();
1000 QAction* aFirstAction = anActionsList[0];
1001 QMap<int, QAction*>::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end();
1002 for (; anIt != aLast; anIt++) {
1003 if (anIt.key() > anActionsListSize)
1004 theMenu->addAction(anIt.value());
1006 theMenu->insertAction(aFirstAction, *anIt);
1010 theMenu->addSeparator();
1011 QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea();
1012 if (aMDI->actions().size() > 0) {
1013 QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
1014 aSubMenu->addActions(aMDI->actions());
1019 QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
1021 QStringList aGroups;
1023 QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
1024 aLast = myObjBrowserMenus.end();
1025 for (; anIt != aLast; anIt++) {
1026 QString aGroupName(anIt.key().c_str());
1027 if (aGroups.contains(aGroupName))
1029 QActionsList anActions = anIt.value();
1030 QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
1031 bool aFound = false;
1032 for (; anAIt != anALast && !aFound; anAIt++)
1033 aFound = (*anAIt)->data().toString() == theName;
1035 aGroups.append(aGroupName);
1040 void XGUI_ContextMenuMgr::onRename()
1042 QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
1043 if (!myWorkshop->abortAllOperations())
1045 // restore selection in case if dialog box was shown
1046 myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
1047 myWorkshop->objectBrowser()->onEditItem();
1050 void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
1052 SessionPtr aMgr = ModelAPI_Session::get();
1053 DocumentPtr anActiveDoc = aMgr->activeDocument();
1055 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
1056 XGUI_ActionsMgr* anActionMgr = myWorkshop->actionsMgr();
1057 const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
1058 QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
1062 bool aIsRoot = false;
1063 foreach(QModelIndex aIdx, aSelectedIndexes) {
1064 // Process only first column
1065 if (aIdx.column() == 1) {
1066 aIsRoot = !aIdx.parent().isValid();
1067 // Exit if the selected index belongs to non active document
1068 if (aIsRoot && (anActiveDoc != aMgr->moduleDocument()))
1071 // Get name of the selected index
1072 aName = aIdx.data().toString();
1073 aLen = aName.indexOf('(');
1075 aName = aName.left(--aLen);
1077 std::string aFeaturesStr = aIsRoot?
1078 aDataModelXML->rootFolderFeatures(aName.toStdString()) :
1079 aDataModelXML->subFolderFeatures(aName.toStdString());
1080 if (aFeaturesStr.length() > 0) {
1081 QStringList aFeturesList =
1082 QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
1083 foreach(QString aFea, aFeturesList) {
1084 QAction* anAction = anActionMgr->action(aFea);
1086 theMenu->addAction(anAction);
1093 #define UNCHECK_ACTION(NAME) \
1094 { QAction* anAction = action(NAME); \
1095 bool isBlock = anAction->signalsBlocked(); \
1096 anAction->blockSignals(true); \
1097 anAction->setChecked(false); \
1098 anAction->blockSignals(isBlock); }
1101 void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
1103 UNCHECK_ACTION("SELECT_VERTEX_CMD");
1104 UNCHECK_ACTION("SELECT_EDGE_CMD");
1105 UNCHECK_ACTION("SELECT_FACE_CMD");
1108 void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
1110 UNCHECK_ACTION("SHOW_RESULTS_CMD");