Resolve textvars in plot directory.

Fixes https://gitlab.com/kicad/code/kicad/issues/10405

(cherry picked from commit e5d5ee07f0)
This commit is contained in:
Jeff Young 2022-01-23 17:23:17 +00:00
parent c805144c08
commit ea38056e33
5 changed files with 88 additions and 23 deletions

View File

@ -251,9 +251,20 @@ void DIALOG_EXPORT_SVG::ExportSVGFile( bool aOnlyOneFile )
{ {
m_outputDirectory = m_outputDirectoryName->GetValue(); m_outputDirectory = m_outputDirectoryName->GetValue();
// Create output directory if it does not exist (also transform it in // Create output directory if it does not exist (also transform it in absolute form).
// absolute form). Bail if it fails // Bail if it fails.
wxString path = ExpandEnvVarSubstitutions( m_outputDirectory, &Prj() );
std::function<bool( wxString* )> textResolver =
[&]( wxString* token ) -> bool
{
// Handles m_board->GetTitleBlock() *and* m_board->GetProject()
return m_board->ResolveTextVar( token, 0 );
};
wxString path = m_outputDirectory;
path = ExpandTextVars( path, &textResolver, nullptr, nullptr );
path = ExpandEnvVarSubstitutions( path, nullptr );
wxFileName outputDir = wxFileName::DirName( path ); wxFileName outputDir = wxFileName::DirName( path );
wxString boardFilename = m_board->GetFileName(); wxString boardFilename = m_board->GetFileName();

View File

@ -382,9 +382,20 @@ void DIALOG_GENDRILL::GenDrillAndMapFiles( bool aGenDrill, bool aGenMap )
if( choice >= arrayDim( filefmt ) ) if( choice >= arrayDim( filefmt ) )
choice = 1; choice = 1;
// Create output directory if it does not exist (also transform it in // Create output directory if it does not exist (also transform it in absolute form).
// absolute form). Bail if it fails // Bail if it fails.
wxString path = ExpandEnvVarSubstitutions( m_plotOpts.GetOutputDirectory(), &Prj() );
std::function<bool( wxString* )> textResolver =
[&]( wxString* token ) -> bool
{
// Handles m_board->GetTitleBlock() *and* m_board->GetProject()
return m_board->ResolveTextVar( token, 0 );
};
wxString path = m_plotOpts.GetOutputDirectory();
path = ExpandTextVars( path, &textResolver, nullptr, nullptr );
path = ExpandEnvVarSubstitutions( path, nullptr );
wxFileName outputDir = wxFileName::DirName( path ); wxFileName outputDir = wxFileName::DirName( path );
wxString boardFilename = m_board->GetFileName(); wxString boardFilename = m_board->GetFileName();

View File

@ -803,12 +803,23 @@ void DIALOG_PLOT::Plot( wxCommandEvent& event )
return; return;
} }
// Create output directory if it does not exist (also transform it in // Create output directory if it does not exist (also transform it in absolute form).
// absolute form). Bail if it fails // Bail if it fails.
wxString path = ExpandEnvVarSubstitutions( m_plotOpts.GetOutputDirectory(), &Prj() );
wxFileName outputDir = wxFileName::DirName( path ); std::function<bool( wxString* )> textResolver =
wxString boardFilename = m_parent->GetBoard()->GetFileName(); [&]( wxString* token ) -> bool
REPORTER& reporter = m_messagesPanel->Reporter(); {
// Handles board->GetTitleBlock() *and* board->GetProject()
return m_parent->GetBoard()->ResolveTextVar( token, 0 );
};
wxString path = m_plotOpts.GetOutputDirectory();
path = ExpandTextVars( path, &textResolver, nullptr, nullptr );
path = ExpandEnvVarSubstitutions( path, nullptr );
wxFileName outputDir = wxFileName::DirName( path );
wxString boardFilename = m_parent->GetBoard()->GetFileName();
REPORTER& reporter = m_messagesPanel->Reporter();
if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) ) if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
{ {

View File

@ -271,9 +271,20 @@ bool DIALOG_GEN_FOOTPRINT_POSITION::CreateGerberFiles()
wxString msg; wxString msg;
int fullcount = 0; int fullcount = 0;
// Create output directory if it does not exist. Also transform it in absolute path. // Create output directory if it does not exist (also transform it in absolute form).
// Bail if it fails // Bail if it fails.
wxString path = ExpandEnvVarSubstitutions( m_plotOpts.GetOutputDirectory(), &Prj() );
std::function<bool( wxString* )> textResolver =
[&]( wxString* token ) -> bool
{
// Handles board->GetTitleBlock() *and* board->GetProject()
return m_parent->GetBoard()->ResolveTextVar( token, 0 );
};
wxString path = m_plotOpts.GetOutputDirectory();
path = ExpandTextVars( path, &textResolver, nullptr, nullptr );
path = ExpandEnvVarSubstitutions( path, nullptr );
wxFileName outputDir = wxFileName::DirName( path ); wxFileName outputDir = wxFileName::DirName( path );
wxString boardFilename = m_parent->GetBoard()->GetFileName(); wxString boardFilename = m_parent->GetBoard()->GetFileName();
@ -368,10 +379,20 @@ bool DIALOG_GEN_FOOTPRINT_POSITION::CreateAsciiFiles()
} }
} }
// Create output directory if it does not exist. // Create output directory if it does not exist (also transform it in absolute form).
// Also transform it in absolute path. // Bail if it fails.
// Bail if it fails
wxString path = ExpandEnvVarSubstitutions( m_plotOpts.GetOutputDirectory(), &Prj() ); std::function<bool( wxString* )> textResolver =
[&]( wxString* token ) -> bool
{
// Handles board->GetTitleBlock() *and* board->GetProject()
return m_parent->GetBoard()->ResolveTextVar( token, 0 );
};
wxString path = m_plotOpts.GetOutputDirectory();
path = ExpandTextVars( path, &textResolver, nullptr, nullptr );
path = ExpandEnvVarSubstitutions( path, nullptr );
wxFileName outputDir = wxFileName::DirName( path ); wxFileName outputDir = wxFileName::DirName( path );
wxString boardFilename = m_parent->GetBoard()->GetFileName(); wxString boardFilename = m_parent->GetBoard()->GetFileName();

View File

@ -447,11 +447,22 @@ bool PLOT_CONTROLLER::OpenPlotfile( const wxString& aSuffix, PLOT_FORMAT aFormat
// Ensure that the previous plot is closed // Ensure that the previous plot is closed
ClosePlot(); ClosePlot();
// Now compute the full filename for the output and start the plot // Now compute the full filename for the output and start the plot (after ensuring the
// (after ensuring the output directory is OK) // output directory is OK).
wxString outputDirName = GetPlotOptions().GetOutputDirectory() ;
std::function<bool( wxString* )> textResolver =
[&]( wxString* token ) -> bool
{
// Handles m_board->GetTitleBlock() *and* m_board->GetProject()
return m_board->ResolveTextVar( token, 0 );
};
wxString outputDirName = GetPlotOptions().GetOutputDirectory();
outputDirName = ExpandTextVars( outputDirName, &textResolver, nullptr, nullptr );
outputDirName = ExpandEnvVarSubstitutions( outputDirName, nullptr );
wxFileName outputDir = wxFileName::DirName( outputDirName ); wxFileName outputDir = wxFileName::DirName( outputDirName );
wxString boardFilename = m_board->GetFileName(); wxString boardFilename = m_board->GetFileName();
if( EnsureFileDirectoryExists( &outputDir, boardFilename ) ) if( EnsureFileDirectoryExists( &outputDir, boardFilename ) )
{ {