diff --git a/common/jobs/job_dispatcher.cpp b/common/jobs/job_dispatcher.cpp index c722719137..3d958ddcbf 100644 --- a/common/jobs/job_dispatcher.cpp +++ b/common/jobs/job_dispatcher.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2022 Mark Roszko - * 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 * under the terms of the GNU General Public License as published by the @@ -20,6 +20,15 @@ #include #include +#include +#include + + +JOB_DISPATCHER::JOB_DISPATCHER() +{ + m_reporter = &NULL_REPORTER::GetInstance(); +} + void JOB_DISPATCHER::Register( const std::string& aJobTypeName, std::function aHandler ) @@ -27,6 +36,7 @@ void JOB_DISPATCHER::Register( const std::string& aJobTypeName, m_jobHandlers.emplace( aJobTypeName, aHandler ); } + int JOB_DISPATCHER::RunJob( JOB* job ) { if( m_jobHandlers.count( job->GetType() ) ) @@ -35,4 +45,11 @@ int JOB_DISPATCHER::RunJob( JOB* job ) } return CLI::EXIT_CODES::ERR_UNKNOWN; -} \ No newline at end of file +} + + +void JOB_DISPATCHER::SetReporter( REPORTER* aReporter ) +{ + wxCHECK( aReporter != nullptr, /*void*/ ); + m_reporter = aReporter; +} diff --git a/common/jobs/job_dispatcher.h b/common/jobs/job_dispatcher.h index f7a8f701a8..5ab5c93ede 100644 --- a/common/jobs/job_dispatcher.h +++ b/common/jobs/job_dispatcher.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2022 Mark Roszko - * 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 * under the terms of the GNU General Public License as published by the @@ -26,14 +26,23 @@ #include #include + +class REPORTER; + class JOB_DISPATCHER { public: + JOB_DISPATCHER(); void Register( const std::string& aJobTypeName, std::function aHandler ); - int RunJob( JOB* job ); + int RunJob( JOB* job ); + void SetReporter( REPORTER* aReporter ); + +protected: + REPORTER* m_reporter; // non-owning private: std::map> m_jobHandlers; + }; #endif \ No newline at end of file diff --git a/common/reporter.cpp b/common/reporter.cpp index bd8da08cc3..3e4d530923 100644 --- a/common/reporter.cpp +++ b/common/reporter.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -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 ) { switch( aSeverity ) diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 5464358919..40654872a0 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -349,6 +349,9 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) m_jobHandler = std::make_unique(); + if( m_start_flags & KFCTL_CLI ) + m_jobHandler->SetReporter( &CLI_REPORTER::GetInstance() ); + return true; } diff --git a/eeschema/eeschema_jobs_handler.cpp b/eeschema/eeschema_jobs_handler.cpp index b7c629a61c..56af04be63 100644 --- a/eeschema/eeschema_jobs_handler.cpp +++ b/eeschema/eeschema_jobs_handler.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -96,18 +95,7 @@ void EESCHEMA_JOBS_HANDLER::InitRenderSettings( KIGFX::SCH_RENDER_SETTINGS* aRen aSch->Prj().GetProjectPath() ); if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) ) - wxFprintf( stderr, _( "Error loading drawing sheet." ) ); -} - - -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; + m_reporter->Report( _( "Error loading drawing sheet." ), RPT_SEVERITY_ERROR ); } @@ -122,7 +110,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPlot( JOB* aJob ) 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; } @@ -131,7 +119,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPlot( JOB* aJob ) InitRenderSettings( renderSettings.get(), aPlotJob->settings.m_theme, sch ); std::unique_ptr schPlotter = std::make_unique( 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; } @@ -148,7 +136,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob ) 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; } @@ -165,7 +153,9 @@ int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob ) } ) > 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 ) { - 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( sch ); break; default: - wxFprintf( stderr, _( "Unknown netlist format.\n" ) ); + m_reporter->Report( _( "Unknown netlist format.\n" ), RPT_SEVERITY_ERROR ); return CLI::EXIT_CODES::ERR_UNKNOWN; } @@ -230,7 +220,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob ) 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) { @@ -252,7 +242,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob ) 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; } @@ -272,8 +262,10 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob ) } ) > 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 ); } } @@ -282,7 +274,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob ) 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; 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; } @@ -392,7 +388,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPythonBom( JOB* aJob ) 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; } @@ -409,8 +405,10 @@ int EESCHEMA_JOBS_HANDLER::JobExportPythonBom( JOB* aJob ) } ) > 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 ); } } @@ -418,7 +416,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPythonBom( JOB* aJob ) ERC_TESTER erc( sch ); 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 xmlNetlist = std::make_unique( sch ); @@ -432,7 +430,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPythonBom( JOB* aJob ) 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 ) return CLI::EXIT_CODES::ERR_UNKNOWN; @@ -492,8 +490,9 @@ int EESCHEMA_JOBS_HANDLER::doSymExportSvg( JOB_SYM_EXPORT_SVG* aSvgJob, filename += wxS( "_demorgan" ); fn.SetName( filename ); - wxPrintf( _( "Plotting symbol '%s' unit %d to '%s'\n" ), symbol->GetName(), unit, - fn.GetFullPath() ); + m_reporter->Report( wxString::Format( _( "Plotting symbol '%s' unit %d to '%s'\n" ), + symbol->GetName(), unit, fn.GetFullPath() ), + RPT_SEVERITY_ACTION ); } else { @@ -503,7 +502,9 @@ int EESCHEMA_JOBS_HANDLER::doSymExportSvg( JOB_SYM_EXPORT_SVG* aSvgJob, filename += wxS( "_demorgan" ); 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 @@ -527,7 +528,9 @@ int EESCHEMA_JOBS_HANDLER::doSymExportSvg( JOB_SYM_EXPORT_SVG* aSvgJob, 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; return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE; @@ -580,7 +583,7 @@ int EESCHEMA_JOBS_HANDLER::JobSymExportSvg( JOB* aJob ) } 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; } @@ -593,7 +596,7 @@ int EESCHEMA_JOBS_HANDLER::JobSymExportSvg( JOB* aJob ) 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; } } @@ -650,7 +653,7 @@ int EESCHEMA_JOBS_HANDLER::JobSymUpgrade( JOB* aJob ) } 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; } @@ -658,7 +661,8 @@ int EESCHEMA_JOBS_HANDLER::JobSymUpgrade( JOB* aJob ) { 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; } } @@ -668,7 +672,7 @@ int EESCHEMA_JOBS_HANDLER::JobSymUpgrade( JOB* aJob ) if( shouldSave ) { - wxPrintf( _( "Saving symbol library in updated format\n" ) ); + m_reporter->Report( _( "Saving symbol library in updated format\n", RPT_SEVERITY_ACTION ) ); try { @@ -682,13 +686,13 @@ int EESCHEMA_JOBS_HANDLER::JobSymUpgrade( JOB* aJob ) } 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; } } 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; diff --git a/eeschema/eeschema_jobs_handler.h b/eeschema/eeschema_jobs_handler.h index 178699db00..29418b6f91 100644 --- a/eeschema/eeschema_jobs_handler.h +++ b/eeschema/eeschema_jobs_handler.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2022 Mark Roszko - * 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 * under the terms of the GNU General Public License as published by the @@ -37,7 +37,7 @@ class LIB_SYMBOL; /** * Handles eeschema job dispatches */ -class EESCHEMA_JOBS_HANDLER : public JOB_DISPATCHER, REPORTER +class EESCHEMA_JOBS_HANDLER : public JOB_DISPATCHER { public: EESCHEMA_JOBS_HANDLER(); @@ -62,16 +62,6 @@ public: void InitRenderSettings( KIGFX::SCH_RENDER_SETTINGS* aRenderSettings, const wxString& aTheme, SCHEMATIC* aSch ); - /* - * REPORTER INTERFACE - */ - REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override; - - bool HasMessage() const override - { - return false; - } - }; #endif diff --git a/include/reporter.h b/include/reporter.h index daf82a5ba0..60515f5812 100644 --- a/include/reporter.h +++ b/include/reporter.h @@ -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. */ diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 14d7817b14..a44776f176 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -364,6 +364,9 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) m_jobHandler = std::make_unique(); + if( m_start_flags & KFCTL_CLI ) + m_jobHandler->SetReporter( &CLI_REPORTER::GetInstance() ); + return true; } diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index 7756fd8494..b389a84c07 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -82,7 +81,7 @@ int PCBNEW_JOBS_HANDLER::JobExportStep( JOB* aJob ) return CLI::EXIT_CODES::ERR_UNKNOWN; if( aJob->IsCli() ) - wxPrintf( _( "Loading board\n" ) ); + m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO ); BOARD* brd = LoadBoard( aStepJob->m_filename ); @@ -137,16 +136,16 @@ int PCBNEW_JOBS_HANDLER::JobExportSvg( JOB* aJob ) svgPlotOptions.m_plotFrame = aSvgJob->m_plotDrawingSheet; if( aJob->IsCli() ) - wxPrintf( _( "Loading board\n" ) ); + m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO ); BOARD* brd = LoadBoard( aSvgJob->m_filename ); if( aJob->IsCli() ) { if( PCB_PLOT_SVG::Plot( brd, svgPlotOptions ) ) - wxPrintf( _( "Successfully created svg file" ) ); + m_reporter->Report( _( "Successfully created svg file" ), RPT_SEVERITY_INFO ); else - wxPrintf( _( "Error creating svg file" ) ); + m_reporter->Report( _( "Error creating svg file" ), RPT_SEVERITY_ERROR ); } return CLI::EXIT_CODES::OK; @@ -161,7 +160,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDxf( JOB* aJob ) return CLI::EXIT_CODES::ERR_UNKNOWN; if( aJob->IsCli() ) - wxPrintf( _( "Loading board\n" ) ); + m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO ); BOARD* brd = LoadBoard( aDxfJob->m_filename ); @@ -216,7 +215,7 @@ int PCBNEW_JOBS_HANDLER::JobExportPdf( JOB* aJob ) return CLI::EXIT_CODES::ERR_UNKNOWN; if( aJob->IsCli() ) - wxPrintf( _( "Loading board\n" ) ); + m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO ); BOARD* brd = LoadBoard( aPdfJob->m_filename ); @@ -269,7 +268,7 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob ) return CLI::EXIT_CODES::ERR_UNKNOWN; if( aJob->IsCli() ) - wxPrintf( _( "Loading board\n" ) ); + m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO ); BOARD* brd = LoadBoard( aGerberJob->m_filename ); PCB_PLOT_PARAMS boardPlotOptions = brd->GetPlotOptions(); @@ -333,13 +332,16 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob ) 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 ); plotter->EndPlot(); } 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; } @@ -387,7 +389,7 @@ int PCBNEW_JOBS_HANDLER::JobExportGerber( JOB* aJob ) return CLI::EXIT_CODES::ERR_UNKNOWN; if( aJob->IsCli() ) - wxPrintf( _( "Loading board\n" ) ); + m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO ); BOARD* brd = LoadBoard( aGerberJob->m_filename ); @@ -417,7 +419,9 @@ int PCBNEW_JOBS_HANDLER::JobExportGerber( JOB* aJob ) } 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; } @@ -438,7 +442,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob ) return CLI::EXIT_CODES::ERR_UNKNOWN; if( aJob->IsCli() ) - wxPrintf( _( "Loading board\n" ) ); + m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO ); BOARD* brd = LoadBoard( aDrillJob->m_filename ); @@ -514,7 +518,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob ) excellonWriter->SetMapFileFormat( mapFormat ); if( !excellonWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true, - aDrillJob->m_generateMap, this ) ) + aDrillJob->m_generateMap, m_reporter ) ) { return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT; } @@ -534,7 +538,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob ) gerberWriter->SetMapFileFormat( mapFormat ); if( !gerberWriter->CreateDrillandMapFilesSet( aDrillJob->m_outputDir, true, - aDrillJob->m_generateMap, this ) ) + aDrillJob->m_generateMap, m_reporter ) ) { 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; if( aJob->IsCli() ) - wxPrintf( _( "Loading board\n" ) ); + m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO ); BOARD* brd = LoadBoard( aPosJob->m_filename ); @@ -627,14 +631,15 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob ) return CLI::EXIT_CODES::ERR_UNKNOWN; if( aJob->IsCli() ) - wxPrintf( _( "Loading footprint library\n" ) ); + m_reporter->Report( _( "Loading footprint library\n" ), RPT_SEVERITY_INFO ); if( !upgradeJob->m_outputLibraryPath.IsEmpty() ) { if( wxFile::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; } } @@ -648,7 +653,7 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob ) } 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; } @@ -664,7 +669,7 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob ) if( shouldSave ) { - wxPrintf( _( "Saving footprint library\n" ) ); + m_reporter->Report( _( "Saving footprint library\n" ), RPT_SEVERITY_INFO ); try { @@ -677,13 +682,13 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob ) } 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; } } 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; @@ -698,7 +703,7 @@ int PCBNEW_JOBS_HANDLER::JobExportFpSvg( JOB* aJob ) return CLI::EXIT_CODES::ERR_UNKNOWN; 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 ); FP_CACHE fpLib( &pcb_io, svgJob->m_libraryPath ); @@ -709,7 +714,7 @@ int PCBNEW_JOBS_HANDLER::JobExportFpSvg( JOB* aJob ) } 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; } @@ -747,7 +752,10 @@ int PCBNEW_JOBS_HANDLER::JobExportFpSvg( JOB* aJob ) } 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; } @@ -785,8 +793,10 @@ int PCBNEW_JOBS_HANDLER::doFpExportSvg( JOB_FP_EXPORT_SVG* aSvgJob, const FOOTPR outputFile.SetName( aFootprint->GetFPID().GetLibItemName().wx_str() ); outputFile.SetExt( SVGFileExtension ); - wxPrintf( _( "Plotting footprint '%s' to '%s'\n" ), - aFootprint->GetFPID().GetLibItemName().wx_str(), outputFile.GetFullPath() ); + m_reporter->Report( wxString::Format( _( "Plotting footprint '%s' to '%s'\n" ), + aFootprint->GetFPID().GetLibItemName().wx_str(), + outputFile.GetFullPath() ), + RPT_SEVERITY_ACTION ); 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; 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; } - -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; -} diff --git a/pcbnew/pcbnew_jobs_handler.h b/pcbnew/pcbnew_jobs_handler.h index 33a45cd7cd..ff28ae9223 100644 --- a/pcbnew/pcbnew_jobs_handler.h +++ b/pcbnew/pcbnew_jobs_handler.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2022 Mark Roszko - * 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 * 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 FOOTPRINT; -class PCBNEW_JOBS_HANDLER : public JOB_DISPATCHER, REPORTER +class PCBNEW_JOBS_HANDLER : public JOB_DISPATCHER { public: PCBNEW_JOBS_HANDLER(); @@ -44,13 +44,6 @@ public: int JobExportFpUpgrade( 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: void populateGerberPlotOptionsFromJob( PCB_PLOT_PARAMS& aPlotOpts, JOB_EXPORT_PCB_GERBER* aJob );