]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Modify popup menu for features
authorvsv <vsv@opencascade.com>
Fri, 24 Nov 2017 11:34:22 +0000 (14:34 +0300)
committervsv <vsv@opencascade.com>
Fri, 24 Nov 2017 11:34:22 +0000 (14:34 +0300)
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 9b7b99dcf2a9c51d0c81c5403f99cfe073a4bdc9..cb60a464da929248870b8800ebaab162a7246196 100644 (file)
@@ -189,6 +189,13 @@ void XGUI_ContextMenuMgr::createActions()
                                            tr("Insert a folder before"), aDesktop);
   addAction("INSERT_FOLDER_CMD", aAction);
 
+  aAction = ModuleBase_Tools::createAction(QIcon(),
+                                           tr("Move into the previous folder"), aDesktop);
+  addAction("ADD_TO_FOLDER_BEFORE_CMD", aAction);
+
+  aAction = ModuleBase_Tools::createAction(QIcon(),
+                                           tr("Move into the next folder"), aDesktop);
+  addAction("ADD_TO_FOLDER_AFTER_CMD", aAction);
 
   buildObjBrowserMenu();
   buildViewerMenu();
@@ -277,7 +284,7 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
     ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
                                    hasCompositeOwner, hasResultInHistory, hasFolder);
     //Process Feature
-    if (aSelected == 1) {
+    if (aSelected == 1) { // single selection
       ObjectPtr aObject = aObjects.first();
       if (aObject) {
         if (hasResult && myWorkshop->canBeShaded(aObject)) {
@@ -318,7 +325,8 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
                                                   (hasFeature || hasParameter));
         }
       }
-    } else {
+      // end single selection
+    } else { // multiselection
       // parameter is commented because the actions are not in the list of result parameter actions
       if (hasResult /*&& (!hasParameter)*/) {
         action("SHOW_CMD")->setEnabled(true);
@@ -327,7 +335,44 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
         action("SHADING_CMD")->setEnabled(true);
         action("WIREFRAME_CMD")->setEnabled(true);
       }
-    }
+    } // end multiselection
+
+    // Check folder management commands state if only features are selected
+    if ((!hasResult) && hasFeature && (!hasParameter) && (!hasCompositeOwner) &&
+      (!hasResultInHistory) && (!hasFolder)) {
+      QModelIndexList aIndexes = aSelMgr->selection()->selectedIndexes();
+      QModelIndex aFirstIdx = aIndexes.first();
+      QModelIndex aLastIdx = aIndexes.last();
+      QModelIndex aParentIdx = aFirstIdx.parent();
+
+      if (aParentIdx == aLastIdx.parent()) {
+        // if all selected are from the same level
+        XGUI_DataModel* aModel = myWorkshop->objectBrowser()->dataModel();
+        ObjectPtr aDataObj = aModel->object(aParentIdx);
+
+        ObjectPtr aPrevObj;
+        if (aFirstIdx.row() > 0) {
+          QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0);
+          aPrevObj = aModel->object(aPrevIdx);
+        }
+
+        ObjectPtr aNextObj;
+        if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
+          QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
+          aNextObj = aModel->object(aNextIdx);
+        }
+
+        bool isPrevFolder = (aPrevObj.get() && (aPrevObj->groupName() == ModelAPI_Folder::group()));
+        bool isNextFolder = (aNextObj.get() && (aNextObj->groupName() == ModelAPI_Folder::group()));
+        bool isInFolder = (aDataObj.get() && (aDataObj->groupName() == ModelAPI_Folder::group()));
+        bool isOutsideFolder = hasFeature && (!isInFolder);
+
+        action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
+        action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
+        action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
+      }
+    } // end folder management commands
+
     bool allActive = true;
     foreach( ObjectPtr aObject, aObjects )
       if( aMgr->activeDocument() != aObject->document() )  {
@@ -342,9 +387,8 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
       action("CLEAN_HISTORY_CMD")->setEnabled(true);
 
     action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
-    action("INSERT_FOLDER_CMD")->setEnabled(hasFeature);
     action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory);
-  }
+  } // end selection processing
 
   // Show/Hide command has to be disabled for objects from non active document
   bool aDeactivate = false;
@@ -546,6 +590,8 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu()
   aList.append(action("MOVE_CMD"));
   aList.append(mySeparator1);
   aList.append(action("INSERT_FOLDER_CMD"));
+  aList.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
+  aList.append(action("ADD_TO_FOLDER_AFTER_CMD"));
   aList.append(mySeparator2);
   aList.append(action("CLEAN_HISTORY_CMD"));
   aList.append(action("DELETE_CMD"));
index cb5ca1d17f7d12a5eed82ed2fc4c68afe4fb5833..805a5fe00884c760b626cac6fdfeff78b1bd9750 100755 (executable)
@@ -1415,6 +1415,10 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     setViewerSelectionMode(TopAbs_FACE);
   } else if (theId == "INSERT_FOLDER_CMD") {
     insertFeatureFolder();
+  } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
+    insertToFolderBefore();
+  } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
+    insertToFolderAfter();
   } else if (theId == "SELECT_RESULT_CMD") {
     //setViewerSelectionMode(-1);
     //IMP: an attempt to use result selection with other selection modes
@@ -2427,6 +2431,18 @@ void XGUI_Workshop::insertFeatureFolder()
   aMgr->startOperation();
   aDoc->addFolder(aFeature);
   aMgr->finishOperation();
+}
 
-  //myObjectBrowser->rebuildDataTree();
+void XGUI_Workshop::insertToFolderBefore()
+{
+  QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+  if (aObjects.isEmpty())
+    return;
+}
+
+void XGUI_Workshop::insertToFolderAfter()
+{
+  QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+  if (aObjects.isEmpty())
+    return;
 }
index 53ce3b98a2731477b35492d7cf0b0a500aa91a5a..5b6f3bb5ae3790442e44602f84863a702f42a0a4 100755 (executable)
@@ -451,6 +451,12 @@ private:
   /// Insert folder object before currently selected feature
   void insertFeatureFolder();
 
+  /// Insert an object to a folder above
+  void insertToFolderBefore();
+
+  /// Insert an object to a folder below
+  void insertToFolderAfter();
+
  private slots:
   /// SLOT, that is called after the operation is started. Update workshop state according to
   /// the started operation, e.g. visualizes the property panel and connect to it.