2012-06-08 09:56:42 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
2013-12-18 13:33:34 +00:00
|
|
|
#include <class_drawpanel_gal.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <macros.h>
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <wxPcbStruct.h>
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_drawsegment.h>
|
|
|
|
#include <class_pcb_text.h>
|
|
|
|
#include <class_mire.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_dimension.h>
|
|
|
|
#include <class_zone.h>
|
2013-11-19 18:58:12 +00:00
|
|
|
#include <class_edge_mod.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2014-01-29 09:17:14 +00:00
|
|
|
#include <ratsnest_data.h>
|
|
|
|
|
2013-12-18 13:33:34 +00:00
|
|
|
#include <tools/selection_tool.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
/* Functions to undo and redo edit commands.
|
2013-10-14 15:29:16 +00:00
|
|
|
* commands to undo are stored in CurrentScreen->m_UndoList
|
|
|
|
* commands to redo are stored in CurrentScreen->m_RedoList
|
2009-07-29 13:10:36 +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),
|
|
|
|
* 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).
|
2011-09-07 19:41:04 +00:00
|
|
|
* each picker has a pointer pointing to an item to undo or redo (in fact: deleted, added or
|
|
|
|
* modified),
|
2009-07-29 13:10:36 +00:00
|
|
|
* 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
|
2011-09-07 19:41:04 +00:00
|
|
|
* => The list of item(s) is used to create a deleted list in undo list(same as a delete
|
|
|
|
* command)
|
2009-07-29 13:10:36 +00:00
|
|
|
*
|
2013-10-14 15:29:16 +00:00
|
|
|
* Some block operations that change items can be undone without memorize items, just the
|
|
|
|
* coordinates of the transform:
|
2009-07-29 13:10:36 +00:00
|
|
|
* 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
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function TestForExistingItem
|
2009-07-31 05:33:11 +00:00
|
|
|
* test if aItem exists somewhere in lists of items
|
2013-10-14 15:29:16 +00:00
|
|
|
* This is a function used by PutDataInPreviousState to be sure an item was not deleted
|
2009-07-31 05:33:11 +00:00
|
|
|
* since an undo or redo.
|
|
|
|
* This could be possible:
|
2011-09-30 18:15:37 +00:00
|
|
|
* - if a call to SaveCopyInUndoList was forgotten in Pcbnew
|
2009-07-31 05:33:11 +00:00
|
|
|
* - in zones outlines, when a change in one zone merges this zone with an other
|
2011-09-30 18:15:37 +00:00
|
|
|
* This function avoids a Pcbnew crash
|
2011-11-27 12:29:01 +00:00
|
|
|
* Before using this function to test existence of items,
|
|
|
|
* it must be called with aItem = NULL to prepare the list
|
2010-12-28 11:24:42 +00:00
|
|
|
* @param aPcb = board to test
|
2009-07-31 05:33:11 +00:00
|
|
|
* @param aItem = item to find
|
2011-11-27 12:29:01 +00:00
|
|
|
* = NULL to build the list of existing items
|
2009-07-31 05:33:11 +00:00
|
|
|
*/
|
2009-08-01 19:26:05 +00:00
|
|
|
static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem )
|
2009-07-31 05:33:11 +00:00
|
|
|
{
|
2011-11-27 12:29:01 +00:00
|
|
|
static std::vector<BOARD_ITEM*> itemsList;
|
|
|
|
|
|
|
|
if( aItem == NULL ) // Build list
|
|
|
|
{
|
|
|
|
// Count items to store in itemsList:
|
|
|
|
int icnt = 0;
|
|
|
|
BOARD_ITEM* item;
|
|
|
|
|
|
|
|
// Count tracks:
|
|
|
|
for( item = aPcb->m_Track; item != NULL; item = item->Next() )
|
|
|
|
icnt++;
|
|
|
|
|
|
|
|
// Count modules:
|
|
|
|
for( item = aPcb->m_Modules; item != NULL; item = item->Next() )
|
|
|
|
icnt++;
|
|
|
|
|
|
|
|
// Count drawings
|
|
|
|
for( item = aPcb->m_Drawings; item != NULL; item = item->Next() )
|
|
|
|
icnt++;
|
|
|
|
|
|
|
|
// Count zones outlines
|
|
|
|
icnt += aPcb->GetAreaCount();
|
2009-08-01 19:26:05 +00:00
|
|
|
|
2011-11-27 12:29:01 +00:00
|
|
|
// Count zones segm (now obsolete):
|
|
|
|
for( item = aPcb->m_Zone; item != NULL; item = item->Next() )
|
|
|
|
icnt++;
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2011-11-27 12:29:01 +00:00
|
|
|
// Build candidate list:
|
|
|
|
itemsList.clear();
|
|
|
|
itemsList.reserve(icnt);
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2011-11-27 12:29:01 +00:00
|
|
|
// Store items in list:
|
|
|
|
// Append tracks:
|
|
|
|
for( item = aPcb->m_Track; item != NULL; item = item->Next() )
|
|
|
|
itemsList.push_back( item );
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2011-11-27 12:29:01 +00:00
|
|
|
// Append modules:
|
|
|
|
for( item = aPcb->m_Modules; item != NULL; item = item->Next() )
|
|
|
|
itemsList.push_back( item );
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2011-11-27 12:29:01 +00:00
|
|
|
// Append drawings
|
|
|
|
for( item = aPcb->m_Drawings; item != NULL; item = item->Next() )
|
|
|
|
itemsList.push_back( item );
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2011-11-27 12:29:01 +00:00
|
|
|
// Append zones outlines
|
|
|
|
for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ )
|
|
|
|
itemsList.push_back( aPcb->GetArea( ii ) );
|
|
|
|
|
|
|
|
// Append zones segm:
|
|
|
|
for( item = aPcb->m_Zone; item != NULL; item = item->Next() )
|
|
|
|
itemsList.push_back( item );
|
|
|
|
|
|
|
|
// Sort list
|
|
|
|
std::sort( itemsList.begin(), itemsList.end() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// search in list:
|
|
|
|
return std::binary_search( itemsList.begin(), itemsList.end(), aItem );
|
2009-07-31 05:33:11 +00:00
|
|
|
}
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
|
2013-11-20 17:26:47 +00:00
|
|
|
void BOARD_ITEM::SwapData( BOARD_ITEM* aImage )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2013-11-20 17:26:47 +00:00
|
|
|
if( aImage == NULL )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-20 17:26:47 +00:00
|
|
|
EDA_ITEM * pnext = Next();
|
|
|
|
EDA_ITEM * pback = Back();
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2013-11-20 17:26:47 +00:00
|
|
|
switch( Type() )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_MODULE_T:
|
2013-11-19 18:58:12 +00:00
|
|
|
{
|
|
|
|
MODULE* tmp = (MODULE*) aImage->Clone();
|
2013-11-20 17:26:47 +00:00
|
|
|
( (MODULE*) aImage )->Copy( (MODULE*) this );
|
|
|
|
( (MODULE*) this )->Copy( tmp );
|
2013-11-19 18:58:12 +00:00
|
|
|
delete tmp;
|
|
|
|
}
|
2011-12-14 04:29:25 +00:00
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_ZONE_AREA_T:
|
2013-11-19 18:58:12 +00:00
|
|
|
{
|
|
|
|
ZONE_CONTAINER* tmp = (ZONE_CONTAINER*) aImage->Clone();
|
2013-11-20 17:26:47 +00:00
|
|
|
( (ZONE_CONTAINER*) aImage )->Copy( (ZONE_CONTAINER*) this );
|
|
|
|
( (ZONE_CONTAINER*) this )->Copy( tmp );
|
2013-11-19 18:58:12 +00:00
|
|
|
delete tmp;
|
|
|
|
}
|
2011-12-14 04:29:25 +00:00
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_LINE_T:
|
2013-11-20 17:26:47 +00:00
|
|
|
std::swap( *((DRAWSEGMENT*)this), *((DRAWSEGMENT*)aImage) );
|
2009-08-03 07:55:08 +00:00
|
|
|
break;
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_TRACE_T:
|
|
|
|
case PCB_VIA_T:
|
2013-11-19 18:58:12 +00:00
|
|
|
{
|
2013-11-20 17:26:47 +00:00
|
|
|
TRACK* track = (TRACK*) this;
|
2013-11-19 18:58:12 +00:00
|
|
|
TRACK* image = (TRACK*) aImage;
|
|
|
|
|
2013-11-20 17:26:47 +00:00
|
|
|
EXCHG(track->m_Layer, image->m_Layer );
|
|
|
|
|
2013-11-19 18:58:12 +00:00
|
|
|
// swap start, end, width and shape for track and image.
|
|
|
|
wxPoint exchp = track->GetStart();
|
|
|
|
track->SetStart( image->GetStart() );
|
|
|
|
image->SetStart( exchp );
|
|
|
|
exchp = track->GetEnd();
|
|
|
|
track->SetEnd( image->GetEnd() );
|
|
|
|
image->SetEnd( exchp );
|
|
|
|
|
|
|
|
int atmp = track->GetWidth();
|
|
|
|
track->SetWidth( image->GetWidth() );
|
|
|
|
image->SetWidth( atmp );
|
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
if( Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
VIA *via = static_cast<VIA*>( this );
|
|
|
|
VIA *viaimage = static_cast<VIA*>( aImage );
|
2013-11-19 18:58:12 +00:00
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
VIATYPE_T viatmp = via->GetViaType();
|
|
|
|
via->SetViaType( viaimage->GetViaType() );
|
|
|
|
viaimage->SetViaType( viatmp );
|
2013-11-19 18:58:12 +00:00
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
int drilltmp = via->GetDrillValue();
|
2013-11-19 18:58:12 +00:00
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
if( via->IsDrillDefault() )
|
|
|
|
drilltmp = -1;
|
2013-11-19 18:58:12 +00:00
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
int itmp = viaimage->GetDrillValue();
|
2013-11-19 18:58:12 +00:00
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
if( viaimage->IsDrillDefault() )
|
|
|
|
itmp = -1;
|
2013-11-19 18:58:12 +00:00
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
EXCHG(itmp, drilltmp );
|
|
|
|
|
|
|
|
if( drilltmp > 0 )
|
|
|
|
via->SetDrill( drilltmp );
|
|
|
|
else
|
|
|
|
via->SetDrillDefault();
|
|
|
|
|
|
|
|
if( itmp > 0 )
|
|
|
|
viaimage->SetDrill( itmp );
|
|
|
|
else
|
|
|
|
viaimage->SetDrillDefault();
|
|
|
|
}
|
2013-11-19 18:58:12 +00:00
|
|
|
}
|
2009-08-03 18:54:48 +00:00
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_TEXT_T:
|
2013-11-20 17:26:47 +00:00
|
|
|
std::swap( *((TEXTE_PCB*)this), *((TEXTE_PCB*)aImage) );
|
2009-08-03 18:54:48 +00:00
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
case PCB_TARGET_T:
|
2013-11-20 17:26:47 +00:00
|
|
|
std::swap( *((PCB_TARGET*)this), *((PCB_TARGET*)aImage) );
|
2009-08-03 18:54:48 +00:00
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_DIMENSION_T:
|
2013-11-20 17:26:47 +00:00
|
|
|
std::swap( *((DIMENSION*)this), *((DIMENSION*)aImage) );
|
2011-12-14 04:29:25 +00:00
|
|
|
break;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_ZONE_T:
|
2009-07-29 13:10:36 +00:00
|
|
|
default:
|
2013-11-20 17:26:47 +00:00
|
|
|
wxLogMessage( wxT( "SwapData() error: unexpected type %d" ), Type() );
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-11-20 17:26:47 +00:00
|
|
|
|
|
|
|
if( pnext != Next() || pback != Back() )
|
|
|
|
{
|
|
|
|
Pnext = pnext;
|
|
|
|
Pback = pback;
|
|
|
|
#ifdef DEBUG
|
|
|
|
wxLogMessage( wxT( "SwapData Error: %s Pnext or Pback pointers modified" ),
|
|
|
|
GetClass().GetData() );
|
|
|
|
#endif
|
|
|
|
}
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::SaveCopyInUndoList( BOARD_ITEM* aItem,
|
2011-04-05 14:46:51 +00:00
|
|
|
UNDO_REDO_T aCommandType,
|
2011-03-01 19:26:17 +00:00
|
|
|
const wxPoint& aTransformPoint )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2009-08-04 18:21:32 +00:00
|
|
|
if( aItem == NULL ) // Nothing to save
|
|
|
|
return;
|
|
|
|
|
2013-12-19 09:10:42 +00:00
|
|
|
// For texts belonging to modules, we need to save state of the parent module
|
|
|
|
if( aItem->Type() == PCB_MODULE_TEXT_T )
|
|
|
|
{
|
|
|
|
aItem = aItem->GetParent();
|
|
|
|
wxASSERT( aItem->Type() == PCB_MODULE_T );
|
|
|
|
aCommandType = UR_CHANGED;
|
|
|
|
|
|
|
|
if( aItem == NULL )
|
|
|
|
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 );
|
2009-07-29 13:10:36 +00:00
|
|
|
|
|
|
|
switch( aCommandType )
|
|
|
|
{
|
2012-02-05 13:02:46 +00:00
|
|
|
case UR_CHANGED: // Create a copy of item
|
|
|
|
if( itemWrapper.GetLink() == NULL ) // When not null, the copy is already done
|
|
|
|
itemWrapper.SetLink( aItem->Clone() );
|
|
|
|
commandToUndo->PushItem( itemWrapper );
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_NEW:
|
2012-12-23 10:53:54 +00:00
|
|
|
case UR_DELETED:
|
|
|
|
#ifdef USE_WX_OVERLAY
|
2013-02-14 19:57:19 +00:00
|
|
|
// Avoid to redraw when autoplacing
|
2013-10-14 15:29:16 +00:00
|
|
|
if( aItem->Type() == PCB_MODULE_T )
|
2013-02-14 19:57:19 +00:00
|
|
|
if( ((MODULE*)aItem)->GetFlags() & MODULE_to_PLACE )
|
|
|
|
break;
|
2012-12-23 10:53:54 +00:00
|
|
|
m_canvas->Refresh();
|
|
|
|
#endif
|
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
|
|
|
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
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
2009-07-29 13:10:36 +00:00
|
|
|
delete commandToUndo;
|
2012-01-14 19:50:32 +00:00
|
|
|
}
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-18 12:27:18 +00:00
|
|
|
void PCB_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
|
2011-04-05 14:46:51 +00:00
|
|
|
UNDO_REDO_T aTypeCommand,
|
2011-03-01 19:26:17 +00:00
|
|
|
const wxPoint& aTransformPoint )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2011-04-05 14:46:51 +00:00
|
|
|
BOARD_ITEM* item = (BOARD_ITEM*) commandToUndo->GetPickedItem( ii );
|
2013-12-19 09:10:42 +00:00
|
|
|
|
|
|
|
// For texts belonging to modules, we need to save state of the parent module
|
|
|
|
if( item->Type() == PCB_MODULE_TEXT_T )
|
|
|
|
{
|
|
|
|
item = item->GetParent();
|
|
|
|
wxASSERT( item->Type() == PCB_MODULE_T );
|
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
commandToUndo->SetPickedItem( item, ii );
|
|
|
|
commandToUndo->SetPickedItemStatus( UR_CHANGED, ii );
|
|
|
|
}
|
|
|
|
|
2011-04-05 14:46:51 +00:00
|
|
|
UNDO_REDO_T command = commandToUndo->GetPickedItemStatus( ii );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
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 );
|
2012-01-14 19:50:32 +00:00
|
|
|
|
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 )
|
2012-01-14 19:50:32 +00:00
|
|
|
commandToUndo->SetPickedItemLink( item->Clone(), ii );
|
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 );
|
|
|
|
}
|
2012-01-14 19:50:32 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
2012-01-14 19:50:32 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2009-07-29 13:10:36 +00:00
|
|
|
delete commandToUndo;
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::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;
|
2014-01-06 09:29:31 +00:00
|
|
|
KIGFX::VIEW* view = GetGalCanvas()->GetView();
|
2014-01-29 09:17:14 +00:00
|
|
|
RN_DATA* ratsnest = GetBoard()->GetRatsnest();
|
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
|
2011-11-27 12:29:01 +00:00
|
|
|
|
2013-10-14 15:29:16 +00:00
|
|
|
bool build_item_list = true; // if true the list of existing items must be rebuilt
|
|
|
|
|
2014-01-29 09:17:14 +00:00
|
|
|
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 );
|
2011-11-27 12:29:01 +00:00
|
|
|
|
|
|
|
/* Test for existence of item on board.
|
|
|
|
* It could be deleted, and no more on board:
|
|
|
|
* - 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 test avoids a Pcbnew crash
|
2013-10-14 15:29:16 +00:00
|
|
|
* Obviously, this test is not made for deleted items
|
2011-11-27 12:29:01 +00:00
|
|
|
*/
|
2012-02-04 20:30:00 +00:00
|
|
|
UNDO_REDO_T status = aList->GetPickedItemStatus( ii );
|
2013-10-14 15:29:16 +00:00
|
|
|
|
2012-02-05 13:02:46 +00:00
|
|
|
if( status != UR_DELETED )
|
2009-07-31 05:33:11 +00:00
|
|
|
{
|
2012-02-04 20:30:00 +00:00
|
|
|
if( build_item_list )
|
|
|
|
// Build list of existing items, for integrity test
|
|
|
|
TestForExistingItem( GetBoard(), NULL );
|
2013-10-14 15:29:16 +00:00
|
|
|
|
2012-02-04 20:30:00 +00:00
|
|
|
build_item_list = false;
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
if( !TestForExistingItem( GetBoard(), item ) )
|
2009-07-31 05:33:11 +00:00
|
|
|
{
|
2013-10-14 15:29:16 +00:00
|
|
|
// Remove this non existent 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
|
2011-11-27 12:29:01 +00:00
|
|
|
// decrement it because it will be incremented later
|
2009-07-31 05:33:11 +00:00
|
|
|
not_found = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-11-27 12:29:01 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
item->ClearFlags();
|
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() )
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_MODULE_T:
|
|
|
|
case PCB_ZONE_AREA_T:
|
|
|
|
case PCB_TRACE_T:
|
|
|
|
case PCB_VIA_T:
|
2009-08-03 18:54:48 +00:00
|
|
|
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 );
|
2013-12-18 13:33:34 +00:00
|
|
|
|
|
|
|
// Remove all pads/drawings/texts, as they become invalid
|
|
|
|
// for the VIEW after SwapData() called for modules
|
|
|
|
if( item->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
MODULE* oldModule = static_cast<MODULE*>( item );
|
2014-01-29 09:17:14 +00:00
|
|
|
oldModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Remove ), view ) );
|
2013-12-18 13:33:34 +00:00
|
|
|
}
|
2014-01-31 15:08:20 +00:00
|
|
|
ratsnest->Remove( item );
|
2013-12-18 13:33:34 +00:00
|
|
|
|
2013-11-20 17:26:47 +00:00
|
|
|
item->SwapData( image );
|
2013-12-18 13:33:34 +00:00
|
|
|
|
|
|
|
// Update all pads/drawings/texts, as they become invalid
|
|
|
|
// for the VIEW after SwapData() called for modules
|
|
|
|
if( item->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
MODULE* newModule = static_cast<MODULE*>( item );
|
2014-01-29 09:17:14 +00:00
|
|
|
newModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), view ) );
|
2013-12-18 13:33:34 +00:00
|
|
|
}
|
2014-01-31 15:08:20 +00:00
|
|
|
ratsnest->Add( item );
|
2013-12-18 13:33:34 +00:00
|
|
|
|
2014-02-05 09:47:55 +00:00
|
|
|
item->ClearFlags( SELECTED );
|
2013-12-18 13:33:34 +00:00
|
|
|
item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS );
|
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 );
|
2013-12-18 13:33:34 +00:00
|
|
|
|
|
|
|
if( item->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
MODULE* module = static_cast<MODULE*>( item );
|
2014-01-30 14:46:39 +00:00
|
|
|
module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Remove ), view ) );
|
2013-12-18 13:33:34 +00:00
|
|
|
}
|
|
|
|
view->Remove( item );
|
|
|
|
|
|
|
|
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
2009-07-29 13:10:36 +00:00
|
|
|
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 );
|
2013-12-18 13:33:34 +00:00
|
|
|
|
|
|
|
if( item->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
MODULE* module = static_cast<MODULE*>( item );
|
2014-01-30 14:46:39 +00:00
|
|
|
module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), view ) );
|
2013-12-18 13:33:34 +00:00
|
|
|
}
|
|
|
|
view->Add( item );
|
|
|
|
|
|
|
|
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
2012-02-04 20:30:00 +00:00
|
|
|
build_item_list = true;
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_MOVED:
|
2009-08-03 18:54:48 +00:00
|
|
|
item->Move( aRedoCommand ? aList->m_TransformPoint : -aList->m_TransformPoint );
|
2013-12-18 13:33:34 +00:00
|
|
|
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
2014-01-30 14:46:39 +00:00
|
|
|
ratsnest->Update( item );
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
case UR_ROTATED:
|
2013-12-16 21:40:03 +00:00
|
|
|
item->Rotate( aList->m_TransformPoint,
|
|
|
|
aRedoCommand ? m_rotationAngle : -m_rotationAngle );
|
2014-01-29 09:17:14 +00:00
|
|
|
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
2014-01-30 14:46:39 +00:00
|
|
|
ratsnest->Update( item );
|
2009-08-01 19:26:05 +00:00
|
|
|
break;
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2009-08-06 07:11:04 +00:00
|
|
|
case UR_ROTATED_CLOCKWISE:
|
2013-12-16 21:40:03 +00:00
|
|
|
item->Rotate( aList->m_TransformPoint,
|
|
|
|
aRedoCommand ? -m_rotationAngle : m_rotationAngle );
|
2014-01-29 09:17:14 +00:00
|
|
|
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
2014-01-30 14:46:39 +00:00
|
|
|
ratsnest->Update( item );
|
2009-08-06 07:11:04 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
case UR_FLIPPED:
|
|
|
|
item->Flip( aList->m_TransformPoint );
|
2013-12-18 13:33:34 +00:00
|
|
|
item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS );
|
2014-01-30 14:46:39 +00:00
|
|
|
ratsnest->Update( item );
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
wxString msg;
|
2011-09-07 19:41:04 +00:00
|
|
|
msg.Printf( wxT( "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
|
|
|
|
2013-10-14 15:29:16 +00:00
|
|
|
// Rebuild pointers and ratsnest that can be changed.
|
2009-08-13 05:52:53 +00:00
|
|
|
if( reBuild_ratsnest && aRebuildRatsnet )
|
2014-01-29 09:17:14 +00:00
|
|
|
{
|
|
|
|
if( IsGalCanvasActive() )
|
|
|
|
ratsnest->Recalculate();
|
|
|
|
else
|
|
|
|
Compile_Ratsnest( NULL, true );
|
|
|
|
}
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-30 10:18:58 +00:00
|
|
|
void PCB_EDIT_FRAME::GetBoardFromUndoList( wxCommandEvent& aEvent )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
|
|
|
if( GetScreen()->GetUndoCommandCount() <= 0 )
|
|
|
|
return;
|
|
|
|
|
2014-01-31 15:08:20 +00:00
|
|
|
// Inform tools that undo command was issued
|
|
|
|
TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL );
|
|
|
|
m_toolManager->ProcessEvent( event );
|
|
|
|
|
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();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-30 10:18:58 +00:00
|
|
|
void PCB_EDIT_FRAME::GetBoardFromRedoList( wxCommandEvent& aEvent )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
|
|
|
if( GetScreen()->GetRedoCommandCount() == 0 )
|
|
|
|
return;
|
|
|
|
|
2014-01-31 15:08:20 +00:00
|
|
|
// Inform tools that redo command was issued
|
|
|
|
TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL );
|
|
|
|
m_toolManager->ProcessEvent( event );
|
|
|
|
|
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();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
|
|
|
if( aItemCount == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned icnt = aList.m_CommandsList.size();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
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;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|