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#include <macros.h>
33#include <wx/tokenzr.h>
34
35#define ARG_EXCLUDE_DRAWING_SHEET "--exclude-drawing-sheet"
36#define ARG_PAGE_SIZE "--page-size-mode"
37#define ARG_DRILL_SHAPE_OPTION "--drill-shape-opt"
38
39
41{
42 m_argParser.add_description( UTF8STDSTR( _( "Generate SVG outputs of a given layer list" ) ) );
43
44 addLayerArg( true );
47
48 m_argParser.add_argument( "-m", ARG_MIRROR )
49 .help( UTF8STDSTR( _( "Mirror the board (useful for trying to show bottom layers)" ) ) )
50 .implicit_value( true )
51 .default_value( false );
52
53 m_argParser.add_argument( "-t", ARG_THEME )
54 .default_value( std::string() )
55 .help( UTF8STDSTR( _( "Color theme to use (will default to PCB editor settings)" ) ) )
56 .metavar( "THEME_NAME" );
57
59 .help( UTF8STDSTR( _( ARG_NEGATIVE_DESC ) ) )
60 .implicit_value( true )
61 .default_value( false );
62
63 m_argParser.add_argument( ARG_BLACKANDWHITE )
65 .implicit_value( true )
66 .default_value( false );
67
68 m_argParser.add_argument( ARG_PAGE_SIZE )
69 .help( UTF8STDSTR( _( "Set page sizing mode (0 = page with frame and title block, 1 = "
70 "current page size, 2 = board area only)" ) ) )
71 .scan<'i', int>()
72 .default_value( 0 )
73 .metavar( "MODE" );
74
76 .help( UTF8STDSTR( _( "No drawing sheet" ) ) )
77 .implicit_value( true )
78 .default_value( false );
79
81 .help( UTF8STDSTR( _( "Set pad/via drill shape option (0 = no shape, 1 = "
82 "small shape, 2 = actual shape)" ) ) )
83 .scan<'i', int>()
84 .default_value( 2 )
85 .metavar( "SHAPE_OPTION" );
86}
87
88
90{
91 int baseExit = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
92 if( baseExit != EXIT_CODES::OK )
93 return baseExit;
94
95 std::unique_ptr<JOB_EXPORT_PCB_SVG> svgJob( new JOB_EXPORT_PCB_SVG( true ) );
96
97 svgJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
98 svgJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
99 svgJob->m_pageSizeMode = m_argParser.get<int>( ARG_PAGE_SIZE );
100 svgJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
101 svgJob->m_drillShapeOption = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
102 svgJob->m_drawingSheet = m_argDrawingSheet;
103
104 svgJob->m_filename = m_argInput;
105 svgJob->m_outputFile = m_argOutput;
106 svgJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
107 svgJob->m_plotDrawingSheet = !m_argParser.get<bool>( ARG_EXCLUDE_DRAWING_SHEET );
108 svgJob->SetVarOverrides( m_argDefineVars );
109
110 if( !wxFile::Exists( svgJob->m_filename ) )
111 {
112 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
114 }
115
116 svgJob->m_printMaskLayer = m_selectedLayers;
117
118 int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, svgJob.get() );
119
120 return exitCode;
121}
argparse::ArgumentParser m_argParser
Definition: command.h:98
void addDefineArg()
Sets up the drawing sheet arg used by many of the export commands.
Definition: command.cpp:168
void addDrawingSheetArg()
Sets 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:279
int ProcessJob(KIWAY::FACE_T aFace, JOB *job)
Definition: kiway.cpp:729
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:287
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_THEME
#define ARG_NEGATIVE
#define ARG_BLACKANDWHITE_DESC
#define ARG_NEGATIVE_SHORT
#define ARG_BLACKANDWHITE
#define ARG_MIRROR
#define ARG_NEGATIVE_DESC
#define ARG_DRILL_SHAPE_OPTION
#define ARG_PAGE_SIZE
#define ARG_EXCLUDE_DRAWING_SHEET
#define _(s)
This file contains miscellaneous commonly used macros and functions.
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.