Salome HOME
Task #3059 implementation: When “move to the end” of a group, propose to the user...
[modules/shaper.git] / src / XGUI / XGUI_ContextMenuMgr.cpp
index c48b8a8ef7c12ce1525b71662db4351392b2f3bc..a174bea87b737f8ae17402cf8e0e725739ea0687 100644 (file)
 #include <ModelAPI_ResultField.h>
 #include <ModelAPI_Folder.h>
 #include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_ResultField.h>
 
 #include <Config_DataModelReader.h>
 
 #include <ModuleBase_IModule.h>
 #include <ModuleBase_Tools.h>
-#include <ModuleBase_OperationAction.h>
+#include <ModuleBase_Operation.h>
 #include <ModuleBase_ViewerPrs.h>
 
 #include <QAction>
@@ -95,10 +96,14 @@ void XGUI_ContextMenuMgr::createActions()
                                            aDesktop, this, SLOT(onRename()));
   addAction("RENAME_CMD", aAction);
 
-  aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move.png"),
+  aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_to_end.png"),
                                            XGUI_Workshop::MOVE_TO_END_COMMAND, this);
   addAction("MOVE_CMD", aAction);
 
+  aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_to_end_split.png"),
+    XGUI_Workshop::MOVE_TO_END_SPLIT_COMMAND, this);
+  addAction("MOVE_SPLIT_CMD", aAction);
+
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/clean_history.png"),
                                            tr("Clean history"), aDesktop);
   addAction("CLEAN_HISTORY_CMD", aAction);
@@ -144,32 +149,25 @@ void XGUI_ContextMenuMgr::createActions()
   mySeparator3 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
   mySeparator3->setSeparator(true);
 
-  //mySelectActions = new QActionGroup(this);
-  //mySelectActions->setExclusive(true);
-
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
                                            this, SLOT(onShapeSelection(bool)));
   aAction->setCheckable(true);
   addAction("SELECT_VERTEX_CMD", aAction);
-  //mySelectActions->addAction(aAction);
 
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
                                            this, SLOT(onShapeSelection(bool)));
   aAction->setCheckable(true);
   addAction("SELECT_EDGE_CMD", aAction);
-  //mySelectActions->addAction(aAction);
 
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
                                            this, SLOT(onShapeSelection(bool)));
   aAction->setCheckable(true);
   addAction("SELECT_FACE_CMD", aAction);
-  //mySelectActions->addAction(aAction);
 
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop,
                                            this, SLOT(onResultSelection(bool)));
   aAction->setCheckable(true);
   addAction("SELECT_RESULT_CMD", aAction);
-  //mySelectActions->addAction(aAction);
 
   aAction->setChecked(true);
 
@@ -207,6 +205,14 @@ void XGUI_ContextMenuMgr::createActions()
                                            tr("Move out after the folder"), aDesktop);
   addAction("ADD_OUT_FOLDER_AFTER_CMD", aAction);
 
+  aAction = ModuleBase_Tools::createAction(QIcon(":pictures/normal-view-inversed.png"),
+                                           tr("Set view by inverted normal to face"), aDesktop);
+  addAction("SET_VIEW_INVERTEDNORMAL_CMD", aAction);
+
+  aAction = ModuleBase_Tools::createAction(QIcon(":pictures/normal-view.png"),
+                                           tr("Set view by normal to face"), aDesktop);
+  addAction("SET_VIEW_NORMAL_CMD", aAction);
+
   buildObjBrowserMenu();
   buildViewerMenu();
 }
@@ -324,8 +330,10 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
           if (!(hasParameter || hasFeature))
             action("SHOW_ONLY_CMD")->setEnabled(true);
         }
-        else if (hasFeature && myWorkshop->canMoveFeature())
+        else if (hasFeature && myWorkshop->canMoveFeature()) {
           action("MOVE_CMD")->setEnabled(true);
+          action("MOVE_SPLIT_CMD")->setEnabled(true);
+        }
 
         if( aMgr->activeDocument() == aObject->document() )
         {
@@ -345,6 +353,10 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
         action("SHADING_CMD")->setEnabled(true);
         action("WIREFRAME_CMD")->setEnabled(true);
       }
+      if (hasFeature && myWorkshop->canMoveFeature()) {
+        action("MOVE_CMD")->setEnabled(true);
+        action("MOVE_SPLIT_CMD")->setEnabled(true);
+      }
     } // end multi-selection
 
     // Check folder management commands state if only features are selected
@@ -500,16 +512,23 @@ void XGUI_ContextMenuMgr::updateViewerMenu()
     bool isVisible = false;
     bool isShading = false;
     bool canBeShaded = false;
+    bool hasPlanar = false;
     ObjectPtr aObject;
     foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
       aObject = aPrs->object();
