Fix gerbers and drill plot not logging errors

Partial fix for https://gitlab.com/kicad/code/kicad/-/issues/14437
This commit is contained in:
Marek Roszko 2023-04-20 23:28:32 -04:00
parent 9f64c7f354
commit dbed94e4b1
8 changed files with 65 additions and 16 deletions

View File

@ -73,9 +73,10 @@ EXCELLON_WRITER::EXCELLON_WRITER( BOARD* aPcb )
} }
void EXCELLON_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory, bool aGenDrill, bool EXCELLON_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory, bool aGenDrill,
bool aGenMap, REPORTER * aReporter ) bool aGenMap, REPORTER * aReporter )
{ {
bool success = true;
wxFileName fn; wxFileName fn;
wxString msg; wxString msg;
@ -116,6 +117,7 @@ void EXCELLON_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory,
{ {
msg.Printf( _( "Failed to create file '%s'." ), fullFilename ); msg.Printf( _( "Failed to create file '%s'." ), fullFilename );
aReporter->Report( msg, RPT_SEVERITY_ERROR ); aReporter->Report( msg, RPT_SEVERITY_ERROR );
success = false;
} }
break; break;
@ -147,10 +149,12 @@ void EXCELLON_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory,
} }
if( aGenMap ) if( aGenMap )
CreateMapFilesSet( aPlotDirectory, aReporter ); success &= CreateMapFilesSet( aPlotDirectory, aReporter );
if( aReporter ) if( aReporter )
aReporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO ); aReporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO );
return success;
} }

View File

@ -105,7 +105,7 @@ public:
* @param aGenMap set to true to generate a drill map file. * @param aGenMap set to true to generate a drill map file.
* @param aReporter is a #REPORTER to return activity or any message (can be NULL) * @param aReporter is a #REPORTER to return activity or any message (can be NULL)
*/ */
void CreateDrillandMapFilesSet( const wxString& aPlotDirectory, bool aGenDrill, bool aGenMap, bool CreateDrillandMapFilesSet( const wxString& aPlotDirectory, bool aGenDrill, bool aGenMap,
REPORTER* aReporter = nullptr ); REPORTER* aReporter = nullptr );
private: private:

View File

@ -297,7 +297,7 @@ const wxString GENDRILL_WRITER_BASE::getDrillFileName( DRILL_LAYER_PAIR aPair, b
return ret; return ret;
} }
void GENDRILL_WRITER_BASE::CreateMapFilesSet( const wxString& aPlotDirectory, bool GENDRILL_WRITER_BASE::CreateMapFilesSet( const wxString& aPlotDirectory,
REPORTER * aReporter ) REPORTER * aReporter )
{ {
wxFileName fn; wxFileName fn;
@ -341,7 +341,7 @@ void GENDRILL_WRITER_BASE::CreateMapFilesSet( const wxString& aPlotDirectory,
aReporter->Report( msg, RPT_SEVERITY_ERROR ); aReporter->Report( msg, RPT_SEVERITY_ERROR );
} }
return; return false;
} }
else else
{ {
@ -353,6 +353,8 @@ void GENDRILL_WRITER_BASE::CreateMapFilesSet( const wxString& aPlotDirectory,
} }
} }
} }
return true;
} }

View File

