kicad/eeschema/schematic_undo_redo.cpp

703 lines
22 KiB
C++
Raw Normal View History

2007-09-01 12:00:30 +00:00
/********************************************/
/* library editor: undo and redo functions */
/********************************************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "confirm.h"
#include "class_drawpickedstruct.h"
#include "program.h"
#include "libcmp.h"
#include "general.h"
#include "id.h"
#include "protos.h"
/* Functions to undo and redo edit commands.
2007-09-01 12:00:30 +00:00
* commmands to undo are in CurrentScreen->m_UndoList
* commmands to redo are in CurrentScreen->m_RedoList
2008-02-26 19:19:54 +00:00
*
2007-09-01 12:00:30 +00:00
* m_UndoList and m_RedoList are a linked list of DrawPickedStruct.
* each DrawPickedStruct has its .m_Son member pointing to an item to undo or redo,
* or to a list of DrawPickedStruct which points (.m_PickedStruct membre)
* the items to undo or redo
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
2008-02-26 19:19:54 +00:00
*
2007-09-01 12:00:30 +00:00
* Undo command
* - delete item(s) command:
* 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
* A copy of item(s) is made (a DrawPickedStruct list of wrappers)
* the .m_Image member of each wrapper points the modified item.
2008-02-26 19:19:54 +00:00
*
2007-09-01 12:00:30 +00:00
* - add item(s) command
* A list of item(s) is made
* the .m_Image 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:
* deleted items are moved in EEDrawList list
2008-02-26 19:19:54 +00:00
*
2007-09-01 12:00:30 +00:00
* - change item(s) command
* 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
* 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
*
2007-09-01 12:00:30 +00:00
* A problem is the hierarchical sheet handling.
* the data associated (subhierarchy, uno/redo list) is deleted only
* when the sheet is really deleted (i.e. when deleted from undo or redo list)
* and not when it is a copy.
*/
/************************************/
2007-09-01 12:00:30 +00:00
void SwapData( EDA_BaseStruct* Item )
/************************************/
2007-09-01 12:00:30 +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
*/
{
2007-09-01 12:00:30 +00:00
if( Item == NULL )
return;
EDA_BaseStruct* image = Item->m_Image;
if( image == NULL )
return;
switch( Item->Type() )
{
case DRAW_POLYLINE_STRUCT_TYPE:
#undef SOURCE
#undef DEST
#define SOURCE ( (DrawPolylineStruct*) Item )
#define DEST ( (DrawPolylineStruct*) image )
break;
case DRAW_JUNCTION_STRUCT_TYPE:
#undef SOURCE
#undef DEST
#define SOURCE ( (DrawJunctionStruct*) Item )
#define DEST ( (DrawJunctionStruct*) image )
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
2008-03-20 01:50:21 +00:00
#define SOURCE ( (SCH_TEXT*) Item )
#define DEST ( (SCH_TEXT*) image )
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
2008-03-20 01:50:21 +00:00
#define SOURCE ( (SCH_COMPONENT*) Item )
#define DEST ( (SCH_COMPONENT*) image )
2007-09-01 12:00:30 +00:00
DEST->SwapData( SOURCE );
break;
case DRAW_SEGMENT_STRUCT_TYPE:
#undef SOURCE
#undef DEST
#define SOURCE ( (EDA_DrawLineStruct*) Item )
#define DEST ( (EDA_DrawLineStruct*) image )
EXCHG( SOURCE->m_Start, DEST->m_Start );
EXCHG( SOURCE->m_End, DEST->m_End );
break;
case DRAW_BUSENTRY_STRUCT_TYPE:
#undef SOURCE
#undef DEST
#define SOURCE ( (DrawBusEntryStruct*) Item )
#define DEST ( (DrawBusEntryStruct*) image )
EXCHG( SOURCE->m_Pos, DEST->m_Pos );
EXCHG( SOURCE->m_Size, DEST->m_Size );
break;
case DRAW_SHEET_STRUCT_TYPE:
#undef SOURCE
#undef DEST
#define SOURCE ( (DrawSheetStruct*) Item )
#define DEST ( (DrawSheetStruct*) image )
DEST->SwapData( SOURCE );
break;
case DRAW_MARKER_STRUCT_TYPE:
#undef SOURCE
#undef DEST
#define SOURCE ( (DrawMarkerStruct*) Item )
#define DEST ( (DrawMarkerStruct*) image )
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
2008-04-15 19:38:19 +00:00
#define SOURCE ( (Hierarchical_PIN_Sheet_Struct*) Item )
#define DEST ( (Hierarchical_PIN_Sheet_Struct*) image )
2007-09-01 12:00:30 +00:00
EXCHG( SOURCE->m_Edge, DEST->m_Edge );
EXCHG( SOURCE->m_Shape, DEST->m_Shape );
break;
case DRAW_NOCONNECT_STRUCT_TYPE:
#undef SOURCE
#undef DEST
#define SOURCE ( (DrawNoConnectStruct*) Item )
#define DEST ( (DrawNoConnectStruct*) image )
EXCHG( SOURCE->m_Pos, DEST->m_Pos );
break;
case DRAW_PART_TEXT_STRUCT_TYPE:
#undef SOURCE
#undef DEST
#define SOURCE ( (DrawPolylineStruct*) Item )
#define DEST ( (DrawPolylineStruct*) image )
break;
// not directly used in schematic:
default:
DisplayInfoMessage( NULL, wxT( "SwapData() error: unexpected type" ) );
2007-09-01 12:00:30 +00:00
break;
}
}
2007-09-01 12:00:30 +00:00
/***********************************************************************/
void WinEDA_SchematicFrame::SaveCopyInUndoList( SCH_ITEM * ItemToCopy,
2007-09-01 12:00:30 +00:00
int flag_type_command )
2007-05-06 16:03:28 +00:00
/***********************************************************************/
2007-09-01 12:00:30 +00:00
2007-05-06 16:03:28 +00:00
/* Create a copy of the current schematic draw list, and put it in the undo list.
2007-09-01 12:00:30 +00:00
* A DrawPickedStruct wrapper is created to handle the draw list.
* the .m_Son of this wrapper points the list of items
2008-02-26 19:19:54 +00:00
*
2007-09-01 12:00:30 +00:00
* flag_type_command =
* 0 (unspecified)
* IS_CHANGED
* IS_NEW
* IS_DELETED
* IS_WIRE_IMAGE
2008-02-26 19:19:54 +00:00
*
2007-09-01 12:00:30 +00:00
* for 0: only a wrapper is created. The used must init the .Flags member of the
* wrapper, and add the item list to the wrapper
* If it is a delete command, items are put on list with the .Flags member set to IS_DELETED.
* When it will be really deleted, the EEDrawList and the subhierarchy will be deleted.
* If it is only a copy, the EEDrawList and the subhierarchy must NOT be deleted.
2008-02-26 19:19:54 +00:00
*
2007-09-01 12:00:30 +00:00
* Note:
* Edit wires and busses 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 IS_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
*/
{
SCH_ITEM* CopyItem;
2007-09-01 12:00:30 +00:00
DrawPickedStruct* NewList = new DrawPickedStruct( NULL );
NewList->m_Flags = flag_type_command;
if( ItemToCopy )
{
switch( flag_type_command )
{
case 0:
break;
case IS_CHANGED: /* Create a copy of schematic */
CopyItem = DuplicateStruct( ItemToCopy );
NewList->SetSon( CopyItem );
2007-09-01 12:00:30 +00:00
if( ItemToCopy->Type() == DRAW_PICK_ITEM_STRUCT_TYPE )
{
DrawPickedStruct* PickedList = (DrawPickedStruct*) CopyItem;
while( PickedList )
{
CopyItem = (SCH_ITEM*) PickedList->m_PickedStruct;
2007-09-01 12:00:30 +00:00
CopyItem->m_Flags = flag_type_command;
PickedList->m_Image = CopyItem->m_Image;
PickedList = PickedList->Next();
2007-09-01 12:00:30 +00:00
}
}
else
{
CopyItem->m_Flags = flag_type_command;
CopyItem->m_Image = ItemToCopy;
}
break;
case IS_NEW:
if( ItemToCopy->Type() == DRAW_PICK_ITEM_STRUCT_TYPE )
{
NewList->SetSon( ItemToCopy );
2007-09-01 12:00:30 +00:00
DrawPickedStruct* PickedList = (DrawPickedStruct*) ItemToCopy;
while( PickedList )
{
CopyItem = (SCH_ITEM*) PickedList->m_PickedStruct;
2007-09-01 12:00:30 +00:00
PickedList->m_Image = CopyItem;
PickedList->m_PickedStruct = NULL;
PickedList->m_Flags = flag_type_command;
PickedList = PickedList->Next();
2007-09-01 12:00:30 +00:00
}
}
else
{
NewList->m_Image = ItemToCopy;
}
break;
case IS_NEW | IS_CHANGED:
case IS_WIRE_IMAGE:
NewList->SetSon( ItemToCopy );
2007-09-01 12:00:30 +00:00
break;
case IS_DELETED:
NewList->SetSon( ItemToCopy );
2007-09-01 12:00:30 +00:00
ItemToCopy->m_Flags = flag_type_command;
if( ItemToCopy->Type() == DRAW_PICK_ITEM_STRUCT_TYPE )
{
DrawPickedStruct* PickedList = (DrawPickedStruct*) ItemToCopy;
while( PickedList )
{
CopyItem = (SCH_ITEM*) PickedList->m_PickedStruct;
2007-09-01 12:00:30 +00:00
CopyItem->m_Flags = flag_type_command;
PickedList->m_Flags = flag_type_command;
PickedList = PickedList->Next();
2007-09-01 12:00:30 +00:00
}
}
break;
default:
DisplayError( this, wxT( "SaveCopyInUndoList() error" ) );
break;
}
}
/* Save the copy in undo list */
GetScreen()->AddItemToUndoList( NewList );
/* Clear redo list, because after new save there is no redo to do */
2008-02-26 19:19:54 +00:00
( (SCH_SCREEN*) GetScreen() )->ClearUndoORRedoList( GetScreen()->m_RedoList );
2007-09-01 12:00:30 +00:00
GetScreen()->m_RedoList = NULL;
}
2007-09-01 12:00:30 +00:00
/**********************************************************/
2008-02-26 19:19:54 +00:00
bool WinEDA_SchematicFrame::GetSchematicFromRedoList()
2007-05-06 16:03:28 +00:00
/**********************************************************/
2007-09-01 12:00:30 +00:00
/* Redo the last edition:
2007-09-01 12:00:30 +00:00
* - Save the current schematic in undo list
* - Get the old version
* @return FALSE if nothing done, else true
2007-09-01 12:00:30 +00:00
*/
{
2007-09-01 12:00:30 +00:00
if( GetScreen()->m_RedoList == NULL )
2007-09-19 15:29:50 +00:00
return FALSE;
2007-09-01 12:00:30 +00:00
/* Get the old wrapper and put it in UndoList */
DrawPickedStruct* List = (DrawPickedStruct*) GetScreen()->GetItemFromRedoList();
GetScreen()->AddItemToUndoList( List );
/* Redo the command: */
PutDataInPreviousState( List );
CurrentDrawItem = NULL;
GetScreen()->SetModify();
SetSheetNumberAndCount();
2007-09-01 12:00:30 +00:00
ReCreateHToolbar();
SetToolbars();
2008-02-26 19:19:54 +00:00
return true;
2007-05-06 16:03:28 +00:00
}
/***************************************************************************/
2007-09-01 12:00:30 +00:00
void WinEDA_SchematicFrame::PutDataInPreviousState( DrawPickedStruct* List )
/***************************************************************************/
2007-09-01 12:00:30 +00:00
/* Used in undo or redo command.
2007-09-01 12:00:30 +00:00
* Put data pointed by List in the previous state, i.e. the state memorised by List
*/
{
SCH_ITEM* FirstItem = (SCH_ITEM*) List->GetSon();
SCH_ITEM* item;
2007-09-01 12:00:30 +00:00
DrawPickedStruct* PickedList;
switch( List->m_Flags )
{
case IS_CHANGED: /* Exchange old and new data for each item */
if( FirstItem == NULL )
{
DisplayError( this, wxT( "PutDataInPreviousState() error : Null item" ) );
break;
}
if( FirstItem->Type() == DRAW_PICK_ITEM_STRUCT_TYPE )
{
DrawPickedStruct* PickedList = (DrawPickedStruct*) FirstItem;
while( PickedList )
{
SwapData( PickedList->m_PickedStruct );
PickedList = PickedList->Next();
}
}
else
{
SwapData( FirstItem );
}
break;
case IS_NEW: /* new items are deleted */
List->m_Flags = IS_DELETED;
if( FirstItem && FirstItem->Type() == DRAW_PICK_ITEM_STRUCT_TYPE )
{
PickedList = (DrawPickedStruct*) FirstItem;
while( PickedList )
{
item = (SCH_ITEM*) PickedList->m_Image;
2008-02-26 19:19:54 +00:00
( (SCH_SCREEN*) GetScreen() )->RemoveFromDrawList( item );
2007-09-01 12:00:30 +00:00
item->m_Flags = IS_DELETED;
PickedList->m_PickedStruct = item;
PickedList->m_Flags = IS_DELETED;
PickedList = PickedList->Next();
}
}
else
{
FirstItem = (SCH_ITEM*)List->m_Image;
2008-02-26 19:19:54 +00:00
( (SCH_SCREEN*) GetScreen() )->RemoveFromDrawList( FirstItem );
2007-09-01 12:00:30 +00:00
FirstItem->m_Flags = IS_DELETED;
List->SetSon( FirstItem );
2007-09-01 12:00:30 +00:00
}
break;
case IS_DELETED: /* deleted items are put in EEdrawList, as new items */
List->m_Flags = IS_NEW;
if( FirstItem->Type() == DRAW_PICK_ITEM_STRUCT_TYPE )
{
PickedList = (DrawPickedStruct*) FirstItem;
while( PickedList )
{
item = (SCH_ITEM*) PickedList->m_PickedStruct;
item->SetNext( GetScreen()->EEDrawList );
2007-09-01 12:00:30 +00:00
GetScreen()->EEDrawList = item;
item->m_Flags = 0;
PickedList->m_PickedStruct = NULL;
PickedList->m_Image = item;
PickedList->m_Flags = IS_NEW;
PickedList = PickedList->Next();
}
}
else
{
FirstItem->SetNext( GetScreen()->EEDrawList );
2007-09-01 12:00:30 +00:00
GetScreen()->EEDrawList = FirstItem;
FirstItem->m_Flags = 0;
List->m_Image = List->GetSon();
List->SetSon( NULL );
2007-09-01 12:00:30 +00:00
}
break;
case IS_WIRE_IMAGE:
/* Exchange the current wires and the old wires */
List->SetSon( ( (SCH_SCREEN*) GetScreen() )->ExtractWires( FALSE ) );
2007-09-01 12:00:30 +00:00
while( FirstItem )
{
SCH_ITEM* nextitem = FirstItem->Next();
FirstItem->SetNext( GetScreen()->EEDrawList );
2007-09-01 12:00:30 +00:00
GetScreen()->EEDrawList = FirstItem;
FirstItem->m_Flags = 0;
FirstItem = nextitem;
}
break;
case IS_NEW | IS_CHANGED:
case IS_DELETED | IS_CHANGED:
if( !FirstItem || FirstItem->Type() != DRAW_PICK_ITEM_STRUCT_TYPE )
{
DisplayError( this, wxT( "GetSchematicFromUndoList() error: Pickstruct expected" ) );
break;
}
PickedList = (DrawPickedStruct*) FirstItem;
while( PickedList )
{
switch( PickedList->m_Flags )
{
case IS_CHANGED:
SwapData( PickedList->m_PickedStruct );
break;
case IS_NEW:
item = (SCH_ITEM*) PickedList->m_Image;
2008-02-26 19:19:54 +00:00
( (SCH_SCREEN*) GetScreen() )->RemoveFromDrawList( item );
2007-09-01 12:00:30 +00:00
item->m_Flags = IS_DELETED;
PickedList->m_PickedStruct = item;
PickedList->m_Flags = IS_DELETED;
break;
case IS_DELETED:
item = (SCH_ITEM*) PickedList->m_PickedStruct;
item->SetNext( GetScreen()->EEDrawList );
2007-09-01 12:00:30 +00:00
GetScreen()->EEDrawList = item;
item->m_Flags = 0;
PickedList->m_PickedStruct = NULL;
PickedList->m_Image = item;
PickedList->m_Flags = IS_NEW;
break;
}
PickedList = PickedList->Next();
}
break;
default:
DisplayError( this, wxT( "GetSchematicFromUndoList() error: Unknown cmd" ) );
break;
}
}
2007-09-01 12:00:30 +00:00
2007-05-06 16:03:28 +00:00
/**********************************************************/
2007-09-19 15:29:50 +00:00
bool WinEDA_SchematicFrame::GetSchematicFromUndoList()
2007-05-06 16:03:28 +00:00
/**********************************************************/
2007-09-01 12:00:30 +00:00
/** Function GetSchematicFromUndoList
* Undo the last edition:
2007-09-01 12:00:30 +00:00
* - Save the current schematic in Redo list
* - Get an old version of the schematic
* @return FALSE if nothing done, else true
2007-09-01 12:00:30 +00:00
*/
{
2007-09-01 12:00:30 +00:00
if( GetScreen()->m_UndoList == NULL )
2007-09-19 15:29:50 +00:00
return FALSE;
2007-09-01 12:00:30 +00:00
/* Get the old wrapper and put it in RedoList (the real data list is the m_Son member) */
DrawPickedStruct* List = (DrawPickedStruct*) GetScreen()->GetItemFromUndoList();
GetScreen()->AddItemToRedoList( List );
/* Undo the command */
PutDataInPreviousState( List );
CurrentDrawItem = NULL;
GetScreen()->SetModify();
SetSheetNumberAndCount();
2007-09-01 12:00:30 +00:00
ReCreateHToolbar();
SetToolbars();
2008-02-26 19:19:54 +00:00
return true;
}
/*********************************************************/
2007-09-01 12:00:30 +00:00
void SCH_SCREEN::ClearUndoORRedoList( EDA_BaseStruct* List )
/*********************************************************/
2007-09-01 12:00:30 +00:00
/* free the undo or redo list from List element
2007-09-01 12:00:30 +00:00
* Wrappers are deleted.
* datas pointed by wrappers are deleted if not flagged IS_NEW
* because they are copy of used data or they are not in use (DELETED)
*/
{
2007-09-01 12:00:30 +00:00
EDA_BaseStruct* nextitem;
EDA_BaseStruct* FirstItem;
int CmdType;
if( List == NULL )
return;
for( ; List != NULL; List = nextitem )
{
nextitem = List->Next();
FirstItem = List->GetSon();
2007-09-01 12:00:30 +00:00
CmdType = List->m_Flags;
2008-02-26 19:19:54 +00:00
SAFE_DELETE( List );
2007-09-01 12:00:30 +00:00
if( FirstItem == NULL )
continue;
if( FirstItem->Type() == DRAW_PICK_ITEM_STRUCT_TYPE )
{
EDA_BaseStruct* item;
DrawPickedStruct* PickedList = (DrawPickedStruct*) FirstItem;
while( PickedList ) // delete wrapper list and copies
{
item = PickedList->m_PickedStruct;
if( item )
{
#if 0
2007-09-01 12:00:30 +00:00
if( item->Type() == DRAW_SHEET_STRUCT_TYPE )
{
printf(
"schematic undo_redo.cpp: undo_redo with a DRAW_SHEET_STRUCT_TYPE, checkme!!\n" );
2007-09-01 12:00:30 +00:00
DrawSheetStruct* sheet = (DrawSheetStruct*) item;
/* Delete sub hierarchy if the sheet must be deleted */
if( (sheet->m_Flags & IS_DELETED) != 0 )
DeleteSubHierarchy( sheet, FALSE );
else /* EEDrawList, UndoList and Redo list are shared, and are deleted
* only if sheet is deleted */
{
if( (item->m_Flags & IS_NEW) == 0 )
{
2008-02-26 19:19:54 +00:00
/*
* sheet->EEDrawList = NULL;
* sheet->m_UndoList = NULL;
* sheet->m_RedoList = NULL;
*/
2007-09-01 12:00:30 +00:00
}
}
}
#endif
2008-02-26 19:19:54 +00:00
if( (item->m_Flags & IS_NEW) == 0 )
{
SAFE_DELETE( item );
}
2007-09-01 12:00:30 +00:00
}
DrawPickedStruct* wrapper = PickedList;
PickedList = PickedList->Next();
2008-02-26 19:19:54 +00:00
SAFE_DELETE( wrapper );
2007-09-01 12:00:30 +00:00
}
}
else // This is a single item: deleted copy
{
if( CmdType == IS_WIRE_IMAGE )
{
while( FirstItem )
{
EDA_BaseStruct* nextitem = FirstItem->Next();
2007-09-01 12:00:30 +00:00
delete FirstItem;
FirstItem = nextitem;
}
}
else
{
#if 0
2007-09-01 12:00:30 +00:00
if( FirstItem->Type() == DRAW_SHEET_STRUCT_TYPE )
{
DrawSheetStruct* sheet = (DrawSheetStruct*) FirstItem;
/* Delete hierarchy if the sheet must be deleted */
if( (sheet->m_Flags & IS_DELETED) == IS_DELETED )
DeleteSubHierarchy( sheet, FALSE );
else
{
if( (FirstItem->m_Flags & IS_NEW) == 0 )
{
2008-02-26 19:19:54 +00:00
printf(
"schematic undo_redo.cpp undo_redo with a DRAW_SHEET_STRUCT_TYPE, checkme!!\n" );
/*
* sheet->EEDrawList = NULL;
* sheet->m_UndoList = NULL;
* sheet->m_RedoList = NULL;
*/
2007-09-01 12:00:30 +00:00
}
}
}
#endif
2008-02-26 19:19:54 +00:00
if( (FirstItem->m_Flags & IS_NEW) == 0 )
{
SAFE_DELETE( FirstItem );
}
2007-09-01 12:00:30 +00:00
}
}
}
2007-05-06 16:03:28 +00:00
}
2007-09-01 12:00:30 +00:00
2007-05-06 16:03:28 +00:00
/*****************************************/
2007-09-01 12:00:30 +00:00
void SCH_SCREEN::ClearUndoRedoList()
2007-05-06 16:03:28 +00:00
/*****************************************/
2007-09-01 12:00:30 +00:00
2007-05-06 16:03:28 +00:00
/* free the undo and the redo lists
2007-09-01 12:00:30 +00:00
*/
2007-05-06 16:03:28 +00:00
{
2007-09-01 12:00:30 +00:00
ClearUndoORRedoList( m_UndoList ); m_UndoList = NULL;
ClearUndoORRedoList( m_RedoList ); m_RedoList = NULL;
2007-05-06 16:03:28 +00:00
}
2007-09-01 12:00:30 +00:00
2007-05-06 16:03:28 +00:00
/***********************************************************/
2007-09-01 12:00:30 +00:00
void SCH_SCREEN::AddItemToUndoList( EDA_BaseStruct* newitem )
2007-05-06 16:03:28 +00:00
/************************************************************/
2007-09-01 12:00:30 +00:00
2007-05-06 16:03:28 +00:00
/* Put newitem in head of undo list
2007-09-01 12:00:30 +00:00
* Deletes olds items if > count max.
*/
2007-05-06 16:03:28 +00:00
{
2007-09-01 12:00:30 +00:00
int ii;
EDA_BaseStruct* item, * nextitem;
if( newitem == NULL )
return;
if( m_UndoList )
m_UndoList->SetBack( newitem );
newitem->SetNext( m_UndoList );
newitem->SetBack( NULL );
2007-09-01 12:00:30 +00:00
m_UndoList = newitem;
/* Free oldest items, if count max reached */
for( ii = 0, item = m_UndoList; ii < m_UndoRedoCountMax; ii++ )
{
if( item->Next() == NULL )
2007-09-01 12:00:30 +00:00
return;
item = item->Next();
2007-09-01 12:00:30 +00:00
}
if( item == NULL )
return;
nextitem = item->Next();
item->SetNext( NULL ); // Set end of chain
2007-09-01 12:00:30 +00:00
// Delete the extra items
ClearUndoORRedoList( nextitem );
2007-05-06 16:03:28 +00:00
}
2007-09-01 12:00:30 +00:00
2007-05-06 16:03:28 +00:00
/***********************************************************/
2007-09-01 12:00:30 +00:00
void SCH_SCREEN::AddItemToRedoList( EDA_BaseStruct* newitem )
2007-05-06 16:03:28 +00:00
/***********************************************************/
{
2007-09-01 12:00:30 +00:00
int ii;
EDA_BaseStruct* item, * nextitem;
if( newitem == NULL )
return;
newitem->SetBack( NULL );
newitem->SetNext( m_RedoList );
2007-09-01 12:00:30 +00:00
m_RedoList = newitem;
2007-09-01 12:00:30 +00:00
/* Free first items, if count max reached */
for( ii = 0, item = m_RedoList; ii < m_UndoRedoCountMax; ii++ )
{
if( item->Next() == NULL )
2007-09-01 12:00:30 +00:00
break;
item = item->Next();
2007-09-01 12:00:30 +00:00
}
if( item == NULL )
return;
nextitem = item->Next();
item->SetNext( NULL ); // Set end of chain
2007-09-01 12:00:30 +00:00
// Delete the extra items
ClearUndoORRedoList( nextitem );
2007-05-06 16:03:28 +00:00
}