#include "XGUI_SelectionMgr.h"
#include "XGUI_Displayer.h"
#include "XGUI_ViewerProxy.h"
-#include "XGUI_Selection.h"
#include "XGUI_SalomeConnector.h"
+#include "XGUI_Selection.h"
+#include "XGUI_SelectionActivate.h"
#include "XGUI_DataModel.h"
#include "XGUI_OperationMgr.h"
#include "XGUI_Tools.h"
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_ResultField.h>
-#include "ModelAPI_Folder.h"
+#include <ModelAPI_Folder.h>
+#include <ModelAPI_AttributeReference.h>
#include <Config_DataModelReader.h>
XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
: QObject(theParent),
myWorkshop(theParent),
- mySeparator1(0), mySeparator2(0)
+ mySeparator1(0), mySeparator2(0), mySeparator3(0)
{
}
mySeparator2 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
mySeparator2->setSeparator(true);
+ mySeparator3 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
+ mySeparator3->setSeparator(true);
+
//mySelectActions = new QActionGroup(this);
//mySelectActions->setExclusive(true);
#endif
// Features folders actions
- aAction = ModuleBase_Tools::createAction(QIcon(),
+ aAction = ModuleBase_Tools::createAction(QIcon(":pictures/create_folder.png"),
tr("Insert a folder before"), aDesktop);
addAction("INSERT_FOLDER_CMD", aAction);
- aAction = ModuleBase_Tools::createAction(QIcon(),
+ aAction = ModuleBase_Tools::createAction(QIcon(":pictures/insert_folder_before.png"),
tr("Move into the previous folder"), aDesktop);
addAction("ADD_TO_FOLDER_BEFORE_CMD", aAction);
- aAction = ModuleBase_Tools::createAction(QIcon(),
+ aAction = ModuleBase_Tools::createAction(QIcon(":pictures/insert_folder_after.png"),
tr("Move into the next folder"), aDesktop);
addAction("ADD_TO_FOLDER_AFTER_CMD", aAction);
+ aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_out_before.png"),
+ tr("Move out before the folder"), aDesktop);
+ addAction("ADD_OUT_FOLDER_BEFORE_CMD", aAction);
+
+ aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_out_after.png"),
+ tr("Move out after the folder"), aDesktop);
+ addAction("ADD_OUT_FOLDER_AFTER_CMD", aAction);
+
buildObjBrowserMenu();
buildViewerMenu();
}
// 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();
+ std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
+ if (aFeatures.size() > 0) { // Check that features do not include Parts
+ 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);
+ bool isSameParent = true;
+ foreach(QModelIndex aIdx, aIndexes) {
+ if (aIdx.parent() != aParentIdx) {
+ isSameParent = false;
+ break;
+ }
}
+ if (isSameParent) {
+ // Check is selection continuous
+ XGUI_DataModel* aModel = myWorkshop->objectBrowser()->dataModel();
+ DocumentPtr aDoc = aMgr->activeDocument();
+ std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
+
+ bool isContinuos = true;
+ if (aSelected > 1) {
+ int aId = -1;
+ foreach(FeaturePtr aF, aFeatures) {
+ if (aId == -1)
+ aId = aDoc->index(aF);
+ else {
+ aId++;
+ if (aId != aDoc->index(aF)) {
+ isContinuos = false;
+ break;
+ }
+ }
+ }
+ }
+ if (isContinuos) {
+ ObjectPtr aDataObj = aModel->object(aParentIdx);
- ObjectPtr aNextObj;
- if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
- QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
- aNextObj = aModel->object(aNextIdx);
- }
+ ObjectPtr aPrevObj;
+ if (aFirstIdx.row() > 0) {
+ QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0);
+ aPrevObj = aModel->object(aPrevIdx);
+ }
- 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);
+ ObjectPtr aNextObj;
+ if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
+ QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
+ aNextObj = aModel->object(aNextIdx);
+ }
- action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
- action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
- action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
+ 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 = !isInFolder;
+
+ bool hasFirst = false;
+ bool hasLast = false;
+ if (isInFolder) {
+ FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aDataObj);
+ FeaturePtr aFirstFeatureInFolder;
+ AttributeReferencePtr aFirstFeatAttr =
+ aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
+ if (aFirstFeatAttr)
+ aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
+ hasFirst = (aFirstFeatureInFolder == aFeatures.front());
+
+ FeaturePtr aLastFeatureInFolder;
+ AttributeReferencePtr aLastFeatAttr =
+ aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
+ if (aLastFeatAttr)
+ aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
+ hasLast = (aLastFeatureInFolder == aFeatures.back());
+ }
+ action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
+ action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
+ action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
+ action("ADD_OUT_FOLDER_BEFORE_CMD")->setEnabled(isInFolder && hasFirst);
+ action("ADD_OUT_FOLDER_AFTER_CMD")->setEnabled(isInFolder && hasLast);
+ }
+ }
}
} // end folder management commands
#endif
// Update selection menu
- QIntList aModes = aDisplayer->activeSelectionModes();
+ QIntList aModes = myWorkshop->selectionActivate()->activeSelectionModes();
action("SELECT_VERTEX_CMD")->setEnabled(true);
action("SELECT_EDGE_CMD")->setEnabled(true);
action("SELECT_FACE_CMD")->setEnabled(true);
aList.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
aList.append(action("ADD_TO_FOLDER_AFTER_CMD"));
aList.append(mySeparator2);
+ aList.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
+ aList.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
+ aList.append(mySeparator3);
aList.append(action("CLEAN_HISTORY_CMD"));
aList.append(action("DELETE_CMD"));
myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
//-------------------------------------
aList.clear();
+ aList.append(action("RENAME_CMD"));
aList.append(action("DELETE_CMD"));
myObjBrowserMenus[ModelAPI_Folder::group()] = aList;
aActions.append(action("HIDE_CMD"));
aActions.append(action("SHOW_ONLY_CMD"));
aActions.append(mySeparator2);
+ aActions.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
+ aActions.append(action("ADD_TO_FOLDER_AFTER_CMD"));
+ 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("COLOR_CMD"));
aActions.append(action("DEFLECTION_CMD"));
// Create selection menu
XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
- QIntList aModes;
- myWorkshop->module()->activeSelectionModes(aModes);
- if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
+ if (!aOpMgr->hasOperation() &&
+ myWorkshop->selectionActivate()->activeSelectionPlace() == XGUI_SelectionActivate::Workshop) {
QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
aSelMenu->addAction(action("SELECT_EDGE_CMD"));