From 71c2cb318003403fefeff110b4659dfa427c96c9 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 17 Apr 2022 18:14:50 +0100 Subject: [PATCH] ADDED revert for pcbnew and eeschema. Fixes https://gitlab.com/kicad/code/kicad/issues/6802 --- eeschema/menubar.cpp | 2 ++ eeschema/tools/sch_editor_control.cpp | 40 +++++++++++++++++++++++++++ eeschema/tools/sch_editor_control.h | 3 ++ pcbnew/files.cpp | 14 ++++++++++ pcbnew/menubar_pcb_editor.cpp | 2 ++ pcbnew/pcbnew_id.h | 1 + pcbnew/tools/board_editor_control.cpp | 10 ++++++- pcbnew/tools/board_editor_control.h | 3 +- 8 files changed, 73 insertions(+), 2 deletions(-) diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp index 3eb72f8ee5..8ffaf7619d 100644 --- a/eeschema/menubar.cpp +++ b/eeschema/menubar.cpp @@ -91,6 +91,8 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() else fileMenu->Add( EE_ACTIONS::saveCurrSheetCopyAs ); + fileMenu->Add( ACTIONS::revert ); + fileMenu->AppendSeparator(); fileMenu->Add( _( "Insert Schematic Sheet Content..." ), diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index bda1b7ae31..9079845527 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -113,6 +113,45 @@ int SCH_EDITOR_CONTROL::SaveCurrSheetCopyAs( const TOOL_EVENT& aEvent ) } +int SCH_EDITOR_CONTROL::Revert( const TOOL_EVENT& aEvent ) +{ + SCHEMATIC& schematic = m_frame->Schematic(); + SCH_SHEET& root = schematic.Root(); + + if( m_frame->GetCurrentSheet().Last() != &root ) + { + m_toolMgr->RunAction( ACTIONS::cancelInteractive, true ); + m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); + + // Store the current zoom level into the current screen before switching + m_frame->GetScreen()->m_LastZoomLevel = m_frame->GetCanvas()->GetView()->GetScale(); + + SCH_SHEET_PATH rootSheetPath; + rootSheetPath.push_back( &root ); + m_frame->SetCurrentSheet( rootSheetPath ); + m_frame->DisplayCurrentSheet(); + + wxSafeYield(); + } + + wxString msg; + msg.Printf( _( "Revert '%s' (and all sub-sheets) to last version saved?" ), + schematic.GetFileName() ); + + if( !IsOK( m_frame, msg ) ) + return false; + + SCH_SCREENS screenList( schematic.Root() ); + + for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() ) + screen->SetContentModified( false ); // do not prompt the user for changes + + m_frame->OpenProjectFiles( std::vector( 1, schematic.GetFileName() ) ); + + return 0; +} + + int SCH_EDITOR_CONTROL::ShowSchematicSetup( const TOOL_EVENT& aEvent ) { m_frame->ShowSchematicSetupDialog(); @@ -2296,6 +2335,7 @@ void SCH_EDITOR_CONTROL::setTransitions() Go( &SCH_EDITOR_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() ); //Go( &SCH_EDITOR_CONTROL::SaveAs, ACTIONS::saveCopyAs.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::SaveCurrSheetCopyAs, EE_ACTIONS::saveCurrSheetCopyAs.MakeEvent() ); + Go( &SCH_EDITOR_CONTROL::Revert, ACTIONS::revert.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::ShowSchematicSetup, EE_ACTIONS::schematicSetup.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::PageSetup, ACTIONS::pageSettings.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() ); diff --git a/eeschema/tools/sch_editor_control.h b/eeschema/tools/sch_editor_control.h index e7e6147723..f571f4063a 100644 --- a/eeschema/tools/sch_editor_control.h +++ b/eeschema/tools/sch_editor_control.h @@ -53,6 +53,9 @@ public: /// Saves the currently-open schematic sheet to an other name int SaveCurrSheetCopyAs( const TOOL_EVENT& aEvent ); + + int Revert( const TOOL_EVENT& aEvent ); + int ShowSchematicSetup( const TOOL_EVENT& aEvent ); int PageSetup( const TOOL_EVENT& aEvent ); int Print( const TOOL_EVENT& aEvent ); diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 0e5bafc68c..16ab720cba 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -369,6 +369,20 @@ bool PCB_EDIT_FRAME::Files_io_from_id( int id ) return false; } + case ID_REVERT_BOARD: + { + wxFileName fn = Prj().AbsolutePath( GetBoard()->GetFileName() ); + + msg.Printf( _( "Revert '%s' to last version saved?" ), fn.GetFullPath() ); + + if( !IsOK( this, msg ) ) + return false; + + GetScreen()->SetContentModified( false ); // do not prompt the user for changes + + return OpenProjectFiles( std::vector( 1, fn.GetFullPath() ) ); + } + case ID_NEW_BOARD: { if( IsContentModified() ) diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index f4038d8283..3a06102648 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -99,6 +99,8 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() else fileMenu->Add( ACTIONS::saveCopyAs ); + fileMenu->Add( ACTIONS::revert ); + fileMenu->AppendSeparator(); fileMenu->Add( _( "Resc&ue" ), _( "Clear board and get last rescue file automatically saved by PCB editor" ), diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index f39b4fbd74..9e92807a16 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -15,6 +15,7 @@ enum pcbnew_ids { ID_MAIN_MENUBAR = ID_END_LIST, ID_COPY_BOARD_AS, + ID_REVERT_BOARD, ID_IMPORT_NON_KICAD_BOARD, // Tracks and vias sizes general options diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index 9f13adc725..3ca7ac2017 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 CERN - * Copyright (C) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2014-2022 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -325,6 +325,13 @@ int BOARD_EDITOR_CONTROL::SaveCopyAs( const TOOL_EVENT& aEvent ) } +int BOARD_EDITOR_CONTROL::Revert( const TOOL_EVENT& aEvent ) +{ + m_frame->Files_io_from_id( ID_REVERT_BOARD ); + return 0; +} + + int BOARD_EDITOR_CONTROL::PageSettings( const TOOL_EVENT& aEvent ) { PICKED_ITEMS_LIST undoCmd; @@ -1603,6 +1610,7 @@ void BOARD_EDITOR_CONTROL::setTransitions() Go( &BOARD_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() ); Go( &BOARD_EDITOR_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() ); Go( &BOARD_EDITOR_CONTROL::SaveCopyAs, ACTIONS::saveCopyAs.MakeEvent() ); + Go( &BOARD_EDITOR_CONTROL::Revert, ACTIONS::revert.MakeEvent() ); Go( &BOARD_EDITOR_CONTROL::PageSettings, ACTIONS::pageSettings.MakeEvent() ); Go( &BOARD_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() ); diff --git a/pcbnew/tools/board_editor_control.h b/pcbnew/tools/board_editor_control.h index 015002c86d..7b631e5286 100644 --- a/pcbnew/tools/board_editor_control.h +++ b/pcbnew/tools/board_editor_control.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 CERN - * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors. * * @author Maciej Suminski * @@ -56,6 +56,7 @@ public: int Save( const TOOL_EVENT& aEvent ); int SaveAs( const TOOL_EVENT& aEvent ); int SaveCopyAs( const TOOL_EVENT& aEvent ); + int Revert( const TOOL_EVENT& aEvent ); int PageSettings( const TOOL_EVENT& aEvent ); int Plot( const TOOL_EVENT& aEvent );