35#include <wx/filename.h>
41#define ARG_LAYER_MAP "--layer-map"
47 _(
"Import non-KiCad board and/or schematic files into a new KiCad project" ) ) );
50 .
help(
UTF8STDSTR(
_(
"Input file(s) to import; each is autodetected as a board or "
52 .nargs( argparse::nargs_pattern::at_least_one )
53 .metavar(
"INPUT_FILES" );
56 .default_value( std::string() )
57 .
help(
UTF8STDSTR(
_(
"Output project path stem; produces <stem>.kicad_pro plus the "
58 "imported <stem>.kicad_pcb and/or <stem>.kicad_sch beside it. "
59 "Defaults to the first input's name in the current directory." ) ) )
60 .metavar(
"PROJECT" );
63 .default_value( std::string(
"" ) )
64 .
help(
UTF8STDSTR(
_(
"JSON file mapping source layer names to KiCad layer names for "
65 "imported boards; unmapped layers use the automatic best-guess" ) ) )
75 if( rawInputs.empty() )
77 wxFprintf( stderr,
_(
"At least one input file is required\n" ) );
81 std::vector<wxString> inputFiles;
83 for(
const std::string& raw : rawInputs )
84 inputFiles.push_back(
From_UTF8( raw.c_str() ) );
86 std::map<wxString, wxString> layerMap;
89 if( !layerMapFile.IsEmpty() )
95 wxFprintf( stderr, wxS(
"%s\n" ), error );
100 wxFileName projectFn;
102 if( !outputArg.IsEmpty() )
104 projectFn.Assign( outputArg );
108 wxFileName firstInput( inputFiles.front() );
109 projectFn.AssignDir( wxFileName::GetCwd() );
110 projectFn.SetName( firstInput.GetName() );
114 projectFn.MakeAbsolute();
116 if( !projectFn.DirExists()
117 && !wxFileName::Mkdir( projectFn.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
119 wxFprintf( stderr,
_(
"Could not create output directory: %s\n" ), projectFn.GetPath() );
123 wxString stem = projectFn.GetName();
124 wxString dir = projectFn.GetPath();
139 wxFprintf( stderr,
_(
"Could not create project: %s\n" ), projectFn.GetFullPath() );
144 bool haveBoard =
false;
145 bool haveSch =
false;
148 std::map<wxString, wxString> netNameMap;
152 for(
const wxString& input : inputFiles )
197 if( haveBoard && haveSch )
199 wxFprintf( stderr,
_(
"Could not import '%s': a board and a schematic have already "
200 "been imported for this project\n" ), input );
204 wxFprintf( stderr,
_(
"No board or schematic importer recognizes the file: %s\n" ), input );
224 wxFprintf( stderr,
_(
"No inputs could be imported\n" ) );
233 std::vector<FILE_INFO_PAIR>& boards =
project->GetProjectFile().GetBoards();
235 boards.emplace_back( std::make_pair(
KIID(), boardFn.GetFullName() ) );
240 reporter.Report( wxString::Format(
_(
"Created project '%s'\n" ),
241 projectFn.GetFullPath() ),
246 wxFprintf( stderr,
_(
"Failed to write project file: %s\n" ),
247 projectFn.GetFullPath() );
argparse::ArgumentParser m_argParser
COMMAND(const std::string &aName)
Define a new COMMAND instance.
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
static CLI_REPORTER & GetInstance()
Job to import a non-KiCad PCB file to KiCad format.
std::map< wxString, wxString > m_layerMap
Explicit overrides from source layer name to KiCad layer name (canonical board-file name,...
std::map< wxString, wxString > m_netNameMap
Job to import a non-KiCad schematic file to KiCad format.
std::map< wxString, wxString > m_netNameMap
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
virtual SETTINGS_MANAGER & GetSettingsManager() const
Container for project specific data.
A pure virtual class used to derive REPORTER objects from.
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Save a loaded project.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieve a loaded project by name.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
static const std::string ProjectFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string KiCadPcbFileExtension
bool LoadLayerMapFile(const wxString &aFile, std::map< wxString, wxString > &aMap, wxString &aError)
Load an explicit layer-mapping file into aMap.
This file contains miscellaneous commonly used macros and functions.
static const int ERR_ARGS
static const int ERR_INVALID_INPUT_FILE
static const int ERR_INVALID_OUTPUT_CONFLICT
static const int ERR_UNKNOWN_FILE_FORMAT
No plugin for the requested face recognized the input file format.
static const int ERR_UNKNOWN
PGM_BASE & Pgm()
The global program "get" accessor.
wxString From_UTF8(const char *cstring)
IbisParser parser & reporter
Definition of file extensions used in Kicad.