static void abortMoveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) { SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen(); SCH_ITEM* item = screen->GetCurItem(); SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) aPanel->GetParent(); parent->SetRepeatItem( NULL ); screen->SetCurItem( NULL ); if( item == NULL ) /* no current item */ return; if( item->IsNew() ) { delete item; item = NULL; } else { SCH_ITEM* oldItem = parent->GetUndoItem(); SCH_ITEM* currentItem; // Items that are children of other objects are undone by swapping the contents // of the parent items. if( (item->Type() == SCH_SHEET_PIN_T) || (item->Type() == SCH_FIELD_T) ) { currentItem = (SCH_ITEM*) item->GetParent(); } else { currentItem = item; } wxCHECK_RET( oldItem != NULL && currentItem->Type() == oldItem->Type(), wxT( "Cannot restore undefined or bad last schematic item." ) ); // Never delete existing item, because it can be referenced by an undo/redo command // Just restore its data currentItem->SwapData( oldItem ); // Erase the wire representation before the 'normal' view is drawn. if ( item->IsWireImage() ) item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); item->ClearFlags(); } aPanel->Refresh(); }
// Complete sheet move. static void ExitSheet( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) { SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen(); SCH_ITEM* item = screen->GetCurItem(); SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent(); if( (item == NULL) || (item->Type() != SCH_SHEET_T) || (parent == NULL) ) return; parent->SetRepeatItem( NULL ); item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); if( item->IsNew() ) { delete item; } else if( item->IsMoving() || item->IsResized() ) { screen->Remove( item ); delete item; item = parent->GetUndoItem(); wxCHECK_RET( item != NULL, wxT( "Cannot restore undefined last sheet item." ) ); screen->Append( item ); // the owner of item is no more parent, this is the draw list of screen: parent->SetUndoItem( NULL ); item->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); item->ClearFlags(); } else { item->ClearFlags(); } screen->SetCurItem( NULL ); }