From 96392c3371f120ac065f9cc6eec4f92c615eddb3 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 21 May 2015 08:32:15 +0300 Subject: [PATCH] Code improvement: avoid the code duplication for setSelected method in the displayer. It gets currently a list of viewer prs instead of a list of objects. This is necessary to restore the shape selection. --- src/ModuleBase/CMakeLists.txt | 3 +- src/ModuleBase/ModuleBase_ISelection.cpp | 16 ++++++++ src/ModuleBase/ModuleBase_ISelection.h | 5 +++ src/ModuleBase/ModuleBase_WidgetValidated.cpp | 8 +--- src/XGUI/XGUI_Displayer.cpp | 38 ------------------- 5 files changed, 24 insertions(+), 46 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_ISelection.cpp diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 3b2c8a279..c54208e12 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -21,12 +21,12 @@ SET(PROJECT_HEADERS ModuleBase_IWorkshop.h ModuleBase_Definitions.h ModuleBase_SelectionValidator.h - ModuleBase_ISelection.h ModuleBase_ViewerPrs.h ModuleBase_WidgetChoice.h ModuleBase_WidgetFileSelector.h ModuleBase_DoubleSpinBox.h ModuleBase_IPropertyPanel.h + ModuleBase_ISelection.h ModuleBase_IViewer.h ModuleBase_WidgetLineEdit.h ModuleBase_WidgetMultiSelector.h @@ -56,6 +56,7 @@ SET(PROJECT_SOURCES ModuleBase_FilterValidated.cpp ModuleBase_Tools.cpp ModuleBase_IModule.cpp + ModuleBase_ISelection.cpp ModuleBase_IWorkshop.cpp ModuleBase_Operation.cpp ModuleBase_OperationDescription.cpp diff --git a/src/ModuleBase/ModuleBase_ISelection.cpp b/src/ModuleBase/ModuleBase_ISelection.cpp new file mode 100644 index 000000000..190447668 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ISelection.cpp @@ -0,0 +1,16 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#include "ModuleBase_ISelection.h" + +QList ModuleBase_ISelection::getViewerPrs(const QObjectPtrList& theObjects) +{ + QList aSelectedPrs; + QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end(); + for (; anIt != aLast; anIt++) { + ObjectPtr anObject = *anIt; + if (anObject.get() != NULL) { + aSelectedPrs.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL)); + } + } + return aSelectedPrs; +} diff --git a/src/ModuleBase/ModuleBase_ISelection.h b/src/ModuleBase/ModuleBase_ISelection.h index b2686be48..86cfd4f52 100644 --- a/src/ModuleBase/ModuleBase_ISelection.h +++ b/src/ModuleBase/ModuleBase_ISelection.h @@ -70,6 +70,11 @@ class ModuleBase_ISelection virtual void selectedShapes(NCollection_List& theList, std::list& theOwners) const = 0; + //! Wraps the object list into the viewer prs list + //! \param theObjects a list of objects + //! \return a list of prs, where only object is not empty + static MODULEBASE_EXPORT QList getViewerPrs( + const QObjectPtrList& theObjects); }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index a5ec4c5fe..4dcf23973 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -136,13 +136,7 @@ QList ModuleBase_WidgetValidated::getSelectedEntitiesOrObj if (aSelectedPrs.empty()) { // the selection in Object Browser QObjectPtrList anObjects = theSelection->selectedObjects(); - QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); - for (; anIt != aLast; anIt++) { - ObjectPtr anObject = *anIt; - if (anObject.get() != NULL) { - aSelectedPrs.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL)); - } - } + aSelectedPrs = ModuleBase_ISelection::getViewerPrs(anObjects); } return aSelectedPrs; } diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index ce6aadefc..5254c1ea6 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -416,44 +416,6 @@ bool XGUI_Displayer::isActive(ObjectPtr theObject) const return aModes.Extent() > 0; } -void XGUI_Displayer::setSelected(const QObjectPtrList& theResults, const bool isUpdateViewer) -{ - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (aContext.IsNull()) - return; - if (aContext->HasOpenedContext()) { - aContext->UnhilightSelected(); - aContext->ClearSelected(); - foreach(ObjectPtr aResult, theResults) { - if (isVisible(aResult)) { - AISObjectPtr anObj = myResult2AISObjectMap[aResult]; - Handle(AIS_InteractiveObject) anAIS = anObj->impl(); - if (!anAIS.IsNull()) { - // The methods are replaced in order to provide multi-selection, e.g. restore selection - // by activating multi selector widget. It also gives an advantage that the multi - // selection in OB gives multi-selection in the viewer - //aContext->SetSelected(anAIS, false); - // The selection in the context was cleared, so the method sets the objects are selected - aContext->AddOrRemoveSelected(anAIS, false); - } - } - } - } else { - aContext->UnhilightCurrents(); - aContext->ClearCurrents(); - foreach(ObjectPtr aResult, theResults) { - if (isVisible(aResult)) { - AISObjectPtr anObj = myResult2AISObjectMap[aResult]; - Handle(AIS_InteractiveObject) anAIS = anObj->impl(); - if (!anAIS.IsNull()) - aContext->SetCurrentObject(anAIS, false); - } - } - } - if (isUpdateViewer) - updateViewer(); -} - void XGUI_Displayer::setSelected(const QList& theValues, bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); -- 2.39.2