From a2c1642bfb2277cc05c30b5646518a69c07c1952 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 24 Nov 2017 14:34:22 +0300 Subject: [PATCH] Modify popup menu for features --- src/XGUI/XGUI_ContextMenuMgr.cpp | 56 +++++++++++++++++++++++++++++--- src/XGUI/XGUI_Workshop.cpp | 18 +++++++++- src/XGUI/XGUI_Workshop.h | 6 ++++ 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 9b7b99dcf..cb60a464d 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -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")); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index cb5ca1d17..805a5fe00 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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; } diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 53ce3b98a..5b6f3bb5a 100755 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -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. -- 2.39.2