KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_pdf.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 <string_utils.h>
26#include <wx/crt.h>
27
28#define ARG_MODE_SEPARATE "--mode-separate"
29#define ARG_MODE_MULTIPAGE "--mode-multipage"
30#define ARG_MODE_SINGLE "--mode-single"
31#define ARG_NO_PROPERTY_POPUPS "--no-property-popups"
32
35{
36 m_argParser.add_description( UTF8STDSTR( _( "Generate PDF from a list of layers" ) ) );
37
42
43 m_argParser.add_argument( "-m", ARG_MIRROR )
44 .help( UTF8STDSTR( _( "Mirror the board (useful for trying to show bottom layers)" ) ) )
45 .flag();
46
47 m_argParser.add_argument( "--erd", ARG_EXCLUDE_REFDES )
48 .help( UTF8STDSTR( _( "Exclude the reference designator text" ) ) )
49 .flag();
50
51 m_argParser.add_argument( "--ev", ARG_EXCLUDE_VALUE )
52 .help( UTF8STDSTR( _( "Exclude the value text" ) ) )
53 .flag();
54
55 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
56 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
57 .flag();
58
60 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
61 .flag();
62
63 m_argParser.add_argument( "--sp", ARG_SKETCH_PADS_ON_FAB_LAYERS )
65 .flag();
66
67 m_argParser.add_argument( "--hdnp", ARG_HIDE_DNP_FPS_ON_FAB_LAYERS )
69 .flag();
70
71 m_argParser.add_argument( "--sdnp", ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS )
73 .flag();
74
75 m_argParser.add_argument( "--cdnp", ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS )
77 .flag();
78
80 .help( UTF8STDSTR( _( ARG_NEGATIVE_DESC ) ) )
81 .flag();
82
83 m_argParser.add_argument( ARG_BLACKANDWHITE )
85 .flag();
86
87 m_argParser.add_argument( "-t", ARG_THEME )
88 .default_value( std::string() )
89 .help( UTF8STDSTR( _( "Color theme to use (will default to PCB Editor settings)" ) ) )
90 .metavar( "THEME_NAME" );
91
94 .scan<'i', int>()
95 .default_value( 2 );
96
97 m_argParser.add_argument( ARG_MODE_SINGLE )
98 .help( UTF8STDSTR(
99 _( "Generates a single file with the output arg path acting as the complete "
100 "directory and filename path. COMMON_LAYER_LIST does not function in this "
101 "mode. Instead LAYER_LIST controls all layers plotted." ) ) )
102 .flag();
103
104 m_argParser.add_argument( ARG_MODE_SEPARATE )
105 .help( UTF8STDSTR( _( "Plot the layers to individual PDF files" ) ) )
106 .flag();
107
108 m_argParser.add_argument( ARG_MODE_MULTIPAGE )
109 .help( UTF8STDSTR( _( "Plot the layers to a single PDF file with multiple pages" ) ) )
110 .flag();
111
112 m_argParser.add_argument( ARG_SCALE )
113 .help( UTF8STDSTR( _( ARG_SCALE_DESC ) ) )
114 .scan<'g', double>()
115 .default_value( 1.0 )
116 .metavar( "SCALE" );
117
118 m_argParser.add_argument( ARG_BACKGROUND_COLOR )
119 .default_value( std::string() )
121 .metavar( "COLOR" );
122
123 m_argParser.add_argument( ARG_CHECK_ZONES )
124 .help( UTF8STDSTR( _( ARG_CHECK_ZONES_DESC ) ) )
125 .flag();
126
127 m_argParser.add_argument( ARG_NO_PROPERTY_POPUPS )
128 .help( UTF8STDSTR( _( "Suppress footprint property popups" ) ) )
129 .flag();
130
132}
133
134
136{
137 std::unique_ptr<JOB_EXPORT_PCB_PDF> pdfJob( new JOB_EXPORT_PCB_PDF() );
138
139 pdfJob->m_filename = m_argInput;
140 pdfJob->SetConfiguredOutputPath( m_argOutput );
141 pdfJob->m_drawingSheet = m_argDrawingSheet;
142 pdfJob->SetVarOverrides( m_argDefineVars );
143
144 if( !m_argVariantNames.empty() )
145 pdfJob->m_variant = m_argVariantNames.front();
146
147 if( !wxFile::Exists( pdfJob->m_filename ) )
148 {
149 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
151 }
152
153 pdfJob->m_plotFootprintValues = !m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
154 pdfJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
155
156 pdfJob->m_plotDrawingSheet = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
157 pdfJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
158
159 pdfJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
160 pdfJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
161 pdfJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
162 pdfJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
163 pdfJob->m_scale = m_argParser.get<double>( ARG_SCALE );
164 pdfJob->m_checkZonesBeforePlot = m_argParser.get<bool>( ARG_CHECK_ZONES );
165
166 if( m_argParser.get<bool>( ARG_NO_PROPERTY_POPUPS ) )
167 {
168 pdfJob->m_pdfFrontFPPropertyPopups = false;
169 pdfJob->m_pdfBackFPPropertyPopups = false;
170 }
171
172 pdfJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
173 if( pdfJob->m_sketchPadsOnFabLayers )
174 pdfJob->m_plotPadNumbers = true;
175 pdfJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
176 pdfJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
177 pdfJob->m_crossoutDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS );
178
179 wxString bgColor = From_UTF8( m_argParser.get<std::string>( ARG_BACKGROUND_COLOR ).c_str() );
180 if( bgColor != wxEmptyString )
181 pdfJob->m_pdfBackgroundColor = bgColor;
182
183 int drillShape = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
184 pdfJob->m_drillShapeOption = static_cast<DRILL_MARKS>( drillShape );
185
186 bool argModeMulti = m_argParser.get<bool>( ARG_MODE_MULTIPAGE );
187 bool argModeSeparate = m_argParser.get<bool>( ARG_MODE_SEPARATE );
188 bool argModeSingle = m_argParser.get<bool>( ARG_MODE_SINGLE );
189
190 if( argModeMulti && argModeSeparate )
191 {
192 wxFprintf( stderr, _( "Cannot use more than one mode flag\n" ) );
194 }
195
196 pdfJob->m_argLayers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
197 pdfJob->m_argCommonLayers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
198
199 if( argModeMulti )
200 {
202 pdfJob->m_pdfSingle = true;
203 }
204 else if( argModeSeparate )
206 else if( argModeSingle )
208
209 return aKiway.ProcessJob( KIWAY::FACE_PCB, pdfJob.get() );
210}
std::map< wxString, wxString > m_argDefineVars
Value of the drawing sheet arg if configured.
Definition command.h:158
void addVariantsArg()
Set up the list of variants to output arguement.
Definition command.cpp:227
argparse::ArgumentParser m_argParser
Definition command.h:113
void addDefineArg()
Set up the drawing sheet arg used by many of the export commands.
Definition command.cpp:212
wxString m_argDrawingSheet
Value of the drawing sheet arg if configured.
Definition command.h:153
wxString m_argOutput
Value of the output arg if configured.
Definition command.h:148
wxString m_argInput
Value of the common input arg if configured.
Definition command.h:143
std::vector< wxString > m_argVariantNames
The list of variant names to output.
Definition command.h:170
void addDrawingSheetArg()
Set up the drawing sheet arg used by many of the export commands.
Definition command.cpp:200
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
@ ALL_LAYERS_ONE_FILE
DEPRECATED MODE.
@ ONE_PAGE_PER_LAYER_ONE_FILE
The most traditional output mode KiCad has had.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:315
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:750
@ FACE_PCB
pcbnew DSO
Definition kiway.h:323
#define UTF8STDSTR(s)
Definition command.h:27
#define ARG_SKETCH_PADS_ON_FAB_LAYERS_DESC
#define ARG_THEME
#define ARG_NEGATIVE
#define ARG_INCLUDE_BORDER_TITLE
#define ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS_DESC
#define ARG_CHECK_ZONES_DESC
#define ARG_SKETCH_PADS_ON_FAB_LAYERS
#define ARG_COMMON_LAYERS
#define ARG_SCALE_DESC
#define ARG_SCALE
#define ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS_DESC
#define ARG_EXCLUDE_REFDES
#define ARG_BLACKANDWHITE_DESC
#define ARG_CHECK_ZONES
#define ARG_NEGATIVE_SHORT
#define ARG_EXCLUDE_VALUE
#define ARG_BACKGROUND_COLOR
#define ARG_BLACKANDWHITE
#define ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS
#define ARG_MIRROR
#define ARG_HIDE_DNP_FPS_ON_FAB_LAYERS
#define ARG_SUBTRACT_SOLDERMASK
#define ARG_BACKGROUND_COLOR_DESC
#define ARG_DRILL_SHAPE_OPTION_DESC
#define ARG_LAYERS
#define ARG_HIDE_DNP_FPS_ON_FAB_LAYERS_DESC
#define ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS
#define ARG_DRILL_SHAPE_OPTION
#define ARG_NEGATIVE_DESC
#define ARG_MODE_SINGLE
#define ARG_MODE_MULTIPAGE
#define ARG_MODE_SEPARATE
#define ARG_NO_PROPERTY_POPUPS
#define _(s)
static const int ERR_ARGS
Definition exit_codes.h:31
static const int ERR_INVALID_INPUT_FILE
Definition exit_codes.h:33
DRILL_MARKS
Plots and prints can show holes in pads and vias 3 options are available:
wxString From_UTF8(const char *cstring)
PCB_EXPORT_BASE_COMMAND(const std::string &aName, IO_TYPE aInputType=IO_TYPE::FILE, IO_TYPE aOutputType=IO_TYPE::FILE)