32#include <wx/filename.h>
36#define ARG_TARGET "--target"
37#define ARG_FORCE "--force"
38#define ARG_DRY_RUN "--dry-run"
39#define ARG_REPORT_JSON "--report-json"
40#define ARG_VARIANT "--variant"
41#define ARG_DROP_APPROXIMATIONS "--drop-approximations"
48 "KiCad version" ) ) );
51 .default_value( std::string() )
53 _(
"Target version name or id, e.g. \"KiCad 10.0\" or \"10.0\". Defaults to the newest." ) ) );
56 .help(
UTF8STDSTR(
_(
"Export even if some features must be dropped or approximated" ) ) )
60 .help(
UTF8STDSTR(
_(
"Print the compatibility report without writing anything" ) ) )
65 _(
"Omit features instead of approximating them; may remove drawing or electrical data" ) ) )
69 .default_value( std::string() )
70 .help(
UTF8STDSTR(
_(
"Also write the compatibility report as JSON to this file" ) ) );
73 .default_value( std::string() )
74 .help(
UTF8STDSTR(
_(
"Flatten this variant into the export. Default is the base design." ) ) );
96 wxFprintf( stderr,
_(
"Project file does not exist or is not accessible\n" ) );
101 proFn.MakeAbsolute();
103 wxString projectDir = proFn.GetPath();
104 wxString projectName = proFn.GetName();
108 if( targetName.IsEmpty() )
115 wxFprintf( stderr,
_(
"Unknown target version '%s'. Valid targets: %s\n" ), targetName,
123 wxFprintf( stderr,
_(
"An output folder is required. Use --output.\n" ) );
132 reportFile.MakeAbsolute();
133 jsonPath = reportFile.GetFullPath();
134 wxArrayString sources;
135 wxDir::GetAllFiles( projectDir, &sources );
137 for(
const wxString&
source : sources )
142 std::error_code error;
143 bool sameFile = std::filesystem::equivalent(
jsonPath.ToStdWstring(),
source.ToStdWstring(), error );
145 if( sameFile || reportFile.SameAs( wxFileName(
source ) ) )
147 wxFprintf( stderr,
_(
"The report file must differ from the source project files.\n" ) );
159 dropInsteadOfApproximate, variant ) )
161 wxFprintf( stderr, wxT(
"%s\n" ), error );
171 js[
"target"] = std::string( target->
m_name.ToUTF8() );
173 js[
"lossy"] = report.
IsLossy();
174 js[
"drop_approximations"] = dropInsteadOfApproximate;
175 js[
"entries"] = nlohmann::json::array();
179 js[
"entries"].push_back( { {
"category",
bucketName( entry.m_bucket ) },
180 {
"feature", std::string( entry.m_feature.ToUTF8() ) },
181 {
"detail", std::string( entry.m_detail.ToUTF8() ) },
182 {
"count", entry.m_count } } );
185 std::string
text = js.dump( 2 ) +
"\n";
189 wxFprintf( stderr,
_(
"Could not write the JSON report to '%s'\n" ),
jsonPath );
199 wxFprintf( stderr,
_(
"Cannot export: the project uses features the target cannot represent.\n" ) );
205 wxFprintf( stderr,
_(
"Export would lose data. Re-run with --force to export anyway.\n" ) );
210 outDir.MakeAbsolute();
213 dropInsteadOfApproximate ) )
215 wxFprintf( stderr, wxT(
"%s\n" ), error );
219 wxPrintf(
_(
"Exported to '%s'\n" ), outDir.GetPath() );
argparse::ArgumentParser m_argParser
COMMAND(const std::string &aName)
Define a new COMMAND instance.
void addCommonArgs(bool aInput, bool aOutput, IO_TYPE aInputType, IO_TYPE aOutputType)
Set up the most common of args used across cli.
wxString m_argOutput
Value of the output arg if configured.
wxString m_argInput
Value of the common input arg if configured.
static CLI_REPORTER & GetInstance()
What an export to a given target will keep, approximate, drop, or block.
void Print(REPORTER *aReporter) const
bool IsLossy() const
True if anything is approximated or dropped. This is what triggers the lossy warning.
bool IsBlocked() const
True if some feature makes the target impossible. The user cannot export anyway.
const std::vector< COMPAT_ENTRY > & Entries() const
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
#define ARG_DROP_APPROXIMATIONS
static const char * bucketName(DOWNGRADE_BUCKET aBucket)
DOWNGRADE_BUCKET
What happens to a feature when we export to an older KiCad.
@ BLOCK
Cannot be represented at all, export to this target is not possible.
@ KEEP
Exists in the target, written unchanged.
@ LOWER
Approximated down to a simpler equivalent.
@ DROP
No equivalent, left out.
bool IsDowngradeDesignFile(const wxString &aPath)
Files the project export carries over.
const std::vector< DOWNGRADE_TARGET > & GetDowngradeTargets()
Supported downgrade targets, newest first.
const DOWNGRADE_TARGET * FindDowngradeTarget(const wxString &aNameOrId)
Match a user-supplied target string against name or stable id, case-insensitively.
wxString DowngradeTargetNames()
The valid target choices as one user-facing list, for error messages.
static const int ERR_ARGS
static const int ERR_INVALID_INPUT_FILE
static const int ERR_UNKNOWN
bool ExportProjectForDowngrade(KIWAY &aKiway, const wxString &aProjectDir, const wxString &aProjectName, const wxString &aTargetName, const wxString &aDestDir, wxString &aError, const wxString &aVariant, bool aDropInsteadOfApproximate)
Export a downgraded copy of the project into aDestDir.
bool ClassifyProjectForDowngrade(KIWAY &aKiway, const wxString &aProjectDir, const wxString &aProjectName, const wxString &aTargetName, COMPATIBILITY_REPORT &aReport, wxString &aError, std::vector< wxString > *aFoundVariants, bool aDropInsteadOfApproximate, const wxString &aVariant)
Run the board and schematic classification for a whole project without writing anything.
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
PROJECT_DOWNGRADE_COMMAND()
One line in the compatibility report.
An older KiCad release we can export a project back to.
wxString m_name
User-facing name, e.g. "KiCad 10.0".