KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_sym_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 The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <cli/exit_codes.h>
24#include <kiface_base.h>
25#include <layer_ids.h>
26#include <string_utils.h>
27#include <wx/crt.h>
28
29#include <macros.h>
30#include <wx/dir.h>
31#include <wx/tokenzr.h>
32
33
34#define ARG_NO_BACKGROUND_COLOR "--no-background-color"
35#define ARG_SYMBOL "--symbol"
36#define ARG_INC_HIDDEN_PINS "--include-hidden-pins"
37#define ARG_INC_HIDDEN_FIELDS "--include-hidden-fields"
38
39
41{
43
44 m_argParser.add_description( UTF8STDSTR( _( "Exports the symbol or entire symbol library "
45 "to SVG" ) ) );
46
47 m_argParser.add_argument( "-t", ARG_THEME )
48 .default_value( std::string() )
49 .help( UTF8STDSTR( _( "Color theme to use (will default to symbol editor "
50 "settings)" ) ) )
51 .metavar( "THEME_NAME" );
52
53 m_argParser.add_argument( "-s", ARG_SYMBOL )
54 .default_value( std::string() )
55 .help( UTF8STDSTR( _( "Specific symbol to export within the library" ) ) )
56 .metavar( "SYMBOL" );
57
58 m_argParser.add_argument( ARG_BLACKANDWHITE )
60 .flag();
61
62 m_argParser.add_argument( ARG_INC_HIDDEN_PINS )
63 .help( UTF8STDSTR( _( "Include hidden pins" ) ) )
64 .flag();
65
67 .help( UTF8STDSTR( _( "Include hidden fields" ) ) )
68 .flag();
69}
70
71
73{
74 std::unique_ptr<JOB_SYM_EXPORT_SVG> svgJob = std::make_unique<JOB_SYM_EXPORT_SVG>();
75
76 svgJob->m_libraryPath = m_argInput;
77 svgJob->m_outputDirectory = m_argOutput;
78 svgJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
79 svgJob->m_symbol = From_UTF8( m_argParser.get<std::string>( ARG_SYMBOL ).c_str() );
80 svgJob->m_includeHiddenFields = m_argParser.get<bool>( ARG_INC_HIDDEN_FIELDS );
81 svgJob->m_includeHiddenPins = m_argParser.get<bool>( ARG_INC_HIDDEN_PINS );
82
83 // A symbol library may be a single .kicad_sym file or a .kicad_symdir directory.
84 if( !wxFile::Exists( svgJob->m_libraryPath ) && !wxDir::Exists( svgJob->m_libraryPath ) )
85 {
86 wxFprintf( stderr, _( "Symbol file does not exist or is not accessible\n" ) );
88 }
89
90 svgJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
91
92 int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, svgJob.get() );
93
94 return exitCode;
95}
argparse::ArgumentParser m_argParser
Definition command.h:113
COMMAND(const std::string &aName)
Define a new COMMAND instance.
Definition command.cpp:30
void addCommonArgs(bool aInput, bool aOutput, IO_TYPE aInputType, IO_TYPE aOutputType)
Set up the most common of args used across cli.
Definition command.cpp:132
wxString m_argOutput
Value of the output arg if configured.
Definition command.h:143
wxString m_argInput
Value of the common input arg if configured.
Definition command.h:138
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:311
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:746
@ FACE_SCH
eeschema DSO
Definition kiway.h:318
#define UTF8STDSTR(s)
Definition command.h:27
#define ARG_THEME
#define ARG_BLACKANDWHITE_DESC
#define ARG_BLACKANDWHITE
#define ARG_SYMBOL
#define ARG_INC_HIDDEN_PINS
#define ARG_INC_HIDDEN_FIELDS
#define _(s)
This file contains miscellaneous commonly used macros and functions.
static const int ERR_INVALID_INPUT_FILE
Definition exit_codes.h:33
wxString From_UTF8(const char *cstring)