Salome HOME
Issue #1303 Re-ordering of Sketcher menus: Delete to be the last
authornds <nds@opencascade.com>
Fri, 15 Apr 2016 05:34:00 +0000 (08:34 +0300)
committernds <nds@opencascade.com>
Fri, 15 Apr 2016 05:34:27 +0000 (08:34 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/PartSet/PartSet_MenuMgr.cpp
src/PartSet/PartSet_MenuMgr.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_WorkshopListener.cpp

index a89671c2fb37ad38dee7ba3916e2c80bab5e222a..8ac4817bce5d8260faa29be77c1f9310c5c09953 100755 (executable)
@@ -105,11 +105,13 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
   /// Realizes some functionality by an operation start\r
   virtual ModuleBase_Operation* currentOperation() const = 0;\r
 \r
-  /// Add menu items for viewer into the given menu\r
-  /// \param theMenu a popup menu to be shown in the viewer\r
+  /// Add menu items for viewer into the actions map\r
   /// \param theStdActions a map of standard actions\r
+  /// \param theMenuActions map of action/menu for the desirable index in the viewer menu\r
   /// \return true if items are added and there is no necessity to provide standard menu\r
-  virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const\r
+  virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,\r
+                             QWidget* theParent,\r
+                             QMap<int, QAction*>& theMenuActions) const\r
   { return false; }\r
 \r
   /// Add menu items for object browser into the given menu\r
index 293e2fa8cab11275746c5e610db01e265896b15b..0b149456b023ff458e5b80da0135fdaea1a35f6d 100644 (file)
@@ -106,8 +106,12 @@ void PartSet_MenuMgr::onAction(bool isChecked)
   }
 }
 
-bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
+bool PartSet_MenuMgr::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
+                                    QWidget* theParent,
+                                    QMap<int, QAction*>& 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<QString, QAction*
   bool hasFeature = false;
 
   QList<ModuleBase_ViewerPrsPtr> aPrsList = aSelection->getSelected(ModuleBase_ISelection::Viewer);
-  ResultPtr aResult;
-  FeaturePtr aFeature;
-  foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
-    aResult = std::dynamic_pointer_cast<ModelAPI_Result>(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<ModelAPI_Feature>(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<ModelAPI_Result>(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<ModelAPI_Feature>(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<QString, QAction*
                                           SketchPlugin_ConstraintCoincidence::ENTITY_B());
           if (myCoinsideLines.size() > 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 QMap<QString, QAction*
       }
     }
   }
-  if ((!aIsDetach) && hasFeature) {
-    theMenu->addAction(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;
 }
 
index 0e8333caa4a968dcfc71cb0e26bc8dfd9875c361..738c6569f7ef8d571de66dc15b5369ae46949c2f 100644 (file)
@@ -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<QString, QAction*>& theStdActions) const;
+  bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
+                     QWidget* theParent,
+                     QMap<int, QAction*>& theMenuActions) const;
 
   /// Update state of pop-up menu items in viewer
   /// \param theStdActions - a map of standard actions
index e257113e774650107e5fafee31f5802c0bec8266..f8b2fb3eee6c357df9c5ef305b16b9366cb8d491 100755 (executable)
@@ -487,9 +487,11 @@ bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
   return aCanActivate;
 }
 
-bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
+bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
+                                   QWidget* theParent,
+                                   QMap<int, QAction*>& theMenuActions) const
 {
-  return myMenuMgr->addViewerMenu(theMenu, theStdActions);
+  return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
 }
 
 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
index 6b70b2341fa431e90ba3892e25c211a4e65ea3e3..b5aed0bdd53e27de5266d1e1ccde3fb8ae838003 100755 (executable)
@@ -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<QString, QAction*>& theStdActions) const;
+  virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
+                             QWidget* theParent,
+                             QMap<int, QAction*>& theMenuActions) const;
 
   /// Returns a list of modes, where the AIS objects should be activated
   /// \param theModes a list of modes
index 6be0e46bee9ba1851f811788d5ee4a6bbe5ee372..bfd87b0ed693187d4f3a08a93464af604c02466c 100644 (file)
@@ -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<ModuleBase_ViewerPrsPtr> 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<int, QAction*> 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<QAction*> anActions = theMenu->actions();
+  int anActionsSize = anActions.size();
+  QAction* aFirstAction = anActions[0];
+  QMap<int, QAction*>::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();
index afdbe6e8eeb107d69dc959192dd65ad06963979d..79fb1f007313f952ad45671635b398d8ea8c6688 100755 (executable)
@@ -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_ptr<ModelAPI
       FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
       if (aFeature.get()) {
         std::string aKind = aFeature->getKind();
-        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());
         }