KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_sch_downgrade.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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
22#include "cli/exit_codes.h"
23#include <wx/crt.h>
24#include <wx/file.h>
25#include <wx/filename.h>
26
27#define ARG_TARGET "--target"
28#define ARG_FORCE "--force"
29#define ARG_DRY_RUN "--dry-run"
30#define ARG_LIBRARIES "--libraries"
31#define ARG_VARIANT "--variant"
32#define ARG_DROP_APPROXIMATIONS "--drop-approximations"
33
35 COMMAND( "downgrade" )
36{
38 m_argParser.add_description( UTF8STDSTR( _( "Export a copy of the schematic readable by an older KiCad version. "
39 "A new --output folder is required except for --dry-run." ) ) );
40
41 m_argParser.add_argument( ARG_TARGET )
42 .default_value( std::string() )
43 .help( UTF8STDSTR(
44 _( "Target version name or id, e.g. \"KiCad 10.0\" or \"10.0\". Defaults to the newest." ) ) );
45
46 m_argParser.add_argument( ARG_FORCE )
47 .help( UTF8STDSTR( _( "Export even if some features must be dropped or approximated" ) ) )
48 .flag();
49
50 m_argParser.add_argument( ARG_DRY_RUN )
51 .help( UTF8STDSTR( _( "Print the compatibility report without writing anything" ) ) )
52 .flag();
53
55 .help( UTF8STDSTR(
56 _( "Omit features instead of approximating them; may remove drawing or electrical data" ) ) )
57 .flag();
58
59 m_argParser.add_argument( ARG_LIBRARIES )
60 .default_value( std::string() )
61 .help( UTF8STDSTR(
62 _( "Copy this symbol-library folder into the output folder and downgrade the copies" ) ) );
63
64 m_argParser.add_argument( ARG_VARIANT )
65 .default_value( std::string() )
66 .help( UTF8STDSTR( _( "Flatten this variant into the export. Default is the base design." ) ) );
67}
68
70{
71 std::unique_ptr<JOB_SCH_DOWNGRADE> job = std::make_unique<JOB_SCH_DOWNGRADE>();
72
73 job->m_filename = m_argInput;
74 job->m_outputDir = m_argOutput;
75 job->m_target = wxString::FromUTF8( m_argParser.get<std::string>( ARG_TARGET ) );
76 job->m_force = m_argParser.get<bool>( ARG_FORCE );
77 job->m_dryRun = m_argParser.get<bool>( ARG_DRY_RUN );
78 job->m_dropInsteadOfApproximate = m_argParser.get<bool>( ARG_DROP_APPROXIMATIONS );
79 job->m_libraryDir = wxString::FromUTF8( m_argParser.get<std::string>( ARG_LIBRARIES ) );
80 job->m_variant = wxString::FromUTF8( m_argParser.get<std::string>( ARG_VARIANT ) );
81
82 if( !wxFile::Exists( job->m_filename ) )
83 {
84 wxFprintf( stderr, _( "Schematic file does not exist or is not accessible\n" ) );
86 }
87
88 if( !job->m_dryRun && job->m_outputDir.IsEmpty() )
89 {
90 wxFprintf( stderr, _( "An output folder is required. Use --output.\n" ) );
92 }
93
94 if( !job->m_outputDir.IsEmpty() && !job->m_dryRun )
95 {
96 wxFileName inFn( job->m_filename );
97 wxFileName outDir( job->m_outputDir, wxEmptyString );
98 inFn.MakeAbsolute();
99 outDir.MakeAbsolute();
100 job->m_outputDir = outDir.GetPath();
101
102 wxFileName inDir( inFn.GetPath(), wxEmptyString );
103
104 if( outDir.SameAs( inDir ) )
105 {
106 wxFprintf( stderr, _( "The output folder must differ from the schematic folder.\n" ) );
108 }
109 }
110
111 return aKiway.ProcessJob( KIWAY::FACE_SCH, job.get() );
112}
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:134
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
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:348
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:740
@ FACE_SCH
eeschema DSO
Definition kiway.h:355
#define ARG_VARIANT
Definition command.h:38
#define UTF8STDSTR(s)
Definition command.h:27
#define ARG_FORCE
#define ARG_DRY_RUN
#define ARG_LIBRARIES
#define ARG_TARGET
#define ARG_DROP_APPROXIMATIONS
#define _(s)
static const int ERR_ARGS
Definition exit_codes.h:31
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.