KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_sch_import.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "command_sch_import.h"
21#include <cli/exit_codes.h>
22#include <jobs/job_sch_import.h>
24#include <kiface_base.h>
25#include <string_utils.h>
26#include <macros.h>
27#include <wx/crt.h>
28
29
30#define ARG_FORMAT "--format"
31#define ARG_REPORT_FORMAT "--report-format"
32#define ARG_REPORT_FILE "--report-file"
33
34
36{
38
39 m_argParser.add_description(
40 UTF8STDSTR( _( "Import a non-KiCad schematic file to KiCad format" ) ) );
41
42 m_argParser.add_argument( ARG_FORMAT )
43 .default_value( std::string( "auto" ) )
44 .help( UTF8STDSTR( _( "Input format hint: auto, altium, eagle, cadstar, easyeda, "
45 "easyedapro, ltspice, pads, diptrace (default: auto)" ) ) )
46 .metavar( "FORMAT" );
47
48 m_argParser.add_argument( ARG_REPORT_FORMAT )
49 .default_value( std::string( "none" ) )
50 .help( UTF8STDSTR( _( "Import report format: none, json, text (default: none)" ) ) )
51 .metavar( "FORMAT" );
52
53 m_argParser.add_argument( ARG_REPORT_FILE )
54 .default_value( std::string( "" ) )
55 .help( UTF8STDSTR( _( "File path for import report (default: stdout)" ) ) )
56 .metavar( "FILE" );
57}
58
59
61{
62 std::unique_ptr<JOB_SCH_IMPORT> importJob = std::make_unique<JOB_SCH_IMPORT>();
63
64 importJob->m_inputFile = m_argInput;
65 importJob->SetConfiguredOutputPath( m_argOutput );
66
67 wxString format = From_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
68
69 if( format == wxS( "auto" ) )
70 importJob->m_format = JOB_SCH_IMPORT::FORMAT::AUTO;
71 else if( format == wxS( "altium" ) )
72 importJob->m_format = JOB_SCH_IMPORT::FORMAT::ALTIUM;
73 else if( format == wxS( "eagle" ) )
74 importJob->m_format = JOB_SCH_IMPORT::FORMAT::EAGLE;
75 else if( format == wxS( "cadstar" ) )
76 importJob->m_format = JOB_SCH_IMPORT::FORMAT::CADSTAR;
77 else if( format == wxS( "easyeda" ) )
78 importJob->m_format = JOB_SCH_IMPORT::FORMAT::EASYEDA;
79 else if( format == wxS( "easyedapro" ) )
80 importJob->m_format = JOB_SCH_IMPORT::FORMAT::EASYEDAPRO;
81 else if( format == wxS( "ltspice" ) )
82 importJob->m_format = JOB_SCH_IMPORT::FORMAT::LTSPICE;
83 else if( format == wxS( "pads" ) )
84 importJob->m_format = JOB_SCH_IMPORT::FORMAT::PADS;
85 else if( format == wxS( "diptrace" ) )
86 importJob->m_format = JOB_SCH_IMPORT::FORMAT::DIPTRACE;
87 else
88 {
89 wxFprintf( stderr, _( "Invalid format: %s\n" ), format );
91 }
92
93 wxString reportFormat = From_UTF8( m_argParser.get<std::string>( ARG_REPORT_FORMAT ).c_str() );
94
95 if( !ParseImportReportFormat( reportFormat, importJob->m_reportFormat ) )
96 {
97 wxFprintf( stderr, _( "Invalid report format: %s\n" ), reportFormat );
99 }
100
101 importJob->m_reportFile = From_UTF8( m_argParser.get<std::string>( ARG_REPORT_FILE ).c_str() );
102
103 int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, importJob.get() );
104
105 // The sentinel is internal to the top-level `import` classifier; standalone, it is invalid input.
108
109 return exitCode;
110}
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:148
wxString m_argInput
Value of the common input arg if configured.
Definition command.h:143
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_FORMAT
#define ARG_REPORT_FILE
#define ARG_REPORT_FORMAT
#define _(s)
bool ParseImportReportFormat(const wxString &aText, IMPORT_REPORT_FORMAT &aFormat)
Parse the user-facing report format name ("none", "json" or "text") into its enum.
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
static const int ERR_UNKNOWN_FILE_FORMAT
No plugin for the requested face recognized the input file format.
Definition exit_codes.h:42
wxString From_UTF8(const char *cstring)