2009-07-29 13:10:36 +00:00
|
|
|
/*************************************************************/
|
|
|
|
/* board editor: undo and redo functions for board editor */
|
|
|
|
/*************************************************************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "class_drawpanel.h"
|
|
|
|
|
|
|
|
#include "pcbnew.h"
|
2009-07-30 11:04:07 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2009-07-29 13:10:36 +00:00
|
|
|
|
|
|
|
/* Functions to undo and redo edit commands.
|
|
|
|
* commmands to undo are stored in CurrentScreen->m_UndoList
|
|
|
|
* commmands to redo are stored in CurrentScreen->m_RedoList
|
|
|
|
*
|
|
|
|
* 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),
|
|
|
|
* 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)
|
|
|
|
*
|
|
|
|
* there are 3 cases:
|
|
|
|
* - delete item(s) command
|
|
|
|
* - change item(s) command
|
|
|
|
* - add item(s) command
|
|
|
|
* and 3 cases for block:
|
|
|
|
* - move list of items
|
|
|
|
* - mirror (Y) list of items
|
|
|
|
* - Flip list of items
|
|
|
|
*
|
|
|
|
* Undo command
|
|
|
|
* - delete item(s) command:
|
|
|
|
* => deleted items are moved in undo list
|
|
|
|
*
|
|
|
|
* - change item(s) command
|
|
|
|
* => 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.
|
|
|
|
*
|
|
|
|
* - add item(s) command
|
|
|
|
* =>A list of item(s) is made. The .m_Item member of each wrapper points the new item.
|
|
|
|
*
|
|
|
|
* Redo command
|
|
|
|
* - delete item(s) old command:
|
|
|
|
* => deleted items are moved in EEDrawList list, and in
|
|
|
|
*
|
|
|
|
* - change item(s) command
|
|
|
|
* => the copy of item(s) is moved in Undo list
|
|
|
|
*
|
|
|
|
* - add item(s) command
|
|
|
|
* => The list of item(s) is used to create a deleted list in undo list(same as a delete command)
|
|
|
|
*
|
|
|
|
* Some block operations that change items can be undoed without memorise items, just the coordiantes 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-08-03 18:54:48 +00:00
|
|
|
BOARD_ITEM* DuplicateStruct( BOARD_ITEM* aItem );
|
|
|
|
|
|
|
|
|
2009-07-31 05:33:11 +00:00
|
|
|
/** function TestForExistingItem
|
|
|
|
* test if aItem exists somewhere in lists of items
|
|
|
|
* This is a function unsed by PutDataInPreviousState to be sure an item was not deleted
|
|
|
|
* since an undo or redo.
|
|
|
|
* This could be possible:
|
|
|
|
* - if a call to SaveCopyInUndoList was forgotten in pcbnew
|
|
|
|
* - in zones outlines, when a change in one zone merges this zone with an other
|
|
|
|
* This function avoids a pcbnew crash
|
|
|
|
* @param aBoard = board to test
|
|
|
|
* @param aItem = item to find
|
|
|
|
*/
|
2009-08-01 19:26:05 +00:00
|
|
|
static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem )
|
2009-07-31 05:33:11 +00:00
|
|
|
{
|
2009-08-01 19:26:05 +00:00
|
|
|
BOARD_ITEM* item;
|
|
|
|
|
2009-07-31 05:33:11 +00:00
|
|
|
// search in tracks:
|
|
|
|
for( item = aPcb->m_Track; item != NULL; item = item->Next() )
|
2009-08-01 19:26:05 +00:00
|
|
|
if( item == aItem )
|
2009-07-31 05:33:11 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// search in modules:
|
|
|
|
for( item = aPcb->m_Modules; item != NULL; item = item->Next() )
|
2009-08-01 19:26:05 +00:00
|
|
|
if( item == aItem )
|
2009-07-31 05:33:11 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Search in drawings
|
|
|
|
for( item = aPcb->m_Drawings; item != NULL; item = item->Next() )
|
2009-08-01 19:26:05 +00:00
|
|
|
if( item == aItem )
|
2009-07-31 05:33:11 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Search in zones outlines
|
2009-08-01 19:26:05 +00:00
|
|
|
for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ )
|
|
|
|
if( aPcb->GetArea( ii ) == aItem )
|
2009-07-31 05:33:11 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// search in zones segm:
|
|
|
|
for( item = aPcb->m_Zone; item != NULL; item = item->Next() )
|
2009-08-01 19:26:05 +00:00
|
|
|
if( item == aItem )
|
2009-07-31 05:33:11 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
/**************************************************************/
|
2009-08-03 07:55:08 +00:00
|
|
|
void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
|
2009-07-29 13:10:36 +00:00
|
|
|
/***************************************************************/
|
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
/** Function SwapData
|
|
|
|
* Used in undo / redo command:
|
|
|
|
* swap data between Item and a copy
|
|
|
|
* swapped data is data modified by edition, mainly sizes and texts
|
|
|
|
* so ONLY FEW values are swapped
|
|
|
|
* @param aItem = the item
|
|
|
|
* @param aImage = a copy of the item
|
2009-07-29 13:10:36 +00:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
if( aItem == NULL || aImage == NULL )
|
|
|
|
{
|
|
|
|
wxMessageBox( wxT( "SwapData error: NULL pointer" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
// Swap layers:
|
2009-08-08 06:07:08 +00:00
|
|
|
if( aItem->Type() != TYPE_MODULE && aItem->Type() != TYPE_ZONE_CONTAINER ) // these items have a global swap function
|
2009-08-06 15:42:09 +00:00
|
|
|
{
|
|
|
|
int layer, layerimg;
|
|
|
|
layer = aItem->GetLayer();
|
|
|
|
layerimg = aImage->GetLayer();
|
|
|
|
aItem->SetLayer( layerimg );
|
|
|
|
aImage->SetLayer( layer );
|
|
|
|
}
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
2009-08-03 07:55:08 +00:00
|
|
|
case TYPE_MODULE:
|
2009-08-03 18:54:48 +00:00
|
|
|
{
|
2009-08-08 06:07:08 +00:00
|
|
|
MODULE* tmp = (MODULE*) DuplicateStruct( aImage );
|
2009-08-03 18:54:48 +00:00
|
|
|
( (MODULE*) aImage )->Copy( (MODULE*) aItem );
|
2009-08-08 06:07:08 +00:00
|
|
|
( (MODULE*) aItem )->Copy( tmp );
|
|
|
|
delete tmp;
|
2009-08-03 18:54:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
|
|
|
case TYPE_ZONE_CONTAINER:
|
2009-08-08 06:07:08 +00:00
|
|
|
{
|
|
|
|
ZONE_CONTAINER* tmp = (ZONE_CONTAINER*) DuplicateStruct( aImage );
|
|
|
|
( (ZONE_CONTAINER*) aImage )->Copy( (ZONE_CONTAINER*) aItem );
|
|
|
|
( (ZONE_CONTAINER*) aItem )->Copy( tmp );
|
|
|
|
delete tmp;
|
|
|
|
}
|
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
|
|
|
case TYPE_DRAWSEGMENT:
|
2009-08-11 10:27:21 +00:00
|
|
|
EXCHG( ( (DRAWSEGMENT*) aItem )->m_Start, ( (DRAWSEGMENT*) aImage )->m_Start );
|
|
|
|
EXCHG( ( (DRAWSEGMENT*) aItem )->m_End, ( (DRAWSEGMENT*) aImage )->m_End );
|
|
|
|
EXCHG( ( (DRAWSEGMENT*) aItem )->m_Width, ( (DRAWSEGMENT*) aImage )->m_Width );
|
|
|
|
EXCHG( ( (DRAWSEGMENT*) aItem )->m_Shape, ( (DRAWSEGMENT*) aImage )->m_Shape );
|
2009-08-03 07:55:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_TRACK:
|
|
|
|
case TYPE_VIA:
|
2009-08-08 10:08:37 +00:00
|
|
|
{
|
2009-11-21 20:44:19 +00:00
|
|
|
TRACK* track = (TRACK*) aItem;
|
|
|
|
TRACK* image = (TRACK*) aImage;
|
|
|
|
EXCHG( track->m_Start, image->m_Start );
|
|
|
|
EXCHG( track->m_End, image->m_End );
|
|
|
|
EXCHG( track->m_Width, image->m_Width );
|
|
|
|
EXCHG( track->m_Shape, image->m_Shape );
|
|
|
|
int atmp = track->GetDrillValue();
|
|
|
|
if( track->IsDrillDefault() )
|
2009-08-08 10:08:37 +00:00
|
|
|
atmp = -1;
|
2009-11-21 20:44:19 +00:00
|
|
|
int itmp = image->GetDrillValue();
|
|
|
|
if( image->IsDrillDefault() )
|
|
|
|
itmp = -1;
|
|
|
|
EXCHG(itmp, atmp );
|
|
|
|
if( atmp > 0 )
|
|
|
|
track->SetDrillValue( atmp );
|
|
|
|
else
|
|
|
|
track->SetDrillDefault();
|
|
|
|
if( itmp > 0 )
|
|
|
|
image->SetDrillValue( itmp );
|
|
|
|
else
|
|
|
|
image->SetDrillDefault();
|
2009-08-08 10:08:37 +00:00
|
|
|
}
|
2009-08-03 18:54:48 +00:00
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
|
|
|
case TYPE_TEXTE:
|
2009-08-03 18:54:48 +00:00
|
|
|
EXCHG( ( (TEXTE_PCB*) aItem )->m_Mirror, ( (TEXTE_PCB*) aImage )->m_Mirror );
|
|
|
|
EXCHG( ( (TEXTE_PCB*) aItem )->m_Size, ( (TEXTE_PCB*) aImage )->m_Size );
|
|
|
|
EXCHG( ( (TEXTE_PCB*) aItem )->m_Pos, ( (TEXTE_PCB*) aImage )->m_Pos );
|
|
|
|
EXCHG( ( (TEXTE_PCB*) aItem )->m_Width, ( (TEXTE_PCB*) aImage )->m_Width );
|
|
|
|
EXCHG( ( (TEXTE_PCB*) aItem )->m_Orient, ( (TEXTE_PCB*) aImage )->m_Orient );
|
|
|
|
EXCHG( ( (TEXTE_PCB*) aItem )->m_Text, ( (TEXTE_PCB*) aImage )->m_Text );
|
|
|
|
EXCHG( ( (TEXTE_PCB*) aItem )->m_Italic, ( (TEXTE_PCB*) aImage )->m_Italic );
|
|
|
|
EXCHG( ( (TEXTE_PCB*) aItem )->m_Bold, ( (TEXTE_PCB*) aImage )->m_Bold );
|
|
|
|
EXCHG( ( (TEXTE_PCB*) aItem )->m_HJustify, ( (TEXTE_PCB*) aImage )->m_HJustify );
|
|
|
|
EXCHG( ( (TEXTE_PCB*) aItem )->m_VJustify, ( (TEXTE_PCB*) aImage )->m_VJustify );
|
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
|
|
|
case TYPE_MIRE:
|
2009-08-03 18:54:48 +00:00
|
|
|
EXCHG( ( (MIREPCB*) aItem )->m_Pos, ( (MIREPCB*) aImage )->m_Pos );
|
|
|
|
EXCHG( ( (MIREPCB*) aItem )->m_Width, ( (MIREPCB*) aImage )->m_Width );
|
|
|
|
EXCHG( ( (MIREPCB*) aItem )->m_Size, ( (MIREPCB*) aImage )->m_Size );
|
|
|
|
EXCHG( ( (MIREPCB*) aItem )->m_Shape, ( (MIREPCB*) aImage )->m_Shape );
|
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
case TYPE_DIMENSION:
|
2009-08-06 07:11:04 +00:00
|
|
|
{
|
2010-04-23 09:54:40 +00:00
|
|
|
wxString txt = ( (DIMENSION*) aItem )->GetText();
|
|
|
|
( (DIMENSION*) aItem )->SetText( ( (DIMENSION*) aImage )->GetText() );
|
|
|
|
( (DIMENSION*) aImage )->SetText( txt );
|
|
|
|
EXCHG( ( (DIMENSION*) aItem )->m_Width, ( (DIMENSION*) aImage )->m_Width );
|
|
|
|
EXCHG( ( (DIMENSION*) aItem )->m_Text->m_Size, ( (DIMENSION*) aImage )->m_Text->m_Size );
|
|
|
|
EXCHG( ( (DIMENSION*) aItem )->m_Text->m_Width, ( (DIMENSION*) aImage )->m_Text->m_Width );
|
|
|
|
EXCHG( ( (DIMENSION*) aItem )->m_Text->m_Mirror, ( (DIMENSION*) aImage )->m_Text->m_Mirror );
|
2009-08-06 07:11:04 +00:00
|
|
|
}
|
2009-08-08 06:07:08 +00:00
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2009-08-08 10:08:37 +00:00
|
|
|
case TYPE_ZONE:
|
2009-07-29 13:10:36 +00:00
|
|
|
default:
|
|
|
|
wxMessageBox( wxT( "SwapData() error: unexpected type" ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************/
|
|
|
|
BOARD_ITEM* DuplicateStruct( BOARD_ITEM* aItem )
|
|
|
|
/************************************************************/
|
|
|
|
|
|
|
|
/* Routine to create a new copy of given struct.
|
|
|
|
* The new object is not put in list (not linked)
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
if( aItem == NULL )
|
|
|
|
{
|
2009-08-06 15:42:09 +00:00
|
|
|
wxMessageBox( wxT( "DuplicateStruct() error: NULL aItem" ) );
|
2009-07-29 13:10:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
2009-08-01 19:26:05 +00:00
|
|
|
case TYPE_MODULE:
|
|
|
|
{
|
|
|
|
MODULE* new_module;
|
2009-08-03 18:54:48 +00:00
|
|
|
new_module = new MODULE( (BOARD*) aItem->GetParent() );
|
2009-08-01 19:26:05 +00:00
|
|
|
new_module->Copy( (MODULE*) aItem );
|
|
|
|
return new_module;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_TRACK:
|
|
|
|
{
|
|
|
|
TRACK* new_track = ( (TRACK*) aItem )->Copy();
|
|
|
|
return new_track;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_VIA:
|
|
|
|
{
|
|
|
|
SEGVIA* new_via = (SEGVIA*)( (SEGVIA*) aItem )->Copy();
|
|
|
|
return new_via;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_ZONE:
|
|
|
|
{
|
|
|
|
SEGZONE* new_segzone = (SEGZONE*)( (SEGZONE*) aItem )->Copy();
|
|
|
|
return new_segzone;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_ZONE_CONTAINER:
|
|
|
|
{
|
2009-08-03 18:54:48 +00:00
|
|
|
ZONE_CONTAINER* new_zone = new ZONE_CONTAINER( (BOARD*) aItem->GetParent() );
|
|
|
|
new_zone->Copy( (ZONE_CONTAINER*) aItem );
|
2009-08-01 19:26:05 +00:00
|
|
|
return new_zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_DRAWSEGMENT:
|
|
|
|
{
|
|
|
|
DRAWSEGMENT* new_drawsegment = new DRAWSEGMENT( aItem->GetParent() );
|
2009-08-03 18:54:48 +00:00
|
|
|
new_drawsegment->Copy( (DRAWSEGMENT*) aItem );
|
2009-08-01 19:26:05 +00:00
|
|
|
return new_drawsegment;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_TEXTE:
|
|
|
|
{
|
|
|
|
TEXTE_PCB* new_pcbtext = new TEXTE_PCB( aItem->GetParent() );
|
2009-08-03 18:54:48 +00:00
|
|
|
new_pcbtext->Copy( (TEXTE_PCB*) aItem );
|
2009-08-01 19:26:05 +00:00
|
|
|
return new_pcbtext;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_MIRE:
|
|
|
|
{
|
|
|
|
MIREPCB* new_mire = new MIREPCB( aItem->GetParent() );
|
2009-08-03 18:54:48 +00:00
|
|
|
new_mire->Copy( (MIREPCB*) aItem );
|
2009-08-01 19:26:05 +00:00
|
|
|
return new_mire;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-23 09:54:40 +00:00
|
|
|
case TYPE_DIMENSION:
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2010-04-23 09:54:40 +00:00
|
|
|
DIMENSION* new_cotation = new DIMENSION( aItem->GetParent() );
|
|
|
|
new_cotation->Copy( (DIMENSION*) aItem );
|
2009-08-01 19:26:05 +00:00
|
|
|
return new_cotation;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg << wxT( "DuplicateStruct error: unexpected StructType " ) <<
|
|
|
|
aItem->Type() << wxT( " " ) << aItem->GetClass();
|
2009-08-01 19:26:05 +00:00
|
|
|
wxMessageBox( msg );
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
return NULL;
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************/
|
2009-08-03 07:55:08 +00:00
|
|
|
void WinEDA_PcbFrame::SaveCopyInUndoList( BOARD_ITEM* aItem,
|
2009-07-29 13:10:36 +00:00
|
|
|
UndoRedoOpType aCommandType,
|
|
|
|
const wxPoint& aTransformPoint )
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/** function SaveCopyInUndoList
|
|
|
|
* Create a copy of the current schematic item, and put it in the undo list.
|
|
|
|
*
|
|
|
|
* flag_type_command =
|
|
|
|
* UR_CHANGED
|
|
|
|
* UR_NEW
|
|
|
|
* UR_DELETED
|
2009-08-01 19:26:05 +00:00
|
|
|
* UR_MOVED
|
|
|
|
* UR_FLIPPED
|
|
|
|
* UR_ROTATED
|
2009-07-29 13:10:36 +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 subhierarchy will be deleted.
|
|
|
|
* If it is only a copy, the EEDrawList and the subhierarchy must NOT be deleted.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
{
|
2009-08-04 18:21:32 +00:00
|
|
|
if( aItem == NULL ) // Nothing to save
|
|
|
|
return;
|
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
|
|
|
|
|
|
|
|
commandToUndo->m_TransformPoint = aTransformPoint;
|
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
ITEM_PICKER itemWrapper( aItem, aCommandType );
|
|
|
|
itemWrapper.m_PickedItemType = aItem->Type();
|
2009-07-29 13:10:36 +00:00
|
|
|
|
|
|
|
switch( aCommandType )
|
|
|
|
{
|
2009-08-08 06:07:08 +00:00
|
|
|
case UR_CHANGED: /* Create a copy of schematic */
|
2009-08-06 07:11:04 +00:00
|
|
|
if( itemWrapper.m_Link == NULL ) // When not null, the copy is already done
|
|
|
|
itemWrapper.m_Link = DuplicateStruct( aItem );;
|
|
|
|
if( itemWrapper.m_Link )
|
2009-07-29 13:10:36 +00:00
|
|
|
commandToUndo->PushItem( itemWrapper );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_NEW:
|
2009-08-01 19:26:05 +00:00
|
|
|
case UR_MOVED:
|
|
|
|
case UR_FLIPPED:
|
|
|
|
case UR_ROTATED:
|
2009-08-06 07:11:04 +00:00
|
|
|
case UR_ROTATED_CLOCKWISE:
|
2009-07-29 13:10:36 +00:00
|
|
|
case UR_DELETED:
|
|
|
|
commandToUndo->PushItem( itemWrapper );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT( "SaveCopyInUndoList() error (unknown code %X)" ), aCommandType );
|
|
|
|
wxMessageBox( msg );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( commandToUndo->GetCount() )
|
|
|
|
{
|
|
|
|
/* Save the copy in undo list */
|
|
|
|
GetScreen()->PushCommandToUndoList( commandToUndo );
|
|
|
|
|
|
|
|
/* Clear redo list, because after new save there is no redo to do */
|
|
|
|
GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
delete commandToUndo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** function SaveCopyInUndoList
|
|
|
|
* @param aItemsList = a PICKED_ITEMS_LIST of items to save
|
|
|
|
* @param aTypeCommand = type of comand ( UR_CHANGED, UR_NEW, UR_DELETED ...
|
|
|
|
*/
|
|
|
|
void WinEDA_PcbFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
|
|
|
|
UndoRedoOpType aTypeCommand,
|
|
|
|
const wxPoint& aTransformPoint )
|
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
|
|
|
|
|
|
|
|
commandToUndo->m_TransformPoint = aTransformPoint;
|
2009-08-08 06:07:08 +00:00
|
|
|
|
2009-08-06 15:42:09 +00:00
|
|
|
// Copy picker list:
|
|
|
|
commandToUndo->CopyList( aItemsList );
|
2009-07-29 13:10:36 +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-29 13:10:36 +00:00
|
|
|
{
|
2009-08-06 15:42:09 +00:00
|
|
|
BOARD_ITEM* item = (BOARD_ITEM*) commandToUndo->GetPickedItem( ii );
|
|
|
|
UndoRedoOpType command = commandToUndo->GetPickedItemStatus( ii );
|
2009-07-29 13:10:36 +00:00
|
|
|
if( command == UR_UNSPECIFIED )
|
2009-08-06 15:42:09 +00:00
|
|
|
{
|
2009-07-29 13:10:36 +00:00
|
|
|
command = aTypeCommand;
|
2009-08-08 06:07:08 +00:00
|
|
|
commandToUndo->SetPickedItemStatus( command, ii );
|
2009-08-06 15:42:09 +00:00
|
|
|
}
|
2009-08-03 18:54:48 +00:00
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
wxASSERT( item );
|
2009-07-29 13:10:36 +00:00
|
|
|
switch( command )
|
|
|
|
{
|
2009-08-06 15:42:09 +00:00
|
|
|
case UR_CHANGED:
|
2009-08-08 06:07:08 +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
|
|
|
|
*/
|
2009-08-08 06:07:08 +00:00
|
|
|
if( commandToUndo->GetPickedItemLink( ii ) == NULL )
|
2009-08-06 15:42:09 +00:00
|
|
|
commandToUndo->SetPickedItemLink( DuplicateStruct( item ), ii );
|
2009-08-23 15:22:44 +00:00
|
|
|
if( commandToUndo->GetPickedItemLink( ii ) == NULL )
|
|
|
|
wxMessageBox( wxT( "SaveCopyInUndoList() in UR_CHANGED mode: NULL link" ) );
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_MOVED:
|
2009-08-01 19:26:05 +00:00
|
|
|
case UR_ROTATED:
|
2009-08-06 07:11:04 +00:00
|
|
|
case UR_ROTATED_CLOCKWISE:
|
2009-08-01 19:26:05 +00:00
|
|
|
case UR_FLIPPED:
|
2009-07-29 13:10:36 +00:00
|
|
|
case UR_NEW:
|
|
|
|
case UR_DELETED:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT( "SaveCopyInUndoList() error (unknown code %X)" ), command );
|
|
|
|
wxMessageBox( msg );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( commandToUndo->GetCount() )
|
|
|
|
{
|
|
|
|
/* Save the copy in undo list */
|
|
|
|
GetScreen()->PushCommandToUndoList( commandToUndo );
|
|
|
|
|
2009-08-06 15:42:09 +00:00
|
|
|
/* Clear redo list, because after a new command one cannot redo a command */
|
2009-07-29 13:10:36 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/** Function PutDataInPreviousState()
|
|
|
|
* Used in undo or redo command.
|
|
|
|
* Put data pointed by List in the previous state, i.e. the state memorised by List
|
|
|
|
* @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
|
2009-08-13 05:52:53 +00:00
|
|
|
* @param aRebuildRatsnet = a bool: true to rebuid ratsnet (normal use, and default), false
|
|
|
|
* to just retrieve las state (used in abort commands that do not need to rebuild ratsnest)
|
2009-07-29 13:10:36 +00:00
|
|
|
*/
|
2009-08-13 05:52:53 +00:00
|
|
|
void WinEDA_PcbFrame::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRedoCommand, bool aRebuildRatsnet )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
|
|
|
BOARD_ITEM* item;
|
2009-07-31 05:33:11 +00:00
|
|
|
bool not_found = false;
|
2009-08-03 07:55:08 +00:00
|
|
|
bool reBuild_ratsnest = false;
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2009-08-08 06:07:08 +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
|
|
|
|
for( int ii = aList->GetCount()-1; ii >= 0 ; ii-- )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2009-08-03 18:54:48 +00:00
|
|
|
item = (BOARD_ITEM*) aList->GetPickedItem( ii );
|
2009-07-29 13:10:36 +00:00
|
|
|
wxASSERT( item );
|
2009-08-06 15:42:09 +00:00
|
|
|
#if 1
|
2009-08-03 18:54:48 +00:00
|
|
|
if( aList->GetPickedItemStatus( ii ) != UR_DELETED )
|
2009-07-31 05:33:11 +00:00
|
|
|
{
|
2009-08-01 19:26:05 +00:00
|
|
|
if( !TestForExistingItem( GetBoard(), item ) )
|
2009-07-31 05:33:11 +00:00
|
|
|
{
|
|
|
|
// Remove this non existant item
|
2009-08-06 15:42:09 +00:00
|
|
|
aList->RemovePicker( ii );
|
2009-08-08 06:07:08 +00:00
|
|
|
ii++; // the current item was removed, ii points now the next item
|
2009-07-31 05:33:11 +00:00
|
|
|
// whe must decrement it because it will be incremented
|
|
|
|
not_found = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2009-08-06 15:42:09 +00:00
|
|
|
#endif
|
2009-08-03 07:55:08 +00:00
|
|
|
item->m_Flags = 0;
|
2009-08-03 18:54:48 +00:00
|
|
|
|
2009-08-06 15:42:09 +00:00
|
|
|
// see if we must rebuild ratsnets and pointers lists
|
2009-08-03 07:55:08 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2009-08-03 18:54:48 +00:00
|
|
|
case TYPE_MODULE:
|
|
|
|
case TYPE_ZONE_CONTAINER:
|
|
|
|
case TYPE_TRACK:
|
|
|
|
case TYPE_VIA:
|
|
|
|
reBuild_ratsnest = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 18:54:48 +00:00
|
|
|
switch( aList->GetPickedItemStatus( ii ) )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
|
|
|
case UR_CHANGED: /* Exchange old and new data for each item */
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2009-08-03 18:54:48 +00:00
|
|
|
BOARD_ITEM* image = (BOARD_ITEM*) aList->GetPickedItemLink( ii );
|
|
|
|
SwapData( item, image );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2009-08-03 18:54:48 +00:00
|
|
|
break;
|
2009-07-29 13:10:36 +00:00
|
|
|
|
|
|
|
case UR_NEW: /* new items are deleted */
|
2009-07-31 05:33:11 +00:00
|
|
|
aList->SetPickedItemStatus( UR_DELETED, ii );
|
2009-07-29 13:10:36 +00:00
|
|
|
GetBoard()->Remove( item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_DELETED: /* deleted items are put in List, as new items */
|
2009-07-31 05:33:11 +00:00
|
|
|
aList->SetPickedItemStatus( UR_NEW, ii );
|
2009-07-29 13:10:36 +00:00
|
|
|
GetBoard()->Add( item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_MOVED:
|
2009-08-03 18:54:48 +00:00
|
|
|
item->Move( aRedoCommand ? aList->m_TransformPoint : -aList->m_TransformPoint );
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
case UR_ROTATED:
|
|
|
|
item->Rotate( aList->m_TransformPoint, aRedoCommand ? 900 : -900 );
|
|
|
|
break;
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
case UR_ROTATED_CLOCKWISE:
|
|
|
|
item->Rotate( aList->m_TransformPoint, aRedoCommand ? -900 : 900 );
|
|
|
|
break;
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
case UR_FLIPPED:
|
|
|
|
item->Flip( aList->m_TransformPoint );
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT(
|
2009-08-03 18:54:48 +00:00
|
|
|
"PutDataInPreviousState() error (unknown code %X)" ),
|
|
|
|
aList->GetPickedItemStatus( ii ) );
|
2009-07-29 13:10:36 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-31 05:33:11 +00:00
|
|
|
if( not_found )
|
2009-08-06 15:42:09 +00:00
|
|
|
wxMessageBox( wxT( "Incomplete undo/redo operation: some items not found" ) );
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2009-08-06 15:42:09 +00:00
|
|
|
// Rebuild pointers and rastnest that can be changed.
|
2009-08-13 05:52:53 +00:00
|
|
|
if( reBuild_ratsnest && aRebuildRatsnet )
|
2009-08-03 07:55:08 +00:00
|
|
|
Compile_Ratsnest( NULL, true );
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************/
|
|
|
|
void WinEDA_PcbFrame::GetBoardFromUndoList( wxCommandEvent& event )
|
|
|
|
/**********************************************************/
|
2009-08-03 18:54:48 +00:00
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/** Function GetBoardFromUndoList
|
2009-07-29 13:10:36 +00:00
|
|
|
* Undo the last edition:
|
2009-08-06 15:42:09 +00:00
|
|
|
* - Save the current board state in Redo list
|
|
|
|
* - Get an old version of the board state from Undo list
|
2009-08-01 19:26:05 +00:00
|
|
|
* @return none
|
2009-07-29 13:10:36 +00:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
if( GetScreen()->GetUndoCommandCount() <= 0 )
|
|
|
|
return;
|
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
/* Get the old list */
|
2009-07-29 13:10:36 +00:00
|
|
|
PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromUndoList();
|
|
|
|
/* Undo the command */
|
2009-08-01 19:26:05 +00:00
|
|
|
PutDataInPreviousState( List, false );
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2009-08-11 10:27:21 +00:00
|
|
|
/* Put the old list in RedoList */
|
|
|
|
List->ReversePickersListOrder();
|
2009-08-08 06:07:08 +00:00
|
|
|
GetScreen()->PushCommandToRedoList( List );
|
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2009-07-29 13:10:36 +00:00
|
|
|
ReCreateHToolbar();
|
|
|
|
SetToolbars();
|
|
|
|
|
|
|
|
DrawPanel->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/** Function GetBoardFromRedoList
|
|
|
|
* Redo the last edition:
|
|
|
|
* - Save the current board in Undo list
|
|
|
|
* - Get an old version of the board from Redo list
|
|
|
|
* @return none
|
2009-07-29 13:10:36 +00:00
|
|
|
*/
|
2009-08-01 19:26:05 +00:00
|
|
|
void WinEDA_PcbFrame::GetBoardFromRedoList( wxCommandEvent& event )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
|
|
|
if( GetScreen()->GetRedoCommandCount() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
2009-08-08 06:07:08 +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-08 06:07:08 +00:00
|
|
|
/* Put the old list in UndoList */
|
|
|
|
List->ReversePickersListOrder();
|
|
|
|
GetScreen()->PushCommandToUndoList( List );
|
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2009-07-29 13:10:36 +00:00
|
|
|
ReCreateHToolbar();
|
|
|
|
SetToolbars();
|
|
|
|
|
|
|
|
DrawPanel->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************************/
|
|
|
|
void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount )
|
|
|
|
/**********************************************************************************/
|
|
|
|
|
|
|
|
/** Function ClearUndoORRedoList
|
|
|
|
* free the undo or redo list from List element
|
|
|
|
* Wrappers are deleted.
|
|
|
|
* datas pointed by wrappers are deleted if not in use in schematic
|
|
|
|
* i.e. when they are copy of a schematic item or they are no more in use (DELETED)
|
|
|
|
* @param aList = the UNDO_REDO_CONTAINER to clear
|
|
|
|
* @param aItemCount = the count of items to remove. < 0 for all items
|
|
|
|
* items (commands stored in list) are removed from the beginning of the list.
|
|
|
|
* So this function can be called to remove old commands
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
if( aItemCount == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned icnt = aList.m_CommandsList.size();
|
|
|
|
if( aItemCount > 0 )
|
|
|
|
icnt = aItemCount;
|
2009-08-06 15:42:09 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
for( unsigned ii = 0; ii < icnt; ii++ )
|
|
|
|
{
|
|
|
|
if( aList.m_CommandsList.size() == 0 )
|
|
|
|
break;
|
|
|
|
PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0];
|
|
|
|
aList.m_CommandsList.erase( aList.m_CommandsList.begin() );
|
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
curr_cmd->ClearListAndDeleteItems();
|
2009-07-29 13:10:36 +00:00
|
|
|
delete curr_cmd; // Delete command
|
|
|
|
}
|
|
|
|
}
|