X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_ContextMenuMgr.cpp;h=494ecf28d011cf8dcf54d04dae64ac496ebd843e;hb=564df60468b225bbce2f1cc055299b47c3be9355;hp=21fc9672b7617e33b05e9496e34f5f650de76c51;hpb=036ba4eb4c2df048fd651a54f68882a01769eb08;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 21fc9672b..494ecf28d 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -1,27 +1,37 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> #include "XGUI_ContextMenuMgr.h" #include "XGUI_Workshop.h" #include "XGUI_ObjectsBrowser.h" #include "XGUI_SelectionMgr.h" #include "XGUI_Displayer.h" -#include "XGUI_MainWindow.h" #include "XGUI_ViewerProxy.h" #include "XGUI_Selection.h" +#include "XGUI_SalomeConnector.h" +#include "XGUI_Tools.h" -#include "PartSetPlugin_Part.h" +#include + +//#include "PartSetPlugin_Part.h" #include #include #include #include +#include +#include +#include + +#include #include #include #include #include -XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent) : -QObject(theParent), myWorkshop(theParent) +XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent) + : QObject(theParent), + myWorkshop(theParent) { } @@ -41,13 +51,35 @@ void XGUI_ContextMenuMgr::createActions() addAction("DEACTIVATE_PART_CMD", aAction); aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this); + QMainWindow* aDesktop = myWorkshop->mainWindow(); + if (!aDesktop) + aDesktop = myWorkshop->salomeConnector()->desktop(); + aDesktop->addAction(aAction); + addAction("DELETE_CMD", aAction); + aAction->setShortcut(Qt::Key_Delete); + aAction->setShortcutContext(Qt::ApplicationShortcut); + + aAction = new QAction(QIcon(":pictures/color.png"), tr("Color"), this); + addAction("COLOR_CMD", aAction); aAction = new QAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), this); addAction("SHOW_CMD", aAction); + aAction = new QAction(QIcon(":pictures/eye_pencil.png"), tr("Show only"), this); + addAction("SHOW_ONLY_CMD", aAction); + aAction = new QAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"), this); addAction("HIDE_CMD", aAction); + + aAction = new QAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide all"), this); + addAction("HIDEALL_CMD", aAction); + + aAction = new QAction(QIcon(":pictures/shading.png"), tr("Shading"), this); + addAction("SHADING_CMD", aAction); + + aAction = new QAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"), this); + addAction("WIREFRAME_CMD", aAction); } void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction) @@ -66,6 +98,16 @@ QAction* XGUI_ContextMenuMgr::action(const QString& theId) const return 0; } +QAction* XGUI_ContextMenuMgr::actionByName(const QString& theName) const +{ + foreach(QAction* eachAction, myActions) { + if (eachAction->text() == theName) { + return eachAction; + } + } + return NULL; +} + QStringList XGUI_ContextMenuMgr::actionIds() const { return myActions.keys(); @@ -89,9 +131,14 @@ void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent) else if (sender() == myWorkshop->viewer()) { aMenu = viewerMenu(); } - + if (aMenu && (aMenu->actions().size() > 0)) { + // it is possible that some objects should do something before and after the popup menu exec + // e.g. a sketch manager changes an internal flag on this signals in order to do not hide + // a created entity + emit beforeContextMenu(); aMenu->exec(theEvent->globalPos()); + emit afterContextMenu(); delete aMenu; } } @@ -100,46 +147,73 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const { QMenu* aMenu = new QMenu(); XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); - QList aObjects = aSelMgr->selection()->selectedObjects(); - if (aObjects.size() == 1) { - PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); - ObjectPtr aObject = aObjects.first(); + QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects(); + int aSelected = aObjects.size(); + if (aSelected > 0) { + SessionPtr aMgr = ModelAPI_Session::get(); + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + bool hasResult = false; + bool hasFeature = false; + bool hasParameter = false; + XGUI_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter); + //Process Feature - if (aObject) { - ResultPartPtr aPart = boost::dynamic_pointer_cast(aObject); - if (aPart) { - DocumentPtr aFeaDoc = aPart->document(); - if (aMgr->currentDocument() == aFeaDoc) - aMenu->addAction(action("DEACTIVATE_PART_CMD")); - else - aMenu->addAction(action("ACTIVATE_PART_CMD")); - } else { - ResultPtr aResult = boost::dynamic_pointer_cast(aObject); - if (aResult) { + if (aSelected == 1) { + ObjectPtr aObject = aObjects.first(); + if (aObject) { + ResultPartPtr aPart = std::dynamic_pointer_cast(aObject); + if (aPart) { + if (aMgr->activeDocument() == aPart->partDoc()) + aMenu->addAction(action("DEACTIVATE_PART_CMD")); + else + aMenu->addAction(action("ACTIVATE_PART_CMD")); + } else if (hasFeature && aObject->document() == aMgr->activeDocument()) { aMenu->addAction(action("EDIT_CMD")); - - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - if (aDisplayer->isVisible(aResult)) + } else { + if (aDisplayer->isVisible(aObject)) { + if (aDisplayer->canBeShaded(aObject)) { + if (aDisplayer->displayMode(aObject) == XGUI_Displayer::Shading) + aMenu->addAction(action("WIREFRAME_CMD")); + else + aMenu->addAction(action("SHADING_CMD")); + } + aMenu->addSeparator(); aMenu->addAction(action("HIDE_CMD")); - else + } else if (!hasParameter) { aMenu->addAction(action("SHOW_CMD")); - } else { - FeaturePtr aResult = boost::dynamic_pointer_cast(aObject); - if (aResult) { - aMenu->addAction(action("DELETE_CMD")); } + if (hasParameter) + aMenu->addAction(action("EDIT_CMD")); + else + aMenu->addAction(action("SHOW_ONLY_CMD")); } + } else { // If feature is 0 the it means that selected root object (document) + if (aMgr->activeDocument() != aMgr->moduleDocument()) + aMenu->addAction(action("ACTIVATE_PART_CMD")); } - aMenu->addSeparator(); - - // Process Root object (document) - } else { // If feature is 0 the it means that selected root object (document) - if (aMgr->currentDocument() != aMgr->rootDocument()) { - aMenu->addAction(action("ACTIVATE_PART_CMD")); + } else { + if (hasResult && (!hasParameter)) { + aMenu->addAction(action("SHOW_CMD")); + aMenu->addAction(action("HIDE_CMD")); + aMenu->addAction(action("SHOW_ONLY_CMD")); + aMenu->addSeparator(); + aMenu->addAction(action("SHADING_CMD")); + aMenu->addAction(action("WIREFRAME_CMD")); } } + if (hasFeature || hasParameter) + aMenu->addAction(action("DELETE_CMD")); } + if (myWorkshop->canChangeColor()) + aMenu->addAction(action("COLOR_CMD")); + + aMenu->addSeparator(); aMenu->addActions(myWorkshop->objectBrowser()->actions()); + + ModuleBase_IModule* aModule = myWorkshop->module(); + if (aModule) + aModule->addObjectBrowserItems(aMenu); + if (aMenu->actions().size() > 0) { return aMenu; } @@ -160,43 +234,69 @@ QMenu* XGUI_ContextMenuMgr::viewerMenu() const void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const { - XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); - QList aObjects = aSelMgr->selection()->selectedObjects(); - if (aObjects.size() > 0) { - if (aObjects.size() == 1) - theMenu->addAction(action("EDIT_CMD")); - bool isVisible = false; - foreach(ObjectPtr aObject, aObjects) { - ResultPtr aRes = boost::dynamic_pointer_cast(aObject); - if (aRes && myWorkshop->displayer()->isVisible(aRes)) { - isVisible = true; - break; + bool aIsDone = false; + ModuleBase_IModule* aModule = myWorkshop->module(); + if (aModule) + aIsDone = aModule->addViewerItems(theMenu, myActions); + + if (!aIsDone) { + XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); + QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects(); + if (aObjects.size() > 0) { + //if (aObjects.size() == 1) + // theMenu->addAction(action("EDIT_CMD")); + bool isVisible = false; + bool isShading = false; + bool canBeShaded = false; + foreach(ObjectPtr aObject, aObjects) + { + ResultPtr aRes = std::dynamic_pointer_cast(aObject); + if (aRes && myWorkshop->displayer()->isVisible(aRes)) { + isVisible = true; + canBeShaded = myWorkshop->displayer()->canBeShaded(aObject); + isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading); + break; + } } + if (isVisible) { + if (canBeShaded) { + if (isShading) + theMenu->addAction(action("WIREFRAME_CMD")); + else + theMenu->addAction(action("SHADING_CMD")); + } + theMenu->addSeparator(); + theMenu->addAction(action("SHOW_ONLY_CMD")); + theMenu->addAction(action("HIDE_CMD")); + } else + theMenu->addAction(action("SHOW_CMD")); + //theMenu->addAction(action("DELETE_CMD")); } - if (isVisible) - theMenu->addAction(action("HIDE_CMD")); - else - theMenu->addAction(action("SHOW_CMD")); - theMenu->addAction(action("DELETE_CMD")); + if (myWorkshop->displayer()->objectsCount() > 0) + theMenu->addAction(action("HIDEALL_CMD")); + if (myWorkshop->canChangeColor()) + theMenu->addAction(action("COLOR_CMD")); } if (!myWorkshop->isSalomeMode()) { + theMenu->addSeparator(); QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea(); if (aMDI->actions().size() > 0) { QMenu* aSubMenu = theMenu->addMenu(tr("Windows")); aSubMenu->addActions(aMDI->actions()); } } + } void XGUI_ContextMenuMgr::connectObjectBrowser() const { - connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), - this, SLOT(onContextMenuRequest(QContextMenuEvent*))); + connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this, + SLOT(onContextMenuRequest(QContextMenuEvent*))); } void XGUI_ContextMenuMgr::connectViewer() const { - connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), - this, SLOT(onContextMenuRequest(QContextMenuEvent*))); + connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this, + SLOT(onContextMenuRequest(QContextMenuEvent*))); }