From 90233e5ec66bad8f1afad3ee0c6f2fa375dc578e Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 23 Oct 2018 21:20:44 -0700 Subject: [PATCH] SELECTION: Prevent double select/deselect. When processing the selection filter, items were deselected before being reselected after passing through the filter. This adjusts the logic to only deselect those items that are filtered out. --- include/collector.h | 8 ++++++++ pcbnew/tools/selection_tool.cpp | 18 ++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/collector.h b/include/collector.h index bc4262336b..3872e08522 100644 --- a/include/collector.h +++ b/include/collector.h @@ -86,6 +86,14 @@ public: virtual SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) = 0; + using ITER = std::vector::iterator; + using CITER = std::vector::const_iterator; + + ITER begin() { return m_List.begin(); } + ITER end() { return m_List.end(); } + CITER begin() const { return m_List.cbegin(); } + CITER end() const { return m_List.cend(); } + /** * Function IsValidIndex * tests if \a aIndex is with the limits of the list of collected items. diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 8d84b01d60..fff9eb573d 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -422,19 +422,17 @@ SELECTION& SELECTION_TOOL::RequestSelection( CLIENT_SELECTION_FILTER aClientFilt { GENERAL_COLLECTOR collector; - while( m_selection.GetSize() ) - { - collector.Append( m_selection.Front() ); - unselect( static_cast( m_selection.Front() ) ); - } + for( auto item : m_selection ) + collector.Append( item ); aClientFilter( VECTOR2I(), collector ); - for( int i = 0; i < collector.GetCount(); ++i ) - { - m_additive = true; - select( collector[ i ] ); - } + std::vector diff; + std::set_difference( m_selection.begin(), m_selection.end(), collector.begin(), collector.end(), + std::back_inserter( diff ) ); + + for( auto item : diff ) + unhighlight( static_cast( item ), SELECTED, m_selection ); m_frame->GetGalCanvas()->ForceRefresh(); }