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 <layer_ids.h>
28#include <string_utils.h>
29#include <regex>
30#include <wx/crt.h>
31
32
33#define ARG_EXCLUDE_DRAWING_SHEET "--exclude-drawing-sheet"
34#define ARG_PAGE_SIZE "--page-size-mode"
35#define ARG_FIT_PAGE_TO_BOARD "--fit-page-to-board"
36#define ARG_MODE_SINGLE "--mode-single"
37#define ARG_MODE_MULTI "--mode-multi"
38
40 PCB_EXPORT_BASE_COMMAND( "svg", false, true )
41{
42 m_argParser.add_description( UTF8STDSTR( _( "Generate SVG outputs of a given layer list" ) ) );
43
44 addLayerArg( true );
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( "--cl", ARG_COMMON_LAYERS )
107 .default_value( std::string() )
109 _( "Layers to include on each plot, comma separated list of untranslated "
110 "layer names to include such as "
111 "F.Cu,B.Cu" ) ) )
112 .metavar( "COMMON_LAYER_LIST" );
113
114
115 m_argParser.add_argument( ARG_MODE_SINGLE )
116 .help( UTF8STDSTR(
117 _( "Generates a single file with the output arg path acting as the complete "
118 "directory and filename path. COMMON_LAYER_LIST does not function in this "
119 "mode. Instead LAYER_LIST controls all layers plotted." ) ) )
120 .flag();
121
122 m_argParser.add_argument( ARG_MODE_MULTI )
123 .help( UTF8STDSTR( _( "Generates one or more files with behavior similar to the KiCad "
124 "GUI plotting. The given output path specifies a directory in "
125 "which files may be output." ) ) )
126 .flag();
127
130 .flag();
131}
132
133
135{
136 int baseExit = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
137 if( baseExit != EXIT_CODES::OK )
138 return baseExit;
139
140 std::unique_ptr<JOB_EXPORT_PCB_SVG> svgJob( new JOB_EXPORT_PCB_SVG() );
141
142 svgJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
143 svgJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
144 svgJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
145 svgJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
146 svgJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
147 svgJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
148 svgJob->m_crossoutDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS );
149 int drillShape = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
150 svgJob->m_drillShapeOption = static_cast<JOB_EXPORT_PCB_SVG::DRILL_MARKS>( drillShape );
151 svgJob->m_drawingSheet = m_argDrawingSheet;
152 svgJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
153
154 if( m_argParser.get<bool>( DEPRECATED_ARG_PLOT_INVISIBLE_TEXT ) )
156
157 svgJob->m_fitPageToBoard = m_argParser.get<bool>( ARG_FIT_PAGE_TO_BOARD );
158
159 // legacy compat, should eliminate this arg eventually
160 int legacyPageSizeMode = m_argParser.get<int>( ARG_PAGE_SIZE );
161
162 if( legacyPageSizeMode == 0 )
163 {
164 svgJob->m_plotDrawingSheet = true;
165 }
166 else if( legacyPageSizeMode == 1 )
167 {
168 svgJob->m_plotDrawingSheet = false;
169 }
170 else if( legacyPageSizeMode == 2 )
171 {
172 svgJob->m_fitPageToBoard = true;
173 svgJob->m_plotDrawingSheet = false;
174 }
175
176 svgJob->m_filename = m_argInput;
177 svgJob->SetConfiguredOutputPath( m_argOutput );
178 svgJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
179 svgJob->m_plotDrawingSheet = !m_argParser.get<bool>( ARG_EXCLUDE_DRAWING_SHEET );
180 svgJob->SetVarOverrides( m_argDefineVars );
181
182 wxString layers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
183 svgJob->m_plotOnAllLayersSequence = convertLayerStringList( layers );
184
185 if( !wxFile::Exists( svgJob->m_filename ) )
186 {
187 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
189 }
190
191 svgJob->m_plotLayerSequence = m_selectedLayers;
192
193 if( m_argParser.get<bool>( ARG_MODE_MULTI ) )
194 svgJob->m_genMode = JOB_EXPORT_PCB_SVG::GEN_MODE::MULTI;
195 else if( m_argParser.get<bool>( ARG_MODE_SINGLE ) )
196 svgJob->m_genMode = JOB_EXPORT_PCB_SVG::GEN_MODE::SINGLE;
197 else if( svgJob->m_genMode == JOB_EXPORT_PCB_SVG::GEN_MODE::SINGLE )
198 {
199 // TODO remove this block when changing the default for JOB_EXPORT_PCB_SVG::m_genMode
200 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
201 _( "This command has deprecated behavior as of KiCad 9.0, the default behavior "
202 "of this command will change in a future release." ) );
203
204 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
205 _( "The new behavior will match --mode-multi" ) );
206 }
207
208 int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, svgJob.get() );
209
210 return exitCode;
211}
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:711
#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_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_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 OK
Definition: exit_codes.h:30
static const int ERR_INVALID_INPUT_FILE
Definition: exit_codes.h:33
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.
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.