From d51ac6534989edb8596a3b38da74aae478168e24 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 7 Jul 2021 21:52:55 +0100 Subject: [PATCH] Don't try to resolve variables before the schematic is set up. Fixes https://gitlab.com/kicad/code/kicad/issues/8746 --- eeschema/sch_sheet.cpp | 2 +- eeschema/schematic.cpp | 45 +++++++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 805bfc074f..979bc0c376 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -695,7 +695,7 @@ int SCH_SHEET::CountSheets() const if( m_screen ) { - for( auto aItem : m_screen->Items().OfType( SCH_SHEET_T ) ) + for( SCH_ITEM* aItem : m_screen->Items().OfType( SCH_SHEET_T ) ) count += static_cast( aItem )->CountSheets(); } diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index be7faea822..2bf790067a 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -122,29 +122,34 @@ SCH_SCREEN* SCHEMATIC::RootScreen() const bool SCHEMATIC::ResolveTextVar( wxString* token, int aDepth ) const { - if( token->IsSameAs( wxT( "#" ) ) ) + if( !CurrentSheet().empty() ) { - *token = CurrentSheet().GetPageNumber(); - return true; - } - else if( token->IsSameAs( wxT( "##" ) ) ) - { - *token = wxString::Format( "%i", Root().CountSheets() ); - return true; - } - else if( token->IsSameAs( wxT( "SHEETNAME" ) ) ) - { - *token = CurrentSheet().PathHumanReadable(); - return true; - } - else if( token->IsSameAs( wxT( "FILENAME" ) ) ) - { - wxFileName fn( GetFileName() ); - *token = fn.GetFullName(); - return true; + if( token->IsSameAs( wxT( "#" ) ) ) + { + *token = CurrentSheet().GetPageNumber(); + return true; + } + else if( token->IsSameAs( wxT( "##" ) ) ) + { + *token = wxString::Format( "%i", Root().CountSheets() ); + return true; + } + else if( token->IsSameAs( wxT( "SHEETNAME" ) ) ) + { + *token = CurrentSheet().PathHumanReadable(); + return true; + } + else if( token->IsSameAs( wxT( "FILENAME" ) ) ) + { + wxFileName fn( GetFileName() ); + *token = fn.GetFullName(); + return true; + } + + return CurrentSheet().LastScreen()->GetTitleBlock().TextVarResolver( token, m_project ); } - return CurrentSheet().LastScreen()->GetTitleBlock().TextVarResolver( token, m_project ); + return false; }