2009-07-29 13:10:36 +00:00
|
|
|
/************************************************************/
|
|
|
|
/* eeschema: undo and redo functions for schematic editor */
|
|
|
|
/************************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-07-29 13:10:36 +00:00
|
|
|
#include "class_drawpanel.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2009-07-07 17:50:02 +00:00
|
|
|
#include "class_marker_sch.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-07-26 17:16:42 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Functions to undo and redo edit commands.
|
2009-12-02 21:44:03 +00:00
|
|
|
* commands to undo are stored in CurrentScreen->m_UndoList
|
|
|
|
* commands to redo are stored in CurrentScreen->m_RedoList
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2009-07-25 04:53:39 +00:00
|
|
|
* m_UndoList and m_RedoList handle a std::vector of PICKED_ITEMS_LIST
|
|
|
|
* Each PICKED_ITEMS_LIST handle a std::vector of pickers (class ITEM_PICKER),
|
2009-12-02 21:44:03 +00:00
|
|
|
* that store the list of schematic items that are concerned by the command to
|
|
|
|
* undo or redo and is created for each command to undo (handle also a command
|
|
|
|
* to redo). each picker has a pointer pointing to an item to undo or redo (in
|
|
|
|
* fact: deleted, added or modified), and has a pointer to a copy of this item,
|
|
|
|
* when this item has been modified (the old values of parameters are
|
|
|
|
* therefore saved)
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* there are 3 cases:
|
|
|
|
* - delete item(s) command
|
|
|
|
* - change item(s) command
|
|
|
|
* - add item(s) command
|
2009-07-29 13:10:36 +00:00
|
|
|
* and 2 cases for block:
|
|
|
|
* - move list of items
|
|
|
|
* - mirror (Y) list of items
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* Undo command
|
|
|
|
* - delete item(s) command:
|
2009-07-25 04:53:39 +00:00
|
|
|
* => deleted items are moved in undo list
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* - change item(s) command
|
2009-07-25 04:53:39 +00:00
|
|
|
* => A copy of item(s) is made (a DrawPickedStruct list of wrappers)
|
|
|
|
* the .m_Link member of each wrapper points the modified item.
|
|
|
|
* the .m_Item member of each wrapper points the old copy of this item.
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* - add item(s) command
|
2009-12-02 21:44:03 +00:00
|
|
|
* =>A list of item(s) is made. The .m_Item member of each wrapper points
|
|
|
|
* the new item.
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* Redo command
|
|
|
|
* - delete item(s) old command:
|
2009-07-25 04:53:39 +00:00
|
|
|
* => deleted items are moved in EEDrawList list, and in
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* - change item(s) command
|
2009-07-25 04:53:39 +00:00
|
|
|
* => the copy of item(s) is moved in Undo list
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* - add item(s) command
|
2009-12-02 21:44:03 +00:00
|
|
|
* => The list of item(s) is used to create a deleted list in undo
|
|
|
|
* list(same as a delete command)
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2009-12-02 21:44:03 +00:00
|
|
|
* Some block operations that change items can be undone without memorized
|
|
|
|
* items, just the coordinates of the transform: move list of items (undo/
|
|
|
|
* redo is made by moving with the opposite move vector) mirror (Y) and flip
|
|
|
|
* list of items (undo/redo is made by mirror or flip items) so they are
|
|
|
|
* handled specifically.
|
2009-07-29 13:10:36 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* A problem is the hierarchical sheet handling.
|
2009-12-02 21:44:03 +00:00
|
|
|
* the data associated (sub-hierarchy, undo/redo list) is deleted only
|
2007-09-01 12:00:30 +00:00
|
|
|
* when the sheet is really deleted (i.e. when deleted from undo or redo list)
|
2009-07-25 04:53:39 +00:00
|
|
|
* This is handled by its destructor.
|
2007-09-01 12:00:30 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Used if undo / redo command:
|
2007-09-01 12:00:30 +00:00
|
|
|
* swap data between Item and its copy, pointed by its .m_Image member
|
2009-07-25 04:53:39 +00:00
|
|
|
* swapped data is data modified by edition, so not all values are swapped
|
2007-09-01 12:00:30 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void SwapData( EDA_BaseStruct* aItem, EDA_BaseStruct* aImage )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-07-23 15:37:00 +00:00
|
|
|
if( aItem == NULL || aImage == NULL )
|
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
wxMessageBox( wxT( "SwapData error: NULL pointer" ) );
|
2007-09-01 12:00:30 +00:00
|
|
|
return;
|
2009-07-23 15:37:00 +00:00
|
|
|
}
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2009-07-23 15:37:00 +00:00
|
|
|
switch( aItem->Type() )
|
2007-09-01 12:00:30 +00:00
|
|
|
{
|
|
|
|
case DRAW_POLYLINE_STRUCT_TYPE:
|
|
|
|
#undef SOURCE
|
|
|
|
#undef DEST
|
2009-12-02 21:44:03 +00:00
|
|
|
#define SOURCE ( (SCH_POLYLINE*) aItem )
|
|
|
|
#define DEST ( (SCH_POLYLINE*) aImage )
|
2007-09-01 12:00:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_JUNCTION_STRUCT_TYPE:
|
|
|
|
#undef SOURCE
|
|
|
|
#undef DEST
|
2009-12-02 21:44:03 +00:00
|
|
|
#define SOURCE ( (SCH_JUNCTION*) aItem )
|
|
|
|
#define DEST ( (SCH_JUNCTION*) aImage )
|
2007-09-01 12:00:30 +00:00
|
|
|
EXCHG( SOURCE->m_Pos, DEST->m_Pos );
|
|
|
|
break;
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
case TYPE_SCH_LABEL:
|
|
|
|
case TYPE_SCH_GLOBALLABEL:
|
|
|
|
case TYPE_SCH_HIERLABEL:
|
|
|
|
case TYPE_SCH_TEXT:
|
2007-09-01 12:00:30 +00:00
|
|
|
#undef SOURCE
|
|
|
|
#undef DEST
|
2009-07-23 15:37:00 +00:00
|
|
|
#define SOURCE ( (SCH_TEXT*) aItem )
|
|
|
|
#define DEST ( (SCH_TEXT*) aImage )
|
2007-09-01 12:00:30 +00:00
|
|
|
DEST->SwapData( SOURCE );
|
|
|
|
break;
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
case TYPE_SCH_COMPONENT:
|
2007-09-01 12:00:30 +00:00
|
|
|
#undef SOURCE
|
|
|
|
#undef DEST
|
2009-07-23 15:37:00 +00:00
|
|
|
#define SOURCE ( (SCH_COMPONENT*) aItem )
|
|
|
|
#define DEST ( (SCH_COMPONENT*) aImage )
|
2007-09-01 12:00:30 +00:00
|
|
|
DEST->SwapData( SOURCE );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_SEGMENT_STRUCT_TYPE:
|
|
|
|
#undef SOURCE
|
|
|
|
#undef DEST
|
2009-12-02 21:44:03 +00:00
|
|
|
#define SOURCE ( (SCH_LINE*) aItem )
|
|
|
|
#define DEST ( (SCH_LINE*) aImage )
|
2007-09-01 12:00:30 +00:00
|
|
|
EXCHG( SOURCE->m_Start, DEST->m_Start );
|
|
|
|
EXCHG( SOURCE->m_End, DEST->m_End );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_BUSENTRY_STRUCT_TYPE:
|
|
|
|
#undef SOURCE
|
|
|
|
#undef DEST
|
2009-12-02 21:44:03 +00:00
|
|
|
#define SOURCE ( (SCH_BUS_ENTRY*) aItem )
|
|
|
|
#define DEST ( (SCH_BUS_ENTRY*) aImage )
|
2007-09-01 12:00:30 +00:00
|
|
|
EXCHG( SOURCE->m_Pos, DEST->m_Pos );
|
|
|
|
EXCHG( SOURCE->m_Size, DEST->m_Size );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_SHEET_STRUCT_TYPE:
|
|
|
|
#undef SOURCE
|
|
|
|
#undef DEST
|
2009-11-04 20:46:53 +00:00
|
|
|
#define SOURCE ( (SCH_SHEET*) aItem )
|
|
|
|
#define DEST ( (SCH_SHEET*) aImage )
|
2007-09-01 12:00:30 +00:00
|
|
|
DEST->SwapData( SOURCE );
|
|
|
|
break;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
case TYPE_SCH_MARKER:
|
2007-09-01 12:00:30 +00:00
|
|
|
#undef SOURCE
|
|
|
|
#undef DEST
|
2009-12-02 21:44:03 +00:00
|
|
|
#define SOURCE ( (SCH_MARKER*) aItem )
|
|
|
|
#define DEST ( (SCH_MARKER*) aImage )
|
2007-09-01 12:00:30 +00:00
|
|
|
EXCHG( SOURCE->m_Pos, DEST->m_Pos );
|
|
|
|
break;
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE:
|
2007-09-01 12:00:30 +00:00
|
|
|
#undef SOURCE
|
|
|
|
#undef DEST
|
2009-11-04 20:46:53 +00:00
|
|
|
#define SOURCE ( (SCH_SHEET_PIN*) aItem )
|
|
|
|
#define DEST ( (SCH_SHEET_PIN*) aImage )
|
2010-09-05 17:01:48 +00:00
|
|
|
DEST->SwapData( SOURCE );
|
2007-09-01 12:00:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_NOCONNECT_STRUCT_TYPE:
|
|
|
|
#undef SOURCE
|
|
|
|
#undef DEST
|
2009-12-02 21:44:03 +00:00
|
|
|
#define SOURCE ( (SCH_NO_CONNECT*) aItem )
|
|
|
|
#define DEST ( (SCH_NO_CONNECT*) aImage )
|
2007-09-01 12:00:30 +00:00
|
|
|
EXCHG( SOURCE->m_Pos, DEST->m_Pos );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_PART_TEXT_STRUCT_TYPE:
|
|
|
|
break;
|
|
|
|
|
2009-07-23 15:37:00 +00:00
|
|
|
// not directly used in schematic:
|
2007-09-01 12:00:30 +00:00
|
|
|
default:
|
2010-09-05 17:01:48 +00:00
|
|
|
wxMessageBox( wxT( "SwapData() error: unexpected type" ) );
|
2007-09-01 12:00:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2007-09-01 12:00:30 +00:00
|
|
|
|
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
/** function SaveCopyInUndoList
|
|
|
|
* Create a copy of the current schematic item, and put it in the undo list.
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* flag_type_command =
|
2009-07-26 17:16:42 +00:00
|
|
|
* UR_CHANGED
|
|
|
|
* UR_NEW
|
|
|
|
* UR_DELETED
|
|
|
|
* UR_WIRE_IMAGE
|
2009-08-03 07:55:08 +00:00
|
|
|
* UR_MOVED
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2009-12-02 21:44:03 +00:00
|
|
|
* If it is a delete command, items are put on list with the .Flags member
|
|
|
|
* set to UR_DELETED. When it will be really deleted, the EEDrawList and the
|
|
|
|
* sub-hierarchy will be deleted. If it is only a copy, the EEDrawList and the
|
|
|
|
* sub-hierarchy must NOT be deleted.
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2009-12-02 21:44:03 +00:00
|
|
|
* Note:
|
|
|
|
* Edit wires and buses is a bit complex.
|
|
|
|
* because when a new wire is added, modifications in wire list
|
|
|
|
* (wire concatenation) there are modified items, deleted items and new items
|
|
|
|
* so flag_type_command is UR_WIRE_IMAGE: the struct ItemToCopy is a list of
|
|
|
|
* wires saved in Undo List (for Undo or Redo commands, saved wires will be
|
|
|
|
* exchanged with current wire list
|
2007-09-01 12:00:30 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void WinEDA_SchematicFrame::SaveCopyInUndoList( SCH_ITEM* aItem,
|
|
|
|
UndoRedoOpType aCommandType,
|
|
|
|
const wxPoint& aTransformPoint )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-04 18:21:32 +00:00
|
|
|
/* Does not save a null item.
|
|
|
|
* but if aCommandType == UR_WIRE_IMAGE, we must save null item.
|
|
|
|
* It happens for the first wire entered in schematic:
|
|
|
|
* To undo this first command, the previous state is a NULL item,
|
|
|
|
* and we accept this
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
if( aItem == NULL && ( aCommandType != UR_WIRE_IMAGE ) )
|
2009-08-04 18:21:32 +00:00
|
|
|
return;
|
|
|
|
|
2009-07-23 15:37:00 +00:00
|
|
|
SCH_ITEM* CopyOfItem;
|
|
|
|
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
|
2009-07-26 17:16:42 +00:00
|
|
|
commandToUndo->m_TransformPoint = aTransformPoint;
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
ITEM_PICKER itemWrapper( aItem, aCommandType );
|
2009-08-04 18:21:32 +00:00
|
|
|
if( aItem )
|
2009-08-27 13:51:02 +00:00
|
|
|
{
|
2009-08-04 18:21:32 +00:00
|
|
|
itemWrapper.m_PickedItemType = aItem->Type();
|
2010-09-05 17:01:48 +00:00
|
|
|
itemWrapper.m_PickerFlags = aItem->m_Flags;
|
2009-08-27 13:51:02 +00:00
|
|
|
}
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2009-07-25 07:31:07 +00:00
|
|
|
switch( aCommandType )
|
2007-09-01 12:00:30 +00:00
|
|
|
{
|
2009-08-03 07:55:08 +00:00
|
|
|
case UR_CHANGED: /* Create a copy of item */
|
2010-03-24 18:26:04 +00:00
|
|
|
CopyOfItem = DuplicateStruct( aItem, true );
|
2009-08-03 07:55:08 +00:00
|
|
|
itemWrapper.m_Link = CopyOfItem;
|
2010-09-05 17:01:48 +00:00
|
|
|
if( CopyOfItem )
|
2009-07-29 13:10:36 +00:00
|
|
|
commandToUndo->PushItem( itemWrapper );
|
2009-07-25 07:31:07 +00:00
|
|
|
break;
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2009-07-26 17:16:42 +00:00
|
|
|
case UR_NEW:
|
|
|
|
case UR_WIRE_IMAGE:
|
|
|
|
case UR_DELETED:
|
|
|
|
case UR_MOVED:
|
2009-07-25 07:31:07 +00:00
|
|
|
commandToUndo->PushItem( itemWrapper );
|
2009-07-25 04:53:39 +00:00
|
|
|
break;
|
2009-07-25 07:31:07 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
wxString msg;
|
2009-12-02 21:44:03 +00:00
|
|
|
msg.Printf( wxT( "SaveCopyInUndoList() error (unknown code %X)" ),
|
|
|
|
aCommandType );
|
2009-07-29 13:10:36 +00:00
|
|
|
wxMessageBox( msg );
|
2009-07-25 07:31:07 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-07-25 04:53:39 +00:00
|
|
|
}
|
2009-07-25 07:31:07 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
if( commandToUndo->GetCount() )
|
|
|
|
{
|
|
|
|
/* Save the copy in undo list */
|
|
|
|
GetScreen()->PushCommandToUndoList( commandToUndo );
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
/* Clear redo list, because after new save there is no redo to do */
|
|
|
|
GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
delete commandToUndo;
|
2009-07-25 04:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** function SaveCopyInUndoList
|
|
|
|
* @param aItemsList = a PICKED_ITEMS_LIST of items to save
|
2009-12-02 21:44:03 +00:00
|
|
|
* @param aTypeCommand = type of command ( UR_CHANGED, UR_NEW, UR_DELETED ...
|
2009-07-25 04:53:39 +00:00
|
|
|
*/
|
2009-07-26 17:16:42 +00:00
|
|
|
void WinEDA_SchematicFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
|
|
|
|
UndoRedoOpType aTypeCommand,
|
2010-09-05 17:01:48 +00:00
|
|
|
const wxPoint& aTransformPoint )
|
2009-07-25 04:53:39 +00:00
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-07-26 17:16:42 +00:00
|
|
|
commandToUndo->m_TransformPoint = aTransformPoint;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-08-06 15:42:09 +00:00
|
|
|
// Copy picker list:
|
|
|
|
commandToUndo->CopyList( aItemsList );
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2009-08-06 15:42:09 +00:00
|
|
|
// Verify list, and creates data if needed
|
|
|
|
for( unsigned ii = 0; ii < commandToUndo->GetCount(); ii++ )
|
2009-07-25 04:53:39 +00:00
|
|
|
{
|
2009-08-06 15:42:09 +00:00
|
|
|
SCH_ITEM* item = (SCH_ITEM*) commandToUndo->GetPickedItem( ii );
|
|
|
|
wxASSERT( item );
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
UndoRedoOpType command = commandToUndo->GetPickedItemStatus( ii );
|
2009-07-26 17:16:42 +00:00
|
|
|
if( command == UR_UNSPECIFIED )
|
2009-07-25 04:53:39 +00:00
|
|
|
{
|
|
|
|
command = aTypeCommand;
|
2010-09-05 17:01:48 +00:00
|
|
|
commandToUndo->SetPickedItemStatus( command, ii );
|
2009-07-23 15:37:00 +00:00
|
|
|
}
|
2009-08-06 15:42:09 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
switch( command )
|
|
|
|
{
|
2009-08-03 07:55:08 +00:00
|
|
|
case UR_CHANGED: /* Create a copy of item */
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-08-06 15:42:09 +00:00
|
|
|
/* If needed, create a copy of item, and put in undo list
|
|
|
|
* in the picker, as link
|
|
|
|
* If this link is not null, the copy is already done
|
|
|
|
*/
|
2010-09-05 17:01:48 +00:00
|
|
|
if( commandToUndo->GetPickedItemLink( ii ) == NULL )
|
2010-03-24 18:26:04 +00:00
|
|
|
commandToUndo->SetPickedItemLink( DuplicateStruct( item, true ), ii );
|
2010-09-05 17:01:48 +00:00
|
|
|
wxASSERT( commandToUndo->GetPickedItemLink( ii ) );
|
2009-07-25 04:53:39 +00:00
|
|
|
break;
|
|
|
|
|
2009-07-26 17:16:42 +00:00
|
|
|
case UR_MOVED:
|
|
|
|
case UR_MIRRORED_Y:
|
2010-09-05 17:01:48 +00:00
|
|
|
case UR_MIRRORED_X:
|
|
|
|
case UR_ROTATED:
|
2009-07-26 17:16:42 +00:00
|
|
|
case UR_NEW:
|
|
|
|
case UR_DELETED:
|
2007-09-01 12:00:30 +00:00
|
|
|
break;
|
2009-07-25 04:53:39 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
wxString msg;
|
2009-12-02 21:44:03 +00:00
|
|
|
msg.Printf( wxT( "SaveCopyInUndoList() error (unknown code %X)" ),
|
|
|
|
command );
|
2009-07-29 13:10:36 +00:00
|
|
|
wxMessageBox( msg );
|
2009-07-25 04:53:39 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-09-01 12:00:30 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
if( commandToUndo->GetCount() )
|
|
|
|
{
|
|
|
|
/* Save the copy in undo list */
|
|
|
|
GetScreen()->PushCommandToUndoList( commandToUndo );
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
/* Clear redo list, because after new save there is no redo to do */
|
|
|
|
GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList );
|
|
|
|
}
|
2009-08-06 15:42:09 +00:00
|
|
|
else // Should not occur
|
2009-07-29 13:10:36 +00:00
|
|
|
delete commandToUndo;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/** Function PutDataInPreviousState()
|
|
|
|
* Used in undo or redo command.
|
2009-12-02 21:44:03 +00:00
|
|
|
* Put data pointed by List in the previous state, i.e. the state memorized
|
|
|
|
* by List
|
2009-08-01 19:26:05 +00:00
|
|
|
* @param aList = a PICKED_ITEMS_LIST pointer to the list of items to undo/redo
|
|
|
|
* @param aRedoCommand = a bool: true for redo, false for undo
|
2007-09-01 12:00:30 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void WinEDA_SchematicFrame::PutDataInPreviousState( PICKED_ITEMS_LIST* aList,
|
2010-09-05 17:01:48 +00:00
|
|
|
bool aRedoCommand )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
SCH_ITEM* item;
|
|
|
|
SCH_ITEM* alt_item;
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
// Undo in the reverse order of list creation: (this can allow stacked
|
|
|
|
// changes like the same item can be changes and deleted in the same
|
|
|
|
// complex command
|
2010-09-05 17:01:48 +00:00
|
|
|
for( int ii = aList->GetCount() - 1; ii >= 0; ii-- )
|
2007-09-01 12:00:30 +00:00
|
|
|
{
|
2009-07-23 15:37:00 +00:00
|
|
|
ITEM_PICKER itemWrapper = aList->GetItemWrapper( ii );
|
2009-07-31 05:33:11 +00:00
|
|
|
item = (SCH_ITEM*) itemWrapper.m_PickedItem;
|
2010-09-05 17:01:48 +00:00
|
|
|
if( item )
|
2009-08-04 18:21:32 +00:00
|
|
|
item->m_Flags = 0;
|
2010-09-05 17:01:48 +00:00
|
|
|
SCH_ITEM* image = (SCH_ITEM*) itemWrapper.m_Link;
|
2009-07-23 15:37:00 +00:00
|
|
|
switch( itemWrapper.m_UndoRedoStatus )
|
2007-09-01 12:00:30 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
case UR_CHANGED: /* Exchange old and new data for each item */
|
2009-07-23 15:37:00 +00:00
|
|
|
SwapData( item, image );
|
2007-09-01 12:00:30 +00:00
|
|
|
break;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
case UR_NEW: /* new items are deleted */
|
2009-07-31 05:33:11 +00:00
|
|
|
aList->SetPickedItemStatus( UR_DELETED, ii );
|
2009-07-23 15:37:00 +00:00
|
|
|
GetScreen()->RemoveFromDrawList( item );
|
|
|
|
break;
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
case UR_DELETED: /* deleted items are put in EEdrawList, as new items */
|
2009-07-31 05:33:11 +00:00
|
|
|
aList->SetPickedItemStatus( UR_NEW, ii );
|
2009-07-23 15:37:00 +00:00
|
|
|
item->SetNext( GetScreen()->EEDrawList );
|
|
|
|
GetScreen()->EEDrawList = item;
|
|
|
|
break;
|
|
|
|
|
2009-07-26 17:16:42 +00:00
|
|
|
case UR_MOVED:
|
2010-09-05 17:01:48 +00:00
|
|
|
item->m_Flags = aList->GetPickerFlags( ii );
|
2009-12-02 21:44:03 +00:00
|
|
|
item->Move( aRedoCommand ?
|
2010-09-05 17:01:48 +00:00
|
|
|
aList->m_TransformPoint : -aList->m_TransformPoint );
|
2009-08-27 13:51:02 +00:00
|
|
|
item->m_Flags = 0;
|
2009-07-26 17:16:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_MIRRORED_Y:
|
|
|
|
{
|
|
|
|
wxPoint mirrorPoint = aList->m_TransformPoint;
|
2009-07-27 14:32:40 +00:00
|
|
|
item->Mirror_Y( mirrorPoint.x );
|
2009-07-26 17:16:42 +00:00
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_MIRRORED_X:
|
|
|
|
{
|
|
|
|
wxPoint mirrorPoint = aList->m_TransformPoint;
|
|
|
|
item->Mirror_X( mirrorPoint.y );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_ROTATED:
|
|
|
|
{
|
|
|
|
wxPoint RotationPoint = aList->m_TransformPoint;
|
|
|
|
item->Rotate( RotationPoint );
|
|
|
|
item->Rotate( RotationPoint );
|
|
|
|
item->Rotate( RotationPoint );
|
|
|
|
}
|
|
|
|
break;
|
2009-07-26 17:16:42 +00:00
|
|
|
|
|
|
|
case UR_WIRE_IMAGE:
|
2009-07-23 15:37:00 +00:00
|
|
|
/* Exchange the current wires and the old wires */
|
|
|
|
alt_item = GetScreen()->ExtractWires( false );
|
2009-07-31 05:33:11 +00:00
|
|
|
aList->SetPickedItem( alt_item, ii );
|
2009-07-23 15:37:00 +00:00
|
|
|
while( item )
|
2007-09-01 12:00:30 +00:00
|
|
|
{
|
2009-07-23 15:37:00 +00:00
|
|
|
SCH_ITEM* nextitem = item->Next();
|
2008-11-24 06:53:43 +00:00
|
|
|
item->SetNext( GetScreen()->EEDrawList );
|
2007-09-01 12:00:30 +00:00
|
|
|
GetScreen()->EEDrawList = item;
|
|
|
|
item->m_Flags = 0;
|
2009-07-23 15:37:00 +00:00
|
|
|
item = nextitem;
|
2007-09-01 12:00:30 +00:00
|
|
|
}
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2009-07-23 15:37:00 +00:00
|
|
|
break;
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2009-07-23 15:37:00 +00:00
|
|
|
default:
|
2007-09-01 12:00:30 +00:00
|
|
|
{
|
2009-07-23 15:37:00 +00:00
|
|
|
wxString msg;
|
2009-12-02 21:44:03 +00:00
|
|
|
msg.Printf( wxT( "PutDataInPreviousState() error (unknown code %X)" ),
|
2009-07-25 04:53:39 +00:00
|
|
|
itemWrapper.m_UndoRedoStatus );
|
2009-07-29 13:10:36 +00:00
|
|
|
wxMessageBox( msg );
|
2007-09-01 12:00:30 +00:00
|
|
|
}
|
2009-07-25 04:53:39 +00:00
|
|
|
break;
|
2007-09-01 12:00:30 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
/** Function GetSchematicFromUndoList
|
|
|
|
* Undo the last edition:
|
2007-09-01 12:00:30 +00:00
|
|
|
* - Save the current schematic in Redo list
|
2009-12-02 21:44:03 +00:00
|
|
|
* - Get the previous version of the schematic from undo list
|
2009-08-01 19:26:05 +00:00
|
|
|
* @return none
|
2007-09-01 12:00:30 +00:00
|
|
|
*/
|
2010-09-05 17:01:48 +00:00
|
|
|
void WinEDA_SchematicFrame::GetSchematicFromUndoList( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-07-23 15:37:00 +00:00
|
|
|
if( GetScreen()->GetUndoCommandCount() <= 0 )
|
2009-07-29 13:10:36 +00:00
|
|
|
return;
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
/* Get the old list */
|
2009-07-23 15:37:00 +00:00
|
|
|
PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromUndoList();
|
2009-08-11 10:27:21 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
/* Undo the command */
|
2009-08-01 19:26:05 +00:00
|
|
|
PutDataInPreviousState( List, false );
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
/* Put the old list in RedoList */
|
|
|
|
List->ReversePickersListOrder();
|
|
|
|
GetScreen()->PushCommandToRedoList( List );
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
// m_drawItem = NULL;
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2009-01-06 20:09:32 +00:00
|
|
|
SetSheetNumberAndCount();
|
2007-09-01 12:00:30 +00:00
|
|
|
ReCreateHToolbar();
|
|
|
|
SetToolbars();
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
TestDanglingEnds( GetScreen()->EEDrawList, NULL );
|
2010-09-05 17:01:48 +00:00
|
|
|
DrawPanel->Refresh();
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/** Function GetSchematicFromRedoList
|
|
|
|
* Redo the last edition:
|
2009-07-29 13:10:36 +00:00
|
|
|
* - Save the current schematic in undo list
|
2009-08-01 19:26:05 +00:00
|
|
|
* - Get the previous version from Redo list
|
|
|
|
* @return none
|
2009-07-29 13:10:36 +00:00
|
|
|
*/
|
2010-09-05 17:01:48 +00:00
|
|
|
void WinEDA_SchematicFrame::GetSchematicFromRedoList( wxCommandEvent& event )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
|
|
|
if( GetScreen()->GetRedoCommandCount() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
/* Get the old list */
|
2009-07-29 13:10:36 +00:00
|
|
|
PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromRedoList();
|
|
|
|
|
|
|
|
/* Redo the command: */
|
2009-08-01 19:26:05 +00:00
|
|
|
PutDataInPreviousState( List, true );
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
/* Put the old list in UndoList */
|
|
|
|
List->ReversePickersListOrder();
|
|
|
|
GetScreen()->PushCommandToUndoList( List );
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
// m_drawItem = NULL;
|
2010-09-05 17:01:48 +00:00
|
|
|
OnModify();
|
2009-07-29 13:10:36 +00:00
|
|
|
SetSheetNumberAndCount();
|
|
|
|
ReCreateHToolbar();
|
|
|
|
SetToolbars();
|
|
|
|
|
|
|
|
TestDanglingEnds( GetScreen()->EEDrawList, NULL );
|
2010-09-05 17:01:48 +00:00
|
|
|
DrawPanel->Refresh();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|