From 4e79d1ecdd0eedfecf38e4a47f124a37b3791e55 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 16 Jun 2023 07:13:45 -0400 Subject: [PATCH] Command line PCB gerber export fix and improvement. The --board-plot-params argument was never parsed so it was always ignored. [ADDED] A '--no-protel-ext' option to allow plotting gerbers with the KiCad file extension (gbr) instead of the Protel gerber file extensions. --- common/jobs/job_export_pcb_gerber.h | 2 ++ kicad/cli/command_export_pcb_gerber.cpp | 10 +++++++++- kicad/cli/command_export_pcb_gerber.h | 1 + kicad/cli/command_export_pcb_gerbers.cpp | 6 +++++- pcbnew/pcbnew_jobs_handler.cpp | 10 +++++++--- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/common/jobs/job_export_pcb_gerber.h b/common/jobs/job_export_pcb_gerber.h index 67b5fc2547..ffa664bf5e 100644 --- a/common/jobs/job_export_pcb_gerber.h +++ b/common/jobs/job_export_pcb_gerber.h @@ -40,6 +40,7 @@ public: m_useX2Format( true ), m_disableApertureMacros( false ), m_useAuxOrigin( false ), + m_useProtelFileExtension( true ), m_precision( 5 ), m_printMaskLayer() { @@ -61,6 +62,7 @@ public: bool m_useX2Format; bool m_disableApertureMacros; bool m_useAuxOrigin; + bool m_useProtelFileExtension; int m_precision; diff --git a/kicad/cli/command_export_pcb_gerber.cpp b/kicad/cli/command_export_pcb_gerber.cpp index 1a1e70bebb..6148b826dd 100644 --- a/kicad/cli/command_export_pcb_gerber.cpp +++ b/kicad/cli/command_export_pcb_gerber.cpp @@ -80,6 +80,11 @@ CLI::EXPORT_PCB_GERBER_COMMAND::EXPORT_PCB_GERBER_COMMAND( const std::string& aN .help( UTF8STDSTR( _( "Precision of gerber coordinates, valid options: 5 or 6" ) ) ) .scan<'i', int>() .default_value( 6 ); + + m_argParser.add_argument( ARG_NO_PROTEL_EXTENSION ) + .help( UTF8STDSTR( _( "Use KiCad gerber file extension" ) ) ) + .implicit_value( true ) + .default_value( false ); } @@ -101,6 +106,7 @@ int CLI::EXPORT_PCB_GERBER_COMMAND::populateJob( JOB_EXPORT_PCB_GERBER* aJob ) aJob->m_includeNetlistAttributes = !m_argParser.get( ARG_NO_NETLIST ); aJob->m_useX2Format = !m_argParser.get( ARG_NO_X2 ); aJob->m_useAuxOrigin = m_argParser.get( ARG_USE_DRILL_FILE_ORIGIN ); + aJob->m_useProtelFileExtension = !m_argParser.get( ARG_NO_PROTEL_EXTENSION ); aJob->m_precision = m_argParser.get( ARG_PRECISION ); aJob->m_printMaskLayer = m_selectedLayers; @@ -123,12 +129,14 @@ int CLI::EXPORT_PCB_GERBER_COMMAND::populateJob( JOB_EXPORT_PCB_GERBER* aJob ) int CLI::EXPORT_PCB_GERBER_COMMAND::doPerform( KIWAY& aKiway ) { int exitCode = EXPORT_PCB_BASE_COMMAND::doPerform( aKiway ); + if( exitCode != EXIT_CODES::OK ) return exitCode; std::unique_ptr gerberJob( new JOB_EXPORT_PCB_GERBER( true ) ); exitCode = populateJob( gerberJob.get() ); + if( exitCode != EXIT_CODES::OK ) return exitCode; @@ -136,4 +144,4 @@ int CLI::EXPORT_PCB_GERBER_COMMAND::doPerform( KIWAY& aKiway ) exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, gerberJob.get() ); return exitCode; -} \ No newline at end of file +} diff --git a/kicad/cli/command_export_pcb_gerber.h b/kicad/cli/command_export_pcb_gerber.h index 96f53c3995..e260bd79c4 100644 --- a/kicad/cli/command_export_pcb_gerber.h +++ b/kicad/cli/command_export_pcb_gerber.h @@ -33,6 +33,7 @@ namespace CLI #define ARG_DISABLE_APERTURE_MACROS "--disable-aperture-macros" #define ARG_USE_DRILL_FILE_ORIGIN "--use-drill-file-origin" #define ARG_PRECISION "--precision" +#define ARG_NO_PROTEL_EXTENSION "--no-protel-ext" class EXPORT_PCB_GERBER_COMMAND : public EXPORT_PCB_BASE_COMMAND { diff --git a/kicad/cli/command_export_pcb_gerbers.cpp b/kicad/cli/command_export_pcb_gerbers.cpp index 12a00b0b51..85f908e232 100644 --- a/kicad/cli/command_export_pcb_gerbers.cpp +++ b/kicad/cli/command_export_pcb_gerbers.cpp @@ -33,6 +33,7 @@ #define ARG_COMMON_LAYERS "--common-layers" #define ARG_USE_BOARD_PLOT_PARAMS "--board-plot-params" + CLI::EXPORT_PCB_GERBERS_COMMAND::EXPORT_PCB_GERBERS_COMMAND() : EXPORT_PCB_GERBER_COMMAND( "gerbers" ) { @@ -54,21 +55,24 @@ CLI::EXPORT_PCB_GERBERS_COMMAND::EXPORT_PCB_GERBERS_COMMAND() : int CLI::EXPORT_PCB_GERBERS_COMMAND::doPerform( KIWAY& aKiway ) { int exitCode = EXPORT_PCB_BASE_COMMAND::doPerform( aKiway ); + if( exitCode != EXIT_CODES::OK ) return exitCode; std::unique_ptr gerberJob( new JOB_EXPORT_PCB_GERBERS( true ) ); exitCode = populateJob( gerberJob.get() ); + if( exitCode != EXIT_CODES::OK ) return exitCode; wxString layers = FROM_UTF8( m_argParser.get( ARG_COMMON_LAYERS ).c_str() ); gerberJob->m_layersIncludeOnAll = convertLayerStringList( layers, gerberJob->m_layersIncludeOnAllSet ); + gerberJob->m_useBoardPlotParams = m_argParser.get( ARG_USE_BOARD_PLOT_PARAMS ); LOCALE_IO dummy; exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, gerberJob.get() ); return exitCode; -} \ No newline at end of file +} diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index 3d2c8752bb..7b7c76d0e5 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -311,8 +311,6 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob ) // Pick the basename from the board file wxFileName fn( brd->GetFileName() ); PCB_LAYER_ID layer = *seq; - fileExt = GetGerberProtelExtension( layer ); - PCB_PLOT_PARAMS plotOpts; if( aGerberJob->m_useBoardPlotParams ) @@ -320,6 +318,11 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob ) else populateGerberPlotOptionsFromJob( plotOpts, aGerberJob ); + if( plotOpts.GetUseGerberProtelExtensions() ) + fileExt = GetGerberProtelExtension( layer ); + else + fileExt = GerberFileExtension; + BuildPlotFileName( &fn, aGerberJob->m_outputFile, brd->GetLayerName( layer ), fileExt ); wxString fullname = fn.GetFullName(); @@ -345,6 +348,7 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob ) } wxFileName fn( aGerberJob->m_filename ); + // Build gerber job file from basename BuildPlotFileName( &fn, aGerberJob->m_outputFile, wxT( "job" ), GerberJobFileExtension ); jobfile_writer.CreateJobFile( fn.GetFullPath() ); @@ -371,7 +375,7 @@ void PCBNEW_JOBS_HANDLER::populateGerberPlotOptionsFromJob( PCB_PLOT_PARAMS& aPlotOpts.SetUseGerberX2format( aJob->m_useX2Format ); aPlotOpts.SetIncludeGerberNetlistInfo( aJob->m_includeNetlistAttributes ); aPlotOpts.SetUseAuxOrigin( aJob->m_useAuxOrigin ); - + aPlotOpts.SetUseGerberProtelExtensions( aJob->m_useProtelFileExtension ); aPlotOpts.SetGerberPrecision( aJob->m_precision ); }