KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_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 <downgrade_copy.h>
24#include <wx/crt.h>
25#include <wx/file.h>
26#include <wx/filename.h>
27
28#define ARG_TARGET "--target"
29#define ARG_FORCE "--force"
30#define ARG_DRY_RUN "--dry-run"
31#define ARG_LIBRARIES "--libraries"
32#define ARG_VARIANT "--variant"
33#define ARG_DROP_APPROXIMATIONS "--drop-approximations"
34
36 COMMAND( "downgrade" )
37{
39 m_argParser.add_description( UTF8STDSTR( _( "Export a copy of the board readable by an older KiCad version" ) ) );
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( _( "Copy this library folder beside the output board and downgrade its footprints" ) ) );
62
63 m_argParser.add_argument( ARG_VARIANT )
64 .default_value( std::string() )
65 .help( UTF8STDSTR( _( "Flatten this variant into the export. Default is the base design." ) ) );
66}
67
69{
70 std::unique_ptr<JOB_PCB_DOWNGRADE> job = std::make_unique<JOB_PCB_DOWNGRADE>();
71
72 job->m_filename = m_argInput;
73 job->m_outputFile = m_argOutput;
74 job->m_target = wxString::FromUTF8( m_argParser.get<std::string>( ARG_TARGET ) );
75 job->m_force = m_argParser.get<bool>( ARG_FORCE );
76 job->m_dryRun = m_argParser.get<bool>( ARG_DRY_RUN );
77 job->m_dropInsteadOfApproximate = m_argParser.get<bool>( ARG_DROP_APPROXIMATIONS );
78 job->m_libraryDir = wxString::FromUTF8( m_argParser.get<std::string>( ARG_LIBRARIES ) );
79 job->m_variant = wxString::FromUTF8( m_argParser.get<std::string>( ARG_VARIANT ) );
80
81 if( !wxFile::Exists( job->m_filename ) )
82 {
83 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
85 }
86
87 if( job->m_dryRun )
88 return aKiway.ProcessJob( KIWAY::FACE_PCB, job.get() );
89
90 if( job->m_outputFile.IsEmpty() )
91 {
92 wxFprintf( stderr, _( "An output file is required. Use --output.\n" ) );
94 }
95
96 wxString error;
97
98 if( !ValidateFreshDowngradeOutput( job->m_outputFile, error ) )
99 {
100 wxFprintf( stderr, wxT( "%s\n" ), error );
102 }
103
104 return aKiway.ProcessJob( KIWAY::FACE_PCB, job.get() );
105}
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_PCB
pcbnew DSO
Definition kiway.h:356
#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
bool ValidateFreshDowngradeOutput(const wxString &aOutput, wxString &aError)
#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.