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>
|
2016-05-25 09:52:43 +00:00
|
|
|
* Copyright (C) 2016 CERN
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-06-08 09:56:42 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2014-04-04 09:56:04 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <macros.h>
|
|
|
|
#include <pcbnew.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
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>
|
2017-10-31 15:38:10 +00:00
|
|
|
#include <class_pcb_target.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#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>
|
2018-01-24 10:19:33 +00:00
|
|
|
#include <origin_viewitem.h>
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2019-05-26 15:36:40 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tool/actions.h>
|
2013-12-18 13:33:34 +00:00
|
|
|
#include <tools/selection_tool.h>
|
2018-01-24 10:19:33 +00:00
|
|
|
#include <tools/pcbnew_control.h>
|
|
|
|
#include <tools/pcb_editor_control.h>
|
2016-12-02 17:58:12 +00:00
|
|
|
#include <view/view.h>
|
2019-05-26 15:36:40 +00:00
|
|
|
#include <ws_proxy_undo_item.h>
|
2016-12-02 17:58: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
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
2016-01-29 14:43:40 +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
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto item : aPcb->Tracks() )
|
2011-11-27 12:29:01 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
if( aItem == static_cast<BOARD_ITEM*>( item ) )
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
// Append modules:
|
|
|
|
for( auto item : aPcb->Modules() )
|
|
|
|
{
|
|
|
|
if( aItem == static_cast<BOARD_ITEM*>( item ) )
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-31 05:33:11 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
// Append drawings
|
|
|
|
for( auto item : aPcb->Drawings() )
|
|
|
|
{
|
|
|
|
if( aItem == static_cast<BOARD_ITEM*>( item ) )
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-27 12:29:01 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
// Append zones outlines
|
|
|
|
for( auto item : aPcb->Zones() )
|
|
|
|
{
|
|
|
|
if( aItem == static_cast<BOARD_ITEM*>( item ) )
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-18 10:17:08 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
NETINFO_LIST& netInfo = aPcb->GetNetInfo();
|
2016-05-18 10:17:08 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )
|
|
|
|
{
|
|
|
|
if( aItem == static_cast<BOARD_ITEM*>( *i ) )
|
|
|
|
return true;
|
2011-11-27 12:29:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
return false;
|
2009-07-31 05:33:11 +00:00
|
|
|
}
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2017-10-31 13:59:03 +00:00
|
|
|
static void SwapItemData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
|
|
|
|
{
|
|
|
|
if( aImage == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxASSERT( aItem->Type() == aImage->Type() );
|
|
|
|
|
|
|
|
// Remark: to create images of edited items to undo, we are using Clone method
|
|
|
|
// which can duplication of items foe copy, but does not clone all members
|
|
|
|
// mainly pointers in chain and time stamp, which is set to new, unique value.
|
|
|
|
// So we have to use the current values of these parameters.
|
|
|
|
|
2017-12-07 08:29:10 +00:00
|
|
|
timestamp_t timestamp = aItem->GetTimeStamp();
|
2017-10-31 13:59:03 +00:00
|
|
|
EDA_ITEM* parent = aItem->GetParent();
|
|
|
|
|
|
|
|
aItem->SwapData( aImage );
|
|
|
|
|
|
|
|
// Restore pointers and time stamp, to be sure they are not broken
|
|
|
|
aItem->SetTimeStamp( timestamp );
|
|
|
|
aItem->SetParent( parent );
|
|
|
|
}
|
2009-08-01 19:26:05 +00:00
|
|
|
|
2016-05-25 09:52:43 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType,
|
|
|
|
const wxPoint& aTransformPoint )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2016-05-25 09:52:43 +00:00
|
|
|
PICKED_ITEMS_LIST commandToUndo;
|
|
|
|
commandToUndo.PushItem( ITEM_PICKER( aItem, aCommandType ) );
|
|
|
|
SaveCopyInUndoList( commandToUndo, aCommandType, aTransformPoint );
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-25 09:52:43 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
|
2019-05-11 10:06:28 +00:00
|
|
|
UNDO_REDO_T aTypeCommand,
|
|
|
|
const wxPoint& aTransformPoint )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
static KICAD_T moduleChildren[] = { PCB_MODULE_TEXT_T, PCB_MODULE_EDGE_T, PCB_PAD_T, EOT };
|
|
|
|
|
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
|
|
|
|
2016-01-29 10:21:13 +00:00
|
|
|
// First, filter unnecessary stuff from the list (i.e. for multiple pads / labels modified),
|
2016-05-25 09:52:43 +00:00
|
|
|
// take the first occurence of the module (we save copies of modules when one of its subitems
|
|
|
|
// is changed).
|
2016-01-29 10:21:13 +00:00
|
|
|
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2016-09-29 17:34:51 +00:00
|
|
|
ITEM_PICKER curr_picker = aItemsList.GetItemWrapper(ii);
|
2019-05-26 15:36:40 +00:00
|
|
|
BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( aItemsList.GetPickedItem( ii ) );
|
2013-12-19 09:10:42 +00:00
|
|
|
|
2016-05-25 09:52:43 +00:00
|
|
|
// For items belonging to modules, we need to save state of the parent module
|
2019-05-26 15:36:40 +00:00
|
|
|
if( item && item->IsType( moduleChildren ) )
|
2013-12-19 09:10:42 +00:00
|
|
|
{
|
2016-05-25 09:52:43 +00:00
|
|
|
// Item to be stored in the undo buffer is the parent module
|
2013-12-19 09:10:42 +00:00
|
|
|
item = item->GetParent();
|
2016-05-25 09:52:43 +00:00
|
|
|
wxASSERT( item && item->Type() == PCB_MODULE_T );
|
2013-12-19 09:10:42 +00:00
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
continue;
|
|
|
|
|
2016-05-25 09:52:43 +00:00
|
|
|
// Check if the parent module has already been saved in another entry
|
2016-01-29 10:21:13 +00:00
|
|
|
bool found = false;
|
2015-11-04 08:48:34 +00:00
|
|
|
|
2016-01-29 14:43:40 +00:00
|
|
|
for( unsigned j = 0; j < commandToUndo->GetCount(); j++ )
|
2016-01-29 10:21:13 +00:00
|
|
|
{
|
2019-05-11 10:06:28 +00:00
|
|
|
if( commandToUndo->GetPickedItem( j ) == item
|
|
|
|
&& commandToUndo->GetPickedItemStatus( j ) == UR_CHANGED )
|
2016-01-29 10:21:13 +00:00
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !found )
|
2016-05-25 09:52:43 +00:00
|
|
|
{
|
|
|
|
// Create a clean copy of the parent module
|
2016-06-07 14:55:56 +00:00
|
|
|
MODULE* orig = static_cast<MODULE*>( item );
|
|
|
|
MODULE* clone = new MODULE( *orig );
|
2016-05-25 09:52:43 +00:00
|
|
|
clone->SetParent( GetBoard() );
|
|
|
|
|
|
|
|
// Clear current flags (which can be temporary set by a current edit command)
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto child : clone->GraphicalItems() )
|
2019-05-11 10:06:28 +00:00
|
|
|
child->ClearEditFlags();
|
2016-05-25 09:52:43 +00:00
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : clone->Pads() )
|
2019-05-11 10:06:28 +00:00
|
|
|
pad->ClearEditFlags();
|
2016-05-25 09:52:43 +00:00
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
clone->Reference().ClearEditFlags();
|
|
|
|
clone->Value().ClearEditFlags();
|
2016-05-25 09:52:43 +00:00
|
|
|
|
|
|
|
ITEM_PICKER picker( item, UR_CHANGED );
|
|
|
|
picker.SetLink( clone );
|
|
|
|
commandToUndo->PushItem( picker );
|
2016-06-07 14:55:56 +00:00
|
|
|
|
|
|
|
orig->SetLastEditTime();
|
2016-05-25 09:52:43 +00:00
|
|
|
}
|
2016-01-29 10:21:13 +00:00
|
|
|
else
|
2016-05-25 09:52:43 +00:00
|
|
|
{
|
2016-01-29 10:21:13 +00:00
|
|
|
continue;
|
2016-05-25 09:52:43 +00:00
|
|
|
}
|
2016-09-29 17:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-25 09:52:43 +00:00
|
|
|
// Normal case: all other BOARD_ITEMs, are simply copied to the new list
|
2016-09-29 17:34:51 +00:00
|
|
|
commandToUndo->PushItem( curr_picker );
|
2013-12-19 09:10:42 +00:00
|
|
|
}
|
2016-01-29 10:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < commandToUndo->GetCount(); ii++ )
|
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
EDA_ITEM* item = aItemsList.GetPickedItem( 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:
|
2018-01-24 10:19:33 +00:00
|
|
|
case UR_DRILLORIGIN:
|
|
|
|
case UR_GRIDORIGIN:
|
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 )
|
2016-01-29 14:43:40 +00:00
|
|
|
{
|
|
|
|
EDA_ITEM* cloned = item->Clone();
|
|
|
|
commandToUndo->SetPickedItemLink( cloned, 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:
|
2019-05-26 15:36:40 +00:00
|
|
|
case UR_PAGESETTINGS:
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2019-01-02 04:43:13 +00:00
|
|
|
wxLogDebug( wxT( "SaveCopyInUndoList() error (unknown code %X)" ), command );
|
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 );
|
|
|
|
}
|
2016-05-25 09:52:43 +00:00
|
|
|
else
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2016-05-25 09:52:43 +00:00
|
|
|
// Should not occur
|
|
|
|
wxASSERT( false );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-25 09:52:43 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( UndoRedoBlocked() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( GetScreen()->GetUndoCommandCount() <= 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Inform tools that undo command was issued
|
2016-09-23 09:31:36 +00:00
|
|
|
m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_PRE, AS_GLOBAL } );
|
2016-05-25 09:52:43 +00:00
|
|
|
|
|
|
|
// Get the old list
|
|
|
|
PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromUndoList();
|
|
|
|
|
|
|
|
// Undo the command
|
|
|
|
PutDataInPreviousState( List, false );
|
|
|
|
|
|
|
|
// Put the old list in RedoList
|
|
|
|
List->ReversePickersListOrder();
|
|
|
|
GetScreen()->PushCommandToRedoList( List );
|
|
|
|
|
|
|
|
OnModify();
|
2016-09-23 09:31:36 +00:00
|
|
|
|
|
|
|
m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_POST, AS_GLOBAL } );
|
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2016-05-25 09:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_BASE_EDIT_FRAME::RestoreCopyFromRedoList( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( UndoRedoBlocked() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( GetScreen()->GetRedoCommandCount() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Inform tools that redo command was issued
|
2016-09-23 09:31:36 +00:00
|
|
|
m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_PRE, AS_GLOBAL } );
|
2016-05-25 09:52:43 +00:00
|
|
|
|
|
|
|
// Get the old list
|
|
|
|
PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromRedoList();
|
|
|
|
|
|
|
|
// Redo the command
|
|
|
|
PutDataInPreviousState( List, true );
|
|
|
|
|
|
|
|
// Put the old list in UndoList
|
|
|
|
List->ReversePickersListOrder();
|
|
|
|
GetScreen()->PushCommandToUndoList( List );
|
|
|
|
|
|
|
|
OnModify();
|
2016-09-23 09:31:36 +00:00
|
|
|
|
|
|
|
m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_POST, AS_GLOBAL } );
|
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2016-05-25 09:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRedoCommand,
|
2019-05-27 17:58:36 +00:00
|
|
|
bool aRebuildRatsnet )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2019-05-27 17:58:36 +00:00
|
|
|
bool not_found = false;
|
|
|
|
bool reBuild_ratsnest = false;
|
|
|
|
bool deep_reBuild_ratsnest = false; // true later if pointers must be rebuilt
|
2016-01-29 14:43:40 +00:00
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
auto view = GetCanvas()->GetView();
|
2017-03-22 13:43:10 +00:00
|
|
|
auto connectivity = GetBoard()->GetConnectivity();
|
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
|
|
|
|
2016-09-05 10:18:26 +00:00
|
|
|
// Restore changes in reverse order
|
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
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
EDA_ITEM* eda_item = aList->GetPickedItem( (unsigned) ii );
|
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
|
|
|
|
2018-01-24 10:19:33 +00:00
|
|
|
if( status != UR_DELETED
|
|
|
|
&& status != UR_DRILLORIGIN // origin markers never on board
|
2019-05-26 15:36:40 +00:00
|
|
|
&& status != UR_GRIDORIGIN // origin markers never on board
|
|
|
|
&& status != UR_PAGESETTINGS ) // nor are page settings proxy items
|
2009-07-31 05:33:11 +00:00
|
|
|
{
|
2019-05-27 17:58:36 +00:00
|
|
|
if( !TestForExistingItem( GetBoard(), (BOARD_ITEM*) eda_item ) )
|
2009-07-31 05:33:11 +00:00
|
|
|
{
|
2016-05-25 09:52:43 +00:00
|
|
|
// Checking if it ever happens
|
|
|
|
wxASSERT_MSG( false, "Item in the undo buffer does not exist" );
|
|
|
|
|
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;
|
2019-05-31 02:30:28 +00:00
|
|
|
|
|
|
|
if( aList->GetCount() == 0 )
|
|
|
|
break;
|
|
|
|
|
2009-07-31 05:33:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-11-27 12:29:01 +00:00
|
|
|
|
2009-08-06 15:42:09 +00:00
|
|
|
// see if we must rebuild ratsnets and pointers lists
|
2019-05-27 17:58:36 +00:00
|
|
|
switch( eda_item->Type() )
|
2009-08-03 07:55:08 +00:00
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_MODULE_T:
|
2016-09-30 09:09:17 +00:00
|
|
|
deep_reBuild_ratsnest = true; // Pointers on pads can be invalid
|
|
|
|
// Fall through
|
2011-10-01 19:24:27 +00:00
|
|
|
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;
|
|
|
|
|
2016-01-29 14:43:40 +00:00
|
|
|
case PCB_NETINFO_T:
|
|
|
|
reBuild_ratsnest = true;
|
|
|
|
deep_reBuild_ratsnest = true;
|
|
|
|
break;
|
|
|
|
|
2009-08-03 18:54:48 +00:00
|
|
|
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
|
|
|
{
|
2019-05-27 21:17:22 +00:00
|
|
|
BOARD_ITEM* item = (BOARD_ITEM*) eda_item;
|
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
|
2019-05-27 17:58:36 +00:00
|
|
|
view->Remove( eda_item );
|
2017-03-22 13:43:10 +00:00
|
|
|
connectivity->Remove( item );
|
2013-12-18 13:33:34 +00:00
|
|
|
|
2017-10-31 13:59:03 +00:00
|
|
|
SwapItemData( item, image );
|
2013-12-18 13:33:34 +00:00
|
|
|
|
2019-05-27 17:58:36 +00:00
|
|
|
view->Add( eda_item );
|
2017-03-22 13:43:10 +00:00
|
|
|
connectivity->Add( item );
|
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 );
|
2019-05-27 17:58:36 +00:00
|
|
|
GetModel()->Remove( (BOARD_ITEM*) eda_item );
|
|
|
|
view->Remove( eda_item );
|
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 );
|
2019-05-27 17:58:36 +00:00
|
|
|
GetModel()->Add( (BOARD_ITEM*) eda_item );
|
|
|
|
view->Add( eda_item );
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UR_MOVED:
|
2019-05-27 17:58:36 +00:00
|
|
|
{
|
2019-05-27 21:17:22 +00:00
|
|
|
BOARD_ITEM* item = (BOARD_ITEM*) eda_item;
|
2009-08-03 18:54:48 +00:00
|
|
|
item->Move( aRedoCommand ? aList->m_TransformPoint : -aList->m_TransformPoint );
|
2016-12-09 11:04:32 +00:00
|
|
|
view->Update( item, KIGFX::GEOMETRY );
|
2017-03-22 13:43:10 +00:00
|
|
|
connectivity->Update( item );
|
2019-05-27 17:58:36 +00:00
|
|
|
}
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
case UR_ROTATED:
|
2019-05-27 17:58:36 +00:00
|
|
|
{
|
2019-05-27 21:17:22 +00:00
|
|
|
BOARD_ITEM* item = (BOARD_ITEM*) eda_item;
|
2013-12-16 21:40:03 +00:00
|
|
|
item->Rotate( aList->m_TransformPoint,
|
|
|
|
aRedoCommand ? m_rotationAngle : -m_rotationAngle );
|
2016-12-09 11:04:32 +00:00
|
|
|
view->Update( item, KIGFX::GEOMETRY );
|
2017-03-22 13:43:10 +00:00
|
|
|
connectivity->Update( item );
|
2019-05-27 17:58:36 +00:00
|
|
|
}
|
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:
|
2019-05-27 17:58:36 +00:00
|
|
|
{
|
2019-05-27 21:17:22 +00:00
|
|
|
BOARD_ITEM* item = (BOARD_ITEM*) eda_item;
|
2013-12-16 21:40:03 +00:00
|
|
|
item->Rotate( aList->m_TransformPoint,
|
|
|
|
aRedoCommand ? -m_rotationAngle : m_rotationAngle );
|
2016-12-09 11:04:32 +00:00
|
|
|
view->Update( item, KIGFX::GEOMETRY );
|
2017-03-22 13:43:10 +00:00
|
|
|
connectivity->Update( item );
|
2019-05-27 17:58:36 +00:00
|
|
|
}
|
2009-08-06 07:11:04 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
case UR_FLIPPED:
|
2019-05-27 17:58:36 +00:00
|
|
|
{
|
2019-05-27 21:17:22 +00:00
|
|
|
BOARD_ITEM* item = (BOARD_ITEM*) eda_item;
|
2019-07-12 21:02:10 +00:00
|
|
|
item->Flip( aList->m_TransformPoint, m_configSettings.m_FlipLeftRight );
|
2016-12-09 11:04:32 +00:00
|
|
|
view->Update( item, KIGFX::LAYERS );
|
2017-03-22 13:43:10 +00:00
|
|
|
connectivity->Update( item );
|
2019-05-27 17:58:36 +00:00
|
|
|
}
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
2018-01-24 10:19:33 +00:00
|
|
|
case UR_DRILLORIGIN:
|
|
|
|
case UR_GRIDORIGIN:
|
|
|
|
{
|
2019-05-27 21:17:22 +00:00
|
|
|
BOARD_ITEM* item = (BOARD_ITEM*) eda_item;
|
2018-01-24 10:19:33 +00:00
|
|
|
BOARD_ITEM* image = (BOARD_ITEM*) aList->GetPickedItemLink( ii );
|
|
|
|
VECTOR2D origin = image->GetPosition();
|
|
|
|
image->SetPosition( item->GetPosition() );
|
|
|
|
|
|
|
|
if( aList->GetPickedItemStatus( ii ) == UR_DRILLORIGIN )
|
|
|
|
PCB_EDITOR_CONTROL::DoSetDrillOrigin( view, this, item, origin );
|
|
|
|
else
|
|
|
|
PCBNEW_CONTROL::DoSetGridOrigin( view, this, item, origin );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-05-26 15:36:40 +00:00
|
|
|
case UR_PAGESETTINGS:
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
// swap current settings with stored settings
|
|
|
|
WS_PROXY_UNDO_ITEM alt_item( this );
|
|
|
|
WS_PROXY_UNDO_ITEM* item = (WS_PROXY_UNDO_ITEM*) eda_item;
|
|
|
|
item->Restore( this );
|
|
|
|
*item = alt_item;
|
2019-06-03 23:50:44 +00:00
|
|
|
GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true );
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-05-26 15:36:40 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
wxLogDebug( wxT( "PutDataInPreviousState() error (unknown code %X)" ),
|
|
|
|
aList->GetPickedItemStatus( ii ) );
|
|
|
|
break;
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-31 05:33:11 +00:00
|
|
|
if( not_found )
|
2019-01-02 04:43:13 +00:00
|
|
|
wxMessageBox( _( "Incomplete undo/redo operation: some items not found" ) );
|
2018-09-23 17:21:16 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
// Rebuild pointers and connectivity that can be changed.
|
2017-06-29 18:39:11 +00:00
|
|
|
// connectivity can be rebuilt only in the board editor frame
|
|
|
|
if( IsType( FRAME_PCB ) && ( reBuild_ratsnest || deep_reBuild_ratsnest ) )
|
2014-01-29 09:17:14 +00:00
|
|
|
{
|
2019-05-30 15:11:17 +00:00
|
|
|
Compile_Ratsnest( false );
|
2014-01-29 09:17:14 +00:00
|
|
|
}
|
2018-09-23 17:21:16 +00:00
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
SELECTION_TOOL* selTool = m_toolManager->GetTool<SELECTION_TOOL>();
|
|
|
|
selTool->RebuildSelection();
|
|
|
|
|
2018-09-23 17:21:16 +00:00
|
|
|
GetBoard()->SanitizeNetcodes();
|
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
|
|
|
|
}
|
|
|
|
}
|
2019-05-26 15:36:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
void PCB_BASE_EDIT_FRAME::RollbackFromUndo()
|
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST* undo = GetScreen()->PopCommandFromUndoList();
|
|
|
|
PutDataInPreviousState( undo, false );
|
|
|
|
|
|
|
|
undo->ClearListAndDeleteItems();
|
|
|
|
delete undo;
|
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2019-05-31 00:15:57 +00:00
|
|
|
}
|