From: vsv Date: Tue, 14 Jul 2015 11:47:25 +0000 (+0300) Subject: Issue #762: Show Detach menu item in Salome mode. Disable menu items for shapes in... X-Git-Tag: V_1.3.0~16^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ec7c4f6ca5f54babcdb171e1df2b1cfe06d4e6fe;p=modules%2Fshaper.git Issue #762: Show Detach menu item in Salome mode. Disable menu items for shapes in sketcher mode --- diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index f77d5674a..d6bd6e9af 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -166,6 +166,14 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject //! Returns data object by AIS virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0; + /// Update state of pop-up menu items in object browser + /// \param theStdActions - a map of standard actions + virtual void updateObjectBrowserMenu(const QMap& theStdActions) {} + + /// Update state of pop-up menu items in viewer + /// \param theStdActions - a map of standard actions + virtual void updateViewerMenu(const QMap& theStdActions) {} + signals: void operationLaunched(); diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index d88a4ca6b..9a20bca77 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -537,11 +537,9 @@ void NewGeom_Module::selectionChanged() //****************************************************** void NewGeom_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle) { - QMenu* aMenu = myWorkshop->contextMenuMgr()->viewerMenu(); - theMenu->addActions(aMenu->actions()); - //myWorkshop->contextMenuMgr()->addViewerMenu(theMenu); + myWorkshop->contextMenuMgr()->updateViewerMenu(); + myWorkshop->contextMenuMgr()->addViewerMenu(theMenu); LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle); - delete aMenu; // Delete menu because it is not controlled by menu manager } diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index dfc184a42..f232b9b48 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -113,7 +113,7 @@ bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap aPrsList = aSelection->getSelected(ModuleBase_ISelection::AllControls); + QList aPrsList = aSelection->getSelected(ModuleBase_ISelection::Viewer); TopoDS_Shape aShape; ResultPtr aResult; FeaturePtr aFeature; @@ -205,6 +205,23 @@ bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap& theStdActions) +{ + ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation(); + + bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) || + PartSet_SketcherMgr::isNestedSketchOperation(anOperation); + if (isActiveSketch) { + theStdActions["WIREFRAME_CMD"]->setEnabled(false); + theStdActions["SHADING_CMD"]->setEnabled(false); + theStdActions["SHOW_ONLY_CMD"]->setEnabled(false); + theStdActions["SHOW_CMD"]->setEnabled(false); + theStdActions["HIDE_CMD"]->setEnabled(false); + theStdActions["HIDEALL_CMD"]->setEnabled(false); + } +} + + void PartSet_MenuMgr::onLineHighlighted(QAction* theAction) { if (myPrevId != -1) { diff --git a/src/PartSet/PartSet_MenuMgr.h b/src/PartSet/PartSet_MenuMgr.h index 93f545360..b31493dcd 100644 --- a/src/PartSet/PartSet_MenuMgr.h +++ b/src/PartSet/PartSet_MenuMgr.h @@ -42,6 +42,10 @@ public: /// \return true if items are added and there is no necessity to provide standard menu bool addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const; + /// Update state of pop-up menu items in viewer + /// \param theStdActions - a map of standard actions + void updateViewerMenu(const QMap& theStdActions); + public slots: /// Processes the context menu action click /// \param isChecked a state of toggle if the action is checkable diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index ccc0565cc..8bde3e6f8 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -362,6 +362,12 @@ bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap return myMenuMgr->addViewerMenu(theMenu, theStdActions); } +void PartSet_Module::updateViewerMenu(const QMap& theStdActions) +{ + myMenuMgr->updateViewerMenu(theStdActions); +} + + void PartSet_Module::activeSelectionModes(QIntList& theModes) { theModes.clear(); @@ -917,7 +923,6 @@ void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*) TColStd_SequenceOfInteger aZList; aViewer->GetAllZLayers(aZList); bool aFound = false; - //TColStd_SequenceIteratorOfSequenceOfInteger aIt; for (int i = 1; i <= aZList.Length(); i++) { if (aZList(i) == myVisualLayerId) { aFound = true; diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index ecb1dffdc..f97713ce7 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -164,6 +164,10 @@ public: //! Returns data object by AIS virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const; + /// Update state of pop-up menu items in viewer + /// \param theStdActions - a map of standard actions + virtual void updateViewerMenu(const QMap& theStdActions); + public slots: /// SLOT, that is called by no more widget signal emitted by property panel /// Set a specific flag to restart the sketcher operation diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 81e6fe2b8..7e7b90446 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -129,13 +129,13 @@ void XGUI_ContextMenuMgr::updateCommandsStatus() void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent) { - QMenu* aMenu = 0; + QMenu* aMenu = new QMenu(); if (sender() == myWorkshop->objectBrowser()) { updateObjectBrowserMenu(); - aMenu = objBrowserMenu(); + addObjBrowserMenu(aMenu); } else if (sender() == myWorkshop->viewer()) { updateViewerMenu(); - aMenu = viewerMenu(); + addViewerMenu(aMenu); } if (aMenu && (aMenu->actions().size() > 0)) { @@ -203,6 +203,10 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu() } if (myWorkshop->canChangeColor()) action("COLOR_CMD")->setEnabled(true); + + ModuleBase_IModule* aModule = myWorkshop->module(); + if (aModule) + aModule->updateObjectBrowserMenu(myActions); } void XGUI_ContextMenuMgr::updateViewerMenu() @@ -211,13 +215,14 @@ void XGUI_ContextMenuMgr::updateViewerMenu() aAction->setEnabled(false); XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); - QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects(); - if (aObjects.size() > 0) { + QList aPrsList = aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer); + if (aPrsList.size() > 0) { bool isVisible = false; bool isShading = false; bool canBeShaded = false; - foreach(ObjectPtr aObject, aObjects) - { + ObjectPtr aObject; + foreach(ModuleBase_ViewerPrs aPrs, aPrsList) { + aObject = aPrs.object(); ResultPtr aRes = std::dynamic_pointer_cast(aObject); if (aRes && aRes->isDisplayed()) { isVisible = true; @@ -242,6 +247,10 @@ void XGUI_ContextMenuMgr::updateViewerMenu() action("COLOR_CMD")->setEnabled(true); action("DELETE_CMD")->setEnabled(true); + + ModuleBase_IModule* aModule = myWorkshop->module(); + if (aModule) + aModule->updateViewerMenu(myActions); } void XGUI_ContextMenuMgr::connectObjectBrowser() @@ -327,9 +336,8 @@ void XGUI_ContextMenuMgr::buildViewerMenu() } -QMenu* XGUI_ContextMenuMgr::objBrowserMenu() const +void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const { - QMenu* aMenu = new QMenu(); XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects(); int aSelected = aObjects.size(); @@ -350,49 +358,46 @@ QMenu* XGUI_ContextMenuMgr::objBrowserMenu() const aActions.append(action("DELETE_CMD")); //aActions.append(action("MOVE_CMD")); } - aMenu->addActions(aActions); + theMenu->addActions(aActions); ModuleBase_IModule* aModule = myWorkshop->module(); if (aModule) { - aMenu->addSeparator(); - aModule->addObjectBrowserMenu(aMenu); + theMenu->addSeparator(); + aModule->addObjectBrowserMenu(theMenu); } - aMenu->addSeparator(); - aMenu->addActions(myWorkshop->objectBrowser()->actions()); - - return aMenu; + theMenu->addSeparator(); + theMenu->addActions(myWorkshop->objectBrowser()->actions()); } -QMenu* XGUI_ContextMenuMgr::viewerMenu() const +void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const { - QMenu* aMenu = new QMenu(); ModuleBase_IModule* aModule = myWorkshop->module(); - if (aModule) - aModule->addViewerMenu(aMenu, myActions); - + if (aModule) { + if (aModule->addViewerMenu(theMenu, myActions)) + theMenu->addSeparator(); + } XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); - QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects(); - int aSelected = aObjects.size(); + QList aPrsList = aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer); + int aSelected = aPrsList.size(); QActionsList aActions; if (aSelected == 1) { - ObjectPtr aObject = aObjects.first(); + ObjectPtr aObject = aPrsList.first().object(); std::string aName = aObject->groupName(); if (myViewerMenu.contains(aName)) aActions = myViewerMenu[aName]; } else if (aSelected > 1) { aActions.append(action("HIDE_CMD")); } - aMenu->addActions(aActions); + theMenu->addActions(aActions); if (!myWorkshop->isSalomeMode()) { - aMenu->addSeparator(); + theMenu->addSeparator(); QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea(); if (aMDI->actions().size() > 0) { - QMenu* aSubMenu = aMenu->addMenu(tr("Windows")); + QMenu* aSubMenu = theMenu->addMenu(tr("Windows")); aSubMenu->addActions(aMDI->actions()); } } - return aMenu; } QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName) diff --git a/src/XGUI/XGUI_ContextMenuMgr.h b/src/XGUI/XGUI_ContextMenuMgr.h index 254baf198..1ce4bcb1b 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.h +++ b/src/XGUI/XGUI_ContextMenuMgr.h @@ -49,14 +49,17 @@ Q_OBJECT /// Connect to viewer from workshop. Has to called at creation of viewer. void connectViewer(); - QMenu* objBrowserMenu() const; - QMenu* viewerMenu() const; + void addObjBrowserMenu(QMenu*) const; + void addViewerMenu(QMenu*) const; /// Returns a list of object group names of the action /// \param theName a name of the action /// \return a list of group names QStringList actionObjectGroups(const QString& theName); + /// Updates menu for viewer + void updateViewerMenu(); + signals: /// Signal aabout triggered action /// \param theId an id of triggered action @@ -89,9 +92,6 @@ signals: /// Updates menu for object browser void updateObjectBrowserMenu(); - /// Updates menu for viewer - void updateViewerMenu(); - /// Creates menu for object browser void buildObjBrowserMenu();