From ea38056e33b15774a67bcacd28da9f74e178193d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 23 Jan 2022 17:23:17 +0000 Subject: [PATCH] Resolve textvars in plot directory. Fixes https://gitlab.com/kicad/code/kicad/issues/10405 (cherry picked from commit e5d5ee07f09e8206e3d11255dd0b603304088575) --- pcbnew/dialogs/dialog_export_svg.cpp | 17 +++++++-- pcbnew/dialogs/dialog_gendrill.cpp | 17 +++++++-- pcbnew/dialogs/dialog_plot.cpp | 23 ++++++++---- pcbnew/exporters/gen_footprints_placefile.cpp | 35 +++++++++++++++---- pcbnew/pcbplot.cpp | 19 +++++++--- 5 files changed, 88 insertions(+), 23 deletions(-) diff --git a/pcbnew/dialogs/dialog_export_svg.cpp b/pcbnew/dialogs/dialog_export_svg.cpp index 2480f6848e..5b4fdcaa11 100644 --- a/pcbnew/dialogs/dialog_export_svg.cpp +++ b/pcbnew/dialogs/dialog_export_svg.cpp @@ -251,9 +251,20 @@ void DIALOG_EXPORT_SVG::ExportSVGFile( bool aOnlyOneFile ) { m_outputDirectory = m_outputDirectoryName->GetValue(); - // Create output directory if it does not exist (also transform it in - // absolute form). Bail if it fails - wxString path = ExpandEnvVarSubstitutions( m_outputDirectory, &Prj() ); + // Create output directory if it does not exist (also transform it in absolute form). + // Bail if it fails. + + std::function 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 ); wxString boardFilename = m_board->GetFileName(); diff --git a/pcbnew/dialogs/dialog_gendrill.cpp b/pcbnew/dialogs/dialog_gendrill.cpp index 85c4871c44..f743a882e8 100644 --- a/pcbnew/dialogs/dialog_gendrill.cpp +++ b/pcbnew/dialogs/dialog_gendrill.cpp @@ -382,9 +382,20 @@ void DIALOG_GENDRILL::GenDrillAndMapFiles( bool aGenDrill, bool aGenMap ) if( choice >= arrayDim( filefmt ) ) choice = 1; - // Create output directory if it does not exist (also transform it in - // absolute form). Bail if it fails - wxString path = ExpandEnvVarSubstitutions( m_plotOpts.GetOutputDirectory(), &Prj() ); + // Create output directory if it does not exist (also transform it in absolute form). + // Bail if it fails. + + std::function 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 ); wxString boardFilename = m_board->GetFileName(); diff --git a/pcbnew/dialogs/dialog_plot.cpp b/pcbnew/dialogs/dialog_plot.cpp index b9c68c8fa5..ee6f3daed9 100644 --- a/pcbnew/dialogs/dialog_plot.cpp +++ b/pcbnew/dialogs/dialog_plot.cpp @@ -803,12 +803,23 @@ void DIALOG_PLOT::Plot( wxCommandEvent& event ) return; } - // Create output directory if it does not exist (also transform it in - // absolute form). Bail if it fails - wxString path = ExpandEnvVarSubstitutions( m_plotOpts.GetOutputDirectory(), &Prj() ); - wxFileName outputDir = wxFileName::DirName( path ); - wxString boardFilename = m_parent->GetBoard()->GetFileName(); - REPORTER& reporter = m_messagesPanel->Reporter(); + // Create output directory if it does not exist (also transform it in absolute form). + // Bail if it fails. + + std::function 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 ); + wxString boardFilename = m_parent->GetBoard()->GetFileName(); + REPORTER& reporter = m_messagesPanel->Reporter(); if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) ) { diff --git a/pcbnew/exporters/gen_footprints_placefile.cpp b/pcbnew/exporters/gen_footprints_placefile.cpp index 9739586e7a..76d8461312 100644 --- a/pcbnew/exporters/gen_footprints_placefile.cpp +++ b/pcbnew/exporters/gen_footprints_placefile.cpp @@ -271,9 +271,20 @@ bool DIALOG_GEN_FOOTPRINT_POSITION::CreateGerberFiles() wxString msg; int fullcount = 0; - // Create output directory if it does not exist. Also transform it in absolute path. - // Bail if it fails - wxString path = ExpandEnvVarSubstitutions( m_plotOpts.GetOutputDirectory(), &Prj() ); + // Create output directory if it does not exist (also transform it in absolute form). + // Bail if it fails. + + std::function 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 ); wxString boardFilename = m_parent->GetBoard()->GetFileName(); @@ -368,10 +379,20 @@ bool DIALOG_GEN_FOOTPRINT_POSITION::CreateAsciiFiles() } } - // Create output directory if it does not exist. - // Also transform it in absolute path. - // Bail if it fails - wxString path = ExpandEnvVarSubstitutions( m_plotOpts.GetOutputDirectory(), &Prj() ); + // Create output directory if it does not exist (also transform it in absolute form). + // Bail if it fails. + + std::function 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 ); wxString boardFilename = m_parent->GetBoard()->GetFileName(); diff --git a/pcbnew/pcbplot.cpp b/pcbnew/pcbplot.cpp index a377d60478..dc7345d02b 100644 --- a/pcbnew/pcbplot.cpp +++ b/pcbnew/pcbplot.cpp @@ -447,11 +447,22 @@ bool PLOT_CONTROLLER::OpenPlotfile( const wxString& aSuffix, PLOT_FORMAT aFormat // Ensure that the previous plot is closed ClosePlot(); - // Now compute the full filename for the output and start the plot - // (after ensuring the output directory is OK) - wxString outputDirName = GetPlotOptions().GetOutputDirectory() ; + // Now compute the full filename for the output and start the plot (after ensuring the + // output directory is OK). + + std::function 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 ); - wxString boardFilename = m_board->GetFileName(); + wxString boardFilename = m_board->GetFileName(); if( EnsureFileDirectoryExists( &outputDir, boardFilename ) ) {