Browse Source

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
pull/13/head
Seth Hillbrand 7 years ago
parent
commit
7470d5ba98
  1. 13
      pcbnew/board_commit.cpp
  2. 14
      pcbnew/tools/edit_tool.cpp

13
pcbnew/board_commit.cpp

@ -30,6 +30,7 @@
#include <view/view.h>
#include <board_commit.h>
#include <tools/pcb_tool.h>
#include <tools/pcb_actions.h>
#include <connectivity_data.h>
#include <functional>
@ -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<MODULE*>( 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<MODULE*>( 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

14
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<BOARD_ITEM*>( 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;
}

Loading…
Cancel
Save