Convert remaining schematic undo/redo calls to commit system.

The schematic commit system currently does not handle renaming symbols
in the symbol library editor or page settings in the schematic editor.
The schematic commit system will have to be modified to support the two
remaining direct calls to the undo/redo code.
This commit is contained in:
Wayne Stambaugh 2024-12-20 09:54:24 -05:00
parent eed7222bc3
commit 424438ace1
5 changed files with 29 additions and 26 deletions

View File

@ -29,6 +29,7 @@
#include <confirm.h>
#include <sch_commit.h>
#include <sch_edit_frame.h>
#include <sch_symbol.h>
#include <sch_reference_list.h>
@ -707,6 +708,8 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::TransferDataFromWindow()
if( !validateLibIds() )
return false;
SCH_COMMIT commit( GetParent() );
auto getName = []( const LIB_ID& aLibId )
{
return UnescapeString( aLibId.GetLibItemName().wx_str() );
@ -751,8 +754,7 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::TransferDataFromWindow()
if( symbol == nullptr )
continue;
GetParent()->SaveCopyInUndoList( candidate.m_Screen, candidate.m_Symbol,
UNDO_REDO::CHANGED, m_isModified );
commit.Modify( candidate.m_Symbol, candidate.m_Screen );
m_isModified = true;
candidate.m_Screen->Remove( candidate.m_Symbol );
@ -779,6 +781,9 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::TransferDataFromWindow()
}
}
if( m_modified )
commit.Push( wxS( "Change Symbol Library Indentifier" ) );
return true;
}

View File

@ -28,6 +28,7 @@
#include <kiface_base.h>
#include <sch_edit_frame.h>
#include <wildcards_and_files_ext.h>
#include <sch_commit.h>
#include <sch_sheet_path.h>
#include <sch_symbol.h>
#include <sch_reference_list.h>
@ -45,8 +46,8 @@ void SCH_EDITOR_CONTROL::AssignFootprints( const std::string& aChangedSetOfRefer
{
// Build a flat list of symbols in schematic:
SCH_REFERENCE_LIST refs;
SCH_COMMIT commit( m_frame );
bool isChanged = false;
bool appendToUndoList = false;
m_frame->Schematic().Hierarchy().GetSymbols( refs, false );
@ -97,9 +98,7 @@ void SCH_EDITOR_CONTROL::AssignFootprints( const std::string& aChangedSetOfRefer
isChanged = true;
SCH_SCREEN* screen = refs[ii].GetSheetPath().LastScreen();
m_frame->SaveCopyInUndoList( screen, symbol, UNDO_REDO::CHANGED,
appendToUndoList, false );
appendToUndoList = true;
commit.Modify( symbol, screen );
symbol->SetFootprintFieldText( footprint );
}
@ -116,8 +115,7 @@ void SCH_EDITOR_CONTROL::AssignFootprints( const std::string& aChangedSetOfRefer
if( isChanged )
{
m_frame->SyncView();
m_frame->GetCanvas()->Refresh();
m_frame->OnModify();
commit.Push( wxS( "Assign Footprints" ) );
}
}

View File

@ -2970,7 +2970,9 @@ int SCH_EDIT_TOOL::EditPageNumber( const TOOL_EVENT& aEvent )
if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue() == instance.GetPageNumber() )
return 0;
m_frame->SaveCopyInUndoList( screen, sheet, UNDO_REDO::CHANGED, false );
SCH_COMMIT commit( m_frame );
commit.Modify( sheet, screen );
instance.SetPageNumber( dlg.GetValue() );
@ -2980,12 +2982,7 @@ int SCH_EDIT_TOOL::EditPageNumber( const TOOL_EVENT& aEvent )
m_frame->OnPageSettingsChange();
}
m_frame->OnModify();
// Update the hierarchy navigator labels if needed
if( pageNumber != dlg.GetValue() )
m_frame->UpdateLabelsHierarchyNavigator();
commit.Push( wxS( "Change Sheet Page Number" ) );
return 0;
}

View File

@ -434,6 +434,7 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent )
bool map = IsOK( m_frame, _( "Update symbols in schematic to refer to new library?" ) );
bool append = false;
SCH_COMMIT commit( m_frame );
SYMBOL_LIB_TABLE_ROW* row = mgr.GetLibrary( targetLib );
SCH_IO_MGR::SCH_FILE_T type = SCH_IO_MGR::EnumFromStr( row->GetType() );
IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( type ) );
@ -467,8 +468,11 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent )
for( SCH_SYMBOL* symbol : symbolMap[it.first] )
{
m_frame->SaveCopyInUndoList( m_frame->GetScreen(), symbol, UNDO_REDO::CHANGED,
append, false );
SCH_SCREEN* parentScreen = static_cast<SCH_SCREEN*>( symbol->GetParent() );
wxCHECK2( parentScreen, continue );
commit.Modify( symbol, parentScreen );
symbol->SetLibId( id );
append = true;
}
@ -529,7 +533,7 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent )
}
}
m_frame->OnModify();
commit.Push( wxS( "Update Library Identifiers" ) );
}
return 0;

View File

@ -22,6 +22,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <sch_commit.h>
#include <sch_sheet_pin.h>
#include <schematic.h>
#include <tools/ee_actions.h>
@ -366,19 +367,17 @@ int SCH_FIND_REPLACE_TOOL::ReplaceAndFindNext( const TOOL_EVENT& aEvent )
if( data.findString.IsEmpty() )
return FindAndReplace( ACTIONS::find.MakeEvent() );
// TODO: move to SCH_COMMIT....
if( item && HasMatch() )
{
SCH_COMMIT commit( m_frame );
SCH_ITEM* sch_item = static_cast<SCH_ITEM*>( item );
m_frame->SaveCopyInUndoList( sheet->LastScreen(), sch_item, UNDO_REDO::CHANGED, false );
commit.Modify( sch_item, sheet->LastScreen() );
if( item->Replace( data, sheet ) )
{
m_frame->UpdateItem( item, false, true );
m_frame->GetCurrentSheet().UpdateAllScreenReferences();
m_frame->OnModify();
commit.Push( wxS( "Find and Replace" ) );
}
FindNext( ACTIONS::findNext.MakeEvent() );
@ -404,6 +403,7 @@ int SCH_FIND_REPLACE_TOOL::ReplaceAll( const TOOL_EVENT& aEvent )
{
}
SCH_COMMIT commit( m_frame );
bool modified = false; // TODO: move to SCH_COMMIT....
if( data.findString.IsEmpty() )
@ -412,8 +412,7 @@ int SCH_FIND_REPLACE_TOOL::ReplaceAll( const TOOL_EVENT& aEvent )
auto doReplace =
[&]( SCH_ITEM* aItem, SCH_SHEET_PATH* aSheet, EDA_SEARCH_DATA& aData )
{
m_frame->SaveCopyInUndoList( aSheet->LastScreen(), aItem, UNDO_REDO::CHANGED,
modified );
commit.Modify( aItem, aSheet->LastScreen() );
if( aItem->Replace( aData, aSheet ) )
{
@ -485,8 +484,8 @@ int SCH_FIND_REPLACE_TOOL::ReplaceAll( const TOOL_EVENT& aEvent )
if( modified )
{
commit.Push( wxS( "Find and Replace All" ) );
m_frame->GetCurrentSheet().UpdateAllScreenReferences();
m_frame->OnModify();
}
return 0;