@ -212,7 +212,7 @@ public:
* @param aPlotDirectory is the output folder. * @param aPlotDirectory is the output folder.
* @param aReporter is a REPORTER to return activity or any message (can be NULL) * @param aReporter is a REPORTER to return activity or any message (can be NULL)
*/ */
void CreateMapFilesSet( const wxString& aPlotDirectory, REPORTER* aReporter = nullptr ); bool CreateMapFilesSet( const wxString& aPlotDirectory, REPORTER* aReporter = nullptr );
/** /**
* Create a plain text report file giving a list of drill values and drill count for through * Create a plain text report file giving a list of drill values and drill count for through

View File

@ -54,9 +54,10 @@ GERBER_WRITER::GERBER_WRITER( BOARD* aPcb )
} }
void GERBER_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory, bool aGenDrill, bool GERBER_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory, bool aGenDrill,
bool aGenMap, REPORTER* aReporter ) bool aGenMap, REPORTER* aReporter )
{ {
bool success = true;
// Note: In Gerber drill files, NPTH and PTH are always separate files // Note: In Gerber drill files, NPTH and PTH are always separate files
m_merge_PTH_NPTH = false; m_merge_PTH_NPTH = false;
@ -100,6 +101,7 @@ void GERBER_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory, b
{ {
msg.Printf( _( "Failed to create file '%s'." ), fullFilename ); msg.Printf( _( "Failed to create file '%s'." ), fullFilename );
aReporter->Report( msg, RPT_SEVERITY_ERROR ); aReporter->Report( msg, RPT_SEVERITY_ERROR );
success = false;
} }
break; break;
@ -118,10 +120,12 @@ void GERBER_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory, b
} }
if( aGenMap ) if( aGenMap )
CreateMapFilesSet( aPlotDirectory, aReporter ); success &= CreateMapFilesSet( aPlotDirectory, aReporter );
if( aReporter ) if( aReporter )
aReporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO ); aReporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO );
return success;
} }

View File

@ -74,8 +74,10 @@ public:
* @param aGenDrill set to true to generate the EXCELLON drill file. * @param aGenDrill set to true to generate the EXCELLON drill file.
* @param aGenMap set to true to generate a drill map file. * @param aGenMap set to true to generate a drill map file.
* @param aReporter is a #REPORTER to return activity or any message (can be NULL). * @param aReporter is a #REPORTER to return activity or any message (can be NULL).
*
* @return True if successful, false if any error occurred
*/ */
void CreateDrillandMapFilesSet( const wxString& aPlotDirectory, bool CreateDrillandMapFilesSet( const wxString& aPlotDirectory,
bool aGenDrill, bool aGenMap, bool aGenDrill, bool aGenMap,
REPORTER * aReporter = nullptr ); REPORTER * aReporter = nullptr );

View File

