X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_ContextMenuMgr.cpp;h=8ecb179b3d1b77a46503126208ead9d91469b882;hb=47c18d4de2719126f6b045b5c37525cd8f170aa1;hp=2a8fe108b3e4a5b23ff8e4515ebe37a5128a2f21;hpb=23378e19cee76b189c2bfdea631002b005f3237a;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 2a8fe108b..8ecb179b3 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -3,15 +3,25 @@ #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 "PartSetPlugin_Part.h" + +#include +#include +#include #include #include #include +#include XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent) : QObject(theParent), myWorkshop(theParent) { - } XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr() @@ -28,6 +38,15 @@ void XGUI_ContextMenuMgr::createActions() aAction = new QAction(QIcon(":pictures/assembly.png"), tr("Deactivate"), this); addAction("DEACTIVATE_PART_CMD", aAction); + + aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this); + addAction("DELETE_CMD", aAction); + + aAction = new QAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), this); + addAction("SHOW_CMD", aAction); + + aAction = new QAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"), this); + addAction("HIDE_CMD", aAction); } void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction) @@ -66,8 +85,11 @@ void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent) QMenu* aMenu = 0; if (sender() == myWorkshop->objectBrowser()) aMenu = objectBrowserMenu(); - - if (aMenu) { + else if (sender() == myWorkshop->viewer()) { + aMenu = viewerMenu(); + } + + if (aMenu && (aMenu->actions().size() > 0)) { aMenu->exec(theEvent->globalPos()); delete aMenu; } @@ -75,24 +97,97 @@ void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent) QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const { + QMenu* aMenu = new QMenu(); XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); - QFeatureList aFeatures = aSelMgr->selectedFeatures(); + QFeatureList aFeatures = aSelMgr->selection()->selectedFeatures(); if (aFeatures.size() == 1) { + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); FeaturePtr aFeature = aFeatures.first(); - QMenu* aMenu = new QMenu(); - if (aFeature->getKind() == "Part") { - //TODO: Check that feature is active - aMenu->addAction(action("ACTIVATE_PART_CMD")); - } else { - aMenu->addAction(action("EDIT_CMD")); + //Process Feature + if (aFeature) { + if (aFeature->getKind() == PARTSET_PART_KIND) { + ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); + DocumentPtr aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value(); + if (aMgr->currentDocument() == aFeaDoc) + aMenu->addAction(action("DEACTIVATE_PART_CMD")); + else + aMenu->addAction(action("ACTIVATE_PART_CMD")); + } else { + aMenu->addAction(action("EDIT_CMD")); + + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + if (aDisplayer->isVisible(aFeature)) + aMenu->addAction(action("HIDE_CMD")); + else + aMenu->addAction(action("SHOW_CMD")); + } + aMenu->addAction(action("DELETE_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")); + } } + } + aMenu->addActions(myWorkshop->objectBrowser()->actions()); + if (aMenu->actions().size() > 0) { + return aMenu; + } + delete aMenu; + return 0; +} + +QMenu* XGUI_ContextMenuMgr::viewerMenu() const +{ + QMenu* aMenu = new QMenu(); + addViewerItems(aMenu); + if (aMenu->actions().size() > 0) { return aMenu; } + delete aMenu; return 0; } +void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const +{ + XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); + QFeatureList aFeatures = aSelMgr->selection()->selectedFeatures(); + if (aFeatures.size() > 0) { + if (aFeatures.size() == 1) + theMenu->addAction(action("EDIT_CMD")); + bool isVisible = false; + foreach(FeaturePtr aFeature, aFeatures) { + if (myWorkshop->displayer()->isVisible(aFeature)) { + isVisible = true; + break; + } + } + if (isVisible) + theMenu->addAction(action("HIDE_CMD")); + else + theMenu->addAction(action("SHOW_CMD")); + theMenu->addAction(action("DELETE_CMD")); + } + if (!myWorkshop->isSalomeMode()) { + 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*))); -} \ No newline at end of file +} + +void XGUI_ContextMenuMgr::connectViewer() const +{ + connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), + this, SLOT(onContextMenuRequest(QContextMenuEvent*))); +} +