KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_png.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21#include <cli/exit_codes.h>
24#include <kiface_base.h>
26#include <string_utils.h>
27#include <wx/crt.h>
28#include <wx/file.h>
29
30
31#define ARG_DPI "--dpi"
32#define ARG_NO_ANTIALIAS "--no-antialias"
33
36{
37 m_argParser.add_description( UTF8STDSTR( _( "Generate PNG outputs of a given layer list" ) ) );
38
43
45 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
46 .flag();
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( "-t", ARG_THEME )
53 .default_value( std::string() )
54 .help( UTF8STDSTR( _( "Color theme to use (will default to PCB editor settings)" ) ) )
55 .metavar( "THEME_NAME" );
56
58 .help( UTF8STDSTR( _( ARG_NEGATIVE_DESC ) ) )
59 .flag();
60
61 m_argParser.add_argument( ARG_BLACKANDWHITE )
63 .flag();
64
65 m_argParser.add_argument( "--sp", ARG_SKETCH_PADS_ON_FAB_LAYERS )
67 .flag();
68
69 m_argParser.add_argument( "--hdnp", ARG_HIDE_DNP_FPS_ON_FAB_LAYERS )
71 .flag();
72
73 m_argParser.add_argument( "--sdnp", ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS )
75 .flag();
76
77 m_argParser.add_argument( "--cdnp", ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS )
79 .flag();
80
81 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
82 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
83 .flag();
84
87 .scan<'i', int>()
88 .default_value( 2 )
89 .metavar( "SHAPE_OPTION" );
90
91 m_argParser.add_argument( ARG_SCALE )
92 .help( UTF8STDSTR( _( ARG_SCALE_DESC ) ) )
93 .scan<'g', double>()
94 .default_value( 1.0 )
95 .metavar( "SCALE" );
96
97 m_argParser.add_argument( ARG_DPI )
98 .help( UTF8STDSTR( wxString::Format( _( "Resolution in dots per inch (default %d)" ),
99 DEFAULT_PNG_DPI ) ) )
100 .scan<'i', int>()
101 .default_value( DEFAULT_PNG_DPI )
102 .metavar( "DPI" );
103
104 m_argParser.add_argument( ARG_NO_ANTIALIAS )
105 .help( UTF8STDSTR( _( "Disable anti-aliasing" ) ) )
106 .flag();
107
108 m_argParser.add_argument( ARG_CHECK_ZONES )
109 .help( UTF8STDSTR( _( ARG_CHECK_ZONES_DESC ) ) )
110 .flag();
111
113}
114
115
117{
118 std::unique_ptr<JOB_EXPORT_PCB_PNG> pngJob( new JOB_EXPORT_PCB_PNG() );
119
120 pngJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
121 pngJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
122 pngJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
123 pngJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
124
125 if( pngJob->m_sketchPadsOnFabLayers )
126 pngJob->m_plotPadNumbers = true;
127
128 pngJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
129 pngJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
130 pngJob->m_crossoutDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS );
131 int drillShape = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
132 pngJob->m_drillShapeOption = static_cast<DRILL_MARKS>( drillShape );
133 pngJob->m_drawingSheet = m_argDrawingSheet;
134 pngJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
135 pngJob->m_scale = m_argParser.get<double>( ARG_SCALE );
136 pngJob->m_checkZonesBeforePlot = m_argParser.get<bool>( ARG_CHECK_ZONES );
137 int dpi = m_argParser.get<int>( ARG_DPI );
138
139 if( dpi < MIN_PNG_DPI || dpi > MAX_PNG_DPI )
140 {
141 wxFprintf( stderr, _( "DPI must be between %d and %d\n" ), MIN_PNG_DPI, MAX_PNG_DPI );
143 }
144
145 pngJob->m_dpi = dpi;
146 pngJob->m_antialias = !m_argParser.get<bool>( ARG_NO_ANTIALIAS );
147
148 pngJob->m_filename = m_argInput;
149 pngJob->SetConfiguredOutputPath( m_argOutput );
150 pngJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
151
153 pngJob->m_plotDrawingSheet = true;
154
155 pngJob->SetVarOverrides( m_argDefineVars );
156
157 if( !m_argVariantNames.empty() )
158 pngJob->m_variant = m_argVariantNames.front();
159
160 pngJob->m_argLayers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
161 pngJob->m_argCommonLayers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
162
163 if( !wxFile::Exists( pngJob->m_filename ) )
164 {
165 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
167 }
168
169 return aKiway.ProcessJob( KIWAY::FACE_PCB, pngJob.get() );
170}
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
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_NO_ANTIALIAS
#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_BLACKANDWHITE_DESC
#define ARG_CHECK_ZONES
#define ARG_NEGATIVE_SHORT
#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 _(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:
constexpr int DEFAULT_PNG_DPI
Definition plotter_png.h:28
constexpr int MIN_PNG_DPI
Definition plotter_png.h:29
constexpr int MAX_PNG_DPI
Definition plotter_png.h:30
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)
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.