Clean up the RepeatItem architecture and finish deleting the UndoItem facility.

This commit is contained in:
Jeff Young 2019-05-10 17:48:46 +01:00
parent 5685174808
commit f3c95ad83c
9 changed files with 20 additions and 57 deletions

View File

@ -48,8 +48,6 @@ SCH_TEXT* SCH_EDIT_FRAME::CreateNewText( int aType )
{ {
SCH_TEXT* textItem = NULL; SCH_TEXT* textItem = NULL;
SetRepeatItem( NULL );
switch( aType ) switch( aType )
{ {
case LAYER_NOTES: case LAYER_NOTES:
@ -157,8 +155,6 @@ void SCH_EDIT_FRAME::ConvertTextType( SCH_TEXT* aText, KICAD_T aType )
if( selected ) if( selected )
m_toolManager->RunAction( SCH_ACTIONS::addItemToSel, true, newtext ); m_toolManager->RunAction( SCH_ACTIONS::addItemToSel, true, newtext );
SetRepeatItem( nullptr );
delete aText; delete aText;
OnModify(); OnModify();

View File

@ -335,8 +335,6 @@ void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent )
if( undoItem == NULL ) if( undoItem == NULL )
undoItem = item; undoItem = item;
SetUndoItem( undoItem );
sheet = schematic.GetSheetByPath( data.GetSheetPath() ); sheet = schematic.GetSheetByPath( data.GetSheetPath() );
wxCHECK_RET( sheet != NULL, wxT( "Could not find sheet path " ) + data.GetSheetPath() ); wxCHECK_RET( sheet != NULL, wxT( "Could not find sheet path " ) + data.GetSheetPath() );
@ -366,8 +364,6 @@ void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent )
if( undoItem == NULL ) if( undoItem == NULL )
undoItem = item; undoItem = item;
SetUndoItem( undoItem );
sheet = schematic.GetSheetByPath( data.GetSheetPath() ); sheet = schematic.GetSheetByPath( data.GetSheetPath() );
wxCHECK_RET( sheet != NULL, wxT( "Could not find sheet path " ) + data.GetSheetPath() ); wxCHECK_RET( sheet != NULL, wxT( "Could not find sheet path " ) + data.GetSheetPath() );

View File

@ -259,9 +259,6 @@ void SCH_EDIT_FRAME::DisplayCurrentSheet()
m_toolManager->RunAction( ACTIONS::cancelInteractive, true ); m_toolManager->RunAction( ACTIONS::cancelInteractive, true );
m_toolManager->RunAction( SCH_ACTIONS::clearSelection, true ); m_toolManager->RunAction( SCH_ACTIONS::clearSelection, true );
SetRepeatItem( NULL );
ClearMsgPanel();
SCH_SCREEN* screen = g_CurrentSheet->LastScreen(); SCH_SCREEN* screen = g_CurrentSheet->LastScreen();
// Switch to current sheet, // Switch to current sheet,

View File

@ -399,7 +399,7 @@ SCH_EDIT_FRAME::~SCH_EDIT_FRAME()
Unbind( wxEVT_COMMAND_MENU_SELECTED, &SCH_EDIT_FRAME::OnEditSymbolLibTable, this, Unbind( wxEVT_COMMAND_MENU_SELECTED, &SCH_EDIT_FRAME::OnEditSymbolLibTable, this,
ID_EDIT_SYM_LIB_TABLE ); ID_EDIT_SYM_LIB_TABLE );
delete m_item_to_repeat; // we own the cloned object, see this->SetRepeatItem() delete m_item_to_repeat; // we own the cloned object, see this->SaveCopyForRepeatItem()
SetScreen( NULL ); SetScreen( NULL );
@ -446,7 +446,7 @@ void SCH_EDIT_FRAME::setupTools()
} }
void SCH_EDIT_FRAME::SetRepeatItem( SCH_ITEM* aItem ) void SCH_EDIT_FRAME::SaveCopyForRepeatItem( SCH_ITEM* aItem )
{ {
// we cannot store a pointer to an item in the display list here since // we cannot store a pointer to an item in the display list here since
// that item may be deleted, such as part of a line concatonation or other. // that item may be deleted, such as part of a line concatonation or other.
@ -597,24 +597,6 @@ void SCH_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
} }
void SCH_EDIT_FRAME::SetUndoItem( const SCH_ITEM* aItem )
{
// if aItem != NULL, delete a previous m_undoItem, if exists
// if aItme = NULL, just clear m_undoItem,
// because when calling SetUndoItem( NULL ), we only clear m_undoItem,
// because the owner of m_undoItem is no more me.
if( aItem && m_undoItem )
{
delete m_undoItem;
}
m_undoItem = NULL;
if( aItem )
m_undoItem = (SCH_ITEM*) aItem->Clone();
}
void SCH_EDIT_FRAME::SaveUndoItemInUndoList( SCH_ITEM* aItem, bool aAppend ) void SCH_EDIT_FRAME::SaveUndoItemInUndoList( SCH_ITEM* aItem, bool aAppend )
{ {
wxCHECK_RET( aItem != NULL, wxCHECK_RET( aItem != NULL,
@ -1259,7 +1241,7 @@ void SCH_EDIT_FRAME::AddItemToScreenAndUndoList( SCH_ITEM* aItem, bool aUndoAppe
if( !screen->CheckIfOnDrawList( aItem ) ) // don't want a loop! if( !screen->CheckIfOnDrawList( aItem ) ) // don't want a loop!
AddToScreen( aItem ); AddToScreen( aItem );
SetRepeatItem( aItem ); SaveCopyForRepeatItem( aItem );
SaveCopyInUndoList( undoItem, UR_NEW, aUndoAppend ); SaveCopyInUndoList( undoItem, UR_NEW, aUndoAppend );
} }

View File

@ -1073,7 +1073,7 @@ public:
/** /**
* Clone \a aItem and owns that clone in this container. * Clone \a aItem and owns that clone in this container.
*/ */
void SetRepeatItem( SCH_ITEM* aItem ); void SaveCopyForRepeatItem( SCH_ITEM* aItem );
/** /**
* Return the item which is to be repeated with the insert key. * Return the item which is to be repeated with the insert key.
@ -1082,17 +1082,6 @@ public:
*/ */
SCH_ITEM* GetRepeatItem() const { return m_item_to_repeat; } SCH_ITEM* GetRepeatItem() const { return m_item_to_repeat; }
/**
* Clone \a aItem which can be used to restore the state of the item being edited
* when the user cancels the editing in progress.
*
* @param aItem The item to make a clone of for undoing the last change. Set to
* NULL to free the current undo item.
*/
void SetUndoItem( const SCH_ITEM* aItem );
SCH_ITEM* GetUndoItem() const { return m_undoItem; }
/** /**
* Swap the cloned item in member variable m_undoItem with \a aItem and saves it to * Swap the cloned item in member variable m_undoItem with \a aItem and saves it to
* the undo list then swap the data back. * the undo list then swap the data back.

View File

@ -196,6 +196,7 @@ int LIB_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType )
// First click creates... // First click creates...
if( !item ) if( !item )
{ {
m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
m_frame->GetCanvas()->SetIgnoreMouseEvents( true ); m_frame->GetCanvas()->SetIgnoreMouseEvents( true );
switch( aType ) switch( aType )
@ -340,6 +341,8 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
if( !part ) if( !part )
continue; continue;
m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
switch( m_frame->GetToolId() ) switch( m_frame->GetToolId() )
{ {
case ID_LIBEDIT_BODY_ARC_BUTT: item = new LIB_ARC( part ); break; case ID_LIBEDIT_BODY_ARC_BUTT: item = new LIB_ARC( part ); break;

View File

@ -144,7 +144,7 @@ SCH_DRAWING_TOOLS::SCH_DRAWING_TOOLS() :
m_frame( nullptr ), m_frame( nullptr ),
m_menu( *this ) m_menu( *this )
{ {
}; }
SCH_DRAWING_TOOLS::~SCH_DRAWING_TOOLS() SCH_DRAWING_TOOLS::~SCH_DRAWING_TOOLS()
@ -288,7 +288,6 @@ int SCH_DRAWING_TOOLS::doPlaceComponent( SCH_COMPONENT* aComponent, SCHLIB_FILTE
if( !aComponent ) if( !aComponent )
{ {
m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
m_frame->SetRepeatItem( nullptr );
// Pick the module to be placed // Pick the module to be placed
m_frame->GetCanvas()->SetIgnoreMouseEvents( true ); m_frame->GetCanvas()->SetIgnoreMouseEvents( true );
@ -315,7 +314,7 @@ int SCH_DRAWING_TOOLS::doPlaceComponent( SCH_COMPONENT* aComponent, SCHLIB_FILTE
if( m_frame->GetAutoplaceFields() ) if( m_frame->GetAutoplaceFields() )
aComponent->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false ); aComponent->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
m_frame->SetRepeatItem( aComponent ); m_frame->SaveCopyForRepeatItem( aComponent );
m_view->ClearPreview(); m_view->ClearPreview();
m_view->AddToPreview( aComponent->Clone() ); m_view->AddToPreview( aComponent->Clone() );
@ -415,11 +414,13 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
{ {
if( !image ) if( !image )
{ {
wxFileDialog dlg( m_frame, _( "Choose Image" ), wxEmptyString, wxEmptyString, m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
_( "Image Files " ) + wxImage::GetImageExtWildcard(), wxFD_OPEN );
m_frame->GetCanvas()->SetIgnoreMouseEvents( true ); m_frame->GetCanvas()->SetIgnoreMouseEvents( true );
wxFileDialog dlg( m_frame, _( "Choose Image" ), wxEmptyString, wxEmptyString,
_( "Image Files " ) + wxImage::GetImageExtWildcard(), wxFD_OPEN );
if( dlg.ShowModal() != wxID_OK ) if( dlg.ShowModal() != wxID_OK )
continue; continue;
@ -443,7 +444,7 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
image->SetFlags( IS_NEW | IS_MOVED ); image->SetFlags( IS_NEW | IS_MOVED );
m_frame->SetRepeatItem( image ); m_frame->SaveCopyForRepeatItem( image );
m_view->ClearPreview(); m_view->ClearPreview();
m_view->AddToPreview( image->Clone() ); m_view->AddToPreview( image->Clone() );
@ -564,7 +565,7 @@ int SCH_DRAWING_TOOLS::doSingleClickPlace( KICAD_T aType )
item->SetFlags( IS_NEW ); item->SetFlags( IS_NEW );
m_frame->AddItemToScreenAndUndoList( item ); m_frame->AddItemToScreenAndUndoList( item );
m_frame->SetRepeatItem( item ); m_frame->SaveCopyForRepeatItem( item );
m_frame->SchematicCleanUp(); m_frame->SchematicCleanUp();
m_frame->TestDanglingEnds(); m_frame->TestDanglingEnds();
@ -662,7 +663,7 @@ int SCH_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType )
// First click creates... // First click creates...
if( !item ) if( !item )
{ {
m_frame->SetRepeatItem( NULL ); m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
m_frame->GetCanvas()->SetIgnoreMouseEvents( true ); m_frame->GetCanvas()->SetIgnoreMouseEvents( true );
switch( aType ) switch( aType )
@ -794,6 +795,8 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
else if( evt->IsClick( BUT_LEFT ) && !sheet ) else if( evt->IsClick( BUT_LEFT ) && !sheet )
{ {
m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
sheet = new SCH_SHEET( (wxPoint) cursorPos ); sheet = new SCH_SHEET( (wxPoint) cursorPos );
sheet->SetFlags( IS_NEW | IS_RESIZED ); sheet->SetFlags( IS_NEW | IS_RESIZED );
sheet->SetTimeStamp( GetNewTimeStamp() ); sheet->SetTimeStamp( GetNewTimeStamp() );
@ -801,8 +804,6 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
sheet->SetScreen( NULL ); sheet->SetScreen( NULL );
sizeSheet( sheet, cursorPos ); sizeSheet( sheet, cursorPos );
m_frame->SetRepeatItem( nullptr );
m_selectionTool->AddItemToSel( sheet ); m_selectionTool->AddItemToSel( sheet );
m_view->ClearPreview(); m_view->ClearPreview();
m_view->AddToPreview( sheet->Clone() ); m_view->AddToPreview( sheet->Clone() );

View File

@ -899,7 +899,7 @@ int SCH_EDIT_TOOL::RepeatDrawItem( const TOOL_EVENT& aEvent )
m_frame->TestDanglingEnds(); m_frame->TestDanglingEnds();
// newItem newItem, now that it has been moved, thus saving new position. // newItem newItem, now that it has been moved, thus saving new position.
m_frame->SetRepeatItem( newItem ); m_frame->SaveCopyForRepeatItem( newItem );
return 0; return 0;
} }
@ -959,7 +959,6 @@ int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
} }
} }
m_frame->SetRepeatItem( nullptr );
m_frame->TestDanglingEnds(); m_frame->TestDanglingEnds();
m_frame->GetCanvas()->Refresh(); m_frame->GetCanvas()->Refresh();

View File

@ -947,7 +947,7 @@ void SCH_WIRE_BUS_TOOL::finishSegments()
} }
// Get the last non-null wire (this is the last created segment). // Get the last non-null wire (this is the last created segment).
m_frame->SetRepeatItem( s_wires.GetLast() ); m_frame->SaveCopyForRepeatItem( s_wires.GetLast());
// Add the new wires // Add the new wires
while( s_wires.GetFirst() ) while( s_wires.GetFirst() )