Eeschema: Add 'append' option to undo

Allows eeschema to add elements to previous undo commits,
permitting stacking of changes through multiple calls
This commit is contained in:
Seth Hillbrand 2017-11-16 12:36:09 -08:00 committed by Wayne Stambaugh
parent a0c922e493
commit f8e0099ecc
4 changed files with 50 additions and 11 deletions

View File

@ -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();
}

View File

@ -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();

View File

@ -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++ )

View File

@ -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: