KiCad PCB EDA Suite
command_export_pcb_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-2022 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>
25#include <kiface_base.h>
26#include <layer_ids.h>
27#include <regex>
28#include <wx/crt.h>
29
30#include <macros.h>
31#include <wx/tokenzr.h>
32
33#define ARG_EXCLUDE_DRAWING_SHEET "--exclude-drawing-sheet"
34#define ARG_PAGE_SIZE "--page-size-mode"
35#define ARG_MIRROR "--mirror"
36
37
39{
40 addLayerArg( true );
41
42 m_argParser.add_argument( "-m", ARG_MIRROR )
43 .help( UTF8STDSTR( _( "Mirror the board (useful for trying to show bottom layers)" ) ) )
44 .implicit_value( true )
45 .default_value( false );
46
47 m_argParser.add_argument( "-t", ARG_THEME )
48 .default_value( std::string() )
49 .help( UTF8STDSTR( _( "Color theme to use (will default to pcbnew settings)" ) ) );
50
51 m_argParser.add_argument( ARG_BLACKANDWHITE )
53 .implicit_value( true )
54 .default_value( false );
55
56 m_argParser.add_argument( ARG_PAGE_SIZE )
57 .help( UTF8STDSTR( _( "Set page sizing mode (0 = page with frame and title block, 1 = "
58 "current page size, 2 = board area only)" ) ) )
59 .scan<'i', int>()
60 .default_value( 0 );
61
63 .help( UTF8STDSTR( _( "No drawing sheet" ) ) )
64 .implicit_value( true )
65 .default_value( false );
66}
67
68
70{
71 int baseExit = EXPORT_PCB_BASE_COMMAND::doPerform( aKiway );
72 if( baseExit != EXIT_CODES::OK )
73 return baseExit;
74
75 std::unique_ptr<JOB_EXPORT_PCB_SVG> svgJob( new JOB_EXPORT_PCB_SVG( true ) );
76
77 svgJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
78 svgJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
79 svgJob->m_pageSizeMode = m_argParser.get<int>( ARG_PAGE_SIZE );
80
81 svgJob->m_filename = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
82 svgJob->m_outputFile = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
83 svgJob->m_colorTheme = FROM_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
84 svgJob->m_plotDrawingSheet = !m_argParser.get<bool>( ARG_EXCLUDE_DRAWING_SHEET );
85
86 if( !wxFile::Exists( svgJob->m_filename ) )
87 {
88 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
90 }
91
92 svgJob->m_printMaskLayer = m_selectedLayers;
93
94 int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, svgJob.get() );
95
96 return exitCode;
97}
argparse::ArgumentParser m_argParser
Definition: command.h:68
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:660
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:287
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_OUTPUT
#define ARG_INPUT
#define ARG_THEME
#define ARG_BLACKANDWHITE_DESC
#define ARG_BLACKANDWHITE
#define ARG_PAGE_SIZE
#define ARG_MIRROR
#define ARG_EXCLUDE_DRAWING_SHEET
#define _(s)
This file contains miscellaneous commonly used macros and functions.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
static const int OK
Definition: exit_codes.h:30
static const int ERR_INVALID_INPUT_FILE
Definition: exit_codes.h:33
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.