]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1306: Set default selection mode at neutral point in local selection
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 6 Apr 2016 12:20:21 +0000 (15:20 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 6 Apr 2016 12:26:46 +0000 (15:26 +0300)
13 files changed:
src/ModuleBase/ModuleBase_Preferences.cpp
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/XGUI/SHAPER.xml
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_ContextMenuMgr.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/result.png [new file with mode: 0644]

index 03aec786b07bbbb57d7f2efa1c44308e45803801..bef2ab96f7df7b062fce99f8c2810c8c584471af 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <Config_PropManager.h>
 
+#include <TopAbs_ShapeEnum.hxx>
+
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_PreferenceMgr.h>
 #include <Qtx.h>
@@ -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<QVariant> 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)
index 8a45411db9b0b3147c83eb74b5b0ef63b3dcdec7..94e2d3c9224b58912c0e40d55e88ed272edd4229 100644 (file)
@@ -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);
index 267113d71dd84bf4fbbded27cc45cb3a62462f41..02ac10bb2e0cf169c78b11370958c6789d62dd5c 100644 (file)
@@ -11,6 +11,7 @@
   <section name="Viewer" >
     <!-- Viewer preferences -->
     <parameter name="background" value="bt=2;fn=;tm=0;ts=false;c1=#cddbff;c2=#698fff;gt=1;gr=" />
+    <parameter name="selection" value="4" />
   </section>
   <section name="Menu" >
     <!-- Menu bar preferences -->
index 9342ae43750e9de96091a7c9755c0af707d70024..9c81a942c23d212e4b01fb03a5cea2362eccceae 100644 (file)
@@ -33,6 +33,7 @@
 #include <ModuleBase_OperationAction.h>
 
 #include <QAction>
+#include <QActionGroup>
 #include <QContextMenuEvent>
 #include <QMenu>
 #include <QMdiArea>
@@ -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<ModuleBase_ViewerPrs> 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<ModuleBase_ViewerPrs> 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) {
index 40de3f5335dffc244cdebb58e907e80421532eb7..34e3d7b92a8b02e30fd4ff39db07404b4ba6c98f 100644 (file)
@@ -12,6 +12,7 @@ class XGUI_Workshop;
 class QAction;
 class QContextMenuEvent;
 class QMenu;
+class QActionGroup;
 
 /**
  * \ingroup GUI
@@ -113,7 +114,9 @@ signals:
   QMap<std::string, QActionsList> myObjBrowserMenus;
   QMap<std::string, QActionsList> myViewerMenu;
 
-   QAction* mySeparator;
+  QActionGroup* mySelectActions;
+
+  QAction* mySeparator;
 };
 
 #endif
index c4cdd88f59dfd747281cafb7039f21cd5cd00e93..20e4c300c23b6d0d579649939a1a92b6f3831eef 100644 (file)
@@ -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; 
+}
index dd221d7bf9cbb9b9398e501f31fa1858270c48e6..489508c2ca0f39e7f4bab6ab76080a6568ce5b3c 100644 (file)
@@ -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);
index bc8d74140c16a92a0e5c824875800a9e4aa7c87d..cf8ec1f37e3061a43ef07a30b8d492ba455b0902 100644 (file)
@@ -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
index ad92b420b0568a91ebf1e53bfbf049e71a6a6231..5570632c5d1dbee3c76cad47e55a80ad73b462b8 100644 (file)
@@ -96,6 +96,22 @@ void XGUI_SelectionMgr::onObjectBrowserSelection()
   QList<ModuleBase_ViewerPrs> aSelectedPrs =
              myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
 
+  QList<ModuleBase_ViewerPrs> aTmpList = aSelectedPrs;
+  ObjectPtr aObject;
+  FeaturePtr aFeature;
+  foreach(ModuleBase_ViewerPrs aPrs, aTmpList) {
+    aObject = aPrs.object();
+    if (aObject.get()) {
+      aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
+      if (aFeature.get()) {
+        const std::list<std::shared_ptr<ModelAPI_Result>> aResList = aFeature->results();
+        std::list<ResultPtr>::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<ModelAPI_Result>(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);
index 8290f2c72c6ce9eabdbb0b46c11881d7b6fe3590..e55d6406ee87b8e455180942a72d13a77a25b216 100755 (executable)
@@ -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()
 {
index 37685b16975e972402f10fd5ed111b13e3157fe2..187182e6686dc30e3a4f2f2ad3aeafe217d5d520 100755 (executable)
@@ -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
index 692f569d6e180d63fc79f9b2dfb9b959ff158409..b1c2569a27e5f0bffec2a4af874225743cb12043 100644 (file)
@@ -56,5 +56,6 @@
      <file>pictures/compound.png</file>
      <file>pictures/shell.png</file>
      <file>pictures/wire.png</file>
+     <file>pictures/result.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/result.png b/src/XGUI/pictures/result.png
new file mode 100644 (file)
index 0000000..0ad7728
Binary files /dev/null and b/src/XGUI/pictures/result.png differ