mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 18:23:15 +02:00
Always look for pre-existing undo/redo record. Checking for IsNew() is less robust and should be avoided. Also moves the checking to a location where it will be easier to ensure that it's uniform. Push get-undo-level-item processing down a level so it is uniformly called. Make sure tables & labels are uniformly handled. Remove incorrect usage of Get/SetGroupId() for storing lastPin (which we don't use anyway). Lists of deleted and changed items MUST include the screen pointer. An item could be changed on one screen but not on another. Also tightens handling of PCB_NETINFO_T items, which are not in the view. Also fixes a bug where there is no increment parameter if you assign the base increment command to a hotkey. (This was discovered while testing the above changes.) Also fixes a bug where delete during a move in PCB Editor did an undo instead of a delete. (Again, found while testing above.) An experiment was also run to collapse shared parts of SCH_EDIT_FRAME and SYMBOL_EDITOR_FRAME into SCH_BASE_EDIT_FRAME. However, sharing the undo code actually increased complexity, and there was very little else of value in SCH_BASE_EDIT_FRAME (other than the Increment() routines).
166 lines
5.6 KiB
C++
166 lines
5.6 KiB
C++
/*
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
*
|
|
* Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
* Copyright The 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
|
|
*/
|
|
|
|
#include <symbol_edit_frame.h>
|
|
#include <lib_symbol_library_manager.h>
|
|
#include <widgets/lib_tree.h>
|
|
#include <tool/tool_manager.h>
|
|
#include <tools/sch_selection_tool.h>
|
|
#include <tools/symbol_editor_drawing_tools.h>
|
|
|
|
|
|
void SYMBOL_EDIT_FRAME::PushSymbolToUndoList( const wxString& aDescription, LIB_SYMBOL* aSymbolCopy,
|
|
UNDO_REDO aUndoType )
|
|
{
|
|
if( !aSymbolCopy )
|
|
return;
|
|
|
|
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
|
|
|
|
// Clear current flags (which can be temporary set by a current edit command).
|
|
aSymbolCopy->ClearTempFlags();
|
|
aSymbolCopy->ClearEditFlags();
|
|
aSymbolCopy->SetFlags( UR_TRANSIENT );
|
|
|
|
ITEM_PICKER wrapper( GetScreen(), aSymbolCopy, aUndoType );
|
|
lastcmd->PushItem( wrapper );
|
|
lastcmd->SetDescription( aDescription );
|
|
PushCommandToUndoList( lastcmd );
|
|
|
|
// Clear redo list, because after new save there is no redo to do.
|
|
ClearUndoORRedoList( REDO_LIST );
|
|
}
|
|
|
|
|
|
void SYMBOL_EDIT_FRAME::SaveCopyInUndoList( const wxString& aDescription, LIB_SYMBOL* aSymbol,
|
|
UNDO_REDO aUndoType )
|
|
{
|
|
if( aSymbol )
|
|
PushSymbolToUndoList( aDescription, new LIB_SYMBOL( *aSymbol ), aUndoType );
|
|
}
|
|
|
|
|
|
void SYMBOL_EDIT_FRAME::GetSymbolFromRedoList()
|
|
{
|
|
if( GetRedoCommandCount() <= 0 )
|
|
return;
|
|
|
|
// Load the last redo entry
|
|
PICKED_ITEMS_LIST* redoCommand = PopCommandFromRedoList();
|
|
ITEM_PICKER redoWrapper = redoCommand->PopItem();
|
|
wxString description = redoCommand->GetDescription();
|
|
|
|
delete redoCommand;
|
|
|
|
LIB_SYMBOL* symbol = (LIB_SYMBOL*) redoWrapper.GetItem();
|
|
UNDO_REDO undoRedoType = redoWrapper.GetStatus();
|
|
wxCHECK( symbol, /* void */ );
|
|
symbol->ClearFlags( UR_TRANSIENT );
|
|
|
|
// Store the current symbol in the undo buffer
|
|
PICKED_ITEMS_LIST* undoCommand = new PICKED_ITEMS_LIST();
|
|
LIB_SYMBOL* oldSymbol = m_symbol;
|
|
|
|
oldSymbol->SetFlags( UR_TRANSIENT );
|
|
ITEM_PICKER undoWrapper( GetScreen(), oldSymbol, undoRedoType );
|
|
undoCommand->SetDescription( description );
|
|
undoCommand->PushItem( undoWrapper );
|
|
PushCommandToUndoList( undoCommand );
|
|
|
|
// Do not delete the previous symbol by calling SetCurSymbol( symbol )
|
|
// which calls delete <previous symbol>.
|
|
// <previous symbol> is now put in undo list and is owned by this list
|
|
// Just set the current symbol to the symbol which come from the redo list
|
|
m_symbol = symbol;
|
|
|
|
if( undoRedoType == UNDO_REDO::LIB_RENAME )
|
|
{
|
|
wxString lib = GetCurLib();
|
|
m_libMgr->UpdateSymbolAfterRename( symbol, oldSymbol->GetName(), lib );
|
|
|
|
// Reselect the renamed symbol
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, symbol->GetName() ) );
|
|
}
|
|
|
|
RebuildSymbolUnitsList();
|
|
SetShowDeMorgan( symbol->HasAlternateBodyStyle() );
|
|
UpdateTitle();
|
|
|
|
RebuildView();
|
|
OnModify();
|
|
}
|
|
|
|
|
|
void SYMBOL_EDIT_FRAME::GetSymbolFromUndoList()
|
|
{
|
|
if( GetUndoCommandCount() <= 0 )
|
|
return;
|
|
|
|
// Load the last undo entry
|
|
PICKED_ITEMS_LIST* undoCommand = PopCommandFromUndoList();
|
|
wxString description = undoCommand->GetDescription();
|
|
ITEM_PICKER undoWrapper = undoCommand->PopItem();
|
|
|
|
delete undoCommand;
|
|
|
|
LIB_SYMBOL* symbol = (LIB_SYMBOL*) undoWrapper.GetItem();
|
|
UNDO_REDO undoRedoType = undoWrapper.GetStatus();
|
|
wxCHECK( symbol, /* void */ );
|
|
symbol->ClearFlags( UR_TRANSIENT );
|
|
|
|
// Store the current symbol in the redo buffer
|
|
PICKED_ITEMS_LIST* redoCommand = new PICKED_ITEMS_LIST();
|
|
LIB_SYMBOL* oldSymbol = m_symbol;
|
|
|
|
oldSymbol->SetFlags( UR_TRANSIENT );
|
|
ITEM_PICKER redoWrapper( GetScreen(), oldSymbol, undoRedoType );
|
|
redoCommand->PushItem( redoWrapper );
|
|
redoCommand->SetDescription( description );
|
|
PushCommandToRedoList( redoCommand );
|
|
|
|
// Do not delete the previous symbol by calling SetCurSymbol( symbol ),
|
|
// which calls delete <previous symbol>.
|
|
// <previous symbol> is now put in redo list and is owned by this list.
|
|
// Just set the current symbol to the symbol which come from the undo list
|
|
m_symbol = symbol;
|
|
|
|
if( undoRedoType == UNDO_REDO::LIB_RENAME )
|
|
{
|
|
wxString lib = GetCurLib();
|
|
m_libMgr->UpdateSymbolAfterRename( symbol, oldSymbol->GetName(), lib );
|
|
|
|
// Reselect the renamed symbol
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, symbol->GetName() ) );
|
|
}
|
|
|
|
RebuildSymbolUnitsList();
|
|
SetShowDeMorgan( symbol->HasAlternateBodyStyle() );
|
|
UpdateTitle();
|
|
|
|
RebuildView();
|
|
OnModify();
|
|
}
|
|
|
|
|