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 .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( ARG_NO_X2 )
56 .help( UTF8STDSTR( _( "Do not use the extended X2 format" ) ) )
57 .flag();
58
59 m_argParser.add_argument( ARG_NO_NETLIST )
60 .help( UTF8STDSTR( _( "Do not generate netlist attributes" ) ) )
61 .flag();
62
64 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
65 .flag();
66
68 .help( UTF8STDSTR( _( "Disable aperture macros" ) ) )
69 .implicit_value( true )
70 .default_value( false );
71
73 .help( UTF8STDSTR( _( "Use drill/place file origin" ) ) )
74 .flag();
75
76 m_argParser.add_argument( ARG_PRECISION )
77 .help( UTF8STDSTR( _( "Precision of Gerber coordinates, valid options: 5 or 6" ) ) )
78 .scan<'i', int>()
79 .default_value( 6 )
80 .metavar( "PRECISION" );
81
83 .help( UTF8STDSTR( _( "Use KiCad Gerber file extension" ) ) )
84 .flag();
85}
86
87
89{
90}
91
92
94{
95 aJob->m_filename = m_argInput;
96 aJob->m_outputFile = m_argOutput;
97 aJob->m_drawingSheet = m_argDrawingSheet;
98 aJob->SetVarOverrides( m_argDefineVars );
99
100 aJob->m_plotFootprintValues = !m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
101 aJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
102 aJob->m_plotBorderTitleBlocks = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
103 aJob->m_disableApertureMacros = m_argParser.get<bool>( ARG_DISABLE_APERTURE_MACROS );
104 aJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
105 aJob->m_includeNetlistAttributes = !m_argParser.get<bool>( ARG_NO_NETLIST );
106 aJob->m_useX2Format = !m_argParser.get<bool>( ARG_NO_X2 );
107 aJob->m_useAuxOrigin = m_argParser.get<bool>( ARG_USE_DRILL_FILE_ORIGIN );
108 aJob->m_useProtelFileExtension = !m_argParser.get<bool>( ARG_NO_PROTEL_EXTENSION );
109 aJob->m_precision = m_argParser.get<int>( ARG_PRECISION );
110 aJob->m_printMaskLayer = m_selectedLayers;
111
112 if( !wxFile::Exists( aJob->m_filename ) )
113 {
114 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
116 }
117
118 if( aJob->m_precision != 5 && aJob->m_precision != 6 )
119 {
120 wxFprintf( stderr, _( "Gerber coordinate precision should be either 5 or 6\n" ) );
122 }
123
124 return EXIT_CODES::OK;
125}
126
127
129{
130 int exitCode = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
131
132 if( exitCode != EXIT_CODES::OK )
133 return exitCode;
134
135 std::unique_ptr<JOB_EXPORT_PCB_GERBER> gerberJob( new JOB_EXPORT_PCB_GERBER( true ) );
136
137 exitCode = populateJob( gerberJob.get() );
138
139 if( exitCode != EXIT_CODES::OK )
140 return exitCode;
141
143 exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, gerberJob.get() );
144
145 return exitCode;
146}
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.
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:709
@ 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.