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 (C) 1992-2022 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
36{
37 addLayerArg( true );
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 .implicit_value( true )
46 .default_value( false );
47
48 m_argParser.add_argument( "--ev", ARG_EXCLUDE_VALUE )
49 .help( UTF8STDSTR( _( "Exclude the value text" ) ) )
50 .implicit_value( true )
51 .default_value( false );
52
53 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
54 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
55 .implicit_value( true )
56 .default_value( false );
57
58 m_argParser.add_argument( ARG_NO_X2 )
59 .help( UTF8STDSTR( _( "Do not use the extended X2 format" ) ) )
60 .implicit_value( true )
61 .default_value( false );
62
63 m_argParser.add_argument( ARG_NO_NETLIST )
64 .help( UTF8STDSTR( _( "Do not generate netlist attributes" ) ) )
65 .implicit_value( true )
66 .default_value( false );
67
69 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
70 .implicit_value( true )
71 .default_value( false );
72
74 .help( UTF8STDSTR( _( "Disable aperture macros" ) ) )
75 .implicit_value( true )
76 .default_value( false );
77
79 .help( UTF8STDSTR( _( "Use drill/place file origin" ) ) )
80 .implicit_value( true )
81 .default_value( false );
82
83 m_argParser.add_argument( ARG_PRECISION )
84 .help( UTF8STDSTR( _( "Precision of Gerber coordinates, valid options: 5 or 6" ) ) )
85 .scan<'i', int>()
86 .default_value( 6 )
87 .metavar( "PRECISION" );
88
90 .help( UTF8STDSTR( _( "Use KiCad Gerber file extension" ) ) )
91 .implicit_value( true )
92 .default_value( false );
93}
94
95
97{
98}
99
100
102{
103 aJob->m_filename = m_argInput;
104 aJob->m_outputFile = m_argOutput;
105 aJob->m_drawingSheet = m_argDrawingSheet;
106 aJob->SetVarOverrides( m_argDefineVars );
107
108 aJob->m_plotFootprintValues = !m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
109 aJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
110 aJob->m_plotBorderTitleBlocks = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
111 aJob->m_disableApertureMacros = m_argParser.get<bool>( ARG_DISABLE_APERTURE_MACROS );
112 aJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
113 aJob->m_includeNetlistAttributes = !m_argParser.get<bool>( ARG_NO_NETLIST );
114 aJob->m_useX2Format = !m_argParser.get<bool>( ARG_NO_X2 );
115 aJob->m_useAuxOrigin = m_argParser.get<bool>( ARG_USE_DRILL_FILE_ORIGIN );
116 aJob->m_useProtelFileExtension = !m_argParser.get<bool>( ARG_NO_PROTEL_EXTENSION );
117 aJob->m_precision = m_argParser.get<int>( ARG_PRECISION );
118 aJob->m_printMaskLayer = m_selectedLayers;
119
120 if( !wxFile::Exists( aJob->m_filename ) )
121 {
122 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
124 }
125
126 if( aJob->m_precision != 5 && aJob->m_precision != 6 )
127 {
128 wxFprintf( stderr, _( "Gerber coordinate precision should be either 5 or 6\n" ) );
130 }
131
132 return EXIT_CODES::OK;
133}
134
135
137{
138 int exitCode = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
139
140 if( exitCode != EXIT_CODES::OK )
141 return exitCode;
142
143 std::unique_ptr<JOB_EXPORT_PCB_GERBER> gerberJob( new JOB_EXPORT_PCB_GERBER( true ) );
144
145 exitCode = populateJob( gerberJob.get() );
146
147 if( exitCode != EXIT_CODES::OK )
148 return exitCode;
149
151 exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, gerberJob.get() );
152
153 return exitCode;
154}
argparse::ArgumentParser m_argParser
Definition: command.h:98
void addDefineArg()
Sets up the drawing sheet arg used by many of the export commands.
Definition: command.cpp:168
void addDrawingSheetArg()
Sets 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.
void SetVarOverrides(const std::map< wxString, wxString > &aVarOverrides)
Definition: job.h:43
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
int ProcessJob(KIWAY::FACE_T aFace, JOB *job)
Definition: kiway.cpp:729
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:287
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_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.