Add some defensive code for selection anomalies.

Fixes https://gitlab.com/kicad/code/kicad/issues/4021
This commit is contained in:
Jeff Young 2020-03-21 20:54:35 +00:00
parent d8e99dc5be
commit 66382db7dd
2 changed files with 22 additions and 5 deletions

View File

@ -472,9 +472,7 @@ void LIB_EDIT_FRAME::SetCurPart( LIB_PART* aPart )
{ {
m_toolManager->RunAction( EE_ACTIONS::clearSelection, true ); m_toolManager->RunAction( EE_ACTIONS::clearSelection, true );
if( m_my_part ) delete m_my_part;
delete m_my_part;
m_my_part = aPart; m_my_part = aPart;
// select the current component in the tree widget // select the current component in the tree widget
@ -837,6 +835,21 @@ void LIB_EDIT_FRAME::RebuildView()
void LIB_EDIT_FRAME::HardRedraw() void LIB_EDIT_FRAME::HardRedraw()
{ {
SyncLibraries( true ); SyncLibraries( true );
if( m_my_part )
{
EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
EE_SELECTION& selection = selectionTool->GetSelection();
for( LIB_ITEM& item : m_my_part->GetDrawItems() )
{
if( std::find( selection.begin(), selection.end(), &item ) == selection.end() )
item.ClearSelected();
else
item.SetSelected();
}
}
RebuildView(); RebuildView();
} }

View File

@ -649,7 +649,6 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent )
if( !part ) if( !part )
return 0; return 0;
EE_SELECTION& selection = m_selectionTool->GetSelection();
std::string text = m_toolMgr->GetClipboard(); std::string text = m_toolMgr->GetClipboard();
STRING_LINE_READER reader( text, "Clipboard" ); STRING_LINE_READER reader( text, "Clipboard" );
LIB_PART* newPart; LIB_PART* newPart;
@ -674,6 +673,9 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent )
m_frame->SaveCopyInUndoList( part ); m_frame->SaveCopyInUndoList( part );
m_selectionTool->ClearSelection(); m_selectionTool->ClearSelection();
for( LIB_ITEM& item : part->GetDrawItems() )
item.ClearFlags( IS_NEW | IS_PASTED | SELECTED );
for( LIB_ITEM& item : newPart->GetDrawItems() ) for( LIB_ITEM& item : newPart->GetDrawItems() )
{ {
if( item.Type() == LIB_FIELD_T ) if( item.Type() == LIB_FIELD_T )
@ -694,6 +696,8 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent )
m_selectionTool->RebuildSelection(); m_selectionTool->RebuildSelection();
EE_SELECTION& selection = m_selectionTool->GetSelection();
if( !selection.Empty() ) if( !selection.Empty() )
{ {
selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) ); selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) );
@ -726,7 +730,7 @@ int LIB_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
{ {
LIB_ITEM* oldItem = static_cast<LIB_ITEM*>( selection.GetItem( ii ) ); LIB_ITEM* oldItem = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
LIB_ITEM* newItem = (LIB_ITEM*) oldItem->Clone(); LIB_ITEM* newItem = (LIB_ITEM*) oldItem->Clone();
oldItem->ClearFlags( SELECTED ); oldItem->ClearFlags( IS_NEW | IS_PASTED | SELECTED );
newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED ); newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
newItem->SetParent( part ); newItem->SetParent( part );
newItems.push_back( newItem ); newItems.push_back( newItem );