Use external REPORTER for EESCHEMA_JOBS_HANDLER / PCB_JOBS_HANDLER

This commit is contained in:
Roberto Fernandez Bautista 2023-03-24 11:31:08 +01:00
parent fcb156c323
commit 3f758711fd
10 changed files with 170 additions and 104 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com> * Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
@ -20,6 +20,15 @@
#include <cli/exit_codes.h> #include <cli/exit_codes.h>
#include <jobs/job_dispatcher.h> #include <jobs/job_dispatcher.h>
#include <reporter.h>
#include <wx/debug.h>
JOB_DISPATCHER::JOB_DISPATCHER()
{
m_reporter = &NULL_REPORTER::GetInstance();
}
void JOB_DISPATCHER::Register( const std::string& aJobTypeName, void JOB_DISPATCHER::Register( const std::string& aJobTypeName,
std::function<int( JOB* job )> aHandler ) std::function<int( JOB* job )> aHandler )
@ -27,6 +36,7 @@ void JOB_DISPATCHER::Register( const std::string& aJobTypeName,
m_jobHandlers.emplace( aJobTypeName, aHandler ); m_jobHandlers.emplace( aJobTypeName, aHandler );
} }
int JOB_DISPATCHER::RunJob( JOB* job ) int JOB_DISPATCHER::RunJob( JOB* job )
{ {
if( m_jobHandlers.count( job->GetType() ) ) if( m_jobHandlers.count( job->GetType() ) )
@ -35,4 +45,11 @@ int JOB_DISPATCHER::RunJob( JOB* job )
} }
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
} }
void JOB_DISPATCHER::SetReporter( REPORTER* aReporter )
{
wxCHECK( aReporter != nullptr, /*void*/ );
m_reporter = aReporter;
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com> * Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
@ -26,14 +26,23 @@
#include <map> #include <map>
#include <jobs/job.h> #include <jobs/job.h>
class REPORTER;
class JOB_DISPATCHER class JOB_DISPATCHER
{ {
public: public:
JOB_DISPATCHER();
void Register( const std::string& aJobTypeName, std::function<int( JOB* job )> aHandler ); void Register( const std::string& aJobTypeName, std::function<int( JOB* job )> aHandler );
int RunJob( JOB* job ); int RunJob( JOB* job );
void SetReporter( REPORTER* aReporter );
protected:
REPORTER* m_reporter; // non-owning
private: private:
std::map<std::string, std::function<int( JOB* job )>> m_jobHandlers; std::map<std::string, std::function<int( JOB* job )>> m_jobHandlers;
}; };
#endif #endif

View File

@ -29,6 +29,7 @@
#include <reporter.h> #include <reporter.h>
#include <widgets/wx_infobar.h> #include <widgets/wx_infobar.h>
#include <widgets/wx_html_report_panel.h> #include <widgets/wx_html_report_panel.h>
#include <wx/crt.h>
#include <wx/log.h> #include <wx/log.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/statusbr.h> #include <wx/statusbr.h>
@ -125,6 +126,30 @@ REPORTER& NULL_REPORTER::GetInstance()
} }
REPORTER& CLI_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
{
FILE* target = stdout;
if( aSeverity == RPT_SEVERITY_ERROR )
target = stderr;
if( aMsg.EndsWith( wxS( "\n" ) ) )
wxFprintf( target, aMsg );
else
wxFprintf( target, aMsg + wxS( "\n" ) );
return *this;
}
REPORTER& CLI_REPORTER::GetInstance()
{
static CLI_REPORTER s_cliReporter;
return s_cliReporter;
}
REPORTER& STDOUT_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity ) REPORTER& STDOUT_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
{ {
switch( aSeverity ) switch( aSeverity )

View File

@ -349,6 +349,9 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
m_jobHandler = std::make_unique<EESCHEMA_JOBS_HANDLER>(); m_jobHandler = std::make_unique<EESCHEMA_JOBS_HANDLER>();
if( m_start_flags & KFCTL_CLI )
m_jobHandler->SetReporter( &CLI_REPORTER::GetInstance() );
return true; return true;
} }

View File

