+ connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
+ SLOT(onContextMenuRequest(QContextMenuEvent*)));
+}
+
+void XGUI_ContextMenuMgr::connectViewer()
+{
+ connect(myWorkshop->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
+ SLOT(onContextMenuRequest(QContextMenuEvent*)));
+}
+
+
+void XGUI_ContextMenuMgr::buildObjBrowserMenu()
+{
+ QAction* aSeparator = ModuleBase_Tools::createAction(QIcon(), "", myWorkshop->desktop());
+ 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(mySeparator);
+ aList.append(action("RENAME_CMD"));
+ aList.append(action("COLOR_CMD"));
+ aList.append(action("DEFLECTION_CMD"));
+#ifdef USE_TRANSPARENCY
+ aList.append(action("TRANSPARENCY_CMD"));
+#endif
+ 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(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("DEFLECTION_CMD"));
+#ifdef USE_TRANSPARENCY
+ aList.append(action("TRANSPARENCY_CMD"));
+#endif
+ aList.append(action("SHOW_FEATURE_CMD"));
+ myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
+ // Group menu
+ myObjBrowserMenus[ModelAPI_ResultGroup::group()] = aList;
+ myObjBrowserMenus[ModelAPI_ResultField::group()] = aList;
+ // Result part menu
+ myObjBrowserMenus[ModelAPI_ResultPart::group()] = aList;
+ //-------------------------------------
+ // Feature menu
+ aList.clear();
+ aList.append(action("RENAME_CMD"));
+ 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("RENAME_CMD"));
+ aList.append(mySeparator);
+ aList.append(action("CLEAN_HISTORY_CMD"));
+ aList.append(action("DELETE_CMD"));
+ myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
+ //-------------------------------------
+}
+
+void XGUI_ContextMenuMgr::buildViewerMenu()
+{
+ QActionsList aList;
+ // Result construction menu
+ aList.append(action("HIDE_CMD"));
+ aList.append(action("SHOW_ONLY_CMD"));
+ aList.append(mySeparator);
+ aList.append(action("COLOR_CMD"));
+ aList.append(action("DEFLECTION_CMD"));
+#ifdef USE_TRANSPARENCY
+ aList.append(action("TRANSPARENCY_CMD"));
+#endif
+ myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
+ // Result part menu
+ myViewerMenu[ModelAPI_ResultPart::group()] = aList;
+ //-------------------------------------
+ // Result body menu
+ aList.clear();
+ aList.append(action("WIREFRAME_CMD"));
+ aList.append(action("SHADING_CMD"));
+ aList.append(mySeparator);
+ aList.append(action("HIDE_CMD"));
+ aList.append(action("SHOW_ONLY_CMD"));
+ aList.append(mySeparator);
+ aList.append(action("COLOR_CMD"));
+ aList.append(action("DEFLECTION_CMD"));
+#ifdef USE_TRANSPARENCY
+ aList.append(action("TRANSPARENCY_CMD"));
+#endif
+ myViewerMenu[ModelAPI_ResultBody::group()] = aList;
+ // Group menu
+ myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
+ myViewerMenu[ModelAPI_ResultField::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();
+ QActionsList aActions;
+ if (aSelected == 1) {
+ ObjectPtr aObject = aObjects.first();
+ std::string aName = aObject->groupName();
+ if (myObjBrowserMenus.contains(aName))
+ aActions = myObjBrowserMenus[aName];
+ } else if (aSelected > 1) {
+ 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("MOVE_CMD"));
+ aActions.append(action("COLOR_CMD"));
+ aActions.append(action("DEFLECTION_CMD"));
+#ifdef USE_TRANSPARENCY
+ aActions.append(action("TRANSPARENCY_CMD"));
+#endif
+ aActions.append(action("CLEAN_HISTORY_CMD"));
+ aActions.append(action("DELETE_CMD"));
+ }
+#ifdef _DEBUG
+ if (aSelected == 0) {
+ #ifdef TINSPECTOR
+ aActions.append(action("TINSPECTOR_VIEW"));
+ #endif
+ }
+#endif
+ theMenu->addActions(aActions);
+ addFeatures(theMenu);
+
+ // 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
+{
+ XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
+ QList<ModuleBase_ViewerPrsPtr> aPrsList =
+ aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
+ int aSelected = aPrsList.size();
+ QActionsList aActions;
+
+ // Create selection menu
+ XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
+ QIntList aModes;
+ myWorkshop->module()->activeSelectionModes(aModes);
+ if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
+ QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
+ aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
+ aSelMenu->addAction(action("SELECT_EDGE_CMD"));
+ aSelMenu->addAction(action("SELECT_FACE_CMD"));
+ //IMP: an attempt to use result selection with other selection modes
+ //aSelMenu->addSeparator();
+ aSelMenu->addAction(action("SELECT_RESULT_CMD"));
+ theMenu->addMenu(aSelMenu);
+ theMenu->addSeparator();
+ }
+ if (aSelected == 1) {
+ ObjectPtr aObject = aPrsList.first()->object();
+ if (aObject.get() != NULL) {
+ std::string aName = aObject->groupName();
+ if (myViewerMenu.contains(aName))
+ aActions = myViewerMenu[aName];
+ }
+ } else if (aSelected > 1) {
+ 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"));
+#ifdef USE_TRANSPARENCY
+ aActions.append(action("TRANSPARENCY_CMD"));
+#endif
+ 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();
+ if (aMDI->actions().size() > 0) {
+ QMenu* aSubMenu = theMenu->addMenu(tr("Windows"));
+ aSubMenu->addActions(aMDI->actions());
+ }
+#endif
+}
+
+QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName)
+{
+ QStringList aGroups;
+
+ QMap<std::string, QActionsList>::const_iterator anIt = myObjBrowserMenus.begin(),
+ aLast = myObjBrowserMenus.end();
+ for (; anIt != aLast; anIt++) {
+ QString aGroupName(anIt.key().c_str());
+ if (aGroups.contains(aGroupName))
+ continue;
+ QActionsList anActions = anIt.value();
+ QActionsList::const_iterator anAIt = anActions.begin(), anALast = anActions.end();
+ bool aFound = false;
+ for (; anAIt != anALast && !aFound; anAIt++)
+ aFound = (*anAIt)->data().toString() == theName;
+ if (aFound)
+ aGroups.append(aGroupName);
+ }
+ return aGroups;
+}
+
+void XGUI_ContextMenuMgr::onRename()
+{
+ QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects();
+ if (!myWorkshop->abortAllOperations())
+ return;
+ // restore selection in case if dialog box was shown
+ 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() == 1) {
+ 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);
+ }
+ }
+ }
+ }
+}
+
+#define UNCHECK_ACTION(NAME) \
+{ QAction* aAction = action(NAME); \
+bool isBlock = aAction->signalsBlocked(); \
+aAction->blockSignals(true); \
+aAction->setChecked(false); \
+ aAction->blockSignals(isBlock); }
+
+
+void XGUI_ContextMenuMgr::onResultSelection(bool theChecked)
+{
+ UNCHECK_ACTION("SELECT_VERTEX_CMD");
+ UNCHECK_ACTION("SELECT_EDGE_CMD");
+ UNCHECK_ACTION("SELECT_FACE_CMD");
+}
+
+void XGUI_ContextMenuMgr::onShapeSelection(bool theChecked)
+{
+ UNCHECK_ACTION("SHOW_RESULTS_CMD");
+}