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

(cherry picked from commit c44d31fcfb)
This commit is contained in:
Seth Hillbrand 2022-03-18 16:44:48 -07:00
parent 7b82c2ba85
commit 3b6e8464c2
2 changed files with 36 additions and 11 deletions

View File

@ -94,9 +94,14 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c
if( aToken->IsSameAs( wxT( "ISSUE_DATE" ) ) )
{
*aToken = GetDate();
wxString ret = GetDate();
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true;
}
}
else if( aToken->IsSameAs( wxT( "CURRENT_DATE" ) ) )
{
// We can choose different formats. Should probably be kept in sync with ISSUE_DATE
@ -111,19 +116,34 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c
}
else if( aToken->IsSameAs( wxT( "REVISION" ) ) )
{
*aToken = GetRevision();
wxString ret = GetRevision();
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true;
}
}
else if( aToken->IsSameAs( wxT( "TITLE" ) ) )
{
*aToken = GetTitle();
wxString ret = GetTitle();
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true;
}
}
else if( aToken->IsSameAs( wxT( "COMPANY" ) ) )
{
*aToken = GetCompany();
wxString ret = GetCompany();
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true;
}
}
else if( aToken->Left( aToken->Len() - 1 ).IsSameAs( wxT( "COMMENT" ) ) )
{
wxChar c = aToken->Last();
@ -139,10 +159,15 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c
case '7':
case '8':
case '9':
*aToken = GetComment( c - '1' );
wxString ret = GetComment( c - '1' );
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true;
}
}
}
if( tokenUpdated )
{

View File

@ -806,7 +806,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 );