KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_sch_export_netlist.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 along
18 * with this program. If not, see <http://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
31#define ARG_FORMAT "--format"
32
34{
35 m_argParser.add_description( UTF8STDSTR( _( "Export a netlist" ) ) );
36 addCommonArgs( true, true, false, false );
38
39 m_argParser.add_argument( ARG_FORMAT )
40 .default_value( std::string( "kicadsexpr" ) )
41 .help( UTF8STDSTR( _( "Netlist output format, valid options: kicadsexpr, kicadxml, "
42 "cadstar, orcadpcb2, spice, spicemodel, pads, allegro" ) ) )
43 .metavar( "FORMAT" );
44}
45
46
48{
49 std::unique_ptr<JOB_EXPORT_SCH_NETLIST> netJob =
50 std::make_unique<JOB_EXPORT_SCH_NETLIST>();
51
52 netJob->m_filename = m_argInput;
53 netJob->SetConfiguredOutputPath( m_argOutput );
54 netJob->m_variantNames = m_argVariantNames;
55
56 if( !wxFile::Exists( netJob->m_filename ) )
57 {
58 wxFprintf( stderr, _( "Schematic file does not exist or is not accessible\n" ) );
60 }
61
62 wxString format = From_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
63 if( format == "kicadsexpr" )
64 {
66 }
67 else if( format == "kicadxml" )
68 {
70 }
71 else if( format == "cadstar" )
72 {
74 }
75 else if( format == "orcadpcb2" )
76 {
78 }
79 else if( format == "spice" )
80 {
82 }
83 else if( format == "spicemodel" )
84 {
86 }
87 else if( format == "pads" )
88 {
90 }
91 else if( format == "allegro" )
92 {
94 }
95 else
96 {
97 wxFprintf( stderr, _( "Invalid format\n" ) );
99 }
100
101 int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, netJob.get() );
102
103 return exitCode;
104}
void addCommonArgs(bool aInput, bool aOutput, bool aInputCanBeDir, bool aOutputIsDir)
Set up the most common of args used across cli.
Definition command.cpp:133
void addVariantsArg()
Set up the list of variants to output arguement.
Definition command.cpp:201
argparse::ArgumentParser m_argParser
Definition command.h:106
COMMAND(const std::string &aName)
Define a new COMMAND instance.
Definition command.cpp:30
wxString m_argOutput
Value of the output arg if configured.
Definition command.h:141
wxString m_argInput
Value of the common input arg if configured.
Definition command.h:136
std::vector< wxString > m_argVariantNames
The list of variant names to output.
Definition command.h:163
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:294
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:745
@ FACE_SCH
eeschema DSO
Definition kiway.h:301
#define UTF8STDSTR(s)
Definition command.h:27
#define ARG_FORMAT
#define _(s)
This file contains miscellaneous commonly used macros and functions.
static const int ERR_ARGS
Definition exit_codes.h:31
static const int ERR_INVALID_INPUT_FILE
Definition exit_codes.h:33
wxString From_UTF8(const char *cstring)