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#include <locale_io.h>
29
30#define ARG_MODE_SEPARATE "--mode-separate"
31#define ARG_MODE_MULTIPAGE "--mode-multipage"
32#define ARG_MODE_SINGLE "--mode-single"
33
35 PCB_EXPORT_BASE_COMMAND( "pdf", false, true )
36{
37 m_argParser.add_description( UTF8STDSTR( _( "Generate PDF from a list of layers" ) ) );
38
43
44 m_argParser.add_argument( "-m", ARG_MIRROR )
45 .help( UTF8STDSTR( _( "Mirror the board (useful for trying to show bottom layers)" ) ) )
46 .flag();
47
48 m_argParser.add_argument( "--erd", ARG_EXCLUDE_REFDES )
49 .help( UTF8STDSTR( _( "Exclude the reference designator text" ) ) )
50 .flag();
51
52 m_argParser.add_argument( "--ev", ARG_EXCLUDE_VALUE )
53 .help( UTF8STDSTR( _( "Exclude the value text" ) ) )
54 .flag();
55
56 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
57 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
58 .flag();
59
61 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
62 .flag();
63
64 m_argParser.add_argument( "--sp", ARG_SKETCH_PADS_ON_FAB_LAYERS )
66 .flag();
67
68 m_argParser.add_argument( "--hdnp", ARG_HIDE_DNP_FPS_ON_FAB_LAYERS )
70 .flag();
71
72 m_argParser.add_argument( "--sdnp", ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS )
74 .flag();
75
76 m_argParser.add_argument( "--cdnp", ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS )
78 .flag();
79
81 .help( UTF8STDSTR( _( ARG_NEGATIVE_DESC ) ) )
82 .flag();
83
84 m_argParser.add_argument( ARG_BLACKANDWHITE )
86 .flag();
87
88 m_argParser.add_argument( "-t", ARG_THEME )
89 .default_value( std::string() )
90 .help( UTF8STDSTR( _( "Color theme to use (will default to PCB Editor settings)" ) ) )
91 .metavar( "THEME_NAME" );
92
95 .scan<'i', int>()
96 .default_value( 2 );
97
100 .flag();
101
102 m_argParser.add_argument( ARG_MODE_SINGLE )
103 .help( UTF8STDSTR(
104 _( "Generates a single file with the output arg path acting as the complete "
105 "directory and filename path. COMMON_LAYER_LIST does not function in this "
106 "mode. Instead LAYER_LIST controls all layers plotted." ) ) )
107 .flag();
108
109 m_argParser.add_argument( ARG_MODE_SEPARATE )
110 .help( UTF8STDSTR( _( "Plot the layers to individual PDF files" ) ) )
111 .flag();
112
113 m_argParser.add_argument( ARG_MODE_MULTIPAGE )
114 .help( UTF8STDSTR( _( "Plot the layers to a single PDF file with multiple pages" ) ) )
115 .flag();
116
117 m_argParser.add_argument( ARG_SCALE )
118 .help( UTF8STDSTR( _( ARG_SCALE_DESC ) ) )
119 .scan<'g', double>()
120 .default_value( 1.0 )
121 .metavar( "SCALE" );
122
123 m_argParser.add_argument( ARG_BACKGROUND_COLOR )
124 .default_value( std::string() )
126 .metavar( "COLOR" );
127
128 m_argParser.add_argument( ARG_CHECK_ZONES )
129 .help( UTF8STDSTR( _( ARG_CHECK_ZONES_DESC ) ) )
130 .flag();
131}
132
133
135{
136 std::unique_ptr<JOB_EXPORT_PCB_PDF> pdfJob( new JOB_EXPORT_PCB_PDF() );
137
138 pdfJob->m_filename = m_argInput;
139 pdfJob->SetConfiguredOutputPath( m_argOutput );
140 pdfJob->m_drawingSheet = m_argDrawingSheet;
141 pdfJob->SetVarOverrides( m_argDefineVars );
142
143 if( !wxFile::Exists( pdfJob->m_filename ) )
144 {
145 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
147 }
148
149 pdfJob->m_plotFootprintValues = !m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
150 pdfJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
151
152 pdfJob->m_plotDrawingSheet = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
153 pdfJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
154
155 if( m_argParser.get<bool>( DEPRECATED_ARG_PLOT_INVISIBLE_TEXT ) )
157
158 pdfJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
159 pdfJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
160 pdfJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
161 pdfJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
162 pdfJob->m_scale = m_argParser.get<double>( ARG_SCALE );
163 pdfJob->m_checkZonesBeforePlot = m_argParser.get<bool>( ARG_CHECK_ZONES );
164
165 pdfJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
166 pdfJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
167 pdfJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
168 pdfJob->m_crossoutDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS );
169
170 wxString bgColor = From_UTF8( m_argParser.get<std::string>( ARG_BACKGROUND_COLOR ).c_str() );
171 if( bgColor != wxEmptyString )
172 pdfJob->m_pdfBackgroundColor = bgColor;
173
174 int drillShape = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
175 pdfJob->m_drillShapeOption = static_cast<DRILL_MARKS>( drillShape );
176
177 bool argModeMulti = m_argParser.get<bool>( ARG_MODE_MULTIPAGE );
178 bool argModeSeparate = m_argParser.get<bool>( ARG_MODE_SEPARATE );
179 bool argModeSingle = m_argParser.get<bool>( ARG_MODE_SINGLE );
180
181 if( argModeMulti && argModeSeparate )
182 {
183 wxFprintf( stderr, _( "Cannot use more than one mode flag\n" ) );
185 }
186
187 pdfJob->m_argLayers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
188 pdfJob->m_argCommonLayers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
189
190 if( argModeMulti )
191 {
193 pdfJob->m_pdfSingle = true;
194 }
195 else if( argModeSeparate )
197 else if( argModeSingle )
199
200 LOCALE_IO dummy; // Switch to "C" locale
201 return aKiway.ProcessJob( KIWAY::FACE_PCB, pdfJob.get() );
202}
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
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:678
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:294
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_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_ARD_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:
std::vector< FAB_LAYER_COLOR > dummy
wxString From_UTF8(const char *cstring)