KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_svg.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 (C) 2016 Cirilo Bernardo <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
23#include <cli/exit_codes.h>
26#include <kiface_base.h>
27#include <string_utils.h>
28#include <regex>
29#include <wx/crt.h>
30
31
32#define ARG_EXCLUDE_DRAWING_SHEET "--exclude-drawing-sheet"
33#define ARG_PAGE_SIZE "--page-size-mode"
34#define ARG_FIT_PAGE_TO_BOARD "--fit-page-to-board"
35#define ARG_MODE_SINGLE "--mode-single"
36#define ARG_MODE_MULTI "--mode-multi"
37
39 PCB_EXPORT_BASE_COMMAND( "svg", false, true )
40{
41 m_argParser.add_description( UTF8STDSTR( _( "Generate SVG outputs of a given layer list" ) ) );
42
47
49 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
50 .flag();
51
52 m_argParser.add_argument( "-m", ARG_MIRROR )
53 .help( UTF8STDSTR( _( "Mirror the board (useful for trying to show bottom layers)" ) ) )
54 .flag();
55
56 m_argParser.add_argument( "-t", ARG_THEME )
57 .default_value( std::string() )
58 .help( UTF8STDSTR( _( "Color theme to use (will default to PCB editor settings)" ) ) )
59 .metavar( "THEME_NAME" );
60
62 .help( UTF8STDSTR( _( ARG_NEGATIVE_DESC ) ) )
63 .flag();
64
65 m_argParser.add_argument( ARG_BLACKANDWHITE )
67 .flag();
68
69 m_argParser.add_argument( "--sp", ARG_SKETCH_PADS_ON_FAB_LAYERS )
71 .flag();
72
73 m_argParser.add_argument( "--hdnp", ARG_HIDE_DNP_FPS_ON_FAB_LAYERS )
75 .flag();
76
77 m_argParser.add_argument( "--sdnp", ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS )
79 .flag();
80
81 m_argParser.add_argument( "--cdnp", ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS )
83 .flag();
84
85 m_argParser.add_argument( ARG_PAGE_SIZE )
86 .help( UTF8STDSTR( _( "Set page sizing mode (0 = page with frame and title block, 1 = "
87 "current page size, 2 = board area only)" ) ) )
88 .scan<'i', int>()
89 .default_value( 0 )
90 .metavar( "MODE" );
91
93 .help( UTF8STDSTR( _( "Fit the page to the board" ) ) )
94 .flag();
95
97 .help( UTF8STDSTR( _( "No drawing sheet" ) ) )
98 .flag();
99
100 m_argParser.add_argument( ARG_DRILL_SHAPE_OPTION )
102 .scan<'i', int>()
103 .default_value( 2 )
104 .metavar( "SHAPE_OPTION" );
105
106 m_argParser.add_argument( ARG_MODE_SINGLE )
107 .help( UTF8STDSTR(
108 _( "Generates a single file with the output arg path acting as the complete "
109 "directory and filename path. COMMON_LAYER_LIST does not function in this "
110 "mode. Instead LAYER_LIST controls all layers plotted." ) ) )
111 .flag();
112
113 m_argParser.add_argument( ARG_MODE_MULTI )
114 .help( UTF8STDSTR( _( "Generates one or more files with behavior similar to the KiCad "
115 "GUI plotting. The given output path specifies a directory in "
116 "which files may be output." ) ) )
117 .flag();
118
121 .flag();
122
123 m_argParser.add_argument( ARG_SCALE )
124 .help( UTF8STDSTR( _( ARG_SCALE_DESC ) ) )
125 .scan<'g', double>()
126 .default_value( 1.0 )
127 .metavar( "SCALE" );
128}
129
130
132{
133 std::unique_ptr<JOB_EXPORT_PCB_SVG> svgJob( new JOB_EXPORT_PCB_SVG() );
134
135 svgJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
136 svgJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
137 svgJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
138 svgJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
139 svgJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
140 svgJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
141 svgJob->m_crossoutDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS );
142 int drillShape = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
143 svgJob->m_drillShapeOption = static_cast<DRILL_MARKS>( drillShape );
144 svgJob->m_drawingSheet = m_argDrawingSheet;
145 svgJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
146 svgJob->m_scale = m_argParser.get<double>( ARG_SCALE );
147
148 if( m_argParser.get<bool>( DEPRECATED_ARG_PLOT_INVISIBLE_TEXT ) )
150
151 svgJob->m_fitPageToBoard = m_argParser.get<bool>( ARG_FIT_PAGE_TO_BOARD );
152
153 // legacy compat, should eliminate this arg eventually
154 int legacyPageSizeMode = m_argParser.get<int>( ARG_PAGE_SIZE );
155
156 if( legacyPageSizeMode == 0 )
157 {
158 svgJob->m_plotDrawingSheet = true;
159 }
160 else if( legacyPageSizeMode == 1 )
161 {
162 svgJob->m_plotDrawingSheet = false;
163 }
164 else if( legacyPageSizeMode == 2 )
165 {
166 svgJob->m_fitPageToBoard = true;
167 svgJob->m_plotDrawingSheet = false;
168 }
169
170 svgJob->m_filename = m_argInput;
171 svgJob->SetConfiguredOutputPath( m_argOutput );
172 svgJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
173 svgJob->m_plotDrawingSheet = !m_argParser.get<bool>( ARG_EXCLUDE_DRAWING_SHEET );
174 svgJob->SetVarOverrides( m_argDefineVars );
175
176 svgJob->m_argLayers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
177 svgJob->m_argCommonLayers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
178
179 if( !wxFile::Exists( svgJob->m_filename ) )
180 {
181 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
183 }
184
185 if( m_argParser.get<bool>( ARG_MODE_MULTI ) )
186 svgJob->m_genMode = JOB_EXPORT_PCB_SVG::GEN_MODE::MULTI;
187 else if( m_argParser.get<bool>( ARG_MODE_SINGLE ) )
188 svgJob->m_genMode = JOB_EXPORT_PCB_SVG::GEN_MODE::SINGLE;
189 else if( svgJob->m_genMode == JOB_EXPORT_PCB_SVG::GEN_MODE::SINGLE )
190 {
191 // TODO remove this block when changing the default for JOB_EXPORT_PCB_SVG::m_genMode
192 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
193 _( "This command has deprecated behavior as of KiCad 9.0, the default behavior "
194 "of this command will change in a future release." ) );
195
196 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
197 _( "The new behavior will match --mode-multi" ) );
198 }
199
200 return aKiway.ProcessJob( KIWAY::FACE_PCB, svgJob.get() );
201}
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
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
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_SKETCH_PADS_ON_FAB_LAYERS_DESC
#define ARG_THEME
#define ARG_NEGATIVE
#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_BLACKANDWHITE_DESC
#define ARG_NEGATIVE_SHORT
#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_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_MULTI
#define ARG_MODE_SINGLE
#define ARG_FIT_PAGE_TO_BOARD
#define ARG_PAGE_SIZE
#define ARG_EXCLUDE_DRAWING_SHEET
#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:
wxString From_UTF8(const char *cstring)
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.