Eeschema: don't stat files when updating title bar text.

The tests for file existence and write status perform two file stats
which cause performance issues on slow network shares.  Now the file
state is determined at load time and stored in the SCH_SCREEN object
so file access is no longer required.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/9343
This commit is contained in:
Wayne Stambaugh 2021-10-14 09:12:40 -04:00
parent fb8ee1a9d3
commit c61af21da8
5 changed files with 33 additions and 5 deletions

View File

@ -1231,16 +1231,20 @@ void SCH_EDIT_FRAME::AddItemToScreenAndUndoList( SCH_SCREEN* aScreen, SCH_ITEM*
void SCH_EDIT_FRAME::UpdateTitle() void SCH_EDIT_FRAME::UpdateTitle()
{ {
SCH_SCREEN* screen = GetScreen();
wxCHECK( screen, /* void */ );
wxString title; wxString title;
if( !GetScreen()->GetFileName().IsEmpty() ) if( !screen->GetFileName().IsEmpty() )
{ {
wxFileName fn( Prj().AbsolutePath( GetScreen()->GetFileName() ) ); wxFileName fn( Prj().AbsolutePath( screen->GetFileName() ) );
bool readOnly = false; bool readOnly = false;
bool unsaved = false; bool unsaved = false;
if( fn.IsOk() && fn.FileExists() ) if( fn.IsOk() && screen->FileExists() )
readOnly = !fn.IsFileWritable(); readOnly = screen->IsReadOnly();
else else
unsaved = true; unsaved = true;

View File

@ -519,6 +519,9 @@ void SCH_SEXPR_PLUGIN::loadHierarchy( SCH_SHEET* aSheet )
m_error += ioe.What(); m_error += ioe.What();
} }
aSheet->GetScreen()->SetFileReadOnly( !fileName.IsFileWritable() );
aSheet->GetScreen()->SetFileExists( true );
// This was moved out of the try{} block so that any sheets definitionsthat // This was moved out of the try{} block so that any sheets definitionsthat
// the plugin fully parsed before the exception was raised will be loaded. // the plugin fully parsed before the exception was raised will be loaded.
for( SCH_ITEM* aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) ) for( SCH_ITEM* aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
@ -594,6 +597,8 @@ void SCH_SEXPR_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEM
m_out = &formatter; // no ownership m_out = &formatter; // no ownership
Format( aSheet ); Format( aSheet );
aSheet->GetScreen()->SetFileExists( true );
} }

View File

@ -744,6 +744,9 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet )
m_error += ioe.What(); m_error += ioe.What();
} }
aSheet->GetScreen()->SetFileReadOnly( !fileName.IsFileWritable() );
aSheet->GetScreen()->SetFileExists( true );
for( auto aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) ) for( auto aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
{ {
wxCHECK2( aItem->Type() == SCH_SHEET_T, continue ); wxCHECK2( aItem->Type() == SCH_SHEET_T, continue );
@ -1864,6 +1867,7 @@ std::shared_ptr<BUS_ALIAS> SCH_LEGACY_PLUGIN::loadBusAlias( LINE_READER& aReader
{ {
buf.clear(); buf.clear();
parseUnquotedString( buf, aReader, line, &line, true ); parseUnquotedString( buf, aReader, line, &line, true );
if( buf.Len() > 0 ) if( buf.Len() > 0 )
{ {
busAlias->AddMember( buf ); busAlias->AddMember( buf );
@ -1895,6 +1899,8 @@ void SCH_LEGACY_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHE
m_out = &formatter; // no ownership m_out = &formatter; // no ownership
Format( aSheet ); Format( aSheet );
aSheet->GetScreen()->SetFileExists( true );
} }

View File

@ -66,7 +66,9 @@
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_fileFormatVersionAtLoad( 0 ), m_fileFormatVersionAtLoad( 0 ),
m_paper( wxT( "A4" ) ) m_paper( wxT( "A4" ) ),
m_isReadOnly( false ),
m_fileExists( false )
{ {
m_modification_sync = 0; m_modification_sync = 0;
m_refCount = 0; m_refCount = 0;

View File

@ -144,6 +144,12 @@ public:
const wxString& GetFileName() const { return m_fileName; } const wxString& GetFileName() const { return m_fileName; }
void SetFileReadOnly( bool aIsReadOnly ) { m_isReadOnly = aIsReadOnly; }
bool IsReadOnly() const { return m_isReadOnly; }
void SetFileExists( bool aFileExists ) { m_fileExists = aFileExists; }
bool FileExists() const { return m_fileExists; }
const wxPoint& GetAuxOrigin() const { return m_aux_origin; } const wxPoint& GetAuxOrigin() const { return m_aux_origin; }
void SetAuxOrigin( const wxPoint& aPosition ) { m_aux_origin = aPosition; } void SetAuxOrigin( const wxPoint& aPosition ) { m_aux_origin = aPosition; }
@ -512,6 +518,11 @@ private:
bool m_zoomInitialized; // Set to true once the zoom value is initialized with bool m_zoomInitialized; // Set to true once the zoom value is initialized with
// `InitZoom()`. // `InitZoom()`.
bool m_isReadOnly; ///< Read only status of the screen file.
///< Flag to indicate the file associated with this screen has been created.
bool m_fileExists;
/// 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;