@ -29,7 +29,6 @@
#include <jobs/job_sym_export_svg.h> #include <jobs/job_sym_export_svg.h>
#include <jobs/job_sym_upgrade.h> #include <jobs/job_sym_upgrade.h>
#include <schematic.h> #include <schematic.h>
#include <wx/crt.h>
#include <wx/dir.h> #include <wx/dir.h>
#include <wx/file.h> #include <wx/file.h>
#include <memory> #include <memory>
@ -96,18 +95,7 @@ void EESCHEMA_JOBS_HANDLER::InitRenderSettings( KIGFX::SCH_RENDER_SETTINGS* aRen
aSch->Prj().GetProjectPath() ); aSch->Prj().GetProjectPath() );
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) ) if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
wxFprintf( stderr, _( "Error loading drawing sheet." ) ); m_reporter->Report( _( "Error loading drawing sheet." ), RPT_SEVERITY_ERROR );
}
REPORTER& EESCHEMA_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;
} }
@ -122,7 +110,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPlot( JOB* aJob )
if( sch == nullptr ) if( sch == nullptr )
{ {
wxFprintf( stderr, _( "Failed to load schematic file\n" ) ); m_reporter->Report( _( "Failed to load schematic file\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE; return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE;
} }
@ -131,7 +119,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPlot( JOB* aJob )
InitRenderSettings( renderSettings.get(), aPlotJob->settings.m_theme, sch ); InitRenderSettings( renderSettings.get(), aPlotJob->settings.m_theme, sch );
std::unique_ptr<SCH_PLOTTER> schPlotter = std::make_unique<SCH_PLOTTER>( sch ); std::unique_ptr<SCH_PLOTTER> schPlotter = std::make_unique<SCH_PLOTTER>( sch );
schPlotter->Plot( aPlotJob->m_plotFormat, aPlotJob->settings, renderSettings.get(), this ); schPlotter->Plot( aPlotJob->m_plotFormat, aPlotJob->settings, renderSettings.get(), m_reporter );
return CLI::EXIT_CODES::OK; return CLI::EXIT_CODES::OK;
} }
@ -148,7 +136,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob )
if( sch == nullptr ) if( sch == nullptr )
{ {
wxFprintf( stderr, _( "Failed to load schematic file\n" ) ); m_reporter->Report( _( "Failed to load schematic file\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE; return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE;
} }
@ -165,7 +153,9 @@ int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob )
} ) } )
> 0 ) > 0 )
{ {
wxPrintf( _( "Warning: schematic has annotation errors, please use the schematic editor to fix them\n" ) ); m_reporter->Report( _( "Warning: schematic has annotation errors, please use the "
"schematic editor to fix them\n" ),
RPT_SEVERITY_WARNING );
} }
} }
@ -174,7 +164,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob )
if( erc.TestDuplicateSheetNames( false ) > 0 ) if( erc.TestDuplicateSheetNames( false ) > 0 )
{ {
wxPrintf( _( "Warning: duplicate sheet names.\n" ) ); m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
} }
@ -216,7 +206,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob )
helper = std::make_unique<NETLIST_EXPORTER_XML>( sch ); helper = std::make_unique<NETLIST_EXPORTER_XML>( sch );
break; break;
default: default:
wxFprintf( stderr, _( "Unknown netlist format.\n" ) ); m_reporter->Report( _( "Unknown netlist format.\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
} }
@ -230,7 +220,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob )
aNetJob->m_outputFile = fn.GetFullName(); aNetJob->m_outputFile = fn.GetFullName();
} }
bool res = helper->WriteNetlist( aNetJob->m_outputFile, netlistOption, *this ); bool res = helper->WriteNetlist( aNetJob->m_outputFile, netlistOption, *m_reporter );
if(!res) if(!res)
{ {
@ -252,7 +242,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob )
if( sch == nullptr ) if( sch == nullptr )
{ {
wxFprintf( stderr, _( "Failed to load schematic file\n" ) ); m_reporter->Report( _( "Failed to load schematic file\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE; return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE;
} }
@ -272,8 +262,10 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob )
} ) } )
> 0 ) > 0 )
{ {
wxPrintf( _( "Warning: schematic has annotation errors, please use the schematic " m_reporter->Report(
"editor to fix them\n" ) ); _( "Warning: schematic has annotation errors, please use the schematic "
"editor to fix them\n" ),
RPT_SEVERITY_WARNING );
} }
} }
@ -282,7 +274,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob )
if( erc.TestDuplicateSheetNames( false ) > 0 ) if( erc.TestDuplicateSheetNames( false ) > 0 )
{ {
wxPrintf( _( "Warning: duplicate sheet names.\n" ) ); m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
} }
@ -358,7 +350,11 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob )
wxFile f; wxFile f;
if( !f.Open( aBomJob->m_outputFile, wxFile::write ) ) if( !f.Open( aBomJob->m_outputFile, wxFile::write ) )
{ {
wxFprintf( stderr, _( "Unable to open destination '%s'" ), aBomJob->m_outputFile ); m_reporter->Report(
wxString::Format( _( "Unable to open destination '%s'" ), aBomJob->m_outputFile ),
RPT_SEVERITY_ERROR
);
return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE; return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE;
} }
@ -392,7 +388,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPythonBom( JOB* aJob )
if( sch == nullptr ) if( sch == nullptr )
{ {
wxFprintf( stderr, _( "Failed to load schematic file\n" ) ); m_reporter->Report( _( "Failed to load schematic file\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE; return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE;
} }
@ -409,8 +405,10 @@ int EESCHEMA_JOBS_HANDLER::JobExportPythonBom( JOB* aJob )
} ) } )
> 0 ) > 0 )
{ {
wxPrintf( _( "Warning: schematic has annotation errors, please use the schematic " m_reporter->Report(
"editor to fix them\n" ) ); _( "Warning: schematic has annotation errors, please use the schematic "
"editor to fix them\n" ),
RPT_SEVERITY_WARNING );
} }
} }
@ -418,7 +416,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPythonBom( JOB* aJob )
ERC_TESTER erc( sch ); ERC_TESTER erc( sch );
if( erc.TestDuplicateSheetNames( false ) > 0 ) if( erc.TestDuplicateSheetNames( false ) > 0 )
wxPrintf( _( "Warning: duplicate sheet names.\n" ) ); m_reporter->Report( _( "Warning: duplicate sheet names.\n" ), RPT_SEVERITY_WARNING );
std::unique_ptr<NETLIST_EXPORTER_XML> xmlNetlist = std::unique_ptr<NETLIST_EXPORTER_XML> xmlNetlist =
std::make_unique<NETLIST_EXPORTER_XML>( sch ); std::make_unique<NETLIST_EXPORTER_XML>( sch );
@ -432,7 +430,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPythonBom( JOB* aJob )
aNetJob->m_outputFile = fn.GetFullName(); aNetJob->m_outputFile = fn.GetFullName();
} }
bool res = xmlNetlist->WriteNetlist( aNetJob->m_outputFile, GNL_OPT_BOM, *this ); bool res = xmlNetlist->WriteNetlist( aNetJob->m_outputFile, GNL_OPT_BOM, *m_reporter );
if( !res ) if( !res )
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
@ -492,8 +490,9 @@ int EESCHEMA_JOBS_HANDLER::doSymExportSvg( JOB_SYM_EXPORT_SVG* aSvgJob,
filename += wxS( "_demorgan" ); filename += wxS( "_demorgan" );
fn.SetName( filename ); fn.SetName( filename );
wxPrintf( _( "Plotting symbol '%s' unit %d to '%s'\n" ), symbol->GetName(), unit, m_reporter->Report( wxString::Format( _( "Plotting symbol '%s' unit %d to '%s'\n" ),
fn.GetFullPath() ); symbol->GetName(), unit, fn.GetFullPath() ),
RPT_SEVERITY_ACTION );
} }
else else
{ {
@ -503,7 +502,9 @@ int EESCHEMA_JOBS_HANDLER::doSymExportSvg( JOB_SYM_EXPORT_SVG* aSvgJob,
filename += wxS( "_demorgan" ); filename += wxS( "_demorgan" );
fn.SetName( filename ); fn.SetName( filename );
wxPrintf( _( "Plotting symbol '%s' to '%s'\n" ), symbol->GetName(), fn.GetFullPath() ); m_reporter->Report( wxString::Format( _( "Plotting symbol '%s' to '%s'\n" ),
symbol->GetName(), fn.GetFullPath() ),
RPT_SEVERITY_ACTION );
} }
// Get the symbol bounding box to fit the plot page to it // Get the symbol bounding box to fit the plot page to it
@ -527,7 +528,9 @@ int EESCHEMA_JOBS_HANDLER::doSymExportSvg( JOB_SYM_EXPORT_SVG* aSvgJob,
if( !plotter->OpenFile( fn.GetFullPath() ) ) if( !plotter->OpenFile( fn.GetFullPath() ) )
{ {
wxFprintf( stderr, _( "Unable to open destination '%s'" ), fn.GetFullPath() ); m_reporter->Report( wxString::Format( _( "Unable to open destination '%s'" ),
fn.GetFullPath() ),
RPT_SEVERITY_ERROR );
delete plotter; delete plotter;
return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE; return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE;
@ -580,7 +583,7 @@ int EESCHEMA_JOBS_HANDLER::JobSymExportSvg( JOB* aJob )
} }
catch( ... ) catch( ... )
{ {
wxFprintf( stderr, _( "Unable to load library\n" ) ); m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
} }
@ -593,7 +596,7 @@ int EESCHEMA_JOBS_HANDLER::JobSymExportSvg( JOB* aJob )
if( !symbol ) if( !symbol )
{ {
wxFprintf( stderr, _( "There is no symbol selected to save." ) ); m_reporter->Report( _( "There is no symbol selected to save." ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_ARGS; return CLI::EXIT_CODES::ERR_ARGS;
} }
} }
@ -650,7 +653,7 @@ int EESCHEMA_JOBS_HANDLER::JobSymUpgrade( JOB* aJob )
} }
catch( ... ) catch( ... )
{ {
wxFprintf( stderr, _( "Unable to load library\n" ) ); m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
} }
@ -658,7 +661,8 @@ int EESCHEMA_JOBS_HANDLER::JobSymUpgrade( JOB* aJob )
{ {
if( wxFile::Exists( upgradeJob->m_outputLibraryPath ) ) if( wxFile::Exists( upgradeJob->m_outputLibraryPath ) )
{ {
wxFprintf( stderr, _( "Output path must not conflict with existing path\n" ) ); m_reporter->Report(
_( "Output path must not conflict with existing path\n", RPT_SEVERITY_ERROR ) );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT; return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
} }
} }
@ -668,7 +672,7 @@ int EESCHEMA_JOBS_HANDLER::JobSymUpgrade( JOB* aJob )
if( shouldSave ) if( shouldSave )
{ {
wxPrintf( _( "Saving symbol library in updated format\n" ) ); m_reporter->Report( _( "Saving symbol library in updated format\n", RPT_SEVERITY_ACTION ) );
try try
{ {
@ -682,13 +686,13 @@ int EESCHEMA_JOBS_HANDLER::JobSymUpgrade( JOB* aJob )
} }
catch( ... ) catch( ... )
{ {
wxFprintf( stderr, _( "Unable to save library\n" ) ); m_reporter->Report( ( "Unable to save library\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
} }
} }
else else
{ {
wxPrintf( _( "Symbol library was not updated\n" ) ); m_reporter->Report( _( "Symbol library was not updated\n" ), RPT_SEVERITY_INFO );
} }
return CLI::EXIT_CODES::OK; return CLI::EXIT_CODES::OK;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com> * Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
@ -37,7 +37,7 @@ class LIB_SYMBOL;
/** /**
* Handles eeschema job dispatches * Handles eeschema job dispatches
*/ */
class EESCHEMA_JOBS_HANDLER : public JOB_DISPATCHER, REPORTER class EESCHEMA_JOBS_HANDLER : public JOB_DISPATCHER
{ {
public: public:
EESCHEMA_JOBS_HANDLER(); EESCHEMA_JOBS_HANDLER();
@ -62,16 +62,6 @@ public:
void InitRenderSettings( KIGFX::SCH_RENDER_SETTINGS* aRenderSettings, const wxString& aTheme, void InitRenderSettings( KIGFX::SCH_RENDER_SETTINGS* aRenderSettings, const wxString& aTheme,
SCHEMATIC* aSch ); SCHEMATIC* aSch );
/*
* REPORTER INTERFACE
*/
REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
bool HasMessage() const override
{
return false;
}
}; };
#endif #endif

View File

@ -239,6 +239,28 @@ public:
}; };
/**
* Reporter forwarding messages to stdout or stderr as appropriate
*/
class CLI_REPORTER : public REPORTER
{
public:
CLI_REPORTER()
{
}
virtual ~CLI_REPORTER()
{
}
static REPORTER& GetInstance();
REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
bool HasMessage() const override { return false; }
};
/** /**
* Debug type reporter, forwarding messages to std::cout. * Debug type reporter, forwarding messages to std::cout.
*/ */

