From: vsv Date: Wed, 6 Apr 2016 12:20:21 +0000 (+0300) Subject: Issue #1306: Set default selection mode at neutral point in local selection X-Git-Tag: V_2.3.0~293 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5dd132661f3d496bc8af5c70fabc41fe05650d18;p=modules%2Fshaper.git Issue #1306: Set default selection mode at neutral point in local selection --- diff --git a/src/ModuleBase/ModuleBase_Preferences.cpp b/src/ModuleBase/ModuleBase_Preferences.cpp index 03aec786b..bef2ab96f 100644 --- a/src/ModuleBase/ModuleBase_Preferences.cpp +++ b/src/ModuleBase/ModuleBase_Preferences.cpp @@ -9,6 +9,8 @@ #include +#include + #include #include #include @@ -287,6 +289,26 @@ void ModuleBase_PreferencesDlg::createViewerPage(int thePageId) myPreferences->setItemProperty("texture_stretch_enabled", true, bgId); myPreferences->setItemProperty("custom_enabled", false, bgId); myPreferences->setItemProperty("image_formats", aImgFiles, bgId); + + // Create other parameters group in viewer tab + int otherGroup = myPreferences->addItem(tr("Other parameters"), viewTab); + int selId = myPreferences->addItem(tr("Default selection type"), otherGroup, + SUIT_PreferenceMgr::Selector, + ModuleBase_Preferences::VIEWER_SECTION, "selection"); + QStringList aSelectionList; + aSelectionList.append( tr("Vertices") ); + aSelectionList.append( tr("Edges") ); + aSelectionList.append( tr("Faces") ); + aSelectionList.append( tr("Results") ); + + QList anIndexesList; + anIndexesList.append(TopAbs_VERTEX); + anIndexesList.append(TopAbs_EDGE); + anIndexesList.append(TopAbs_FACE); + anIndexesList.append(-1); + + myPreferences->setItemProperty( "strings", aSelectionList, selId ); + myPreferences->setItemProperty( "indexes", anIndexesList, selId ); } void ModuleBase_PreferencesDlg::createMenuPage(int thePageId) diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 8a45411db..94e2d3c92 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -424,6 +424,10 @@ void PartSet_WidgetSketchLabel::activateCustom() myStackWidget->setCurrentIndex(0); bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop); + + // Clear previous selection mode It is necessary for correct activation of preview planes + aDisp->activateObjects(QIntList(), aDisplayed, false); + if (!aBodyIsVisualized) { // We have to select a plane before any operation myPreviewPlanes->showPreviewPlanes(myWorkshop); diff --git a/src/XGUI/SHAPER.xml b/src/XGUI/SHAPER.xml index 267113d71..02ac10bb2 100644 --- a/src/XGUI/SHAPER.xml +++ b/src/XGUI/SHAPER.xml @@ -11,6 +11,7 @@
+
diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 9342ae437..9c81a942c 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -98,6 +99,30 @@ void XGUI_ContextMenuMgr::createActions() mySeparator = new QAction(this); mySeparator->setSeparator(true); + mySelectActions = new QActionGroup(this); + mySelectActions->setExclusive(true); + + aAction = new QAction(QIcon(":pictures/vertex.png"), tr("Vertices"), this); + aAction->setCheckable(true); + addAction("SELECT_VERTEX_CMD", aAction); + mySelectActions->addAction(aAction); + + aAction = new QAction(QIcon(":pictures/edge.png"), tr("Edges"), this); + aAction->setCheckable(true); + addAction("SELECT_EDGE_CMD", aAction); + mySelectActions->addAction(aAction); + + aAction = new QAction(QIcon(":pictures/face.png"), tr("Faces"), this); + aAction->setCheckable(true); + addAction("SELECT_FACE_CMD", aAction); + mySelectActions->addAction(aAction); + + aAction = new QAction(QIcon(":pictures/result.png"), tr("Result"), this); + aAction->setCheckable(true); + addAction("SELECT_RESULT_CMD", aAction); + mySelectActions->addAction(aAction); + + aAction->setChecked(true); buildObjBrowserMenu(); buildViewerMenu(); @@ -282,6 +307,7 @@ void XGUI_ContextMenuMgr::updateViewerMenu() aAction->setEnabled(false); XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); QList aPrsList = aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer); if (aPrsList.size() > 0) { bool isVisible = false; @@ -300,7 +326,6 @@ void XGUI_ContextMenuMgr::updateViewerMenu() } if (isVisible) { if (canBeShaded) { - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject); if (aMode != XGUI_Displayer::NoMode) { action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading); @@ -322,6 +347,30 @@ void XGUI_ContextMenuMgr::updateViewerMenu() action("DELETE_CMD")->setEnabled(true); + // Update selection menu + QIntList aModes = aDisplayer->activeSelectionModes(); + if (aModes.count() <= 1) { + action("SELECT_VERTEX_CMD")->setEnabled(true); + action("SELECT_EDGE_CMD")->setEnabled(true); + action("SELECT_FACE_CMD")->setEnabled(true); + action("SELECT_RESULT_CMD")->setEnabled(true); + if (aModes.count() == 1) { + switch (aModes.first()) { + case TopAbs_VERTEX: + action("SELECT_VERTEX_CMD")->setChecked(true); + break; + case TopAbs_EDGE: + action("SELECT_EDGE_CMD")->setChecked(true); + break; + case TopAbs_FACE: + action("SELECT_FACE_CMD")->setChecked(true); + break; + default: + action("SELECT_RESULT_CMD")->setChecked(true); + } + } else + action("SELECT_RESULT_CMD")->setChecked(true); + } ModuleBase_IModule* aModule = myWorkshop->module(); if (aModule) aModule->updateViewerMenu(myActions); @@ -464,6 +513,20 @@ void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const QList 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")); + aSelMenu->addAction(action("SELECT_RESULT_CMD")); + theMenu->addMenu(aSelMenu); + theMenu->addSeparator(); + } if (aSelected == 1) { ObjectPtr aObject = aPrsList.first().object(); if (aObject.get() != NULL) { diff --git a/src/XGUI/XGUI_ContextMenuMgr.h b/src/XGUI/XGUI_ContextMenuMgr.h index 40de3f533..34e3d7b92 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.h +++ b/src/XGUI/XGUI_ContextMenuMgr.h @@ -12,6 +12,7 @@ class XGUI_Workshop; class QAction; class QContextMenuEvent; class QMenu; +class QActionGroup; /** * \ingroup GUI @@ -113,7 +114,9 @@ signals: QMap myObjBrowserMenus; QMap myViewerMenu; - QAction* mySeparator; + QActionGroup* mySelectActions; + + QAction* mySeparator; }; #endif diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index c4cdd88f5..20e4c300c 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -1245,3 +1245,13 @@ void XGUI_Displayer::displayTrihedron(bool theToDisplay) const updateViewer(); } + +QIntList XGUI_Displayer::activeSelectionModes() const +{ + QIntList aModes; + foreach (int aMode, myActiveSelectionModes) { + // aMode < 9 is a Shape Enum values + aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode); + } + return aModes; +} diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index dd221d7bf..489508c2c 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -243,6 +243,11 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// Returns true if the trihedron should be activated in current selection modes bool isTrihedronActive() const { return myIsTrihedronActive; } + /// Returns list of currently active selection modes + /// Selection modes will be returned according to TopAbs_ShapeEnum + QIntList activeSelectionModes() const; + + /// Converts shape type (TopAbs_ShapeEnum) to selection mode /// \param theShapeType a shape type from TopAbs_ShapeEnum static int getSelectionMode(int theShapeType); diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index bc8d74140..cf8ec1f37 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -85,9 +85,7 @@ void XGUI_ModuleConnector::deactivateSubShapesSelection() void XGUI_ModuleConnector::activateModuleSelectionModes() { XGUI_Displayer* aDisp = myWorkshop->displayer(); - QIntList aModes; - module()->activeSelectionModes(aModes); - aDisp->activateObjects(aModes, activeObjects(aDisp->displayedObjects())); + myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects())); } AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index ad92b420b..5570632c5 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -96,6 +96,22 @@ void XGUI_SelectionMgr::onObjectBrowserSelection() QList aSelectedPrs = myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser); + QList aTmpList = aSelectedPrs; + ObjectPtr aObject; + FeaturePtr aFeature; + foreach(ModuleBase_ViewerPrs aPrs, aTmpList) { + aObject = aPrs.object(); + if (aObject.get()) { + aFeature = std::dynamic_pointer_cast(aObject); + if (aFeature.get()) { + const std::list> aResList = aFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { + aSelectedPrs.append(ModuleBase_ViewerPrs((*aIt), TopoDS_Shape(), NULL)); + } + } + } + } XGUI_Displayer* aDisplayer = myWorkshop->displayer(); aDisplayer->setSelected(aSelectedPrs); emit selectionChanged(); @@ -113,6 +129,18 @@ void XGUI_SelectionMgr::onViewerSelection() aFeatures.append(aPrs.object()); } } + // Add features by selected results + QObjectPtrList aTmpList = aFeatures; + ResultPtr aResult; + FeaturePtr aFeature; + foreach(ObjectPtr aObj, aTmpList) { + aResult = std::dynamic_pointer_cast(aObj); + if (aResult.get()) { + aFeature = ModelAPI_Feature::feature(aResult); + if (aFeature.get() && (!aFeatures.contains(aFeature))) + aFeatures.append(aFeature); + } + } bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true); myWorkshop->objectBrowser()->setObjectsSelected(aFeatures); myWorkshop->objectBrowser()->blockSignals(aBlocked); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 8290f2c72..e55d6406e 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -119,7 +119,8 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) mySalomeConnector(theConnector), myPropertyPanel(0), myObjectBrowser(0), - myDisplayer(0) + myDisplayer(0), + myViewerSelMode(TopAbs_FACE) { #ifndef HAVE_SALOME myMainWindow = new AppElements_MainWindow(); @@ -187,6 +188,9 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR()); Config_PropManager::registerProp("Visualization", "result_part_color", "Part color", Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR()); + + myViewerSelMode = + ModuleBase_Preferences::resourceMgr()->integerValue("Viewer", "selection", TopAbs_FACE); } //****************************************************** @@ -238,12 +242,10 @@ void XGUI_Workshop::activateModule() updateCommandStatus(); + // TODO: get default selection mode + // activate visualized objects in the viewer - XGUI_Displayer* aDisplayer = displayer(); - QObjectPtrList aDisplayed = aDisplayer->displayedObjects(); - QIntList aModes; - module()->activeSelectionModes(aModes); - aDisplayer->activateObjects(aModes, aDisplayed); + activateObjectsSelection(displayer()->displayedObjects()); myOperationMgr->activate(); } @@ -565,9 +567,7 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) } } } - QIntList aModes; - module()->activeSelectionModes(aModes); - myDisplayer->activateObjects(aModes, anObjects); + activateObjectsSelection(anObjects); } @@ -1160,9 +1160,35 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) aObj->setDisplayed(false); } Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } else if (theId == "SELECT_VERTEX_CMD") { + setViewerSelectionMode(TopAbs_VERTEX); + } else if (theId == "SELECT_EDGE_CMD") { + setViewerSelectionMode(TopAbs_EDGE); + } else if (theId == "SELECT_FACE_CMD") { + setViewerSelectionMode(TopAbs_FACE); + } else if (theId == "SELECT_RESULT_CMD") { + setViewerSelectionMode(-1); } } +//************************************************************** +void XGUI_Workshop::setViewerSelectionMode(int theMode) +{ + myViewerSelMode = theMode; + activateObjectsSelection(myDisplayer->displayedObjects()); +} + +//************************************************************** +void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList) +{ + QIntList aModes; + module()->activeSelectionModes(aModes); + if (aModes.isEmpty() && (myViewerSelMode != -1)) + aModes.append(myViewerSelMode); + myDisplayer->activateObjects(aModes, theList); +} + + //************************************************************** void XGUI_Workshop::deleteObjects() { diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 37685b169..187182e66 100755 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -205,6 +205,13 @@ Q_OBJECT /// \param theMode a mode to set (see \ref XGUI_Displayer) void setDisplayMode(const QObjectPtrList& theList, int theMode); + /// Set selection mode in viewer. If theMode=-1 then activate default mode + /// \param theMode the selection mode (according to TopAbs_ShapeEnum) + void setViewerSelectionMode(int theMode); + + /// Activates current selection mode for the given list of objects + void activateObjectsSelection(const QObjectPtrList& theList); + /// Returns current module ModuleBase_IModule* module() const { @@ -352,6 +359,10 @@ signals: /// Activates/deactivates the trihedron in the viewer AIS context void onTrihedronVisibilityChanged(bool theState); + /// Returns defailt selection mode in 3d viewer + int viewerSelectionMode() const { return myViewerSelMode; } + + protected: /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features /// and set them into the operation. Secondly, it asks the module about ids of granted operations. @@ -503,6 +514,8 @@ private: XGUI_WorkshopListener* myEventsListener; QString myCurrentDir; + + int myViewerSelMode; }; #endif diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index 692f569d6..b1c2569a2 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -56,5 +56,6 @@ pictures/compound.png pictures/shell.png pictures/wire.png + pictures/result.png diff --git a/src/XGUI/pictures/result.png b/src/XGUI/pictures/result.png new file mode 100644 index 000000000..0ad7728bf Binary files /dev/null and b/src/XGUI/pictures/result.png differ