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_edit_frame.h>
#include <sch_plugins/legacy/sch_legacy_plugin.h>
#include <sch_file_versions.h>
#include <sch_sheet.h>
#include <sch_sheet_path.h>
#include <schematic.h>
@ -291,6 +292,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& 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<wxString>& 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<wxString>& 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<wxString>& aFileSet, in
UpdateTitle();
wxFileName fn = Prj().AbsolutePath( GetScreen()->GetFileName() );
m_infoBar->Dismiss();
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 );
}
screen->SetFileFormatVersionAtLoad( m_requiredVersion );
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
{
if( aIsCopyableOnly && token == T_EOF )

View File

@ -54,9 +54,7 @@
#include <symbol_lib_table.h>
#include <tool/common_tools.h>
#include <thread>
#include <algorithm>
#include <future>
// TODO(JE) Debugging only
#include <profile.h>
@ -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;

View File

@ -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<SCH_SHEET_PATH> 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; }