Eeschema: Unify delete operations

DeleteItemsInList now shares the code for DeleteItem.
SCH_FRAME::DeleteItem removes junctions that are no longer needed.
This commit is contained in:
Seth Hillbrand 2017-10-12 16:41:25 -07:00 committed by Wayne Stambaugh
parent f8e0099ecc
commit d0b2f078fe
4 changed files with 49 additions and 24 deletions

View File

@ -272,7 +272,7 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* aDC )
if( block->GetCount() )
{
DeleteItemsInList( m_canvas, block->GetItems() );
DeleteItemsInList( block->GetItems() );
OnModify();
}
block->ClearItemsList();
@ -303,7 +303,7 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* aDC )
wxPoint move_vector = -GetScreen()->m_BlockLocate.GetLastCursorPosition();
copyBlockItems( block->GetItems() );
MoveItemsInList( m_blockItems.GetItems(), move_vector );
DeleteItemsInList( m_canvas, block->GetItems() );
DeleteItemsInList( block->GetItems() );
OnModify();
}

View File

@ -115,10 +115,8 @@ void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint& aMoveVector
}
void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList )
void SCH_EDIT_FRAME::DeleteItemsInList( PICKED_ITEMS_LIST& aItemsList, bool aAppend )
{
SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen();
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) panel->GetParent();
PICKED_ITEMS_LIST itemsList;
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
@ -126,46 +124,64 @@ void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList )
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
ITEM_PICKER itemWrapper( item, UR_DELETED );
if( item->Type() == SCH_SHEET_PIN_T )
{
/* this item is depending on a sheet, and is not in global list */
wxMessageBox( wxT( "DeleteItemsInList() err: unexpected SCH_SHEET_PIN_T" ) );
}
else
{
screen->Remove( item );
if( item->GetFlags() & STRUCT_DELETED )
continue;
/* Unlink the structure */
itemsList.PushItem( itemWrapper );
}
DeleteItem( item, aAppend );
aAppend = true;
}
frame->SaveCopyInUndoList( itemsList, UR_DELETED );
GetScreen()->ClearDrawingState();
}
void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem )
void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem, bool aAppend )
{
wxCHECK_RET( aItem != NULL, wxT( "Cannot delete invalid item." ) );
wxCHECK_RET( !( aItem->GetFlags() & STRUCT_DELETED ),
wxT( "Cannot delete item that is already deleted." ) );
// Here, aItem is not null.
SCH_SCREEN* screen = GetScreen();
if( aItem->Type() == SCH_SHEET_PIN_T )
{
// This iten is attached to a node, and is not accessible by the global list directly.
// This item is attached to a node, and is not accessible by the global list directly.
SCH_SHEET* sheet = (SCH_SHEET*) aItem->GetParent();
wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T),
wxT( "Sheet label has invalid parent item." ) );
SaveCopyInUndoList( (SCH_ITEM*) sheet, UR_CHANGED );
SaveCopyInUndoList( (SCH_ITEM*) sheet, UR_CHANGED, aAppend );
sheet->RemovePin( (SCH_SHEET_PIN*) aItem );
m_canvas->RefreshDrawingRect( sheet->GetBoundingBox() );
}
else
{
PICKED_ITEMS_LIST itemsList;
ITEM_PICKER picker( aItem, UR_DELETED );
aItem->SetFlags( STRUCT_DELETED );
itemsList.PushItem( picker );
screen->Remove( aItem );
SaveCopyInUndoList( aItem, UR_DELETED );
if( aItem->IsConnectable() && aItem->Type() != SCH_JUNCTION_T )
{
std::vector< wxPoint > pts;
aItem->GetConnectionPoints( pts );
for( auto point : pts )
{
SCH_ITEM* junction;
if( !screen->IsJunctionNeeded( point )
&& ( junction = screen->GetItem( point, 0, SCH_JUNCTION_T ) ) )
{
ITEM_PICKER picker_juction( junction, UR_DELETED );
junction->SetFlags( STRUCT_DELETED );
itemsList.PushItem( picker_juction );
screen->Remove( junction );
}
}
}
SaveCopyInUndoList( itemsList, UR_DELETED, aAppend );
m_canvas->RefreshDrawingRect( aItem->GetBoundingBox() );
}
}

View File

@ -648,7 +648,7 @@ void SCH_EDIT_FRAME::DeleteConnection( bool aFullConnection )
if( screen->GetConnection( pos, pickList, aFullConnection ) != 0 )
{
DeleteItemsInList( m_canvas, pickList );
DeleteItemsInList( pickList );
OnModify();
}
}

View File

@ -1073,7 +1073,16 @@ public:
*
* @param aItem The item to remove from the current screen.
*/
void DeleteItem( SCH_ITEM* aItem );
void DeleteItem( SCH_ITEM* aItem, bool aAppend = false );
/**
* Removes all items (and unused junctions that connect to them) and saves
* each in the undo list
*
* @param aItemsList The list of items to delete
* @param aAppend True if we are updating a previous commit
*/
void DeleteItemsInList( PICKED_ITEMS_LIST& aItemsList, bool aAppend = false );
int GetLabelIncrement() const { return m_repeatLabelDelta; }