2011-10-19 20:32:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
2024-01-06 12:56:16 +00:00
|
|
|
* Copyright (C) 2004-2024 KiCad Developers, see change_log.txt for contributors.
|
2011-10-19 20:32:21 +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
|
|
|
|
*/
|
|
|
|
|
2022-02-03 19:17:41 +00:00
|
|
|
#include <ee_actions.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2019-04-26 10:42:36 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2020-10-18 20:30:37 +00:00
|
|
|
#include <schematic.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_bus_entry.h>
|
2024-01-27 17:02:22 +00:00
|
|
|
#include <sch_commit.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_bitmap.h>
|
2024-01-27 17:02:22 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2023-11-25 12:38:24 +00:00
|
|
|
#include <sch_table.h>
|
2019-05-11 10:06:28 +00:00
|
|
|
#include <tools/ee_selection_tool.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_proxy_undo_item.h>
|
2019-05-26 15:36:40 +00:00
|
|
|
#include <tool/actions.h>
|
2009-07-26 17:16:42 +00:00
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Functions to undo and redo edit commands.
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2009-07-25 04:53:39 +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),
|
2009-12-02 21:44:03 +00:00
|
|
|
* 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)
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* there are 3 cases:
|
|
|
|
* - delete item(s) command
|
|
|
|
* - change item(s) command
|
|
|
|
* - add item(s) command
|
2009-07-29 13:10:36 +00:00
|
|
|
* and 2 cases for block:
|
|
|
|
* - move list of items
|
|
|
|
* - mirror (Y) list of items
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* Undo command
|
|
|
|
* - delete item(s) command:
|
2009-07-25 04:53:39 +00:00
|
|
|
* => deleted items are moved in undo list
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* - change item(s) command
|
2009-07-25 04:53:39 +00:00
|
|
|
* => 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.
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* - add item(s) command
|
2009-12-02 21:44:03 +00:00
|
|
|
* =>A list of item(s) is made. The .m_Item member of each wrapper points
|
|
|
|
* the new item.
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* Redo command
|
|
|
|
* - delete item(s) old command:
|
2019-06-25 23:39:58 +00:00
|
|
|
* => deleted items are moved into m_tree
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* - change item(s) command
|
2009-07-25 04:53:39 +00:00
|
|
|
* => the copy of item(s) is moved in Undo list
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* - add item(s) command
|
2009-12-02 21:44:03 +00:00
|
|
|
* => The list of item(s) is used to create a deleted list in undo
|
|
|
|
* list(same as a delete command)
|
2008-02-26 19:19:54 +00:00
|
|
|
*
|
2009-12-02 21:44:03 +00:00
|
|
|
* Some block operations that change items can be undone without memorized
|
|
|
|
* items, just the coordinates 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-07-29 13:10:36 +00:00
|
|
|
*
|
2007-09-01 12:00:30 +00:00
|
|
|
* A problem is the hierarchical sheet handling.
|
2009-12-02 21:44:03 +00:00
|
|
|
* the data associated (sub-hierarchy, undo/redo list) is deleted only
|
2007-09-01 12:00:30 +00:00
|
|
|
* when the sheet is really deleted (i.e. when deleted from undo or redo list)
|
2009-07-25 04:53:39 +00:00
|
|
|
* This is handled by its destructor.
|
2007-09-01 12:00:30 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Used if undo / redo command:
|
2016-06-03 13:33:44 +00:00
|
|
|
* swap data between Item and its copy, pointed by its picked item link member
|
2018-06-22 13:05:11 +00:00
|
|
|
* swapped data is data modified by editing, so not all values are swapped
|
2007-09-01 12:00:30 +00:00
|
|
|
*/
|
|
|
|
|
2022-03-16 13:43:19 +00:00
|
|
|
void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_SCREEN* aScreen, SCH_ITEM* aItem,
|
|
|
|
UNDO_REDO aCommandType, bool aAppend,
|
|
|
|
bool aDirtyConnectivity )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
PICKED_ITEMS_LIST* commandToUndo = nullptr;
|
2017-11-16 20:36:09 +00:00
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
wxCHECK( aItem, /* void */ );
|
2009-08-04 18:21:32 +00:00
|
|
|
|
2022-03-16 13:43:19 +00:00
|
|
|
if( aDirtyConnectivity )
|
2023-05-20 17:47:12 +00:00
|
|
|
{
|
2024-01-30 14:03:38 +00:00
|
|
|
if( !aItem->IsConnectivityDirty()
|
|
|
|
&& aItem->Connection()
|
|
|
|
&& ( aItem->Connection()->Name() == m_highlightedConn ) )
|
|
|
|
{
|
2023-05-20 17:47:12 +00:00
|
|
|
m_highlightedConnChanged = true;
|
2024-01-30 14:03:38 +00:00
|
|
|
}
|
2023-05-20 17:47:12 +00:00
|
|
|
|
2022-03-16 13:43:19 +00:00
|
|
|
aItem->SetConnectivityDirty();
|
2023-05-20 17:47:12 +00:00
|
|
|
}
|
2019-03-30 15:57:30 +00:00
|
|
|
|
2021-02-16 18:09:56 +00:00
|
|
|
PICKED_ITEMS_LIST* lastUndo = PopCommandFromUndoList();
|
2021-02-13 01:15:45 +00:00
|
|
|
|
2021-02-16 18:09:56 +00:00
|
|
|
// If the last stack was empty, use that one instead of creating a new stack
|
|
|
|
if( lastUndo )
|
|
|
|
{
|
|
|
|
if( aAppend || !lastUndo->GetCount() )
|
|
|
|
commandToUndo = lastUndo;
|
|
|
|
else
|
|
|
|
PushCommandToUndoList( lastUndo );
|
|
|
|
}
|
2017-11-16 20:36:09 +00:00
|
|
|
|
|
|
|
if( !commandToUndo )
|
|
|
|
{
|
|
|
|
commandToUndo = new PICKED_ITEMS_LIST();
|
|
|
|
}
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
ITEM_PICKER itemWrapper( aScreen, aItem, aCommandType );
|
2015-11-03 19:44:05 +00:00
|
|
|
itemWrapper.SetFlags( aItem->GetFlags() );
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2009-07-25 07:31:07 +00:00
|
|
|
switch( aCommandType )
|
2007-09-01 12:00:30 +00:00
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
case UNDO_REDO::CHANGED: /* Create a copy of item */
|
2019-05-04 13:02:05 +00:00
|
|
|
itemWrapper.SetLink( aItem->Duplicate( true ) );
|
2012-02-05 13:02:46 +00:00
|
|
|
commandToUndo->PushItem( itemWrapper );
|
2009-07-25 07:31:07 +00:00
|
|
|
break;
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
case UNDO_REDO::NEWITEM:
|
|
|
|
case UNDO_REDO::DELETED:
|
2009-07-25 07:31:07 +00:00
|
|
|
commandToUndo->PushItem( itemWrapper );
|
2009-07-25 04:53:39 +00:00
|
|
|
break;
|
2009-07-25 07:31:07 +00:00
|
|
|
|
|
|
|
default:
|
2012-02-26 18:39:39 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "SaveCopyInUndoList() error (unknown code %X)" ),
|
|
|
|
aCommandType ) );
|
|
|
|
break;
|
2009-07-25 04:53:39 +00:00
|
|
|
}
|
2009-07-25 07:31:07 +00:00
|
|
|
|
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-25 04:53:39 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
/* Clear redo list, because after new save there is no redo to do */
|
2020-07-13 13:50:35 +00:00
|
|
|
ClearUndoORRedoList( REDO_LIST );
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
|
|
|
else
|
2012-02-26 18:39:39 +00:00
|
|
|
{
|
2009-07-29 13:10:36 +00:00
|
|
|
delete commandToUndo;
|
2012-02-26 18:39:39 +00:00
|
|
|
}
|
2009-07-25 04:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-18 12:27:18 +00:00
|
|
|
void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
|
2022-03-16 13:43:19 +00:00
|
|
|
UNDO_REDO aTypeCommand, bool aAppend,
|
|
|
|
bool aDirtyConnectivity )
|
2009-07-25 04:53:39 +00:00
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
PICKED_ITEMS_LIST* commandToUndo = nullptr;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2017-11-16 20:36:09 +00:00
|
|
|
if( !aItemsList.GetCount() )
|
|
|
|
return;
|
|
|
|
|
2021-02-16 18:09:56 +00:00
|
|
|
PICKED_ITEMS_LIST* lastUndo = PopCommandFromUndoList();
|
|
|
|
|
|
|
|
// If the last stack was empty, use that one instead of creating a new stack
|
|
|
|
if( lastUndo )
|
|
|
|
{
|
|
|
|
if( aAppend || !lastUndo->GetCount() )
|
|
|
|
commandToUndo = lastUndo;
|
|
|
|
else
|
|
|
|
PushCommandToUndoList( lastUndo );
|
|
|
|
}
|
2017-11-16 20:36:09 +00:00
|
|
|
|
|
|
|
if( !commandToUndo )
|
2023-06-07 13:35:25 +00:00
|
|
|
{
|
2017-11-16 20:36:09 +00:00
|
|
|
commandToUndo = new PICKED_ITEMS_LIST();
|
2023-06-07 13:35:25 +00:00
|
|
|
commandToUndo->SetDescription( aItemsList.GetDescription() );
|
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-08-06 15:42:09 +00:00
|
|
|
// Copy picker list:
|
2017-11-16 20:36:09 +00:00
|
|
|
if( !commandToUndo->GetCount() )
|
|
|
|
commandToUndo->CopyList( aItemsList );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Unless we are appending, in which case, get the picker items
|
|
|
|
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
|
|
|
|
commandToUndo->PushItem( aItemsList.GetItemWrapper( ii) );
|
|
|
|
}
|
2009-07-25 04:53:39 +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-25 04:53:39 +00:00
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( commandToUndo->GetPickedItem( ii ) );
|
|
|
|
|
|
|
|
// Common items implemented in EDA_DRAW_FRAME will not be SCH_ITEMs.
|
|
|
|
if( !sch_item )
|
|
|
|
continue;
|
2009-08-06 15:42:09 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
UNDO_REDO command = commandToUndo->GetPickedItemStatus( ii );
|
2011-04-05 14:46:51 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
if( command == UNDO_REDO::UNSPECIFIED )
|
2009-07-25 04:53:39 +00:00
|
|
|
{
|
|
|
|
command = aTypeCommand;
|
2010-09-05 17:01:48 +00:00
|
|
|
commandToUndo->SetPickedItemStatus( command, ii );
|
2009-07-23 15:37:00 +00:00
|
|
|
}
|
2009-08-06 15:42:09 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
switch( command )
|
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
case UNDO_REDO::CHANGED:
|
2010-09-05 17:01:48 +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
|
|
|
|
*/
|
2019-05-26 15:36:40 +00:00
|
|
|
if( commandToUndo->GetPickedItemLink( ii ) == nullptr )
|
|
|
|
commandToUndo->SetPickedItemLink( sch_item->Duplicate( true ), ii );
|
2012-02-26 18:39:39 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
wxASSERT( commandToUndo->GetPickedItemLink( ii ) );
|
2009-07-25 04:53:39 +00:00
|
|
|
break;
|
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
case UNDO_REDO::NEWITEM:
|
|
|
|
case UNDO_REDO::DELETED:
|
|
|
|
case UNDO_REDO::PAGESETTINGS:
|
2007-09-01 12:00:30 +00:00
|
|
|
break;
|
2009-07-25 04:53:39 +00:00
|
|
|
|
|
|
|
default:
|
2011-04-05 14:46:51 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Unknown undo/redo command %d" ), command ) );
|
|
|
|
break;
|
2007-09-01 12:00:30 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-25 04:53:39 +00:00
|
|
|
|
2019-04-13 02:49:03 +00:00
|
|
|
if( commandToUndo->GetCount() )
|
2009-07-29 13:10:36 +00:00
|
|
|
{
|
|
|
|
/* Save the copy in undo list */
|
2020-07-13 11:21:40 +00:00
|
|
|
PushCommandToUndoList( commandToUndo );
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
/* Clear redo list, because after new save there is no redo to do */
|
2020-07-13 13:50:35 +00:00
|
|
|
ClearUndoORRedoList( REDO_LIST );
|
2009-07-29 13:10:36 +00:00
|
|
|
}
|
2009-08-06 15:42:09 +00:00
|
|
|
else // Should not occur
|
2012-02-26 18:39:39 +00:00
|
|
|
{
|
2009-07-29 13:10:36 +00:00
|
|
|
delete commandToUndo;
|
2012-02-26 18:39:39 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2021-02-15 14:02:41 +00:00
|
|
|
void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2023-08-09 18:22:48 +00:00
|
|
|
std::vector<SCH_ITEM*> bulkAddedItems;
|
|
|
|
std::vector<SCH_ITEM*> bulkRemovedItems;
|
|
|
|
std::vector<SCH_ITEM*> bulkChangedItems;
|
2023-11-25 12:38:24 +00:00
|
|
|
std::set<SCH_TABLE*> changedTables;
|
2024-01-27 17:02:22 +00:00
|
|
|
bool dirtyConnectivity = false;
|
2024-03-17 13:02:07 +00:00
|
|
|
bool rebuildHierarchyNavigator = false;
|
2024-01-27 17:02:22 +00:00
|
|
|
SCH_CLEANUP_FLAGS connectivityCleanUp = NO_CLEANUP;
|
2023-08-09 18:22:48 +00:00
|
|
|
|
2012-02-26 18:39:39 +00:00
|
|
|
// Undo in the reverse order of list creation: (this can allow stacked changes like the
|
2018-12-22 22:12:40 +00:00
|
|
|
// same item can be changed and deleted in the same complex command).
|
2022-01-05 19:32:10 +00:00
|
|
|
// After hitting 0, subtracting 1 will roll the value over to its max representation
|
|
|
|
for( unsigned ii = aList->GetCount() - 1; ii < std::numeric_limits<unsigned>::max(); ii-- )
|
2007-09-01 12:00:30 +00:00
|
|
|
{
|
2022-01-05 19:32:10 +00:00
|
|
|
UNDO_REDO status = aList->GetPickedItemStatus( ii );
|
|
|
|
EDA_ITEM* eda_item = aList->GetPickedItem( ii );
|
|
|
|
SCH_SCREEN* screen = dynamic_cast<SCH_SCREEN*>( aList->GetScreenForItem( ii ) );
|
2021-03-04 22:59:24 +00:00
|
|
|
|
|
|
|
wxCHECK( screen, /* void */ );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2022-01-05 19:32:10 +00:00
|
|
|
eda_item->SetFlags( aList->GetPickerFlags( ii ) );
|
2019-05-26 15:36:40 +00:00
|
|
|
eda_item->ClearEditFlags();
|
|
|
|
eda_item->ClearTempFlags();
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2024-01-27 17:02:22 +00:00
|
|
|
SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( eda_item );
|
|
|
|
|
|
|
|
// Set connectable object connectivity status.
|
2024-03-09 13:50:26 +00:00
|
|
|
auto updateConnectivityFlag = [&, this]()
|
2024-01-27 17:02:22 +00:00
|
|
|
{
|
2024-03-09 13:50:26 +00:00
|
|
|
if( schItem && schItem->IsConnectable() )
|
2024-01-27 17:02:22 +00:00
|
|
|
{
|
2024-03-09 13:50:26 +00:00
|
|
|
schItem->SetConnectivityDirty();
|
2024-01-27 17:02:22 +00:00
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
if( schItem->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( schItem );
|
2024-01-27 17:02:22 +00:00
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
wxCHECK( symbol, /* void */ );
|
2024-01-27 17:02:22 +00:00
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
for( SCH_PIN* pin : symbol->GetPins() )
|
|
|
|
pin->SetConnectivityDirty();
|
|
|
|
}
|
|
|
|
else if( schItem->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( schItem );
|
2024-01-27 17:02:22 +00:00
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
wxCHECK( sheet, /* void */ );
|
2024-01-27 17:02:22 +00:00
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
|
|
|
|
pin->SetConnectivityDirty();
|
|
|
|
}
|
2024-01-27 17:02:22 +00:00
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
m_highlightedConnChanged = true;
|
|
|
|
dirtyConnectivity = true;
|
2024-01-27 17:02:22 +00:00
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
// Do a local clean up if there are any connectable objects in the commit.
|
|
|
|
if( connectivityCleanUp == NO_CLEANUP )
|
|
|
|
connectivityCleanUp = LOCAL_CLEANUP;
|
|
|
|
|
|
|
|
// Do a full rebauild of the connectivity if there is a sheet in the commit.
|
|
|
|
if( schItem->Type() == SCH_SHEET_T )
|
|
|
|
connectivityCleanUp = GLOBAL_CLEANUP;
|
|
|
|
}
|
|
|
|
};
|
2024-01-27 17:02:22 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
if( status == UNDO_REDO::NEWITEM )
|
2007-09-01 12:00:30 +00:00
|
|
|
{
|
2024-03-09 13:50:26 +00:00
|
|
|
updateConnectivityFlag();
|
|
|
|
|
2022-02-03 19:17:41 +00:00
|
|
|
// If we are removing the current sheet, get out first
|
2023-06-24 17:19:44 +00:00
|
|
|
if( eda_item->Type() == SCH_SHEET_T )
|
2022-02-03 19:17:41 +00:00
|
|
|
{
|
2024-03-17 13:02:07 +00:00
|
|
|
rebuildHierarchyNavigator = true;
|
|
|
|
|
2023-06-24 18:54:50 +00:00
|
|
|
if( static_cast<SCH_SHEET*>( eda_item )->GetScreen() == GetScreen() )
|
2023-06-26 22:16:51 +00:00
|
|
|
GetToolManager()->PostAction( EE_ACTIONS::leaveSheet );
|
2022-02-03 19:17:41 +00:00
|
|
|
}
|
|
|
|
|
2021-03-04 22:59:24 +00:00
|
|
|
RemoveFromScreen( eda_item, screen );
|
2022-01-05 19:32:10 +00:00
|
|
|
aList->SetPickedItemStatus( UNDO_REDO::DELETED, ii );
|
2023-08-09 18:22:48 +00:00
|
|
|
|
|
|
|
bulkRemovedItems.emplace_back( schItem );
|
2018-12-22 22:12:40 +00:00
|
|
|
}
|
2020-08-26 18:04:32 +00:00
|
|
|
else if( status == UNDO_REDO::DELETED )
|
2018-12-22 22:12:40 +00:00
|
|
|
{
|
2024-03-17 13:02:07 +00:00
|
|
|
if( eda_item->Type() == SCH_SHEET_T )
|
|
|
|
rebuildHierarchyNavigator = true;
|
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
updateConnectivityFlag();
|
|
|
|
|
2018-12-22 22:12:40 +00:00
|
|
|
// deleted items are re-inserted on undo
|
2021-03-04 22:59:24 +00:00
|
|
|
AddToScreen( eda_item, screen );
|
2022-01-05 19:32:10 +00:00
|
|
|
aList->SetPickedItemStatus( UNDO_REDO::NEWITEM, ii );
|
2023-08-09 18:22:48 +00:00
|
|
|
|
|
|
|
bulkAddedItems.emplace_back( schItem );
|
2018-12-22 22:12:40 +00:00
|
|
|
}
|
2020-08-26 18:04:32 +00:00
|
|
|
else if( status == UNDO_REDO::PAGESETTINGS )
|
2019-05-26 15:36:40 +00:00
|
|
|
{
|
2023-08-27 18:02:12 +00:00
|
|
|
SCH_SHEET_PATH undoSheet = m_schematic->GetSheets().FindSheetForScreen( screen );
|
2023-06-21 22:41:17 +00:00
|
|
|
|
|
|
|
if( GetCurrentSheet() != undoSheet )
|
|
|
|
{
|
|
|
|
SetCurrentSheet( undoSheet );
|
|
|
|
DisplayCurrentSheet();
|
|
|
|
}
|
2021-12-21 21:06:52 +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 );
|
2024-01-26 12:33:04 +00:00
|
|
|
*item = std::move( alt_item );
|
2019-05-26 15:36:40 +00:00
|
|
|
}
|
2024-03-09 13:50:26 +00:00
|
|
|
else if( schItem )
|
2018-12-22 22:12:40 +00:00
|
|
|
{
|
2024-03-09 13:50:26 +00:00
|
|
|
SCH_ITEM* itemCopy = dynamic_cast<SCH_ITEM*>( aList->GetPickedItemLink( ii ) );
|
|
|
|
|
|
|
|
wxCHECK2( itemCopy, continue );
|
|
|
|
|
|
|
|
if( schItem->HasConnectivityChanges( itemCopy, &GetCurrentSheet() ) )
|
|
|
|
updateConnectivityFlag();
|
2020-10-18 20:30:37 +00:00
|
|
|
|
|
|
|
// The root sheet is a pseudo object that owns the root screen object but is not on
|
|
|
|
// the root screen so do not attempt to remove it from the screen it owns.
|
2024-03-09 13:50:26 +00:00
|
|
|
if( schItem != &Schematic().Root() )
|
|
|
|
RemoveFromScreen( schItem, screen );
|
2018-09-05 22:17:22 +00:00
|
|
|
|
2018-12-22 22:12:40 +00:00
|
|
|
switch( status )
|
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
case UNDO_REDO::CHANGED:
|
2024-03-17 13:02:07 +00:00
|
|
|
if( schItem->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
const SCH_SHEET* origSheet = static_cast<const SCH_SHEET*>( schItem );
|
|
|
|
const SCH_SHEET* copySheet = static_cast<const SCH_SHEET*>( schItem );
|
|
|
|
|
|
|
|
wxCHECK2( origSheet && copySheet, continue );
|
|
|
|
|
|
|
|
if( ( origSheet->GetName() != copySheet->GetName() )
|
|
|
|
|| ( origSheet->GetFileName() != copySheet->GetFileName() ) )
|
|
|
|
{
|
|
|
|
rebuildHierarchyNavigator = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
schItem->SwapData( itemCopy );
|
|
|
|
bulkChangedItems.emplace_back( schItem );
|
2022-03-19 19:36:20 +00:00
|
|
|
|
|
|
|
// Special cases for items which have instance data
|
2024-03-09 13:50:26 +00:00
|
|
|
if( schItem->GetParent() && schItem->GetParent()->Type() == SCH_SYMBOL_T
|
|
|
|
&& schItem->Type() == SCH_FIELD_T )
|
2022-03-19 19:36:20 +00:00
|
|
|
{
|
2024-03-09 13:50:26 +00:00
|
|
|
SCH_FIELD* field = static_cast<SCH_FIELD*>( schItem );
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( schItem->GetParent() );
|
2022-03-19 19:36:20 +00:00
|
|
|
|
|
|
|
if( field->GetId() == REFERENCE_FIELD )
|
|
|
|
{
|
2023-08-27 18:02:12 +00:00
|
|
|
SCH_SHEET_PATH sheet = m_schematic->GetSheets().FindSheetForScreen( screen );
|
|
|
|
symbol->SetRef( &sheet, field->GetText() );
|
2022-03-19 19:36:20 +00:00
|
|
|
}
|
2023-08-09 18:22:48 +00:00
|
|
|
|
|
|
|
bulkChangedItems.emplace_back( symbol );
|
2022-03-19 19:36:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-22 22:12:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Unknown undo/redo command %d" ),
|
2022-01-05 19:32:10 +00:00
|
|
|
aList->GetPickedItemStatus( ii ) ) );
|
2018-12-22 22:12:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-04-05 14:46:51 +00:00
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
if( schItem->Type() == SCH_SYMBOL_T )
|
2022-01-05 19:32:10 +00:00
|
|
|
{
|
2024-03-09 13:50:26 +00:00
|
|
|
SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( schItem );
|
2022-01-05 19:32:10 +00:00
|
|
|
sym->UpdatePins();
|
|
|
|
}
|
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
if( schItem != &Schematic().Root() )
|
|
|
|
AddToScreen( schItem, screen );
|
2007-09-01 12:00:30 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2018-12-21 16:38:28 +00:00
|
|
|
GetCanvas()->GetView()->ClearHiddenFlags();
|
2023-08-09 18:22:48 +00:00
|
|
|
|
|
|
|
// Notify our listeners
|
|
|
|
if( bulkAddedItems.size() > 0 )
|
|
|
|
Schematic().OnItemsAdded( bulkAddedItems );
|
|
|
|
|
|
|
|
if( bulkRemovedItems.size() > 0 )
|
|
|
|
Schematic().OnItemsRemoved( bulkRemovedItems );
|
|
|
|
|
|
|
|
if( bulkChangedItems.size() > 0 )
|
|
|
|
Schematic().OnItemsChanged( bulkChangedItems );
|
2024-01-27 17:02:22 +00:00
|
|
|
|
|
|
|
if( dirtyConnectivity )
|
|
|
|
{
|
2024-03-09 13:50:26 +00:00
|
|
|
wxLogTrace( wxS( "CONN_PROFILE" ),
|
|
|
|
wxS( "Undo/redo %s clean up connectivity rebuild." ),
|
|
|
|
( connectivityCleanUp == LOCAL_CLEANUP ) ? wxS( "local" ) : wxS( "global" ) );
|
|
|
|
|
2024-01-27 17:02:22 +00:00
|
|
|
SCH_COMMIT localCommit( m_toolManager );
|
|
|
|
|
|
|
|
RecalculateConnections( &localCommit, connectivityCleanUp );
|
|
|
|
|
|
|
|
// Update the hierarchy navigator when there are sheet changes.
|
|
|
|
if( connectivityCleanUp == GLOBAL_CLEANUP )
|
|
|
|
{
|
|
|
|
SetSheetNumberAndCount();
|
2024-03-17 13:02:07 +00:00
|
|
|
|
|
|
|
if( rebuildHierarchyNavigator )
|
|
|
|
UpdateHierarchyNavigator();
|
2024-01-27 17:02:22 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2019-04-23 17:40:29 +00:00
|
|
|
void SCH_EDIT_FRAME::RollbackSchematicFromUndo()
|
|
|
|
{
|
2020-07-13 11:21:40 +00:00
|
|
|
PICKED_ITEMS_LIST* undo = PopCommandFromUndoList();
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2021-02-12 19:26:48 +00:00
|
|
|
// Skip empty frames
|
2023-08-09 18:04:22 +00:00
|
|
|
while( undo && !undo->GetCount() )
|
2021-02-16 18:09:56 +00:00
|
|
|
{
|
|
|
|
delete undo;
|
|
|
|
undo = PopCommandFromUndoList();
|
|
|
|
}
|
2021-02-12 19:26:48 +00:00
|
|
|
|
2019-08-03 23:14:56 +00:00
|
|
|
if( undo )
|
|
|
|
{
|
2021-02-15 14:02:41 +00:00
|
|
|
PutDataInPreviousState( undo );
|
2022-11-15 23:51:42 +00:00
|
|
|
undo->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
delete aItem;
|
|
|
|
} );
|
2024-01-06 12:56:16 +00:00
|
|
|
|
2019-08-03 23:14:56 +00:00
|
|
|
delete undo;
|
2019-04-23 17:40:29 +00:00
|
|
|
|
2021-05-27 13:24:06 +00:00
|
|
|
m_toolManager->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
|
2019-08-03 23:14:56 +00:00
|
|
|
}
|
2019-04-23 17:40:29 +00:00
|
|
|
|
|
|
|
GetCanvas()->Refresh();
|
|
|
|
}
|
2020-07-13 11:21:40 +00:00
|
|
|
|
|
|
|
|
2020-07-13 13:50:35 +00:00
|
|
|
void SCH_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount )
|
2020-07-13 11:21:40 +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;
|
2020-07-13 13:50:35 +00:00
|
|
|
|
2024-02-07 14:49:50 +00:00
|
|
|
if( aItemCount < 0 )
|
2020-07-13 11:21:40 +00:00
|
|
|
{
|
2024-02-07 14:49:50 +00:00
|
|
|
list.ClearCommandList();
|
2020-07-13 11:21:40 +00:00
|
|
|
}
|
2024-02-07 14:49:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for( int ii = 0; ii < aItemCount; ii++ )
|
|
|
|
{
|
|
|
|
if( list.m_CommandsList.size() == 0 )
|
|
|
|
break;
|
2020-07-13 11:21:40 +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() );
|
|
|
|
|
|
|
|
curr_cmd->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
delete aItem;
|
|
|
|
} );
|
|
|
|
delete curr_cmd; // Delete command
|
|
|
|
}
|
|
|
|
}
|
2020-07-13 11:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|