From c44d31fcfbd9b28cfa5778c428872e0f970908ca Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 18 Mar 2022 16:44:48 -0700 Subject: [PATCH] Fix expand variables for built-in Allow falling back to the alternate variable definitions if the built-in text block variables are not set. Also push the project into variable resolution when plotting Fixes https://gitlab.com/kicad/code/kicad/issues/11168 --- common/title_block.cpp | 45 ++++++++++++++++++++++++++-------- pcbnew/dialogs/dialog_plot.cpp | 2 +- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/common/title_block.cpp b/common/title_block.cpp index 461872ef54..d48dcd6585 100644 --- a/common/title_block.cpp +++ b/common/title_block.cpp @@ -94,8 +94,13 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c if( aToken->IsSameAs( wxT( "ISSUE_DATE" ) ) ) { - *aToken = GetDate(); - tokenUpdated = true; + wxString ret = GetDate(); + + if( !ret.empty() ) + { + *aToken = ret; + tokenUpdated = true; + } } else if( aToken->IsSameAs( wxT( "CURRENT_DATE" ) ) ) { @@ -111,18 +116,33 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c } else if( aToken->IsSameAs( wxT( "REVISION" ) ) ) { - *aToken = GetRevision(); - tokenUpdated = true; + wxString ret = GetRevision(); + + if( !ret.empty() ) + { + *aToken = ret; + tokenUpdated = true; + } } else if( aToken->IsSameAs( wxT( "TITLE" ) ) ) { - *aToken = GetTitle(); - tokenUpdated = true; + wxString ret = GetTitle(); + + if( !ret.empty() ) + { + *aToken = ret; + tokenUpdated = true; + } } else if( aToken->IsSameAs( wxT( "COMPANY" ) ) ) { - *aToken = GetCompany(); - tokenUpdated = true; + wxString ret = GetCompany(); + + if( !ret.empty() ) + { + *aToken = ret; + tokenUpdated = true; + } } else if( aToken->Left( aToken->Len() - 1 ).IsSameAs( wxT( "COMMENT" ) ) ) { @@ -139,8 +159,13 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c case '7': case '8': case '9': - *aToken = GetComment( c - '1' ); - tokenUpdated = true; + wxString ret = GetComment( c - '1' ); + + if( !ret.empty() ) + { + *aToken = ret; + tokenUpdated = true; + } } } diff --git a/pcbnew/dialogs/dialog_plot.cpp b/pcbnew/dialogs/dialog_plot.cpp index 8b637783f6..c4cff87f53 100644 --- a/pcbnew/dialogs/dialog_plot.cpp +++ b/pcbnew/dialogs/dialog_plot.cpp @@ -814,7 +814,7 @@ void DIALOG_PLOT::Plot( wxCommandEvent& event ) }; wxString path = m_plotOpts.GetOutputDirectory(); - path = ExpandTextVars( path, &textResolver, nullptr, nullptr ); + path = ExpandTextVars( path, &textResolver, nullptr, board->GetProject() ); path = ExpandEnvVarSubstitutions( path, nullptr ); wxFileName outputDir = wxFileName::DirName( path );