From f8e0099eccd4c156f0f01203bcf5fcc0e9f64d6b Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 16 Nov 2017 12:36:09 -0800 Subject: [PATCH] Eeschema: Add 'append' option to undo Allows eeschema to add elements to previous undo commits, permitting stacking of changes through multiple calls --- eeschema/block.cpp | 8 +++--- eeschema/edit_bitmap.cpp | 2 +- eeschema/schematic_undo_redo.cpp | 47 ++++++++++++++++++++++++++++---- eeschema/schframe.h | 4 +++ 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/eeschema/block.cpp b/eeschema/block.cpp index b6d0d7824c..2d2af403f7 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -127,7 +127,7 @@ void SCH_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) if( m_canvas->IsMouseCaptured() ) m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); - SaveCopyInUndoList( block->GetItems(), UR_MOVED, block->GetMoveVector() ); + SaveCopyInUndoList( block->GetItems(), UR_MOVED, false, block->GetMoveVector() ); MoveItemsInList( block->GetItems(), block->GetMoveVector() ); block->ClearItemsList(); break; @@ -216,7 +216,7 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* aDC ) wxPoint rotationPoint = block->Centre(); rotationPoint = GetNearestGridPosition( rotationPoint ); SetCrossHairPosition( rotationPoint ); - SaveCopyInUndoList( block->GetItems(), UR_ROTATED, rotationPoint ); + SaveCopyInUndoList( block->GetItems(), UR_ROTATED, false, rotationPoint ); RotateListOfItems( block->GetItems(), rotationPoint ); OnModify(); } @@ -330,7 +330,7 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* aDC ) wxPoint mirrorPoint = block->Centre(); mirrorPoint = GetNearestGridPosition( mirrorPoint ); SetCrossHairPosition( mirrorPoint ); - SaveCopyInUndoList( block->GetItems(), UR_MIRRORED_X, mirrorPoint ); + SaveCopyInUndoList( block->GetItems(), UR_MIRRORED_X, false, mirrorPoint ); MirrorX( block->GetItems(), mirrorPoint ); OnModify(); } @@ -349,7 +349,7 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* aDC ) wxPoint mirrorPoint = block->Centre(); mirrorPoint = GetNearestGridPosition( mirrorPoint ); SetCrossHairPosition( mirrorPoint ); - SaveCopyInUndoList( block->GetItems(), UR_MIRRORED_Y, mirrorPoint ); + SaveCopyInUndoList( block->GetItems(), UR_MIRRORED_Y, false, mirrorPoint ); MirrorY( block->GetItems(), mirrorPoint ); OnModify(); } diff --git a/eeschema/edit_bitmap.cpp b/eeschema/edit_bitmap.cpp index ad2a2b93ab..d49efcda84 100644 --- a/eeschema/edit_bitmap.cpp +++ b/eeschema/edit_bitmap.cpp @@ -161,7 +161,7 @@ void SCH_EDIT_FRAME::MoveImage( SCH_BITMAP* aImageItem, wxDC* aDC ) void SCH_EDIT_FRAME::RotateImage( SCH_BITMAP* aItem ) { if( aItem->GetFlags( ) == 0 ) - SaveCopyInUndoList( aItem, UR_ROTATED, aItem->GetPosition() ); + SaveCopyInUndoList( aItem, UR_ROTATED, false, aItem->GetPosition() ); aItem->Rotate( aItem->GetPosition() ); OnModify(); diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index 09a83a6bce..75c1731eb2 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -108,8 +108,11 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_ITEM* aItem, UNDO_REDO_T aCommandType, + bool aAppend, const wxPoint& aTransformPoint ) { + PICKED_ITEMS_LIST* commandToUndo = NULL; + /* Does not save a null item or a UR_WIRE_IMAGE command type. UR_WIRE_IMAGE commands * are handled by the overloaded version of SaveCopyInUndoList that takes a reference * to a PICKED_ITEMS_LIST. @@ -117,8 +120,14 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_ITEM* aItem, if( aItem == NULL || aCommandType == UR_WIRE_IMAGE ) return; - PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST(); - commandToUndo->m_TransformPoint = aTransformPoint; + if( aAppend ) + commandToUndo = GetScreen()->PopCommandFromUndoList(); + + if( !commandToUndo ) + { + commandToUndo = new PICKED_ITEMS_LIST(); + commandToUndo->m_TransformPoint = aTransformPoint; + } ITEM_PICKER itemWrapper( aItem, aCommandType ); itemWrapper.SetFlags( aItem->GetFlags() ); @@ -160,15 +169,41 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_ITEM* aItem, void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, UNDO_REDO_T aTypeCommand, + bool aAppend, const wxPoint& aTransformPoint ) { - PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST(); + PICKED_ITEMS_LIST* commandToUndo = NULL; - commandToUndo->m_TransformPoint = aTransformPoint; - commandToUndo->m_Status = aTypeCommand; + if( !aItemsList.GetCount() ) + return; + + // Can't append a WIRE IMAGE, so fail to a new undo point + if( aAppend && ( aTypeCommand != UR_WIRE_IMAGE ) ) + { + commandToUndo = GetScreen()->PopCommandFromUndoList(); + if( commandToUndo && commandToUndo->m_Status == UR_WIRE_IMAGE ) + { + GetScreen()->PushCommandToUndoList( commandToUndo ); + commandToUndo = NULL; + } + } + + if( !commandToUndo ) + { + commandToUndo = new PICKED_ITEMS_LIST(); + commandToUndo->m_TransformPoint = aTransformPoint; + commandToUndo->m_Status = aTypeCommand; + } // Copy picker list: - commandToUndo->CopyList( aItemsList ); + if( !commandToUndo->GetCount() ) + commandToUndo->CopyList( aItemsList ); + else + { + // Unless we are appending, in which case, get the picker items + for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) + commandToUndo->PushItem( aItemsList.GetItemWrapper( ii) ); + } // Verify list, and creates data if needed for( unsigned ii = 0; ii < commandToUndo->GetCount(); ii++ ) diff --git a/eeschema/schframe.h b/eeschema/schframe.h index e80e9bbeba..bd0f08a06e 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -1161,11 +1161,13 @@ public: * * @param aItemToCopy = the schematic item modified by the command to undo * @param aTypeCommand = command type (see enum UNDO_REDO_T) + * @param aAppend = add the item to the previous undo list * @param aTransformPoint = the reference point of the transformation, * for commands like move */ void SaveCopyInUndoList( SCH_ITEM* aItemToCopy, UNDO_REDO_T aTypeCommand, + bool aAppend = false, const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ); /** @@ -1173,11 +1175,13 @@ public: * * @param aItemsList = the list of items modified by the command to undo * @param aTypeCommand = command type (see enum UNDO_REDO_T) + * @param aAppend = add the item to the previous undo list * @param aTransformPoint = the reference point of the transformation, * for commands like move */ void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, UNDO_REDO_T aTypeCommand, + bool aAppend = false, const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ); private: