#include "XGUI_DataModel.h"
#include "XGUI_OperationMgr.h"
#include "XGUI_Tools.h"
+#include "XGUI_ActionsMgr.h"
#ifndef HAVE_SALOME
#include <AppElements_MainWindow.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_Tools.h>
+#include <Config_DataModelReader.h>
+
#include <ModuleBase_IModule.h>
#include <ModuleBase_Tools.h>
#include <ModuleBase_OperationAction.h>
#include <QMenu>
#include <QMdiArea>
#include <QMainWindow>
+#include <QModelIndex>
XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
aAction = new QAction(QIcon(":pictures/find_result.png"), tr("Select results"), this);
addAction("SHOW_RESULTS_CMD", aAction);
+ aAction = new QAction(QIcon(":pictures/find_result.png"), tr("Select parent feature"), this);
+ addAction("SHOW_FEATURE_CMD", aAction);
+
buildObjBrowserMenu();
buildViewerMenu();
}
action("CLEAN_HISTORY_CMD")->setEnabled(true);
action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
+ action("SHOW_FEATURE_CMD")->setEnabled(hasResult);
}
// Show/Hide command has to be disabled for objects from non active document
}
if (myWorkshop->displayer()->objectsCount() > 0)
action("HIDEALL_CMD")->setEnabled(true);
- if (myWorkshop->canChangeColor())
- action("COLOR_CMD")->setEnabled(true);
-
- action("DELETE_CMD")->setEnabled(true);
// Update selection menu
QIntList aModes = aDisplayer->activeSelectionModes();
} else
action("SELECT_RESULT_CMD")->setChecked(true);
}
+
ModuleBase_IModule* aModule = myWorkshop->module();
if (aModule)
aModule->updateViewerMenu(myActions);
+
+ if (myWorkshop->canChangeColor())
+ action("COLOR_CMD")->setEnabled(true);
+
+ action("DELETE_CMD")->setEnabled(true);
}
void XGUI_ContextMenuMgr::connectObjectBrowser()
aSeparator->setSeparator(true);
QActionsList aList;
-
+
// Result construction menu
aList.append(action("SHOW_CMD"));
aList.append(action("HIDE_CMD"));
aList.append(action("SHOW_ONLY_CMD"));
- aList.append(action("COLOR_CMD"));
aList.append(mySeparator);
aList.append(action("RENAME_CMD"));
+ aList.append(action("COLOR_CMD"));
+ aList.append(action("SHOW_FEATURE_CMD"));
myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
+
//-------------------------------------
// Result body menu
aList.clear();
aList.append(action("WIREFRAME_CMD"));
aList.append(action("SHADING_CMD"));
- aList.append(action("COLOR_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"));
aList.append(mySeparator);
aList.append(action("RENAME_CMD"));
+ aList.append(action("COLOR_CMD"));
+ aList.append(action("SHOW_FEATURE_CMD"));
myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
// Group menu
myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
//-------------------------------------
// Feature menu
aList.clear();
- aList.append(action("DELETE_CMD"));
- aList.append(action("MOVE_CMD"));
- aList.append(action("CLEAN_HISTORY_CMD"));
- aList.append(mySeparator);
aList.append(action("RENAME_CMD"));
- aList.append(mySeparator);
aList.append(action("SHOW_RESULTS_CMD"));
+ aList.append(action("MOVE_CMD"));
+ aList.append(mySeparator);
+ aList.append(action("CLEAN_HISTORY_CMD"));
+ aList.append(action("DELETE_CMD"));
myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
aList.clear();
- aList.append(action("DELETE_CMD"));
- aList.append(action("CLEAN_HISTORY_CMD"));
- aList.append(mySeparator);
aList.append(action("RENAME_CMD"));
+ aList.append(mySeparator);
+ aList.append(action("CLEAN_HISTORY_CMD"));
+ aList.append(action("DELETE_CMD"));
myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
//-------------------------------------
}
// Result construction menu
aList.append(action("HIDE_CMD"));
aList.append(action("SHOW_ONLY_CMD"));
+ aList.append(mySeparator);
aList.append(action("COLOR_CMD"));
myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
// Result part menu
aList.clear();
aList.append(action("WIREFRAME_CMD"));
aList.append(action("SHADING_CMD"));
- aList.append(action("COLOR_CMD"));
aList.append(mySeparator);
aList.append(action("HIDE_CMD"));
aList.append(action("SHOW_ONLY_CMD"));
+ aList.append(mySeparator);
+ aList.append(action("COLOR_CMD"));
myViewerMenu[ModelAPI_ResultBody::group()] = aList;
// Group menu
myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
//-------------------------------------
-
}
void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
{
+ ModuleBase_IModule* aModule = myWorkshop->module();
+ if (aModule) {
+ theMenu->addSeparator();
+ aModule->addObjectBrowserMenu(theMenu);
+ }
+
XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects();
int aSelected = aObjects.size();
if (myObjBrowserMenus.contains(aName))
aActions = myObjBrowserMenus[aName];
} else if (aSelected > 1) {
- aActions.append(action("SHADING_CMD"));
aActions.append(action("WIREFRAME_CMD"));
+ aActions.append(action("SHADING_CMD"));
aActions.append(mySeparator);
aActions.append(action("SHOW_CMD"));
aActions.append(action("HIDE_CMD"));
aActions.append(action("SHOW_ONLY_CMD"));
aActions.append(mySeparator);
- aActions.append(action("DELETE_CMD"));
//aActions.append(action("MOVE_CMD"));
- aActions.append(action("CLEAN_HISTORY_CMD"));
aActions.append(action("COLOR_CMD"));
+ aActions.append(action("CLEAN_HISTORY_CMD"));
+ aActions.append(action("DELETE_CMD"));
}
theMenu->addActions(aActions);
+ addFeatures(theMenu);
- ModuleBase_IModule* aModule = myWorkshop->module();
- if (aModule) {
- theMenu->addSeparator();
- aModule->addObjectBrowserMenu(theMenu);
- }
- theMenu->addSeparator();
- theMenu->addActions(myWorkshop->objectBrowser()->actions());
+ // It is commented out because Object Browser does not have actions
+ //theMenu->addSeparator();
+ //theMenu->addActions(myWorkshop->objectBrowser()->actions());
}
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();
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();
myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
myWorkshop->objectBrowser()->onEditItem();
}
+
+void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aActiveDoc = aMgr->activeDocument();
+
+ XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
+ XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
+ const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
+ QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
+
+ QString aName;
+ int aLen = 0;
+ bool aIsRoot = false;
+ foreach(QModelIndex aIdx, aSelectedIndexes) {
+ // Process only first column
+ if (aIdx.column() == 0) {
+ aIsRoot = !aIdx.parent().isValid();
+ // 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();
+ aLen = aName.indexOf('(');
+ if (aLen != -1) {
+ aName = aName.left(--aLen);
+ }
+ std::string aFeaturesStr = aIsRoot?
+ aDataModelXML->rootFolderFeatures(aName.toStdString()) :
+ aDataModelXML->subFolderFeatures(aName.toStdString());
+ if (aFeaturesStr.length() > 0) {
+ QStringList aFeturesList =
+ QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
+ foreach(QString aFea, aFeturesList) {
+ QAction* aAction = aActionMgr->action(aFea);
+ if (aAction)
+ theMenu->addAction(aAction);
+ }
+ }
+ }
+ }
+}