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
|
2023-10-06 17:04:00 +00:00
|
|
|
* Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-05-25 09:52:43 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
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 <macros.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2021-06-03 17:03:25 +00:00
|
|
|
#include <pcb_group.h>
|
2023-10-06 17:04:00 +00:00
|
|
|
#include <pcb_generator.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <pcb_target.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.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>
|
2020-12-16 13:31:32 +00:00
|
|
|
#include <tools/pcb_selection_tool.h>
|
|
|
|
#include <tools/pcb_control.h>
|
|
|
|
#include <tools/board_editor_control.h>
|
2024-01-27 20:02:40 +00:00
|
|
|
#include <board_commit.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_proxy_undo_item.h>
|
2021-06-06 12:41:16 +00:00
|
|
|
#include <wx/msgdlg.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
|
|
|
|
2022-02-25 13:05:25 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::saveCopyInUndoList( PICKED_ITEMS_LIST* commandToUndo,
|
|
|
|
const PICKED_ITEMS_LIST& aItemsList,
|
2021-02-15 14:02:41 +00:00
|
|
|
UNDO_REDO aCommandType )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2022-02-25 13:05:25 +00:00
|
|
|
int preExisting = commandToUndo->GetCount();
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2016-01-29 10:21:13 +00:00
|
|
|
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
|
2023-07-15 16:37:17 +00:00
|
|
|
commandToUndo->PushItem( aItemsList.GetItemWrapper(ii) );
|
2016-01-29 10:21:13 +00:00
|
|
|
|
2022-02-25 13:05:25 +00:00
|
|
|
for( unsigned ii = preExisting; ii < commandToUndo->GetCount(); ii++ )
|
2016-01-29 10:21:13 +00:00
|
|
|
{
|
2022-02-25 13:05:25 +00:00
|
|
|
EDA_ITEM* item = commandToUndo->GetPickedItem( ii );
|
2020-08-26 18:04:32 +00:00
|
|
|
UNDO_REDO command = commandToUndo->GetPickedItemStatus( ii );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
if( command == UNDO_REDO::UNSPECIFIED )
|
2009-08-06 15:42:09 +00:00
|
|
|
{
|
2021-02-15 14:02:41 +00:00
|
|
|
command = aCommandType;
|
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 )
|
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
case UNDO_REDO::CHANGED:
|
|
|
|
case UNDO_REDO::DRILLORIGIN:
|
|
|
|
case UNDO_REDO::GRIDORIGIN:
|
2022-02-25 13:05:25 +00:00
|
|
|
// If we don't yet have a copy in the link, set one up
|
|
|
|
if( !commandToUndo->GetPickedItemLink( ii ) )
|
2024-01-27 20:02:40 +00:00
|
|
|
commandToUndo->SetPickedItemLink( BOARD_COMMIT::MakeImage( item ), ii );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
case UNDO_REDO::NEWITEM:
|
|
|
|
case UNDO_REDO::DELETED:
|
|
|
|
case UNDO_REDO::PAGESETTINGS:
|
2023-12-16 16:17:24 +00:00
|
|
|
case UNDO_REDO::REGROUP:
|
2020-09-26 00:52:03 +00:00
|
|
|
case UNDO_REDO::UNGROUP:
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-07-15 16:37:17 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Unrecognized undo command: %X" ), command ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
break;
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( commandToUndo->GetCount() )
|
|
|
|
{
|
|
|
|
/* Save the copy in undo list */
|
2020-07-13 11:21:40 +00:00
|
|
|
PushCommandToUndoList( commandToUndo );
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2009-08-06 15:42:09 +00:00
|
|
|
/* Clear redo list, because after a new command one cannot redo a command */
|
2020-07-13 13:50:35 +00:00
|
|
|
ClearUndoORRedoList( REDO_LIST );
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-25 13:05:25 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( EDA_ITEM* aItem, UNDO_REDO aCommandType )
|
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
|
|
|
|
PICKED_ITEMS_LIST itemsList;
|
|
|
|
|
|
|
|
itemsList.PushItem( ITEM_PICKER( nullptr, aItem, aCommandType ) );
|
|
|
|
saveCopyInUndoList( commandToUndo, itemsList, aCommandType );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
|
|
|
|
UNDO_REDO aCommandType )
|
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
|
2023-06-07 13:35:25 +00:00
|
|
|
commandToUndo->SetDescription( aItemsList.GetDescription() );
|
2022-02-25 13:05:25 +00:00
|
|
|
|
|
|
|
saveCopyInUndoList( commandToUndo, aItemsList, aCommandType );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_BASE_EDIT_FRAME::AppendCopyToUndoList( const PICKED_ITEMS_LIST& aItemsList,
|
|
|
|
UNDO_REDO aCommandType )
|
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST* commandToUndo = PopCommandFromUndoList();
|
|
|
|
|
|
|
|
if( !commandToUndo )
|
2023-06-07 13:35:25 +00:00
|
|
|
{
|
2022-02-25 13:05:25 +00:00
|
|
|
commandToUndo = new PICKED_ITEMS_LIST();
|
2023-06-07 13:35:25 +00:00
|
|
|
commandToUndo->SetDescription( aItemsList.GetDescription() );
|
|
|
|
}
|
2022-02-25 13:05:25 +00:00
|
|
|
|
|
|
|
saveCopyInUndoList( commandToUndo, aItemsList, aCommandType );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-25 09:52:43 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( UndoRedoBlocked() )
|
|
|
|
return;
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
if( GetUndoCommandCount() <= 0 )
|
2016-05-25 09:52:43 +00:00
|
|
|
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
|
2021-02-15 14:02:41 +00:00
|
|
|
PICKED_ITEMS_LIST* list = PopCommandFromUndoList();
|
2016-05-25 09:52:43 +00:00
|
|
|
|
|
|
|
// Undo the command
|
2021-02-15 14:02:41 +00:00
|
|
|
PutDataInPreviousState( list );
|
2016-05-25 09:52:43 +00:00
|
|
|
|
|
|
|
// Put the old list in RedoList
|
2021-02-15 14:02:41 +00:00
|
|
|
list->ReversePickersListOrder();
|
|
|
|
PushCommandToRedoList( list );
|
2016-05-25 09:52:43 +00:00
|
|
|
|
|
|
|
OnModify();
|
2016-09-23 09:31:36 +00:00
|
|
|
|
|
|
|
m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_POST, AS_GLOBAL } );
|
2021-04-17 16:21:54 +00:00
|
|
|
m_toolManager->PostEvent( EVENTS::SelectedItemsModified );
|
2016-09-23 09:31:36 +00:00
|
|
|
|
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;
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
if( GetRedoCommandCount() == 0 )
|
2016-05-25 09:52:43 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Inform tools that redo command was issued
|
2023-09-01 17:46:51 +00:00
|
|
|
m_toolManager->ProcessEvent( EVENTS::UndoRedoPreEvent );
|
2016-05-25 09:52:43 +00:00
|
|
|
|
|
|
|
// Get the old list
|
2021-02-15 14:02:41 +00:00
|
|
|
PICKED_ITEMS_LIST* list = PopCommandFromRedoList();
|
2016-05-25 09:52:43 +00:00
|
|
|
|
|
|
|
// Redo the command
|
2021-02-15 14:02:41 +00:00
|
|
|
PutDataInPreviousState( list );
|
2016-05-25 09:52:43 +00:00
|
|
|
|
|
|
|
// Put the old list in UndoList
|
2021-02-15 14:02:41 +00:00
|
|
|
list->ReversePickersListOrder();
|
|
|
|
PushCommandToUndoList( list );
|
2016-05-25 09:52:43 +00:00
|
|
|
|
|
|
|
OnModify();
|
2016-09-23 09:31:36 +00:00
|
|
|
|
2023-09-01 17:46:51 +00:00
|
|
|
m_toolManager->ProcessEvent( EVENTS::UndoRedoPostEvent );
|
2021-04-17 16:21:54 +00:00
|
|
|
m_toolManager->PostEvent( EVENTS::SelectedItemsModified );
|
2016-09-23 09:31:36 +00:00
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2016-05-25 09:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-15 14:02:41 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
|
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
|
2023-04-14 23:06:33 +00:00
|
|
|
bool solder_mask_dirty = false;
|
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
|
|
|
|
2022-12-02 10:58:01 +00:00
|
|
|
GetBoard()->IncrementTimeStamp(); // clear caches
|
|
|
|
|
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
|
2023-12-17 15:34:33 +00:00
|
|
|
for( int ii = (int) 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
|
|
|
*/
|
2020-08-26 18:04:32 +00:00
|
|
|
UNDO_REDO status = aList->GetPickedItemStatus( ii );
|
2013-10-14 15:29:16 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
if( status != UNDO_REDO::DELETED
|
2023-12-16 16:17:24 +00:00
|
|
|
&& status != UNDO_REDO::REGROUP
|
2023-10-12 16:09:34 +00:00
|
|
|
&& status != UNDO_REDO::UNGROUP
|
2020-08-26 18:04:32 +00:00
|
|
|
&& status != UNDO_REDO::DRILLORIGIN // origin markers never on board
|
|
|
|
&& status != UNDO_REDO::GRIDORIGIN // origin markers never on board
|
|
|
|
&& status != UNDO_REDO::PAGESETTINGS ) // nor are page settings proxy items
|
2009-07-31 05:33:11 +00:00
|
|
|
{
|
2023-07-15 16:37:17 +00:00
|
|
|
if( GetBoard()->GetItem( eda_item->m_Uuid ) == DELETED_BOARD_ITEM::GetInstance() )
|
2009-07-31 05:33:11 +00:00
|
|
|
{
|
2016-05-25 09:52:43 +00:00
|
|
|
// Checking if it ever happens
|
2022-02-04 22:44:59 +00:00
|
|
|
wxASSERT_MSG( false, wxT( "Item in the undo buffer does not exist" ) );
|
2016-05-25 09:52:43 +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-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
|
|
|
{
|
2020-11-13 12:21:02 +00:00
|
|
|
case PCB_FOOTPRINT_T:
|
2016-09-30 09:09:17 +00:00
|
|
|
deep_reBuild_ratsnest = true; // Pointers on pads can be invalid
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_ZONE_T:
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_TRACE_T:
|
2019-05-17 00:13:21 +00:00
|
|
|
case PCB_ARC_T:
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_VIA_T:
|
2021-02-15 13:49:40 +00:00
|
|
|
case PCB_PAD_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
|
|
|
}
|
|
|
|
|
2023-04-14 23:06:33 +00:00
|
|
|
switch( eda_item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_FOOTPRINT_T:
|
|
|
|
solder_mask_dirty = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_VIA_T:
|
|
|
|
solder_mask_dirty = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_ZONE_T:
|
|
|
|
case PCB_TRACE_T:
|
|
|
|
case PCB_ARC_T:
|
|
|
|
case PCB_PAD_T:
|
|
|
|
case PCB_SHAPE_T:
|
|
|
|
{
|
|
|
|
LSET layers = static_cast<BOARD_ITEM*>( eda_item )->GetLayerSet();
|
|
|
|
|
|
|
|
if( layers.test( F_Mask ) || layers.test( B_Mask ) )
|
|
|
|
solder_mask_dirty = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-03 18:54:48 +00:00
|
|
|
switch( aList->GetPickedItemStatus( ii ) )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
case UNDO_REDO::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
|
|
|
|
2020-10-14 17:29:57 +00:00
|
|
|
view->Remove( item );
|
2017-03-22 13:43:10 +00:00
|
|
|
connectivity->Remove( item );
|
2013-12-18 13:33:34 +00:00
|
|
|
|
2022-11-11 17:09:25 +00:00
|
|
|
item->SwapItemData( image );
|
2013-12-18 13:33:34 +00:00
|
|
|
|
2024-01-27 20:02:40 +00:00
|
|
|
eda_item->ClearFlags( UR_TRANSIENT );
|
|
|
|
image->SetFlags( UR_TRANSIENT );
|
|
|
|
|
2023-10-14 14:04:13 +00:00
|
|
|
if( PCB_GROUP* group = dynamic_cast<PCB_GROUP*>( item ) )
|
2022-09-25 20:44:59 +00:00
|
|
|
{
|
|
|
|
group->RunOnChildren( [&]( BOARD_ITEM* child )
|
|
|
|
{
|
|
|
|
child->SetParentGroup( group );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2020-10-14 17:29:57 +00:00
|
|
|
view->Add( item );
|
|
|
|
view->Hide( item, false );
|
2017-03-22 13:43:10 +00:00
|
|
|
connectivity->Add( item );
|
2020-04-12 19:29:16 +00:00
|
|
|
item->GetBoard()->OnItemChanged( item );
|
2021-07-19 23:56:05 +00:00
|
|
|
break;
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2009-07-29 13:10:36 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
case UNDO_REDO::NEWITEM: /* new items are deleted */
|
|
|
|
aList->SetPickedItemStatus( UNDO_REDO::DELETED, ii );
|
2019-05-27 17:58:36 +00:00
|
|
|
GetModel()->Remove( (BOARD_ITEM*) eda_item );
|
2020-07-13 21:35:05 +00:00
|
|
|
|
2020-11-27 23:33:48 +00:00
|
|
|
if( eda_item->Type() != PCB_NETINFO_T )
|
2020-07-13 21:35:05 +00:00
|
|
|
view->Remove( eda_item );
|
|
|
|
|
2024-01-27 20:02:40 +00:00
|
|
|
eda_item->SetFlags( UR_TRANSIENT );
|
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
case UNDO_REDO::DELETED: /* deleted items are put in List, as new items */
|
|
|
|
aList->SetPickedItemStatus( UNDO_REDO::NEWITEM, ii );
|
2024-01-27 20:02:40 +00:00
|
|
|
|
|
|
|
eda_item->ClearFlags( UR_TRANSIENT );
|
|
|
|
|
2019-05-27 17:58:36 +00:00
|
|
|
GetModel()->Add( (BOARD_ITEM*) eda_item );
|
2020-07-13 21:35:05 +00:00
|
|
|
|
2020-11-27 23:33:48 +00:00
|
|
|
if( eda_item->Type() != PCB_NETINFO_T )
|
2020-07-13 21:35:05 +00:00
|
|
|
view->Add( eda_item );
|
|
|
|
|
2020-09-26 00:52:03 +00:00
|
|
|
break;
|
|
|
|
|
2023-12-17 15:34:33 +00:00
|
|
|
case UNDO_REDO::REGROUP: /* grouped items are ungrouped */
|
2021-02-15 13:49:40 +00:00
|
|
|
aList->SetPickedItemStatus( UNDO_REDO::UNGROUP, ii );
|
2023-07-13 10:24:33 +00:00
|
|
|
|
|
|
|
if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( eda_item ) )
|
2023-12-17 15:34:33 +00:00
|
|
|
{
|
|
|
|
if( PCB_GROUP* group = boardItem->GetParentGroup() )
|
|
|
|
{
|
|
|
|
if( !aList->GetPickedItemLink( ii ) )
|
2024-01-27 20:02:40 +00:00
|
|
|
aList->SetPickedItemLink( BOARD_COMMIT::MakeImage( group ), ii );
|
2023-12-17 15:34:33 +00:00
|
|
|
|
2023-12-17 21:01:31 +00:00
|
|
|
group->RemoveItem( boardItem );
|
|
|
|
}
|
2023-12-17 15:34:33 +00:00
|
|
|
}
|
2023-07-13 10:24:33 +00:00
|
|
|
|
2020-09-26 00:52:03 +00:00
|
|
|
break;
|
|
|
|
|
2023-12-17 15:34:33 +00:00
|
|
|
case UNDO_REDO::UNGROUP: /* ungrouped items are re-added to their previuos groups */
|
2023-12-16 16:17:24 +00:00
|
|
|
aList->SetPickedItemStatus( UNDO_REDO::REGROUP, ii );
|
2021-02-15 13:49:40 +00:00
|
|
|
|
2023-07-13 10:24:33 +00:00
|
|
|
if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( eda_item ) )
|
|
|
|
{
|
2023-12-17 15:34:33 +00:00
|
|
|
PCB_GROUP* group = nullptr;
|
|
|
|
|
|
|
|
// The link is just a clone of the original parent group; we need to look up
|
|
|
|
// the UUID in the document to find the real parent.
|
|
|
|
if( EDA_ITEM* link = aList->GetPickedItemLink( ii ) )
|
|
|
|
group = dynamic_cast<PCB_GROUP*>( GetBoard()->GetItem( link->m_Uuid ) );
|
|
|
|
|
|
|
|
if( group )
|
|
|
|
group->AddItem( boardItem );
|
2023-07-13 10:24:33 +00:00
|
|
|
}
|
2020-11-11 00:18:35 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
break;
|
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
case UNDO_REDO::DRILLORIGIN:
|
|
|
|
case UNDO_REDO::GRIDORIGIN:
|
2018-01-24 10:19:33 +00:00
|
|
|
{
|
2023-07-13 08:53:50 +00:00
|
|
|
// Warning: DRILLORIGIN and GRIDORIGIN undo/redo command create EDA_ITEMs
|
|
|
|
// that cannot be casted to BOARD_ITEMs
|
|
|
|
EDA_ITEM* image = aList->GetPickedItemLink( ii );
|
2018-01-24 10:19:33 +00:00
|
|
|
VECTOR2D origin = image->GetPosition();
|
2020-04-24 13:36:10 +00:00
|
|
|
image->SetPosition( eda_item->GetPosition() );
|
2018-01-24 10:19:33 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
if( aList->GetPickedItemStatus( ii ) == UNDO_REDO::DRILLORIGIN )
|
2023-07-13 08:53:50 +00:00
|
|
|
BOARD_EDITOR_CONTROL::DoSetDrillOrigin( view, this, eda_item, origin );
|
2018-01-24 10:19:33 +00:00
|
|
|
else
|
2023-07-13 08:53:50 +00:00
|
|
|
PCB_CONTROL::DoSetGridOrigin( view, this, eda_item, origin );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
break;
|
2018-01-24 10:19:33 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
case UNDO_REDO::PAGESETTINGS:
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
// swap current settings with stored settings
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_PROXY_UNDO_ITEM alt_item( this );
|
|
|
|
DS_PROXY_UNDO_ITEM* item = static_cast<DS_PROXY_UNDO_ITEM*>( eda_item );
|
2019-05-26 15:36:40 +00:00
|
|
|
item->Restore( this );
|
2023-12-18 17:19:15 +00:00
|
|
|
*item = std::move( alt_item );
|
2021-07-19 23:56:05 +00:00
|
|
|
break;
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
2019-05-26 15:36:40 +00:00
|
|
|
|
|
|
|
default:
|
2022-02-04 22:44:59 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "PutDataInPreviousState() error (unknown code %X)" ),
|
2021-07-19 23:56:05 +00:00
|
|
|
aList->GetPickedItemStatus( ii ) ) );
|
2019-05-26 15:36:40 +00:00
|
|
|
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" ) );
|
2020-04-24 23:44:09 +00:00
|
|
|
|
2023-04-14 23:06:33 +00:00
|
|
|
if( IsType( FRAME_PCB_EDITOR ) )
|
2014-01-29 09:17:14 +00:00
|
|
|
{
|
2023-04-14 23:06:33 +00:00
|
|
|
if( reBuild_ratsnest || deep_reBuild_ratsnest )
|
2024-02-12 01:01:05 +00:00
|
|
|
{
|
|
|
|
// Connectivity may have changed; rebuild internal caches to remove stale items
|
|
|
|
GetBoard()->BuildConnectivity();
|
2023-04-14 23:06:33 +00:00
|
|
|
Compile_Ratsnest( false );
|
2024-02-12 01:01:05 +00:00
|
|
|
}
|
2023-04-14 23:06:33 +00:00
|
|
|
|
|
|
|
if( solder_mask_dirty )
|
|
|
|
HideSolderMask();
|
2014-01-29 09:17:14 +00:00
|
|
|
}
|
2018-09-23 17:21:16 +00:00
|
|
|
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
|
2019-05-11 10:06:28 +00:00
|
|
|
selTool->RebuildSelection();
|
|
|
|
|
2018-09-23 17:21:16 +00:00
|
|
|
GetBoard()->SanitizeNetcodes();
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-13 13:50:35 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
|
|
|
if( aItemCount == 0 )
|
|
|
|
return;
|
|
|
|
|
2024-02-07 14:49:50 +00:00
|
|
|
UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2024-02-07 14:49:50 +00:00
|
|
|
if( aItemCount < 0 )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
2024-02-07 14:49:50 +00:00
|
|
|
list.ClearCommandList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( int ii = 0; ii < aItemCount; ii++ )
|
|
|
|
{
|
|
|
|
if( list.m_CommandsList.size() == 0 )
|
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2024-02-07 14:49:50 +00:00
|
|
|
PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
|
|
|
|
list.m_CommandsList.erase( list.m_CommandsList.begin() );
|
|
|
|
ClearListAndDeleteItems( curr_cmd );
|
|
|
|
delete curr_cmd; // Delete command
|
|
|
|
}
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-26 15:36:40 +00:00
|
|
|
|
|
|
|
|
2022-11-11 17:09:25 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::ClearListAndDeleteItems( PICKED_ITEMS_LIST* aList )
|
|
|
|
{
|
2023-07-13 10:24:33 +00:00
|
|
|
aList->ClearListAndDeleteItems(
|
|
|
|
[]( EDA_ITEM* item )
|
|
|
|
{
|
2024-01-27 20:02:40 +00:00
|
|
|
wxASSERT_MSG( item->HasFlag( UR_TRANSIENT ),
|
|
|
|
"Item on undo/redo list not owned by undo/redo!" );
|
|
|
|
|
2023-07-13 10:24:33 +00:00
|
|
|
if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item ) )
|
|
|
|
boardItem->SetParentGroup( nullptr );
|
|
|
|
|
|
|
|
delete item;
|
|
|
|
} );
|
2022-11-11 17:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-26 15:36:40 +00:00
|
|
|
void PCB_BASE_EDIT_FRAME::RollbackFromUndo()
|
|
|
|
{
|
2020-07-13 11:21:40 +00:00
|
|
|
PICKED_ITEMS_LIST* undo = PopCommandFromUndoList();
|
2021-02-15 14:02:41 +00:00
|
|
|
PutDataInPreviousState( undo );
|
2022-11-11 17:09:25 +00:00
|
|
|
ClearListAndDeleteItems( undo );
|
2019-05-26 15:36:40 +00:00
|
|
|
delete undo;
|
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2019-05-31 00:15:57 +00:00
|
|
|
}
|