-      ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
-      if (aRes && aRes->isDisplayed()) {
+      if (!aObject.get())
+        continue;
+      GeomShapePtr aShape = aPrs->shape();
+      if (aObject->isDisplayed()) {
         isVisible = true;
         canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
         isShading =
           (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
-        break;
+      }
+      if (aShape.get()) {
+        if (aShape->isPlanar()) {
+          hasPlanar = true;
+        }
       }
     }
     if (isVisible) {
@@ -527,6 +546,9 @@ void XGUI_ContextMenuMgr::updateViewerMenu()
       action("HIDE_CMD")->setEnabled(true);
     } else
       action("SHOW_CMD")->setEnabled(true);
+
+    action("SET_VIEW_NORMAL_CMD")->setEnabled(hasPlanar);
+    action("SET_VIEW_INVERTEDNORMAL_CMD")->setEnabled(hasPlanar);
   }
   //issue #2159 Hide all incomplete behavior
 #ifdef HAVE_SALOME
@@ -648,6 +670,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu()
   aList.append(action("RENAME_CMD"));
   aList.append(action("SHOW_RESULTS_CMD"));
   aList.append(action("MOVE_CMD"));
+  aList.append(action("MOVE_SPLIT_CMD"));
   aList.append(mySeparator1);
   aList.append(action("INSERT_FOLDER_CMD"));
   aList.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
@@ -673,18 +696,28 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu()
   aList.append(action("DELETE_CMD"));
   myObjBrowserMenus[ModelAPI_Folder::group()] = aList;
 
+  //---------------------------------------
+  // Step objects menu
+  aList.clear();
+  aList.append(action("SHOW_CMD"));
+  aList.append(action("HIDE_CMD"));
+  aList.append(action("SHOW_ONLY_CMD"));
+  myObjBrowserMenus[ModelAPI_ResultField::ModelAPI_FieldStep::group()] = aList;
 }
 
 void XGUI_ContextMenuMgr::buildViewerMenu()
 {
   QActionsList aList;
   // Result construction menu
-  aList.append(action("HIDE_CMD"));
-  aList.append(action("SHOW_ONLY_CMD"));
-  aList.append(mySeparator1);
   aList.append(action("COLOR_CMD"));
   aList.append(action("DEFLECTION_CMD"));
   aList.append(action("TRANSPARENCY_CMD"));
+  aList.append(mySeparator3);
+  aList.append(action("SET_VIEW_NORMAL_CMD"));
+  aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD"));
+  aList.append(mySeparator1);
+  aList.append(action("SHOW_ONLY_CMD"));
+  aList.append(action("HIDE_CMD"));
   myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
   // Result part menu
   myViewerMenu[ModelAPI_ResultPart::group()] = aList;
@@ -693,18 +726,25 @@ void XGUI_ContextMenuMgr::buildViewerMenu()
   aList.clear();
   aList.append(action("WIREFRAME_CMD"));
   aList.append(action("SHADING_CMD"));
-  aList.append(mySeparator1);
-  aList.append(action("HIDE_CMD"));
-  aList.append(action("SHOW_ONLY_CMD"));
   aList.append(mySeparator2);
   aList.append(action("COLOR_CMD"));
   aList.append(action("DEFLECTION_CMD"));
   aList.append(action("TRANSPARENCY_CMD"));
+  aList.append(mySeparator3);
+  aList.append(action("SET_VIEW_NORMAL_CMD"));
+  aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD"));
+  aList.append(mySeparator1);
+  aList.append(action("SHOW_ONLY_CMD"));
+  aList.append(action("HIDE_CMD"));
   myViewerMenu[ModelAPI_ResultBody::group()] = aList;
   // Group menu
   myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
   myViewerMenu[ModelAPI_ResultField::group()] = aList;
   //-------------------------------------
+  // Step objects menu
+  aList.clear();
+  aList.append(action("HIDE_CMD"));
+  myViewerMenu[ModelAPI_ResultField::ModelAPI_FieldStep::group()] = aList;
 }
 
 
@@ -738,7 +778,8 @@ void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
       aActions.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
       aActions.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
       aActions.append(mySeparator3);
-      //aActions.append(action("MOVE_CMD"));
+      aActions.append(action("MOVE_CMD"));
+      aActions.append(action("MOVE_SPLIT_CMD"));
       aActions.append(action("COLOR_CMD"));
       aActions.append(action("DEFLECTION_CMD"));
       aActions.append(action("TRANSPARENCY_CMD"));
@@ -790,14 +831,15 @@ void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
         aActions = myViewerMenu[aName];
     }
   } else if (aSelected > 1) {
+    aActions.append(action("COLOR_CMD"));
+    aActions.append(action("DEFLECTION_CMD"));
+    aActions.append(action("TRANSPARENCY_CMD"));
+    aActions.append(mySeparator1);
     aActions.append(action("SHOW_ONLY_CMD"));
     aActions.append(action("HIDE_CMD"));
   }
   // hide all is shown always even if selection in the viewer is empty
   aActions.append(action("HIDEALL_CMD"));
-  aActions.append(action("COLOR_CMD"));
-  aActions.append(action("DEFLECTION_CMD"));
-  aActions.append(action("TRANSPARENCY_CMD"));
   theMenu->addActions(aActions);
 
   QMap<int, QAction*> aMenuActions;
@@ -881,8 +923,6 @@ void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
       // Exit if the selected index belongs to non active document
       if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
         return;
-      if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
-        return;
 
       // Get name of the selected index
       aName = aIdx.data().toString();