Unify schematic file version checking with PCBNew.

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
This commit is contained in:
Jeff Young 2021-01-31 17:25:38 +00:00
parent 9770ba9739
commit dfc6070178
4 changed files with 33 additions and 32 deletions

View File

@ -44,6 +44,7 @@
#include <sch_component.h> #include <sch_component.h>
#include <sch_edit_frame.h> #include <sch_edit_frame.h>
#include <sch_plugins/legacy/sch_legacy_plugin.h> #include <sch_plugins/legacy/sch_legacy_plugin.h>
#include <sch_file_versions.h>
#include <sch_sheet.h> #include <sch_sheet.h>
#include <sch_sheet_path.h> #include <sch_sheet_path.h>
#include <schematic.h> #include <schematic.h>
@ -291,6 +292,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
} }
SetStatusText( wxEmptyString ); SetStatusText( wxEmptyString );
m_infoBar->Dismiss();
SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromSchPath( fullFileName ); SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromSchPath( fullFileName );
@ -483,24 +485,11 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
// Update all symbol library links for all sheets. // Update all symbol library links for all sheets.
schematic.UpdateSymbolLinks(); schematic.UpdateSymbolLinks();
if( !cfg || cfg->m_Appearance.show_sexpr_file_convert_warning ) m_infoBar->RemoveAllButtons();
{ m_infoBar->AddCloseButton();
wxRichMessageDialog newFileFormatDlg( m_infoBar->ShowMessage( _( "This file was created by an older version of KiCad. "
this, "It will be converted to the new format when saved." ),
_( "The schematic file will be converted to the new file format on save." ), wxICON_WARNING );
_( "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();
}
// Legacy schematic can have duplicate time stamps so fix that before converting // Legacy schematic can have duplicate time stamps so fix that before converting
// to the s-expression format. // to the s-expression format.
@ -511,6 +500,15 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
} }
else // S-expression schematic. 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() ) for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() )
screen->UpdateLocalLibSymbolLinks(); screen->UpdateLocalLibSymbolLinks();
@ -557,7 +555,6 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
UpdateTitle(); UpdateTitle();
wxFileName fn = Prj().AbsolutePath( GetScreen()->GetFileName() ); wxFileName fn = Prj().AbsolutePath( GetScreen()->GetFileName() );
m_infoBar->Dismiss();
if( fn.FileExists() && !fn.IsFileWritable() ) if( fn.FileExists() && !fn.IsFileWritable() )
{ {

View File

@ -1981,6 +1981,8 @@ void SCH_SEXPR_PARSER::ParseSchematic( SCH_SHEET* aSheet, bool aIsCopyableOnly,
parseHeader( T_kicad_sch, SEXPR_SCHEMATIC_FILE_VERSION ); parseHeader( T_kicad_sch, SEXPR_SCHEMATIC_FILE_VERSION );
} }
screen->SetFileFormatVersionAtLoad( m_requiredVersion );
for( token = NextTok(); token != T_RIGHT; token = NextTok() ) for( token = NextTok(); token != T_RIGHT; token = NextTok() )
{ {
if( aIsCopyableOnly && token == T_EOF ) if( aIsCopyableOnly && token == T_EOF )

View File

@ -54,9 +54,7 @@
#include <symbol_lib_table.h> #include <symbol_lib_table.h>
#include <tool/common_tools.h> #include <tool/common_tools.h>
#include <thread>
#include <algorithm> #include <algorithm>
#include <future>
// TODO(JE) Debugging only // TODO(JE) Debugging only
#include <profile.h> #include <profile.h>
@ -64,7 +62,8 @@
SCH_SCREEN::SCH_SCREEN( EDA_ITEM* aParent ) : SCH_SCREEN::SCH_SCREEN( EDA_ITEM* aParent ) :
BASE_SCREEN( aParent, SCH_SCREEN_T ), BASE_SCREEN( aParent, SCH_SCREEN_T ),
m_paper( wxT( "A4" ) ) m_paper( wxT( "A4" ) ),
m_fileFormatVersionAtLoad( 0 )
{ {
m_modification_sync = 0; m_modification_sync = 0;
m_refCount = 0; m_refCount = 0;

View File

@ -95,7 +95,7 @@ class SCH_SCREEN : public BASE_SCREEN
private: private:
wxString m_fileName; // File used to load the screen. wxString m_fileName; // File used to load the screen.
int m_fileFormatVersionAtLoad;
int m_refCount; // Number of sheets referencing this screen. int m_refCount; // Number of sheets referencing this screen.
// Delete when it goes to zero. // Delete when it goes to zero.
/** /**
@ -113,11 +113,11 @@ private:
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; EE_RTREE m_rtree;
int m_modification_sync; // inequality with PART_LIBS::GetModificationHash() will int m_modification_sync; // inequality with PART_LIBS::GetModificationHash()
// trigger ResolveAll(). // will trigger ResolveAll().
/// Set to true once the zoom value is initialized with `InitZoom()`. bool m_zoomInitialized; // Set to true once the zoom value is initialized with
bool m_zoomInitialized; // `InitZoom()`.
/// List of bus aliases stored in this screen. /// List of bus aliases stored in this screen.
std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases; std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases;
@ -181,6 +181,9 @@ public:
return wxT( "SCH_SCREEN" ); 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; } const PAGE_INFO& GetPageSettings() const { return m_paper; }
void SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; } void SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; }