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 (C) 1992-2023 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
36
38{
39 m_argParser.add_description( UTF8STDSTR( _( "Generate SVG outputs of a given layer list" ) ) );
40
41 addLayerArg( true );
44
45 m_argParser.add_argument( "-m", ARG_MIRROR )
46 .help( UTF8STDSTR( _( "Mirror the board (useful for trying to show bottom layers)" ) ) )
47 .flag();
48
49 m_argParser.add_argument( "-t", ARG_THEME )
50 .default_value( std::string() )
51 .help( UTF8STDSTR( _( "Color theme to use (will default to PCB editor settings)" ) ) )
52 .metavar( "THEME_NAME" );
53
55 .help( UTF8STDSTR( _( ARG_NEGATIVE_DESC ) ) )
56 .flag();
57
58 m_argParser.add_argument( ARG_BLACKANDWHITE )
60 .flag();
61
62 m_argParser.add_argument( "--sp", ARG_SKETCH_PADS_ON_FAB_LAYERS )
64 .flag();
65
66 m_argParser.add_argument( "--hdnp", ARG_HIDE_DNP_FPS_ON_FAB_LAYERS )
68 .flag();
69
70 m_argParser.add_argument( "--sdnp", ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS )
72 .flag();
73
74 m_argParser.add_argument( "--cdnp", ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS )
76 .flag();
77
78 m_argParser.add_argument( ARG_PAGE_SIZE )
79 .help( UTF8STDSTR( _( "Set page sizing mode (0 = page with frame and title block, 1 = "
80 "current page size, 2 = board area only)" ) ) )
81 .scan<'i', int>()
82 .default_value( 0 )
83 .metavar( "MODE" );
84
86 .help( UTF8STDSTR( _( "No drawing sheet" ) ) )
87 .flag();
88
91 .scan<'i', int>()
92 .default_value( 2 )
93 .metavar( "SHAPE_OPTION" );
94}
95
96
98{
99 int baseExit = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
100 if( baseExit != EXIT_CODES::OK )
101 return baseExit;
102
103 std::unique_ptr<JOB_EXPORT_PCB_SVG> svgJob( new JOB_EXPORT_PCB_SVG() );
104
105 svgJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
106 svgJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
107 svgJob->m_pageSizeMode = m_argParser.get<int>( ARG_PAGE_SIZE );
108 svgJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
109 svgJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
110 svgJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
111 svgJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
112 svgJob->m_crossoutDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS );
113 svgJob->m_drillShapeOption = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
114 svgJob->m_drawingSheet = m_argDrawingSheet;
115
116 svgJob->m_filename = m_argInput;
117 svgJob->SetOutputPath( m_argOutput );
118 svgJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
119 svgJob->m_plotDrawingSheet = !m_argParser.get<bool>( ARG_EXCLUDE_DRAWING_SHEET );
120 svgJob->SetVarOverrides( m_argDefineVars );
121
122 if( !wxFile::Exists( svgJob->m_filename ) )
123 {
124 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
126 }
127
128 svgJob->m_printMaskLayer = m_selectedLayers;
129
130 int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, svgJob.get() );
131
132 return exitCode;
133}
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:284
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob)
Definition: kiway.cpp:709
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:292
#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_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 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_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.