]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1254 Multiselection field is cleared when trying to add another object
authornds <nds@opencascade.com>
Tue, 23 May 2017 07:48:51 +0000 (10:48 +0300)
committernds <nds@opencascade.com>
Tue, 23 May 2017 07:49:20 +0000 (10:49 +0300)
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_SelectionMgr.h
src/XGUI/XGUI_WorkshopListener.cpp

index 53cc4a919e75838e24ea4e44174d2f71292d15e1..5123e5e4fef7a3a3517357ded40ef3f6ea98cac3 100644 (file)
@@ -121,11 +121,8 @@ void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& the
   XGUI_Displayer* aDisp = myWorkshop->displayer();
   if (theValues.isEmpty()) {
     myWorkshop->selector()->clearSelection();
-  } else {
+  } else
     aDisp->setSelected(theValues);
-    // according to #2154 we need to update OB selection when selection in the viewer happens
-    myWorkshop->selector()->onViewerSelection();
-  }
 }
 
 void XGUI_ModuleConnector::setStatusBarMessage(const QString& theMessage)
index f4a0b397b85659a18874ef03da944f99875bb3af..cf61433f600613749f4f94e4b8fa83be13eff558 100755 (executable)
@@ -117,33 +117,16 @@ void XGUI_SelectionMgr::onObjectBrowserSelection()
 //**************************************************************
 void XGUI_SelectionMgr::onViewerSelection()
 {
-  SessionPtr aMgr = ModelAPI_Session::get();
-  DocumentPtr anActiveDocument = aMgr->activeDocument();
-  QObjectPtrList aFeatures;
-  ResultPtr aResult;
-  FeaturePtr aFeature;
-  bool aHasOperation = (myWorkshop->operationMgr()->currentOperation() != 0);
+  QList<ModuleBase_ViewerPrsPtr> aValues;
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
-  if (!aContext.IsNull()) {
-    QList<ModuleBase_ViewerPrsPtr> aPresentations =
-      selection()->getSelected(ModuleBase_ISelection::Viewer);
-    foreach(ModuleBase_ViewerPrsPtr aPrs, aPresentations) {
-      if (aPrs->object().get()) {
-        if (!aFeatures.contains(aPrs->object()))
-          aFeatures.append(aPrs->object());
-        if (aPrs->shape().get() && (!aHasOperation)) {
-          aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
-          if (aResult.get()) {
-            aFeature = anActiveDocument->producedByFeature(aResult, aPrs->shape());
-            if (aFeature.get() && (!aFeatures.contains(aFeature)))
-              aFeatures.append(aFeature);
-          }
-        }
-      }
-    }
-  }
+  if (!aContext.IsNull())
+    aValues = selection()->getSelected(ModuleBase_ISelection::Viewer);
+
+  QObjectPtrList anObjects;
+  convertToObjectBrowserSelection(aValues, anObjects);
+
   bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
-  myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
+  myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
   myWorkshop->objectBrowser()->blockSignals(aBlocked);
 
   emit selectionChanged();
@@ -176,3 +159,46 @@ void XGUI_SelectionMgr::clearSelection()
 
   emit selectionChanged();
 }
+//**************************************************************
+void XGUI_SelectionMgr::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theValues)
+{
+  // update selection in Viewer
+  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+  aDisplayer->setSelected(theValues);
+
+  // update selection in Object Browser
+  bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
+  QObjectPtrList anObjects;
+  convertToObjectBrowserSelection(theValues, anObjects);
+
+  myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
+  myWorkshop->objectBrowser()->blockSignals(aBlocked);
+}
+//**************************************************************
+void XGUI_SelectionMgr::convertToObjectBrowserSelection(
+                                   const QList<ModuleBase_ViewerPrsPtr>& theValues,
+                                   QObjectPtrList& theObjects)
+{
+  theObjects.clear();
+
+  ResultPtr aResult;
+  FeaturePtr aFeature;
+  bool aHasOperation = (myWorkshop->operationMgr()->currentOperation() != 0);
+  SessionPtr aMgr = ModelAPI_Session::get();
+  DocumentPtr anActiveDocument = aMgr->activeDocument();
+
+  foreach(ModuleBase_ViewerPrsPtr aPrs, theValues) {
+    if (aPrs->object().get()) {
+      if (!theObjects.contains(aPrs->object()))
+        theObjects.append(aPrs->object());
+      if (aPrs->shape().get() && (!aHasOperation)) {
+        aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
+        if (aResult.get()) {
+          aFeature = anActiveDocument->producedByFeature(aResult, aPrs->shape());
+          if (aFeature.get() && (!theObjects.contains(aFeature)))
+            theObjects.append(aFeature);
+        }
+      }
+    }
+  }
+}
index 32344dec78a4bd1ebded87799d6b716b21bdecc4..1ea33bf756a78b6def43272f5a1cb167f7b07cb8 100644 (file)
@@ -50,6 +50,11 @@ Q_OBJECT
   //! Clears selection in Viewer and object Browser
   void clearSelection();
 
+  //! Sets values selected in both, ObjectBrowser and V3d viewer
+  //! Selection is not synchronized between these controls.
+  //! \param theValues a container of values to be selected.
+  void setSelected(const QList<std::shared_ptr<ModuleBase_ViewerPrs> >& theValues);
+
   /// Updates selection, which are depend on the selection in the given place
   /// \param thePlace a widget where selection has happened.
   void updateSelectionBy(const ModuleBase_ISelection::SelectionPlace& thePlace);
@@ -65,7 +70,14 @@ signals:
    /// Reaction on selectio0n in Viewer
   void onViewerSelection();
 
- private:
+private:
+  /// Interates through the values to prepare container of objects that may be selected in OB
+  /// \param theValues selection information
+  /// \param theObjecs an output container
+  void convertToObjectBrowserSelection(
+       const QList<std::shared_ptr<ModuleBase_ViewerPrs> >& theValues, QObjectPtrList& theObjects);
+
+private:
    /// Reference to workshop
   XGUI_Workshop* myWorkshop;
 
index 11e1d9866b551d8d32ed0f39f02d9acfc4708f84..c7cd404078d26ef29c5f4468e2c8158379e626d5 100755 (executable)
@@ -10,6 +10,7 @@
 #include "XGUI_PropertyPanel.h"
 #include "XGUI_ModuleConnector.h"
 #include "XGUI_QtEvents.h"
+#include "XGUI_SelectionMgr.h"
 
 #ifndef HAVE_SALOME
 #include <AppElements_MainWindow.h>
@@ -138,7 +139,7 @@ void XGUI_WorkshopListener::processEvent(const std::shared_ptr<Events_Message>&
       ModuleBase_WidgetSelector* aWidgetSelector =
         dynamic_cast<ModuleBase_WidgetSelector*>(aWidget);
       if (aWidgetSelector)
-        myWorkshop->setSelected(aWidgetSelector->getAttributeSelection());
+        workshop()->selector()->setSelected(aWidgetSelector->getAttributeSelection());
     }
   }