@ -259,6 +259,7 @@ int PCBNEW_JOBS_HANDLER::JobExportPdf( JOB* aJob )
int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob ) int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob )
{ {
int exitCode = CLI::EXIT_CODES::OK;
JOB_EXPORT_PCB_GERBERS* aGerberJob = dynamic_cast<JOB_EXPORT_PCB_GERBERS*>( aJob ); JOB_EXPORT_PCB_GERBERS* aGerberJob = dynamic_cast<JOB_EXPORT_PCB_GERBERS*>( aJob );
if( aGerberJob == nullptr ) if( aGerberJob == nullptr )
@ -333,6 +334,11 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob )
PlotBoardLayers( brd, plotter, plotSequence, plotOpts ); PlotBoardLayers( brd, plotter, plotSequence, plotOpts );
plotter->EndPlot(); plotter->EndPlot();
} }
else
{
wxFprintf( stderr, _( "Failed to plot to '%s'.\n" ), fn.GetFullPath() );
exitCode = CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
}
delete plotter; delete plotter;
} }
@ -342,7 +348,7 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob )
BuildPlotFileName( &fn, aGerberJob->m_outputFile, wxT( "job" ), GerberJobFileExtension ); BuildPlotFileName( &fn, aGerberJob->m_outputFile, wxT( "job" ), GerberJobFileExtension );
jobfile_writer.CreateJobFile( fn.GetFullPath() ); jobfile_writer.CreateJobFile( fn.GetFullPath() );
return CLI::EXIT_CODES::OK; return exitCode;
} }
@ -371,6 +377,7 @@ void PCBNEW_JOBS_HANDLER::populateGerberPlotOptionsFromJob( PCB_PLOT_PARAMS&
int PCBNEW_JOBS_HANDLER::JobExportGerber( JOB* aJob ) int PCBNEW_JOBS_HANDLER::JobExportGerber( JOB* aJob )
{ {
int exitCode = CLI::EXIT_CODES::OK;
JOB_EXPORT_PCB_GERBER* aGerberJob = dynamic_cast<JOB_EXPORT_PCB_GERBER*>( aJob ); JOB_EXPORT_PCB_GERBER* aGerberJob = dynamic_cast<JOB_EXPORT_PCB_GERBER*>( aJob );
if( aGerberJob == nullptr ) if( aGerberJob == nullptr )
@ -405,10 +412,15 @@ int PCBNEW_JOBS_HANDLER::JobExportGerber( JOB* aJob )
plotOpts ); plotOpts );
plotter->EndPlot(); plotter->EndPlot();
} }
else
{
wxFprintf( stderr, _( "Failed to plot to '%s'.\n" ), aGerberJob->m_outputFile );
exitCode = CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
}
delete plotter; delete plotter;
return CLI::EXIT_CODES::OK; return exitCode;
} }
static DRILL_PRECISION precisionListForInches( 2, 4 ); static DRILL_PRECISION precisionListForInches( 2, 4 );
@ -498,8 +510,11 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
excellonWriter->SetRouteModeForOvalHoles( aDrillJob->m_excellonOvalDrillRoute ); excellonWriter->SetRouteModeForOvalHoles( aDrillJob->m_excellonOvalDrillRoute );
excellonWriter->SetMapFileFormat( mapFormat ); excellonWriter->SetMapFileFormat( mapFormat );
excellonWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true, if( !excellonWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true,
aDrillJob->m_generateMap, nullptr ); aDrillJob->m_generateMap, this ) )
{
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
}
} }
else if( aDrillJob->m_format == JOB_EXPORT_PCB_DRILL::DRILL_FORMAT::GERBER ) else if( aDrillJob->m_format == JOB_EXPORT_PCB_DRILL::DRILL_FORMAT::GERBER )
{ {
@ -515,8 +530,11 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
gerberWriter->SetOptions( offset ); gerberWriter->SetOptions( offset );
gerberWriter->SetMapFileFormat( mapFormat ); gerberWriter->SetMapFileFormat( mapFormat );
gerberWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true, if( !gerberWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true,
aDrillJob->m_generateMap, nullptr ); aDrillJob->m_generateMap, this ) )
{
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
}
} }
return CLI::EXIT_CODES::OK; return CLI::EXIT_CODES::OK;
@ -783,3 +801,14 @@ int PCBNEW_JOBS_HANDLER::doFpExportSvg( JOB_FP_EXPORT_SVG* aSvgJob, const FOOTPR
return CLI::EXIT_CODES::OK; return CLI::EXIT_CODES::OK;
} }
REPORTER& PCBNEW_JOBS_HANDLER::Report( const wxString& aText, SEVERITY aSeverity )
{
if( aSeverity == RPT_SEVERITY_ERROR )
wxFprintf( stderr, wxS( "%s\n" ), aText );
else
wxPrintf( wxS( "%s\n" ), aText );
return *this;
}

View File

@ -23,12 +23,13 @@
#include <jobs/job_dispatcher.h> #include <jobs/job_dispatcher.h>
#include <pcb_plot_params.h> #include <pcb_plot_params.h>
#include <reporter.h>
class JOB_EXPORT_PCB_GERBER; class JOB_EXPORT_PCB_GERBER;
class JOB_FP_EXPORT_SVG; class JOB_FP_EXPORT_SVG;
class FOOTPRINT; class FOOTPRINT;
class PCBNEW_JOBS_HANDLER : public JOB_DISPATCHER class PCBNEW_JOBS_HANDLER : public JOB_DISPATCHER, REPORTER
{ {
public: public:
PCBNEW_JOBS_HANDLER(); PCBNEW_JOBS_HANDLER();
@ -43,6 +44,13 @@ public:
int JobExportFpUpgrade( JOB* aJob ); int JobExportFpUpgrade( JOB* aJob );
int JobExportFpSvg( JOB* aJob ); int JobExportFpSvg( JOB* aJob );
/*
* REPORTER INTERFACE
*/
REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
bool HasMessage() const override { return false; }
private: private:
void populateGerberPlotOptionsFromJob( PCB_PLOT_PARAMS& aPlotOpts, void populateGerberPlotOptionsFromJob( PCB_PLOT_PARAMS& aPlotOpts,
JOB_EXPORT_PCB_GERBER* aJob ); JOB_EXPORT_PCB_GERBER* aJob );