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 <layer_ids.h>
26#include <wx/crt.h>
27
28#include <macros.h>
29#include <wx/tokenzr.h>
30
31#include <locale_io.h>
32
33
34
37{
38 addLayerArg( true );
41
42 m_argParser.add_description( UTF8STDSTR( _( "Plot given layers to a single Gerber file" ) ) );
43
44 m_argParser.add_argument( "--erd", ARG_EXCLUDE_REFDES )
45 .help( UTF8STDSTR( _( "Exclude the reference designator text" ) ) )
46 .flag();
47
48 m_argParser.add_argument( "--ev", ARG_EXCLUDE_VALUE )
49 .help( UTF8STDSTR( _( "Exclude the value text" ) ) )
50 .flag();
51
52 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
53 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
54 .flag();
55
56 m_argParser.add_argument( ARG_NO_X2 )
57 .help( UTF8STDSTR( _( "Do not use the extended X2 format" ) ) )
58 .flag();
59
60 m_argParser.add_argument( ARG_NO_NETLIST )
61 .help( UTF8STDSTR( _( "Do not generate netlist attributes" ) ) )
62 .flag();
63
65 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
66 .flag();
67
69 .help( UTF8STDSTR( _( "Disable aperture macros" ) ) )
70 .implicit_value( true )
71 .default_value( false );
72
74 .help( UTF8STDSTR( _( "Use drill/place file origin" ) ) )
75 .flag();
76
77 m_argParser.add_argument( ARG_PRECISION )
78 .help( UTF8STDSTR( _( "Precision of Gerber coordinates, valid options: 5 or 6" ) ) )
79 .scan<'i', int>()
80 .default_value( 6 )
81 .metavar( "PRECISION" );
82
84 .help( UTF8STDSTR( _( "Use KiCad Gerber file extension" ) ) )
85 .flag();
86
87
90 .flag();
91}
92
93
95{
96}
97
98
100{
101 aJob->m_filename = m_argInput;
102 aJob->SetConfiguredOutputPath( m_argOutput );
103 aJob->m_drawingSheet = m_argDrawingSheet;
104 aJob->SetVarOverrides( m_argDefineVars );
105
106 aJob->m_plotFootprintValues = !m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
107 aJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
108 aJob->m_plotDrawingSheet = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
109 aJob->m_disableApertureMacros = m_argParser.get<bool>( ARG_DISABLE_APERTURE_MACROS );
110 aJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
111 aJob->m_includeNetlistAttributes = !m_argParser.get<bool>( ARG_NO_NETLIST );
112 aJob->m_useX2Format = !m_argParser.get<bool>( ARG_NO_X2 );
113 aJob->m_useDrillOrigin = m_argParser.get<bool>( ARG_USE_DRILL_FILE_ORIGIN );
114 aJob->m_useProtelFileExtension = !m_argParser.get<bool>( ARG_NO_PROTEL_EXTENSION );
115 aJob->m_precision = m_argParser.get<int>( ARG_PRECISION );
116 aJob->m_printMaskLayer = m_selectedLayers;
117 aJob->m_plotInvisibleText = m_argParser.get<bool>( ARG_PLOT_INVISIBLE_TEXT );
118
119 if( !wxFile::Exists( aJob->m_filename ) )
120 {
121 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
123 }
124
125 if( aJob->m_precision != 5 && aJob->m_precision != 6 )
126 {
127 wxFprintf( stderr, _( "Gerber coordinate precision should be either 5 or 6\n" ) );
129 }
130
131 return EXIT_CODES::OK;
132}
133
134
136{
137 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
138 _( "This command is deprecated as of KiCad 9.0, please use \"gerbers\" instead\n" ) );
139
140 int exitCode = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
141
142 if( exitCode != EXIT_CODES::OK )
143 return exitCode;
144
145 std::unique_ptr<JOB_EXPORT_PCB_GERBER> gerberJob( new JOB_EXPORT_PCB_GERBER() );
146
147 exitCode = populateJob( gerberJob.get() );
148
149 if( exitCode != EXIT_CODES::OK )
150 return exitCode;
151
153 exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, gerberJob.get() );
154
155 return exitCode;
156}
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:169
void addDrawingSheetArg()
Set up the drawing sheet arg used by many of the export commands.
Definition: command.cpp:157
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.
LSEQ m_printMaskLayer
Layers to include on all individual layer prints.
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:192
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:285
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:293
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr)
Definition: kiway.cpp:711
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_INCLUDE_BORDER_TITLE
#define ARG_EXCLUDE_REFDES
#define ARG_PLOT_INVISIBLE_TEXT_DESC
#define ARG_PLOT_INVISIBLE_TEXT
#define ARG_EXCLUDE_VALUE
#define ARG_PRECISION
#define ARG_NO_X2
#define ARG_NO_NETLIST
#define ARG_DISABLE_APERTURE_MACROS
#define ARG_SUBTRACT_SOLDERMASK
#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
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.