From 7470d5ba9823be7ca016d8cb3f0d463e9436cf34 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 17 Sep 2018 06:14:23 -0700 Subject: [PATCH] pcbnew: retain selection between edits We had been deselecting items after calling edits to be safe in case the item was deleted/exchanged by the edit. The item pointer itself remains valid even when deleting as it is assigned to the undo stack. But it should not remain visible or selected on the schematic if it is removed. This tests for removed items by checking whether it (in the case of first-level BOARD_ITEMS) or its parent (in the case of footprint item components) remain in the view list after editing. If they are still in the view list, then we re-select them. ( cherry-picked from 2c6d0ffe2 ) Fixes: lp:1765774 * https://bugs.launchpad.net/kicad/+bug/1765774 Fixes: lp:1775946 * https://bugs.launchpad.net/kicad/+bug/1775946 --- pcbnew/board_commit.cpp | 13 +++++++++++-- pcbnew/tools/edit_tool.cpp | 14 ++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index 73a9e9ffe2..55a3f44e4e 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -165,6 +166,9 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a view->Remove( boardItem ); + // Removing an item should trigger the unselect + m_toolMgr->RunAction( PCB_ACTIONS::unselectItem, true, boardItem ); + if( !( changeFlags & CHT_DONE ) ) { MODULE* module = static_cast( boardItem->GetParent() ); @@ -188,6 +192,9 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a case PCB_ZONE_AREA_T: view->Remove( boardItem ); + // Removing an item should trigger the unselect + m_toolMgr->RunAction( PCB_ACTIONS::unselectItem, true, boardItem ); + if( !( changeFlags & CHT_DONE ) ) board->Remove( boardItem ); @@ -199,10 +206,12 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a wxASSERT( !m_editModules ); MODULE* module = static_cast( boardItem ); - module->ClearFlags(); - view->Remove( module ); + // Removing an item should trigger the unselect + m_toolMgr->RunAction( PCB_ACTIONS::unselectItem, true, boardItem ); + module->ClearFlags(); + if( !( changeFlags & CHT_DONE ) ) board->Remove( module ); // handles connectivity diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 25a7e46167..dbfc228e0b 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -638,24 +638,22 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) // Display properties dialog BOARD_ITEM* item = static_cast( selection.Front() ); - // Some of properties dialogs alter pointers, so we should deselect them - m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - - // Store flags, so they can be restored later - STATUS_FLAGS flags = item->GetFlags(); - item->ClearFlags(); - // Do not handle undo buffer, it is done by the properties dialogs @todo LEGACY // Display properties dialog provided by the legacy canvas frame editFrame->OnEditItemRequest( NULL, item ); + // Notify other tools of the changes m_toolMgr->RunAction( PCB_ACTIONS::selectionModified, true ); - item->SetFlags( flags ); } if( selection.IsHover() ) + { m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); + // Notify other tools of the changes -- This updates the visual ratsnest + m_toolMgr->RunAction( PCB_ACTIONS::selectionModified, true ); + } + return 0; }