From: nds Date: Fri, 15 Apr 2016 05:34:00 +0000 (+0300) Subject: Issue #1303 Re-ordering of Sketcher menus: Delete to be the last X-Git-Tag: V_2.3.0~220 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=397bec888031ab3d5d0578d3094e01f9a052222f;p=modules%2Fshaper.git Issue #1303 Re-ordering of Sketcher menus: Delete to be the last --- diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index a89671c2f..8ac4817bc 100755 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -105,11 +105,13 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// Realizes some functionality by an operation start virtual ModuleBase_Operation* currentOperation() const = 0; - /// Add menu items for viewer into the given menu - /// \param theMenu a popup menu to be shown in the viewer + /// Add menu items for viewer into the actions map /// \param theStdActions a map of standard actions + /// \param theMenuActions map of action/menu for the desirable index in the viewer menu /// \return true if items are added and there is no necessity to provide standard menu - virtual bool addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const + virtual bool addViewerMenu(const QMap& theStdActions, + QWidget* theParent, + QMap& theMenuActions) const { return false; } /// Add menu items for object browser into the given menu diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index 293e2fa8c..0b149456b 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -106,8 +106,12 @@ void PartSet_MenuMgr::onAction(bool isChecked) } } -bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const +bool PartSet_MenuMgr::addViewerMenu(const QMap& theStdActions, + QWidget* theParent, + QMap& theMenuActions) const { + int anIndex = 0; + ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation(); if (!PartSet_SketcherMgr::isSketchOperation(anOperation) && !PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) @@ -121,23 +125,25 @@ bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap aPrsList = aSelection->getSelected(ModuleBase_ISelection::Viewer); - ResultPtr aResult; - FeaturePtr aFeature; - foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) { - aResult = std::dynamic_pointer_cast(aPrs->object()); - if (aResult.get() != NULL) { - const GeomShapePtr& aShape = aPrs->shape(); - if (aShape.get() && aShape->isEqual(aResult->shape())) - hasFeature = true; - else - hasAttribute = true; - } else { - aFeature = std::dynamic_pointer_cast(aPrs->object()); - hasFeature = (aFeature.get() != NULL); + if (aPrsList.size() > 1) { + hasFeature = true; + } else if (aPrsList.size() == 1) { + ResultPtr aResult; + FeaturePtr aFeature; + foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) { + aResult = std::dynamic_pointer_cast(aPrs->object()); + if (aResult.get() != NULL) { + const GeomShapePtr& aShape = aPrs->shape(); + if (aShape.get() && aShape->isEqual(aResult->shape())) + hasFeature = true; + else + hasAttribute = true; + } else { + aFeature = std::dynamic_pointer_cast(aPrs->object()); + hasFeature = (aFeature.get() != NULL); + } } - } - if (aPrsList.size() == 1) { const GeomShapePtr& aShape = aPrsList.first()->shape(); if (aShape.get() && !aShape->isNull() && aShape->shapeType() == GeomAPI_Shape::VERTEX) { // Find 2d coordinates @@ -162,7 +168,8 @@ bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap 0) { aIsDetach = true; - QMenu* aSubMenu = theMenu->addMenu(tr("Detach")); + QMenu* aSubMenu = new QMenu(tr("Detach"), theParent); + theMenuActions[anIndex++] = aSubMenu->menuAction(); QAction* aAction; int i = 0; foreach (FeaturePtr aCoins, myCoinsideLines) { @@ -178,17 +185,20 @@ bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMapaddAction(theStdActions["DELETE_CMD"]); + if (!hasAttribute) { + bool isAuxiliary; + if (canSetAuxiliary(isAuxiliary)) { + QAction* anAction = action("AUXILIARY_CMD"); + theMenuActions[anIndex++] = anAction; + anAction->setChecked(isAuxiliary); + } } - if (hasAttribute) - return true; - bool isAuxiliary; - if (canSetAuxiliary(isAuxiliary)) { - QAction* anAction = action("AUXILIARY_CMD"); - theMenu->addAction(anAction); - anAction->setChecked(isAuxiliary); + + if (!aIsDetach && hasFeature) { + // Delete item should be the last in the list of actions + theMenuActions[1000] = theStdActions["DELETE_CMD"]; } + return true; } diff --git a/src/PartSet/PartSet_MenuMgr.h b/src/PartSet/PartSet_MenuMgr.h index 0e8333caa..738c6569f 100644 --- a/src/PartSet/PartSet_MenuMgr.h +++ b/src/PartSet/PartSet_MenuMgr.h @@ -37,11 +37,14 @@ public: /// \param theId an action identifier, it should be uniqued in the bounds of the module QAction* action(const QString& theId) const; - /// Add menu atems for viewer into the given menu - /// \param theMenu a popup menu to be shown in the viewer + /// Add menu items for viewer into the actions map /// \param theStdActions a map of standard actions + /// \param theParent a parent widget for the + /// \param theMenuActions map of action/menu for the desirable index in the viewer menu /// \return true if items are added and there is no necessity to provide standard menu - bool addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const; + bool addViewerMenu(const QMap& theStdActions, + QWidget* theParent, + QMap& theMenuActions) const; /// Update state of pop-up menu items in viewer /// \param theStdActions - a map of standard actions diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index e257113e7..f8b2fb3ee 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -487,9 +487,11 @@ bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const return aCanActivate; } -bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const +bool PartSet_Module::addViewerMenu(const QMap& theStdActions, + QWidget* theParent, + QMap& theMenuActions) const { - return myMenuMgr->addViewerMenu(theMenu, theStdActions); + return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions); } void PartSet_Module::updateViewerMenu(const QMap& theStdActions) diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 6b70b2341..b5aed0bdd 100755 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -176,11 +176,13 @@ public: /// \param theMenu a popup menu to be shown in the object browser virtual void addObjectBrowserMenu(QMenu* theMenu) const; - /// Add menu atems for viewer into the given menu - /// \param theMenu a popup menu to be shown in the viewer + /// Add menu items for viewer into the actions map /// \param theStdActions a map of standard actions + /// \param theMenuActions map of action/menu for the desirable index in the viewer menu /// \return true if items are added and there is no necessity to provide standard menu - virtual bool addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const; + virtual bool addViewerMenu(const QMap& theStdActions, + QWidget* theParent, + QMap& theMenuActions) const; /// Returns a list of modes, where the AIS objects should be activated /// \param theModes a list of modes diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 6be0e46be..bfd87b0ed 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -417,7 +417,8 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu() aList.clear(); aList.append(action("WIREFRAME_CMD")); aList.append(action("SHADING_CMD")); - aList.append(mySeparator); + aList.append(mySeparator); // this separator is not shown as this action is added after show only + // qt list container contains only one instance of the same action aList.append(action("SHOW_CMD")); aList.append(action("HIDE_CMD")); aList.append(action("SHOW_ONLY_CMD")); @@ -516,11 +517,6 @@ void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const { - ModuleBase_IModule* aModule = myWorkshop->module(); - if (aModule) { - if (aModule->addViewerMenu(theMenu, myActions)) - theMenu->addSeparator(); - } XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); QList aPrsList = aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer); int aSelected = aPrsList.size(); @@ -546,15 +542,35 @@ void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const if (myViewerMenu.contains(aName)) aActions = myViewerMenu[aName]; } - aActions.append(action("COLOR_CMD")); } else if (aSelected > 1) { aActions.append(action("HIDE_CMD")); - aActions.append(action("COLOR_CMD")); } // hide all is shown always even if selection in the viewer is empty aActions.append(action("HIDEALL_CMD")); + aActions.append(action("COLOR_CMD")); + theMenu->addActions(aActions); + QMap aMenuActions; + ModuleBase_IModule* aModule = myWorkshop->module(); + if (aModule) { + if (aModule->addViewerMenu(myActions, theMenu, aMenuActions)) + theMenu->addSeparator(); + } + + // insert the module menu items on specific positions in the popup menu: some actions should be + // in the begin of the list, Delete action should be the last by #1343 issue + QList anActions = theMenu->actions(); + int anActionsSize = anActions.size(); + QAction* aFirstAction = anActions[0]; + QMap::const_iterator anIt = aMenuActions.begin(), aLast = aMenuActions.end(); + for (; anIt != aLast; anIt++) { + if (anIt.key() > anActionsSize) + theMenu->addAction(anIt.value()); + else + theMenu->insertAction(aFirstAction, *anIt); + } + #ifndef HAVE_SALOME theMenu->addSeparator(); QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea(); diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index afdbe6e8e..79fb1f007 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -62,7 +62,7 @@ //#define DEBUG_RESULT_COMPSOLID #ifdef DEBUG_FEATURE_REDISPLAY -const std::string DebugFeatureKind = "Extrusion"; +const std::string DebugFeatureKind = "";//"Extrusion"; #endif XGUI_WorkshopListener::XGUI_WorkshopListener(ModuleBase_IWorkshop* theWorkshop) @@ -285,7 +285,7 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptrgetKind(); - if (aKind == DebugFeatureKind) { + if (aKind == DebugFeatureKind || DebugFeatureKind.empty()) { qDebug(QString("visible=%1, hide=%2 : display= %2").arg(aDisplayer->isVisible(aObj)) .arg(aHide).arg(anObjInfo).toStdString().c_str()); }