KiCad PCB EDA Suite
command_export_pcb_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 );
38
39 m_argParser.add_argument( "--erd", ARG_EXCLUDE_REFDES )
40 .help( UTF8STDSTR( _( "Exclude the reference designator text" ) ) )
41 .implicit_value( true )
42 .default_value( false );
43
44 m_argParser.add_argument( "--ev", ARG_EXCLUDE_VALUE )
45 .help( UTF8STDSTR( _( "Exclude the value text" ) ) )
46 .implicit_value( true )
47 .default_value( false );
48
49 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
50 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
51 .implicit_value( true )
52 .default_value( false );
53
54 m_argParser.add_argument( ARG_NO_X2 )
55 .help( UTF8STDSTR( _( "Do not use the extended X2 format" ) ) )
56 .implicit_value( true )
57 .default_value( false );
58
59 m_argParser.add_argument( ARG_NO_NETLIST )
60 .help( UTF8STDSTR( _( "Do not generate netlist attributes" ) ) )
61 .implicit_value( true )
62 .default_value( false );
63
65 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
66 .implicit_value( true )
67 .default_value( false );
68
70 .help( UTF8STDSTR( _( "Disable aperture macros" ) ) )
71 .implicit_value( true )
72 .default_value( false );
73
74 m_argParser.add_argument( ARG_PRECISION )
75 .help( UTF8STDSTR( _( "Precision of gerber coordinates, valid options: 5 or 6" ) ) )
76 .scan<'i', int>()
77 .default_value( 6 );
78}
79
80
82{
83}
84
85
87{
88 aJob->m_filename = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
89 aJob->m_outputFile = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
90
91 aJob->m_plotFootprintValues = !m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
92 aJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
93 aJob->m_plotBorderTitleBlocks = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
94 aJob->m_disableApertureMacros = m_argParser.get<bool>( ARG_DISABLE_APERTURE_MACROS );
95 aJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
96 aJob->m_includeNetlistAttributes = !m_argParser.get<bool>( ARG_NO_NETLIST );
97 aJob->m_useX2Format = !m_argParser.get<bool>( ARG_NO_X2 );
98 aJob->m_precision = m_argParser.get<int>( ARG_PRECISION );
99 aJob->m_printMaskLayer = m_selectedLayers;
100
101 if( !wxFile::Exists( aJob->m_filename ) )
102 {
103 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
105 }
106
107 if( aJob->m_precision != 5 && aJob->m_precision != 6 )
108 {
109 wxFprintf( stderr, _( "Gerber coordinate precision should be either 5 or 6\n" ) );
111 }
112
113 return EXIT_CODES::OK;
114}
115
116
118{
119 int exitCode = EXPORT_PCB_BASE_COMMAND::doPerform( aKiway );
120 if( exitCode != EXIT_CODES::OK )
121 return exitCode;
122
123 std::unique_ptr<JOB_EXPORT_PCB_GERBER> gerberJob( new JOB_EXPORT_PCB_GERBER( true ) );
124
125 exitCode = populateJob( gerberJob.get() );
126 if( exitCode != EXIT_CODES::OK )
127 return exitCode;
128
130 exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, gerberJob.get() );
131
132 return exitCode;
133}
argparse::ArgumentParser m_argParser
Definition: command.h:68
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
int populateJob(JOB_EXPORT_PCB_GERBER *aJob)
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:660
@ 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:41
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_OUTPUT
#define ARG_INPUT
#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 _(s)
This file contains miscellaneous commonly used macros and functions.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
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.