From dfc60701780e6cd6f59bea8349925e697e09633b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 31 Jan 2021 17:25:38 +0000 Subject: [PATCH] Unify schematic file version checking with PCBNew. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also makes sure that the user gets a warning before saving over an older s-expr format. While that won't always be wanted, it's now in the infobar (like in PCBNew), so it's not too onerous.ยง Fixes https://gitlab.com/kicad/code/kicad/issues/7347 --- eeschema/files-io.cpp | 35 +++++++++---------- .../sch_plugins/kicad/sch_sexpr_parser.cpp | 2 ++ eeschema/sch_screen.cpp | 5 ++- eeschema/sch_screen.h | 23 ++++++------ 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 6705c4940b..c2efb7a25b 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -291,6 +292,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in } SetStatusText( wxEmptyString ); + m_infoBar->Dismiss(); SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromSchPath( fullFileName ); @@ -483,24 +485,11 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in // Update all symbol library links for all sheets. schematic.UpdateSymbolLinks(); - if( !cfg || cfg->m_Appearance.show_sexpr_file_convert_warning ) - { - wxRichMessageDialog newFileFormatDlg( - this, - _( "The schematic file will be converted to the new file format on save." ), - _( "Project Load Warning" ), - wxOK | wxCENTER | wxICON_EXCLAMATION ); - newFileFormatDlg.ShowDetailedText( - _( "This schematic was saved in the legacy file format which is no " - "longer supported and will be saved using the new file format.\n\nThe " - "new file format cannot be opened with previous versions of KiCad." ) ); - newFileFormatDlg.ShowCheckBox( _( "Do not show this dialog again." ) ); - newFileFormatDlg.ShowModal(); - - if( cfg ) - cfg->m_Appearance.show_sexpr_file_convert_warning = - !newFileFormatDlg.IsCheckBoxChecked(); - } + m_infoBar->RemoveAllButtons(); + m_infoBar->AddCloseButton(); + m_infoBar->ShowMessage( _( "This file was created by an older version of KiCad. " + "It will be converted to the new format when saved." ), + wxICON_WARNING ); // Legacy schematic can have duplicate time stamps so fix that before converting // to the s-expression format. @@ -511,6 +500,15 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in } else // S-expression schematic. { + if( schematic.GetFirst()->GetFileFormatVersionAtLoad() < SEXPR_SCHEMATIC_FILE_VERSION ) + { + m_infoBar->RemoveAllButtons(); + m_infoBar->AddCloseButton(); + m_infoBar->ShowMessage( _( "This file was created by an older version of KiCad. " + "It will be converted to the new format when saved." ), + wxICON_WARNING ); + } + for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() ) screen->UpdateLocalLibSymbolLinks(); @@ -557,7 +555,6 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in UpdateTitle(); wxFileName fn = Prj().AbsolutePath( GetScreen()->GetFileName() ); - m_infoBar->Dismiss(); if( fn.FileExists() && !fn.IsFileWritable() ) { diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index a8657b6101..fa719f97e8 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -1981,6 +1981,8 @@ void SCH_SEXPR_PARSER::ParseSchematic( SCH_SHEET* aSheet, bool aIsCopyableOnly, parseHeader( T_kicad_sch, SEXPR_SCHEMATIC_FILE_VERSION ); } + screen->SetFileFormatVersionAtLoad( m_requiredVersion ); + for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { if( aIsCopyableOnly && token == T_EOF ) diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index c0924fca8e..c67d56bca3 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -54,9 +54,7 @@ #include #include -#include #include -#include // TODO(JE) Debugging only #include @@ -64,7 +62,8 @@ SCH_SCREEN::SCH_SCREEN( EDA_ITEM* aParent ) : BASE_SCREEN( aParent, SCH_SCREEN_T ), - m_paper( wxT( "A4" ) ) + m_paper( wxT( "A4" ) ), + m_fileFormatVersionAtLoad( 0 ) { m_modification_sync = 0; m_refCount = 0; diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index ba64563b5d..b7b5ba1b72 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -94,10 +94,10 @@ class SCH_SCREEN : public BASE_SCREEN { private: - wxString m_fileName; // File used to load the screen. - - int m_refCount; // Number of sheets referencing this screen. - // Delete when it goes to zero. + wxString m_fileName; // File used to load the screen. + int m_fileFormatVersionAtLoad; + int m_refCount; // Number of sheets referencing this screen. + // Delete when it goes to zero. /** * The list of sheet paths sharing this screen. Used in some annotation calculations to * update alternate references. @@ -108,16 +108,16 @@ private: std::vector m_clientSheetPathList; - PAGE_INFO m_paper; // The size of the paper to print or plot on + PAGE_INFO m_paper; // The size of the paper to print or plot on TITLE_BLOCK m_titles; - wxPoint m_aux_origin; // Origin used for drill & place files by PCBNew + wxPoint m_aux_origin; // Origin used for drill & place files by PCBNew EE_RTREE m_rtree; - int m_modification_sync; // inequality with PART_LIBS::GetModificationHash() will - // trigger ResolveAll(). + int m_modification_sync; // inequality with PART_LIBS::GetModificationHash() + // will trigger ResolveAll(). - /// Set to true once the zoom value is initialized with `InitZoom()`. - bool m_zoomInitialized; + bool m_zoomInitialized; // Set to true once the zoom value is initialized with + // `InitZoom()`. /// List of bus aliases stored in this screen. std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases; @@ -181,6 +181,9 @@ public: return wxT( "SCH_SCREEN" ); } + void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; } + int GetFileFormatVersionAtLoad() const { return m_fileFormatVersionAtLoad; } + const PAGE_INFO& GetPageSettings() const { return m_paper; } void SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; }