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_MODE_SINGLE "--mode-single"
36#define ARG_MODE_MULTI "--mode-multi"
37
39{
40 m_argParser.add_description( UTF8STDSTR( _( "Generate SVG outputs of a given layer list" ) ) );
41
42 addLayerArg( true );
45
46 m_argParser.add_argument( "-m", ARG_MIRROR )
47 .help( UTF8STDSTR( _( "Mirror the board (useful for trying to show bottom layers)" ) ) )
48 .flag();
49
50 m_argParser.add_argument( "-t", ARG_THEME )
51 .default_value( std::string() )
52 .help( UTF8STDSTR( _( "Color theme to use (will default to PCB editor settings)" ) ) )
53 .metavar( "THEME_NAME" );
54
56 .help( UTF8STDSTR( _( ARG_NEGATIVE_DESC ) ) )
57 .flag();
58
59 m_argParser.add_argument( ARG_BLACKANDWHITE )
61 .flag();
62
63 m_argParser.add_argument( "--sp", ARG_SKETCH_PADS_ON_FAB_LAYERS )
65 .flag();
66
67 m_argParser.add_argument( "--hdnp", ARG_HIDE_DNP_FPS_ON_FAB_LAYERS )
69 .flag();
70
71 m_argParser.add_argument( "--sdnp", ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS )
73 .flag();
74
75 m_argParser.add_argument( "--cdnp", ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS )
77 .flag();
78
79 m_argParser.add_argument( ARG_PAGE_SIZE )
80 .help( UTF8STDSTR( _( "Set page sizing mode (0 = page with frame and title block, 1 = "
81 "current page size, 2 = board area only)" ) ) )
82 .scan<'i', int>()
83 .default_value( 0 )
84 .metavar( "MODE" );
85
87 .help( UTF8STDSTR( _( "No drawing sheet" ) ) )
88 .flag();
89
92 .scan<'i', int>()
93 .default_value( 2 )
94 .metavar( "SHAPE_OPTION" );
95
96 m_argParser.add_argument( "--cl", ARG_COMMON_LAYERS )
97 .default_value( std::string() )
99 _( "Layers to include on each plot, comma separated list of untranslated "
100 "layer names to include such as "
101 "F.Cu,B.Cu" ) ) )
102 .metavar( "COMMON_LAYER_LIST" );
103
104
105 m_argParser.add_argument( ARG_MODE_SINGLE )
106 .help( UTF8STDSTR(
107 _( "Generates a single file with the output arg path acting as the complete "
108 "directory and filename path. COMMON_LAYER_LIST does not function in this "
109 "mode. Instead LAYER_LIST controls all layers plotted." ) ) )
110 .flag();
111
112 m_argParser.add_argument( ARG_MODE_MULTI )
113 .help( UTF8STDSTR( _( "Generates one or more files with behavior similar to the KiCad "
114 "GUI plotting. The given output path specifies a directory in "
115 "which files may be output." ) ) )
116 .flag();
117
118
121 .flag();
122}
123
124
126{
127 int baseExit = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
128 if( baseExit != EXIT_CODES::OK )
129 return baseExit;
130
131 std::unique_ptr<JOB_EXPORT_PCB_SVG> svgJob( new JOB_EXPORT_PCB_SVG() );
132
133 svgJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
134 svgJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
135 svgJob->m_pageSizeMode = m_argParser.get<int>( ARG_PAGE_SIZE );
136 svgJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
137 svgJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
138 svgJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
139 svgJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
140 svgJob->m_crossoutDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS );
141 int drillShape = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
142 svgJob->m_drillShapeOption = static_cast<JOB_EXPORT_PCB_SVG::DRILL_MARKS>( drillShape );
143 svgJob->m_drawingSheet = m_argDrawingSheet;
144 svgJob->m_plotInvisibleText = m_argParser.get<bool>( ARG_PLOT_INVISIBLE_TEXT );
145
146 svgJob->m_filename = m_argInput;
147 svgJob->SetConfiguredOutputPath( m_argOutput );
148 svgJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
149 svgJob->m_plotDrawingSheet = !m_argParser.get<bool>( ARG_EXCLUDE_DRAWING_SHEET );
150 svgJob->SetVarOverrides( m_argDefineVars );
151
152 wxString layers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
153 bool blah = false;
154 svgJob->m_printMaskLayersToIncludeOnAllLayers = convertLayerStringList( layers, blah );
155
156 if( !wxFile::Exists( svgJob->m_filename ) )
157 {
158 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
160 }
161
162 svgJob->m_printMaskLayer = m_selectedLayers;
163
164 if( m_argParser.get<bool>( ARG_MODE_MULTI ) )
165 svgJob->m_genMode = JOB_EXPORT_PCB_SVG::GEN_MODE::MULTI;
166 else
167 svgJob->m_genMode = JOB_EXPORT_PCB_SVG::GEN_MODE::SINGLE;
168
169 if( svgJob->m_genMode == JOB_EXPORT_PCB_SVG::GEN_MODE::SINGLE )
170 {
171 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
172 _( "This command has deprecated behavior as of KiCad 9.0, the default behavior "
173 "of this command will change in a future release." ) );
174
175 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
176 _( "The new behavior will match --mode-multi" ) );
177 }
178
179 int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, svgJob.get() );
180
181 return exitCode;
182}
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:169
void addDrawingSheetArg()
Set up the drawing sheet arg used by many of the export commands.
Definition: command.cpp:157
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_PLOT_INVISIBLE_TEXT_DESC
#define ARG_PLOT_INVISIBLE_TEXT
#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_DRILL_SHAPE_OPTION_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_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.