diff --git a/pcbnew/dialogs/dialog_export_svg.cpp b/pcbnew/dialogs/dialog_export_svg.cpp index e3a7cdc079..48600f5209 100644 --- a/pcbnew/dialogs/dialog_export_svg.cpp +++ b/pcbnew/dialogs/dialog_export_svg.cpp @@ -248,9 +248,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 7ccbb06d73..bedfa6883f 100644 --- a/pcbnew/dialogs/dialog_gendrill.cpp +++ b/pcbnew/dialogs/dialog_gendrill.cpp @@ -380,9 +380,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 e00e14325f..d9ce106471 100644 --- a/pcbnew/dialogs/dialog_plot.cpp +++ b/pcbnew/dialogs/dialog_plot.cpp @@ -796,12 +796,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 1ec1f9a420..41818b9021 100644 --- a/pcbnew/exporters/gen_footprints_placefile.cpp +++ b/pcbnew/exporters/gen_footprints_placefile.cpp @@ -266,9 +266,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(); @@ -363,10 +374,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 f466a5865f..267b8553df 100644 --- a/pcbnew/pcbplot.cpp +++ b/pcbnew/pcbplot.cpp @@ -437,10 +437,21 @@ bool PLOT_CONTROLLER::OpenPlotfile( const wxString& aSuffix, PLOT_FORMAT aFormat ClosePlot(); // Now compute the full filename for the output and start the plot (after ensuring the - // output directory is OK) - wxString outputDirName = GetPlotOptions().GetOutputDirectory() ; + // 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 ) ) {