View File

@ -364,6 +364,9 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
m_jobHandler = std::make_unique<PCBNEW_JOBS_HANDLER>(); m_jobHandler = std::make_unique<PCBNEW_JOBS_HANDLER>();
if( m_start_flags & KFCTL_CLI )
m_jobHandler->SetReporter( &CLI_REPORTER::GetInstance() );
return true; return true;
} }

View File

@ -41,7 +41,6 @@
#include <board_design_settings.h> #include <board_design_settings.h>
#include <pad.h> #include <pad.h>
#include <pcbnew_settings.h> #include <pcbnew_settings.h>
#include <wx/crt.h>
#include <wx/dir.h> #include <wx/dir.h>
#include <pcb_plot_svg.h> #include <pcb_plot_svg.h>
#include <gendrill_Excellon_writer.h> #include <gendrill_Excellon_writer.h>
@ -82,7 +81,7 @@ int PCBNEW_JOBS_HANDLER::JobExportStep( JOB* aJob )
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
if( aJob->IsCli() ) if( aJob->IsCli() )
wxPrintf( _( "Loading board\n" ) ); m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aStepJob->m_filename ); BOARD* brd = LoadBoard( aStepJob->m_filename );
@ -137,16 +136,16 @@ int PCBNEW_JOBS_HANDLER::JobExportSvg( JOB* aJob )
svgPlotOptions.m_plotFrame = aSvgJob->m_plotDrawingSheet; svgPlotOptions.m_plotFrame = aSvgJob->m_plotDrawingSheet;
if( aJob->IsCli() ) if( aJob->IsCli() )
wxPrintf( _( "Loading board\n" ) ); m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aSvgJob->m_filename ); BOARD* brd = LoadBoard( aSvgJob->m_filename );
if( aJob->IsCli() ) if( aJob->IsCli() )
{ {
if( PCB_PLOT_SVG::Plot( brd, svgPlotOptions ) ) if( PCB_PLOT_SVG::Plot( brd, svgPlotOptions ) )
wxPrintf( _( "Successfully created svg file" ) ); m_reporter->Report( _( "Successfully created svg file" ), RPT_SEVERITY_INFO );
else else
wxPrintf( _( "Error creating svg file" ) ); m_reporter->Report( _( "Error creating svg file" ), RPT_SEVERITY_ERROR );
} }
return CLI::EXIT_CODES::OK; return CLI::EXIT_CODES::OK;
@ -161,7 +160,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDxf( JOB* aJob )
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
if( aJob->IsCli() ) if( aJob->IsCli() )
wxPrintf( _( "Loading board\n" ) ); m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aDxfJob->m_filename ); BOARD* brd = LoadBoard( aDxfJob->m_filename );
@ -216,7 +215,7 @@ int PCBNEW_JOBS_HANDLER::JobExportPdf( JOB* aJob )
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
if( aJob->IsCli() ) if( aJob->IsCli() )
wxPrintf( _( "Loading board\n" ) ); m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aPdfJob->m_filename ); BOARD* brd = LoadBoard( aPdfJob->m_filename );
@ -269,7 +268,7 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob )
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
if( aJob->IsCli() ) if( aJob->IsCli() )
wxPrintf( _( "Loading board\n" ) ); m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aGerberJob->m_filename ); BOARD* brd = LoadBoard( aGerberJob->m_filename );
PCB_PLOT_PARAMS boardPlotOptions = brd->GetPlotOptions(); PCB_PLOT_PARAMS boardPlotOptions = brd->GetPlotOptions();
@ -333,13 +332,16 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob )
if( plotter ) if( plotter )
{ {
wxPrintf( _( "Plotted to '%s'.\n" ), fn.GetFullPath() ); m_reporter->Report( wxString::Format( _( "Plotted to '%s'.\n" ), fn.GetFullPath() ),
RPT_SEVERITY_ACTION );
PlotBoardLayers( brd, plotter, plotSequence, plotOpts ); PlotBoardLayers( brd, plotter, plotSequence, plotOpts );
plotter->EndPlot(); plotter->EndPlot();
} }
else else
{ {
wxFprintf( stderr, _( "Failed to plot to '%s'.\n" ), fn.GetFullPath() ); m_reporter->Report( wxString::Format( _( "Failed to plot to '%s'.\n" ),
fn.GetFullPath() ),
RPT_SEVERITY_ERROR );
exitCode = CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT; exitCode = CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
} }
@ -387,7 +389,7 @@ int PCBNEW_JOBS_HANDLER::JobExportGerber( JOB* aJob )
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
if( aJob->IsCli() ) if( aJob->IsCli() )
wxPrintf( _( "Loading board\n" ) ); m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aGerberJob->m_filename ); BOARD* brd = LoadBoard( aGerberJob->m_filename );
@ -417,7 +419,9 @@ int PCBNEW_JOBS_HANDLER::JobExportGerber( JOB* aJob )
} }
else else
{ {
wxFprintf( stderr, _( "Failed to plot to '%s'.\n" ), aGerberJob->m_outputFile ); m_reporter->Report( wxString::Format( _( "Failed to plot to '%s'.\n" ),
aGerberJob->m_outputFile ),
RPT_SEVERITY_ERROR );
exitCode = CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT; exitCode = CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
} }
@ -438,7 +442,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
if( aJob->IsCli() ) if( aJob->IsCli() )
wxPrintf( _( "Loading board\n" ) ); m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aDrillJob->m_filename ); BOARD* brd = LoadBoard( aDrillJob->m_filename );
@ -514,7 +518,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
excellonWriter->SetMapFileFormat( mapFormat ); excellonWriter->SetMapFileFormat( mapFormat );
if( !excellonWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true, if( !excellonWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true,
aDrillJob->m_generateMap, this ) ) aDrillJob->m_generateMap, m_reporter ) )
{ {
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT; return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
} }
@ -534,7 +538,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
gerberWriter->SetMapFileFormat( mapFormat ); gerberWriter->SetMapFileFormat( mapFormat );
if( !gerberWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true, if( !gerberWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true,
aDrillJob->m_generateMap, this ) ) aDrillJob->m_generateMap, m_reporter ) )
{ {
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT; return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
} }
@ -552,7 +556,7 @@ int PCBNEW_JOBS_HANDLER::JobExportPos( JOB* aJob )
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
if( aJob->IsCli() ) if( aJob->IsCli() )
wxPrintf( _( "Loading board\n" ) ); m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aPosJob->m_filename ); BOARD* brd = LoadBoard( aPosJob->m_filename );
@ -627,14 +631,15 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob )
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
if( aJob->IsCli() ) if( aJob->IsCli() )
wxPrintf( _( "Loading footprint library\n" ) ); m_reporter->Report( _( "Loading footprint library\n" ), RPT_SEVERITY_INFO );
if( !upgradeJob->m_outputLibraryPath.IsEmpty() ) if( !upgradeJob->m_outputLibraryPath.IsEmpty() )
{ {
if( wxFile::Exists( upgradeJob->m_outputLibraryPath ) || if( wxFile::Exists( upgradeJob->m_outputLibraryPath ) ||
wxDir::Exists( upgradeJob->m_outputLibraryPath) ) wxDir::Exists( upgradeJob->m_outputLibraryPath) )
{ {
wxFprintf( stderr, _( "Output path must not conflict with existing path\n" ) ); m_reporter->Report( _( "Output path must not conflict with existing path\n" ),
RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT; return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
} }
} }
@ -648,7 +653,7 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob )
} }
catch(...) catch(...)
{ {
wxFprintf( stderr, _( "Unable to load library\n" ) ); m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
} }
@ -664,7 +669,7 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob )
if( shouldSave ) if( shouldSave )
{ {
wxPrintf( _( "Saving footprint library\n" ) ); m_reporter->Report( _( "Saving footprint library\n" ), RPT_SEVERITY_INFO );
try try
{ {
@ -677,13 +682,13 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob )
} }
catch( ... ) catch( ... )
{ {
wxFprintf( stderr, _( "Unable to save library\n" ) ); m_reporter->Report( _( "Unable to save library\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
} }
} }
else else
{ {
wxPrintf( _( "Footprint library was not updated\n" ) ); m_reporter->Report( _( "Footprint library was not updated\n" ), RPT_SEVERITY_INFO );
} }
return CLI::EXIT_CODES::OK; return CLI::EXIT_CODES::OK;
@ -698,7 +703,7 @@ int PCBNEW_JOBS_HANDLER::JobExportFpSvg( JOB* aJob )
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
if( aJob->IsCli() ) if( aJob->IsCli() )
wxPrintf( _( "Loading footprint library\n" ) ); m_reporter->Report( _( "Loading footprint library\n" ), RPT_SEVERITY_INFO );
PCB_PLUGIN pcb_io( CTL_FOR_LIBRARY ); PCB_PLUGIN pcb_io( CTL_FOR_LIBRARY );
FP_CACHE fpLib( &pcb_io, svgJob->m_libraryPath ); FP_CACHE fpLib( &pcb_io, svgJob->m_libraryPath );
@ -709,7 +714,7 @@ int PCBNEW_JOBS_HANDLER::JobExportFpSvg( JOB* aJob )
} }
catch( ... ) catch( ... )
{ {
wxFprintf( stderr, _( "Unable to load library\n" ) ); m_reporter->Report( _( "Unable to load library\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_UNKNOWN; return CLI::EXIT_CODES::ERR_UNKNOWN;
} }
@ -747,7 +752,10 @@ int PCBNEW_JOBS_HANDLER::JobExportFpSvg( JOB* aJob )
} }
if( !svgJob->m_footprint.IsEmpty() && !singleFpPlotted ) if( !svgJob->m_footprint.IsEmpty() && !singleFpPlotted )
wxFprintf( stderr, _( "The given footprint could not be found to export." ) ); {
m_reporter->Report( _( "The given footprint could not be found to export." ),
RPT_SEVERITY_ERROR );
}
return CLI::EXIT_CODES::OK; return CLI::EXIT_CODES::OK;
} }
@ -785,8 +793,10 @@ int PCBNEW_JOBS_HANDLER::doFpExportSvg( JOB_FP_EXPORT_SVG* aSvgJob, const FOOTPR
outputFile.SetName( aFootprint->GetFPID().GetLibItemName().wx_str() ); outputFile.SetName( aFootprint->GetFPID().GetLibItemName().wx_str() );
outputFile.SetExt( SVGFileExtension ); outputFile.SetExt( SVGFileExtension );
wxPrintf( _( "Plotting footprint '%s' to '%s'\n" ), m_reporter->Report( wxString::Format( _( "Plotting footprint '%s' to '%s'\n" ),
aFootprint->GetFPID().GetLibItemName().wx_str(), outputFile.GetFullPath() ); aFootprint->GetFPID().GetLibItemName().wx_str(),
outputFile.GetFullPath() ),
RPT_SEVERITY_ACTION );
PCB_PLOT_SVG_OPTIONS svgPlotOptions; PCB_PLOT_SVG_OPTIONS svgPlotOptions;
@ -799,19 +809,9 @@ int PCBNEW_JOBS_HANDLER::doFpExportSvg( JOB_FP_EXPORT_SVG* aSvgJob, const FOOTPR
svgPlotOptions.m_plotFrame = false; svgPlotOptions.m_plotFrame = false;
if( !PCB_PLOT_SVG::Plot( brd.get(), svgPlotOptions ) ) if( !PCB_PLOT_SVG::Plot( brd.get(), svgPlotOptions ) )
wxFprintf( stderr, _( "Error creating svg file" ) ); m_reporter->Report( _( "Error creating svg file" ), RPT_SEVERITY_ERROR );
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

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com> * Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
@ -29,7 +29,7 @@ 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, REPORTER class PCBNEW_JOBS_HANDLER : public JOB_DISPATCHER
{ {
public: public:
PCBNEW_JOBS_HANDLER(); PCBNEW_JOBS_HANDLER();
@ -44,13 +44,6 @@ 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 );