From: nds Date: Tue, 23 May 2017 07:48:51 +0000 (+0300) Subject: Issue #1254 Multiselection field is cleared when trying to add another object X-Git-Tag: V_2.7.1.1~34 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6b3768cc806b164bb1b9671aaeed386e9e53d427;p=modules%2Fshaper.git Issue #1254 Multiselection field is cleared when trying to add another object --- diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index 53cc4a919..5123e5e4f 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -121,11 +121,8 @@ void XGUI_ModuleConnector::setSelected(const QList& 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) diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index f4a0b397b..cf61433f6 100755 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -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 aValues; Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - if (!aContext.IsNull()) { - QList 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(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& 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& 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(aPrs->object()); + if (aResult.get()) { + aFeature = anActiveDocument->producedByFeature(aResult, aPrs->shape()); + if (aFeature.get() && (!theObjects.contains(aFeature))) + theObjects.append(aFeature); + } + } + } + } +} diff --git a/src/XGUI/XGUI_SelectionMgr.h b/src/XGUI/XGUI_SelectionMgr.h index 32344dec7..1ea33bf75 100644 --- a/src/XGUI/XGUI_SelectionMgr.h +++ b/src/XGUI/XGUI_SelectionMgr.h @@ -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 >& 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 >& theValues, QObjectPtrList& theObjects); + +private: /// Reference to workshop XGUI_Workshop* myWorkshop; diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index 11e1d9866..c7cd40407 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -10,6 +10,7 @@ #include "XGUI_PropertyPanel.h" #include "XGUI_ModuleConnector.h" #include "XGUI_QtEvents.h" +#include "XGUI_SelectionMgr.h" #ifndef HAVE_SALOME #include @@ -138,7 +139,7 @@ void XGUI_WorkshopListener::processEvent(const std::shared_ptr& ModuleBase_WidgetSelector* aWidgetSelector = dynamic_cast(aWidget); if (aWidgetSelector) - myWorkshop->setSelected(aWidgetSelector->getAttributeSelection()); + workshop()->selector()->setSelected(aWidgetSelector->getAttributeSelection()); } }