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 .flag();
51
52 m_argParser.add_argument( "-t", ARG_THEME )
53 .default_value( std::string() )
54 .help( UTF8STDSTR( _( "Color theme to use (will default to PCB editor settings)" ) ) )
55 .metavar( "THEME_NAME" );
56
58 .help( UTF8STDSTR( _( ARG_NEGATIVE_DESC ) ) )
59 .flag();
60
61 m_argParser.add_argument( ARG_BLACKANDWHITE )
63 .flag();
64
65 m_argParser.add_argument( ARG_PAGE_SIZE )
66 .help( UTF8STDSTR( _( "Set page sizing mode (0 = page with frame and title block, 1 = "
67 "current page size, 2 = board area only)" ) ) )
68 .scan<'i', int>()
69 .default_value( 0 )
70 .metavar( "MODE" );
71
73 .help( UTF8STDSTR( _( "No drawing sheet" ) ) )
74 .flag();
75
77 .help( UTF8STDSTR( _( "Set pad/via drill shape option (0 = no shape, 1 = "
78 "small shape, 2 = actual shape)" ) ) )
79 .scan<'i', int>()
80 .default_value( 2 )
81 .metavar( "SHAPE_OPTION" );
82}
83
84
86{
87 int baseExit = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
88 if( baseExit != EXIT_CODES::OK )
89 return baseExit;
90
91 std::unique_ptr<JOB_EXPORT_PCB_SVG> svgJob( new JOB_EXPORT_PCB_SVG( true ) );
92
93 svgJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
94 svgJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
95 svgJob->m_pageSizeMode = m_argParser.get<int>( ARG_PAGE_SIZE );
96 svgJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
97 svgJob->m_drillShapeOption = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
98 svgJob->m_drawingSheet = m_argDrawingSheet;
99
100 svgJob->m_filename = m_argInput;
101 svgJob->m_outputFile = m_argOutput;
102 svgJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
103 svgJob->m_plotDrawingSheet = !m_argParser.get<bool>( ARG_EXCLUDE_DRAWING_SHEET );
104 svgJob->SetVarOverrides( m_argDefineVars );
105
106 if( !wxFile::Exists( svgJob->m_filename ) )
107 {
108 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
110 }
111
112 svgJob->m_printMaskLayer = m_selectedLayers;
113
114 int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, svgJob.get() );
115
116 return exitCode;
117}
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:279
int ProcessJob(KIWAY::FACE_T aFace, JOB *job)
Definition: kiway.cpp:709
@ 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.