KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_gerber.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022 Mark Roszko <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <cli/exit_codes.h>
24#include <kiface_base.h>
25#include <wx/crt.h>
26
27#include <macros.h>
28#include <locale_io.h>
29#include <string_utils.h>
30
31
32CLI::PCB_EXPORT_GERBER_COMMAND::PCB_EXPORT_GERBER_COMMAND( const std::string& aName, bool aOutputIsDir ) :
33 PCB_EXPORT_BASE_COMMAND( aName, false, aOutputIsDir )
34{
37
40
41 m_argParser.add_description( UTF8STDSTR( _( "Plot given layers to a single Gerber file" ) ) );
42
43 m_argParser.add_argument( "--erd", ARG_EXCLUDE_REFDES )
44 .help( UTF8STDSTR( _( "Exclude the reference designator text" ) ) )
45 .flag();
46
47 m_argParser.add_argument( "--ev", ARG_EXCLUDE_VALUE )
48 .help( UTF8STDSTR( _( "Exclude the value text" ) ) )
49 .flag();
50
51 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
52 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
53 .flag();
54
55 m_argParser.add_argument( "--sp", ARG_SKETCH_PADS_ON_FAB_LAYERS )
57 .flag();
58
59 m_argParser.add_argument( "--hdnp", ARG_HIDE_DNP_FPS_ON_FAB_LAYERS )
61 .flag();
62
63 m_argParser.add_argument( "--sdnp", ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS )
65 .flag();
66
67 m_argParser.add_argument( "--cdnp", ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS )
69 .flag();
70
71 m_argParser.add_argument( ARG_NO_X2 )
72 .help( UTF8STDSTR( _( "Do not use the extended X2 format" ) ) )
73 .flag();
74
75 m_argParser.add_argument( ARG_NO_NETLIST )
76 .help( UTF8STDSTR( _( "Do not generate netlist attributes" ) ) )
77 .flag();
78
80 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
81 .flag();
82
84 .help( UTF8STDSTR( _( "Disable aperture macros" ) ) )
85 .implicit_value( true )
86 .default_value( false );
87
89 .help( UTF8STDSTR( _( "Use drill/place file origin" ) ) )
90 .flag();
91
92 m_argParser.add_argument( ARG_PRECISION )
93 .help( UTF8STDSTR( _( "Precision of Gerber coordinates, valid options: 5 or 6" ) ) )
94 .scan<'i', int>()
95 .default_value( 6 )
96 .metavar( "PRECISION" );
97
99 .help( UTF8STDSTR( _( "Use KiCad Gerber file extension" ) ) )
100 .flag();
101
104 .flag();
105}
106
107
109 PCB_EXPORT_GERBER_COMMAND( "gerber" )
110{
111}
112
113
115{
116 aJob->m_filename = m_argInput;
117 aJob->SetConfiguredOutputPath( m_argOutput );
118 aJob->m_drawingSheet = m_argDrawingSheet;
119 aJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
120 aJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
121 aJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
123 aJob->SetVarOverrides( m_argDefineVars );
124
125 aJob->m_plotFootprintValues = !m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
126 aJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
127 aJob->m_plotDrawingSheet = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
128 aJob->m_disableApertureMacros = m_argParser.get<bool>( ARG_DISABLE_APERTURE_MACROS );
129 aJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
130 aJob->m_includeNetlistAttributes = !m_argParser.get<bool>( ARG_NO_NETLIST );
131 aJob->m_useX2Format = !m_argParser.get<bool>( ARG_NO_X2 );
132 aJob->m_useDrillOrigin = m_argParser.get<bool>( ARG_USE_DRILL_FILE_ORIGIN );
133 aJob->m_useProtelFileExtension = !m_argParser.get<bool>( ARG_NO_PROTEL_EXTENSION );
134 aJob->m_precision = m_argParser.get<int>( ARG_PRECISION );
135
136 aJob->m_argLayers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
137 aJob->m_argCommonLayers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
138
139 if( m_argParser.get<bool>( DEPRECATED_ARG_PLOT_INVISIBLE_TEXT ) )
141
142 if( !wxFile::Exists( aJob->m_filename ) )
143 {
144 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
146 }
147
148 if( aJob->m_precision != 5 && aJob->m_precision != 6 )
149 {
150 wxFprintf( stderr, _( "Gerber coordinate precision should be either 5 or 6\n" ) );
152 }
153
154 return EXIT_CODES::OK;
155}
156
157
159{
160 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
161 _( "This command is deprecated as of KiCad 9.0, please use \"gerbers\" instead\n" ) );
162
163 std::unique_ptr<JOB_EXPORT_PCB_GERBER> gerberJob( new JOB_EXPORT_PCB_GERBER() );
164
165 int exitCode = populateJob( gerberJob.get() );
166
167 if( exitCode != EXIT_CODES::OK )
168 return exitCode;
169
171 return aKiway.ProcessJob( KIWAY::FACE_PCB, gerberJob.get() );
172}
argparse::ArgumentParser m_argParser
Definition: command.h:100
void addDefineArg()
Set up the drawing sheet arg used by many of the export commands.
Definition: command.cpp:168
void addDrawingSheetArg()
Set up the drawing sheet arg used by many of the export commands.
Definition: command.cpp:156
int populateJob(JOB_EXPORT_PCB_GERBER *aJob)
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
std::optional< wxString > m_argLayers
std::optional< wxString > m_argCommonLayers
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
Definition: job.cpp:153
void SetVarOverrides(const std::map< wxString, wxString > &aVarOverrides)
Definition: job.h:193
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:286
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition: kiway.cpp:678
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:294
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_SKETCH_PADS_ON_FAB_LAYERS_DESC
#define ARG_INCLUDE_BORDER_TITLE
#define ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS_DESC
#define ARG_SKETCH_PADS_ON_FAB_LAYERS
#define ARG_COMMON_LAYERS
#define ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS_DESC
#define ARG_EXCLUDE_REFDES
#define ARG_EXCLUDE_VALUE
#define ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS
#define DEPRECATED_ARG_PLOT_INVISIBLE_TEXT
#define ARG_HIDE_DNP_FPS_ON_FAB_LAYERS
#define DEPRECATED_ARD_PLOT_INVISIBLE_TEXT_WARNING
#define ARG_SUBTRACT_SOLDERMASK
#define DEPRECATED_ARG_PLOT_INVISIBLE_TEXT_DESC
#define ARG_LAYERS
#define ARG_HIDE_DNP_FPS_ON_FAB_LAYERS_DESC
#define ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS
#define ARG_PRECISION
#define ARG_NO_X2
#define ARG_NO_NETLIST
#define ARG_DISABLE_APERTURE_MACROS
#define ARG_USE_DRILL_FILE_ORIGIN
#define ARG_NO_PROTEL_EXTENSION
#define _(s)
This file contains miscellaneous commonly used macros and functions.
static const int ERR_ARGS
Definition: exit_codes.h:31
static const int OK
Definition: exit_codes.h:30
static const int ERR_INVALID_INPUT_FILE
Definition: exit_codes.h:33
std::vector< FAB_LAYER_COLOR > dummy
wxString From_UTF8(const char *cstring)