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
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
96 m_argParser.add_argument( ARG_MODE_SINGLE )
97 .help( UTF8STDSTR(
98 _( "Generates a single file with the output arg path acting as the complete "
99 "directory and filename path. COMMON_LAYER_LIST does not function in this "
100 "mode. Instead LAYER_LIST controls all layers plotted." ) ) )
101 .flag();
102
103 m_argParser.add_argument( ARG_MODE_SEPARATE )
104 .help( UTF8STDSTR( _( "Plot the layers to individual PDF files" ) ) )
105 .flag();
106
107 m_argParser.add_argument( ARG_MODE_MULTIPAGE )
108 .help( UTF8STDSTR( _( "Plot the layers to a single PDF file with multiple pages" ) ) )
109 .flag();
110
111 m_argParser.add_argument( ARG_SCALE )
112 .help( UTF8STDSTR( _( ARG_SCALE_DESC ) ) )
113 .scan<'g', double>()
114 .default_value( 1.0 )
115 .metavar( "SCALE" );
116
117 m_argParser.add_argument( ARG_BACKGROUND_COLOR )
118 .default_value( std::string() )
120 .metavar( "COLOR" );
121
122 m_argParser.add_argument( ARG_CHECK_ZONES )
123 .help( UTF8STDSTR( _( ARG_CHECK_ZONES_DESC ) ) )
124 .flag();
125}
126
127
129{
130 std::unique_ptr<JOB_EXPORT_PCB_PDF> pdfJob( new JOB_EXPORT_PCB_PDF() );
131
132 pdfJob->m_filename = m_argInput;
133 pdfJob->SetConfiguredOutputPath( m_argOutput );
134 pdfJob->m_drawingSheet = m_argDrawingSheet;
135 pdfJob->SetVarOverrides( m_argDefineVars );
136
137 if( !wxFile::Exists( pdfJob->m_filename ) )
138 {
139 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
141 }
142
143 pdfJob->m_plotFootprintValues = !m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
144 pdfJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
145
146 pdfJob->m_plotDrawingSheet = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
147 pdfJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
148
149 pdfJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
150 pdfJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
151 pdfJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
152 pdfJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
153 pdfJob->m_scale = m_argParser.get<double>( ARG_SCALE );
154 pdfJob->m_checkZonesBeforePlot = m_argParser.get<bool>( ARG_CHECK_ZONES );
155
156 pdfJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
157 if( pdfJob->m_sketchPadsOnFabLayers )
158 pdfJob->m_plotPadNumbers = true;
159 pdfJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
160 pdfJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
161 pdfJob->m_crossoutDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS );
162
163 wxString bgColor = From_UTF8( m_argParser.get<std::string>( ARG_BACKGROUND_COLOR ).c_str() );
164 if( bgColor != wxEmptyString )
165 pdfJob->m_pdfBackgroundColor = bgColor;
166
167 int drillShape = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
168 pdfJob->m_drillShapeOption = static_cast<DRILL_MARKS>( drillShape );
169
170 bool argModeMulti = m_argParser.get<bool>( ARG_MODE_MULTIPAGE );
171 bool argModeSeparate = m_argParser.get<bool>( ARG_MODE_SEPARATE );
172 bool argModeSingle = m_argParser.get<bool>( ARG_MODE_SINGLE );
173
174 if( argModeMulti && argModeSeparate )
175 {
176 wxFprintf( stderr, _( "Cannot use more than one mode flag\n" ) );
178 }
179
180 pdfJob->m_argLayers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
181 pdfJob->m_argCommonLayers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
182
183 if( argModeMulti )
184 {
186 pdfJob->m_pdfSingle = true;
187 }
188 else if( argModeSeparate )
190 else if( argModeSingle )
192
193 return aKiway.ProcessJob( KIWAY::FACE_PCB, pdfJob.get() );
194}
std::map< wxString, wxString > m_argDefineVars
Value of the drawing sheet arg if configured.
Definition command.h:158
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
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:295
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:744
@ FACE_PCB
pcbnew DSO
Definition kiway.h:303
#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 _(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)