KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_ps.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
21#include <base_units.h>
23#include <cli/exit_codes.h>
25#include <kiface_base.h>
26#include <string_utils.h>
27#include <wx/crt.h>
28
29#include <locale_io.h>
30
31#define ARG_MODE_SINGLE "--mode-single"
32#define ARG_MODE_MULTI "--mode-multi"
33#define ARG_TRACK_WIDTH_CORRECTION "--track-width-correction"
34#define ARG_X_SCALE_FACTOR "--x-scale-factor"
35#define ARG_Y_SCALE_FACTOR "--y-scale-factor"
36#define ARG_FORCE_A4 "--force-a4"
37
39 PCB_EXPORT_BASE_COMMAND( "ps", false, true )
40{
41 m_argParser.add_description( UTF8STDSTR( _( "Generate Postscript from a list of layers" ) ) );
42
47
48 m_argParser.add_argument( "-m", ARG_MIRROR )
49 .help( UTF8STDSTR( _( "Mirror the board (useful for trying to show bottom layers)" ) ) )
50 .flag();
51
52 m_argParser.add_argument( "--erd", ARG_EXCLUDE_REFDES )
53 .help( UTF8STDSTR( _( "Exclude the reference designator text" ) ) )
54 .flag();
55
56 m_argParser.add_argument( "--ev", ARG_EXCLUDE_VALUE )
57 .help( UTF8STDSTR( _( "Exclude the value text" ) ) )
58 .flag();
59
60 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
61 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
62 .flag();
63
65 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
66 .flag();
67
68 m_argParser.add_argument( "--sp", ARG_SKETCH_PADS_ON_FAB_LAYERS )
70 .flag();
71
72 m_argParser.add_argument( "--hdnp", ARG_HIDE_DNP_FPS_ON_FAB_LAYERS )
74 .flag();
75
76 m_argParser.add_argument( "--sdnp", ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS )
78 .flag();
79
80 m_argParser.add_argument( "--cdnp", ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS )
82 .flag();
83
85 .help( UTF8STDSTR( _( ARG_NEGATIVE_DESC ) ) )
86 .flag();
87
88 m_argParser.add_argument( ARG_BLACKANDWHITE )
90 .flag();
91
92 m_argParser.add_argument( "-t", ARG_THEME )
93 .default_value( std::string() )
94 .help( UTF8STDSTR( _( "Color theme to use (will default to PCB Editor settings)" ) ) )
95 .metavar( "THEME_NAME" );
96
99 .scan<'i', int>()
100 .default_value( 2 );
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_MULTI )
110 .help( UTF8STDSTR( _( "Generates one or more files with behavior similar to the KiCad "
111 "GUI plotting. The given output path specifies a directory in "
112 "which files may be output." ) ) )
113 .flag();
114
115 m_argParser.add_argument( "-C", ARG_TRACK_WIDTH_CORRECTION )
116 .help( UTF8STDSTR( _( "Track width correction [mm]. Used to compensate errors in "
117 "track widths, pad and via sizes." ) ) )
118 .scan<'g', double>()
119 .default_value( 0.0 )
120 .metavar( "TRACK_COR" );
121
122 m_argParser.add_argument( "-X", ARG_X_SCALE_FACTOR )
123 .help( UTF8STDSTR( _( "X scale adjust for exact scale." ) ) )
124 .scan<'g', double>()
125 .default_value( 1.0 )
126 .metavar( "X_SCALE" );
127
128 m_argParser.add_argument( "-Y", ARG_Y_SCALE_FACTOR )
129 .help( UTF8STDSTR( _( "Y scale adjust for exact scale." ) ) )
130 .scan<'g', double>()
131 .default_value( 1.0 )
132 .metavar( "Y_SCALE" );
133
134 m_argParser.add_argument( "-A", ARG_FORCE_A4 )
135 .help( UTF8STDSTR( _( "Force A4 paper size." ) ) )
136 .flag();
137
138 m_argParser.add_argument( ARG_SCALE )
139 .help( UTF8STDSTR( _( ARG_SCALE_DESC ) ) )
140 .scan<'g', double>()
141 .default_value( 1.0 )
142 .metavar( "SCALE" );
143}
144
145
147{
148 std::unique_ptr<JOB_EXPORT_PCB_PS> psJob( new JOB_EXPORT_PCB_PS() );
149
150 psJob->m_filename = m_argInput;
151 psJob->SetConfiguredOutputPath( m_argOutput );
152 psJob->m_drawingSheet = m_argDrawingSheet;
153 psJob->SetVarOverrides( m_argDefineVars );
154
155 if( !wxFile::Exists( psJob->m_filename ) )
156 {
157 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
159 }
160
161 psJob->m_plotFootprintValues = !m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
162 psJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
163
164 psJob->m_plotDrawingSheet = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
165 psJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
166 psJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
167 psJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
168 psJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
169 psJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
170 psJob->m_scale = m_argParser.get<double>( ARG_SCALE );
171
172 psJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
173 psJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
174 psJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
175 psJob->m_crossoutDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS );
176
177 int drillShape = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
178 psJob->m_drillShapeOption = static_cast<DRILL_MARKS>( drillShape );
179
180 psJob->m_argLayers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
181 psJob->m_argCommonLayers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
182
183 if( m_argParser.get<bool>( ARG_MODE_MULTI ) )
184 psJob->m_genMode = JOB_EXPORT_PCB_PS::GEN_MODE::MULTI;
185 else if( m_argParser.get<bool>( ARG_MODE_SINGLE ) )
186 psJob->m_genMode = JOB_EXPORT_PCB_PS::GEN_MODE::SINGLE;
187
188 psJob->m_trackWidthCorrection = m_argParser.get<double>( ARG_TRACK_WIDTH_CORRECTION );
189 psJob->m_XScaleAdjust = m_argParser.get<double>( ARG_X_SCALE_FACTOR );
190 psJob->m_YScaleAdjust = m_argParser.get<double>( ARG_Y_SCALE_FACTOR );
191 psJob->m_forceA4 = m_argParser.get<bool>( ARG_FORCE_A4 );
192
193 LOCALE_IO dummy; // Switch to "C" locale
194 return aKiway.ProcessJob( KIWAY::FACE_PCB, psJob.get() );
195}
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.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:285
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:293
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr)
Definition: kiway.cpp:678
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_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_NEGATIVE_SHORT
#define ARG_EXCLUDE_VALUE
#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_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_MULTI
#define ARG_MODE_SINGLE
#define ARG_FORCE_A4
#define ARG_Y_SCALE_FACTOR
#define ARG_X_SCALE_FACTOR
#define ARG_TRACK_WIDTH_CORRECTION
#define _(s)
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)