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
33 PCB_EXPORT_BASE_COMMAND( "pdf", false, true )
34{
35 m_argParser.add_description( UTF8STDSTR( _( "Generate PDF from a list of layers" ) ) );
36
41
42 m_argParser.add_argument( "-m", ARG_MIRROR )
43 .help( UTF8STDSTR( _( "Mirror the board (useful for trying to show bottom layers)" ) ) )
44 .flag();
45
46 m_argParser.add_argument( "--erd", ARG_EXCLUDE_REFDES )
47 .help( UTF8STDSTR( _( "Exclude the reference designator text" ) ) )
48 .flag();
49
50 m_argParser.add_argument( "--ev", ARG_EXCLUDE_VALUE )
51 .help( UTF8STDSTR( _( "Exclude the value text" ) ) )
52 .flag();
53
54 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
55 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
56 .flag();
57
59 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
60 .flag();
61
62 m_argParser.add_argument( "--sp", ARG_SKETCH_PADS_ON_FAB_LAYERS )
64 .flag();
65
66 m_argParser.add_argument( "--hdnp", ARG_HIDE_DNP_FPS_ON_FAB_LAYERS )
68 .flag();
69
70 m_argParser.add_argument( "--sdnp", ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS )
72 .flag();
73
74 m_argParser.add_argument( "--cdnp", ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS )
76 .flag();
77
79 .help( UTF8STDSTR( _( ARG_NEGATIVE_DESC ) ) )
80 .flag();
81
82 m_argParser.add_argument( ARG_BLACKANDWHITE )
84 .flag();
85
86 m_argParser.add_argument( "-t", ARG_THEME )
87 .default_value( std::string() )
88 .help( UTF8STDSTR( _( "Color theme to use (will default to PCB Editor settings)" ) ) )
89 .metavar( "THEME_NAME" );
90
93 .scan<'i', int>()
94 .default_value( 2 );
95
98 .flag();
99
100 m_argParser.add_argument( ARG_MODE_SINGLE )
101 .help( UTF8STDSTR(
102 _( "Generates a single file with the output arg path acting as the complete "
103 "directory and filename path. COMMON_LAYER_LIST does not function in this "
104 "mode. Instead LAYER_LIST controls all layers plotted." ) ) )
105 .flag();
106
107 m_argParser.add_argument( ARG_MODE_SEPARATE )
108 .help( UTF8STDSTR( _( "Plot the layers to individual PDF files" ) ) )
109 .flag();
110
111 m_argParser.add_argument( ARG_MODE_MULTIPAGE )
112 .help( UTF8STDSTR( _( "Plot the layers to a single PDF file with multiple pages" ) ) )
113 .flag();
114
115 m_argParser.add_argument( ARG_SCALE )
116 .help( UTF8STDSTR( _( ARG_SCALE_DESC ) ) )
117 .scan<'g', double>()
118 .default_value( 1.0 )
119 .metavar( "SCALE" );
120
121 m_argParser.add_argument( ARG_BACKGROUND_COLOR )
122 .default_value( std::string() )
124 .metavar( "COLOR" );
125
126 m_argParser.add_argument( ARG_CHECK_ZONES )
127 .help( UTF8STDSTR( _( ARG_CHECK_ZONES_DESC ) ) )
128 .flag();
129}
130
131
133{
134 std::unique_ptr<JOB_EXPORT_PCB_PDF> pdfJob( new JOB_EXPORT_PCB_PDF() );
135
136 pdfJob->m_filename = m_argInput;
137 pdfJob->SetConfiguredOutputPath( m_argOutput );
138 pdfJob->m_drawingSheet = m_argDrawingSheet;
139 pdfJob->SetVarOverrides( m_argDefineVars );
140
141 if( !wxFile::Exists( pdfJob->m_filename ) )
142 {
143 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
145 }
146
147 pdfJob->m_plotFootprintValues = !m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
148 pdfJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
149
150 pdfJob->m_plotDrawingSheet = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
151 pdfJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
152
155
156 pdfJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
157 pdfJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
158 pdfJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
159 pdfJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
160 pdfJob->m_scale = m_argParser.get<double>( ARG_SCALE );
161 pdfJob->m_checkZonesBeforePlot = m_argParser.get<bool>( ARG_CHECK_ZONES );
162
163 pdfJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
164 pdfJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
165 pdfJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
166 pdfJob->m_crossoutDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS );
167
168 wxString bgColor = From_UTF8( m_argParser.get<std::string>( ARG_BACKGROUND_COLOR ).c_str() );
169 if( bgColor != wxEmptyString )
170 pdfJob->m_pdfBackgroundColor = bgColor;
171
172 int drillShape = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
173 pdfJob->m_drillShapeOption = static_cast<DRILL_MARKS>( drillShape );
174
175 bool argModeMulti = m_argParser.get<bool>( ARG_MODE_MULTIPAGE );
176 bool argModeSeparate = m_argParser.get<bool>( ARG_MODE_SEPARATE );
177 bool argModeSingle = m_argParser.get<bool>( ARG_MODE_SINGLE );
178
179 if( argModeMulti && argModeSeparate )
180 {
181 wxFprintf( stderr, _( "Cannot use more than one mode flag\n" ) );
183 }
184
185 pdfJob->m_argLayers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
186 pdfJob->m_argCommonLayers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
187
188 if( argModeMulti )
189 {
191 pdfJob->m_pdfSingle = true;
192 }
193 else if( argModeSeparate )
195 else if( argModeSingle )
197
198 return aKiway.ProcessJob( KIWAY::FACE_PCB, pdfJob.get() );
199}
std::map< wxString, wxString > m_argDefineVars
Value of the drawing sheet arg if configured.
Definition command.h:145
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:168
wxString m_argDrawingSheet
Value of the drawing sheet arg if configured.
Definition command.h:140
wxString m_argOutput
Value of the output arg if configured.
Definition command.h:135
wxString m_argInput
Value of the common input arg if configured.
Definition command.h:130
void addDrawingSheetArg()
Set up the drawing sheet arg used by many of the export commands.
Definition command.cpp:156
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:286
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:701
@ FACE_PCB
pcbnew DSO
Definition kiway.h:294
#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 DEPRECATED_ARG_PLOT_INVISIBLE_TEXT
#define ARG_HIDE_DNP_FPS_ON_FAB_LAYERS
#define DEPRECATED_ARG_PLOT_INVISIBLE_TEXT_WARNING
#define ARG_SUBTRACT_SOLDERMASK
#define ARG_BACKGROUND_COLOR_DESC
#define ARG_DRILL_SHAPE_OPTION_DESC
#define DEPRECATED_ARG_PLOT_INVISIBLE_TEXT_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 _(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, bool aInputCanBeDir=false, bool aOutputIsDir=false)