26#include <wx/filename.h>
29#include <wx/stdpaths.h>
85 wxLogFatalError( wxT(
"Unexpected call to Kiface() in kicad/kicad.cpp" ) );
87 throw std::logic_error(
"Unexpected call to Kiface() in kicad/kicad.cpp" );
252static void printHelp( argparse::ArgumentParser& argParser )
254 std::stringstream ss;
256 wxPrintf(
FROM_UTF8( ss.str().c_str() ) );
263 App().SetAppDisplayName( wxT(
"KiCad-cli" ) );
269 wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
271 if( !wxIsAbsolutePath( absoluteArgv0 ) )
273 wxLogError( wxT(
"No meaningful argv[0]" ) );
292 argparse::ArgumentParser argParser( std::string(
"kicad-cli" ),
GetMajorMinorVersion().ToStdString(),
293 argparse::default_arguments::none );
296 .default_value(
false )
297 .help(
UTF8STDSTR(
_(
"prints version information and exits" ) ) )
298 .implicit_value(
true )
302 .default_value(
false )
304 .implicit_value(
true )
316 catch(
const std::runtime_error& err )
318 wxPrintf(
"%s\n", err.what() );
324 if( argParser.is_subcommand_used( entry.handler->GetName() ) )
345 std::stringstream ss;
347 wxPrintf(
FROM_UTF8( ss.str().c_str() ) );
364 if( argParser.is_subcommand_used( entry.handler->GetName() ) )
367 if( cmdSubEntry !=
nullptr )
417#if defined( __WXMAC__ )
418 wxFAIL_MSG(
"kicad-cli should not call MacOpenFile" );
468#if defined( __FreeBSD__ )
470 wxLog::EnableLogging(
false );
473 return wxAppConsole::OnExit();
482 catch(
const std::exception& e )
484 wxLogError( wxT(
"Unhandled exception class: %s what: %s" ),
489 wxLogError( ioe.
What() );
493 wxLogError( wxT(
"Unhandled exception of unknown type" ) );
501 if( aEvent.GetEventType() == wxEVT_SHOW )
503 wxShowEvent&
event =
static_cast<wxShowEvent&
>( aEvent );
504 wxDialog* dialog =
dynamic_cast<wxDialog*
>(
event.GetEventObject() );
510 if( event.IsShown() && dialog->IsModal() )
512 dlgs.push_back( dialog );
515 else if( !event.IsShown() && !dlgs.empty() )
518 if( dlgs.back() == dialog )
521 else if(
auto it = std::find( dlgs.begin(), dlgs.end(), dialog ) ; it != dlgs.end() )
522 dlgs.erase( it, dlgs.end() );
534 bool ProcessEvent( wxEvent& aEvent )
override
536 if( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
538 wxKeyEvent* keyEvent =
static_cast<wxKeyEvent*
>( &aEvent );
557 bool OnExceptionInMainLoop()
override
563 catch(
const std::exception& e )
565 wxLogError(
"Unhandled exception class: %s what: %s",
FROM_UTF8(
typeid( e ).
name() ),
570 wxLogError( ioe.
What() );
574 wxLogError(
"Unhandled exception of unknown type" );
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
argparse::ArgumentParser & GetArgParser()
const std::string & GetName() const
int Perform(KIWAY &aKiway)
Entry point to processing commands from args and doing work.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Container for data for KiCad programs.
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
int m_argcUtf8
argv parameters converted to utf8 form, because wxwidgets has opinions and will return argv as either...
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
bool InitPgm(bool aHeadless=false, bool aSkipPyInit=false, bool aIsUnitTest=false)
Initialize this program.
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
std::vector< void * > m_ModalDialogs
virtual SETTINGS_MANAGER & GetSettingsManager() const
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
PGM_KICAD extends PGM_BASE to bring in FileHistory() and PdfBrowser() which were moved from EDA_APP i...
void MacOpenFile(const wxString &aFileName) override
Specific to MacOSX (not used under Linux or Windows).
APP_SETTINGS_BASE * PgmSettings()
Container for project specific data.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
void SetKiway(KIWAY *aKiway)
Associate this setting manager with the given Kiway.
#define KICAD_CLI_APP_NAME
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
static CLI::EXPORT_PCB_POS_COMMAND exportPcbPosCmd
static CLI::EXPORT_PCB_PDF_COMMAND exportPcbPdfCmd
static CLI::EXPORT_PCB_DXF_COMMAND exportPcbDxfCmd
static CLI::EXPORT_SCH_COMMAND exportSchCmd
static CLI::FP_EXPORT_SVG_COMMAND fpExportSvgCmd
static CLI::SYM_UPGRADE_COMMAND symUpgradeCmd
static CLI::FP_EXPORT_COMMAND fpExportCmd
static CLI::FP_UPGRADE_COMMAND fpUpgradeCmd
static void printHelp(argparse::ArgumentParser &argParser)
static CLI::EXPORT_PCB_GERBER_COMMAND exportPcbGerberCmd
static CLI::EXPORT_PCB_COMMAND exportPcbCmd
static CLI::EXPORT_SCH_NETLIST_COMMAND exportSchNetlistCmd
static CLI::EXPORT_PCB_DRILL_COMMAND exportPcbDrillCmd
static CLI::SYM_COMMAND symCmd
static CLI::EXPORT_PCB_GERBERS_COMMAND exportPcbGerbersCmd
static CLI::EXPORT_PCB_STEP_COMMAND exportPcbStepCmd
static CLI::EXPORT_PCB_SVG_COMMAND exportPcbSvgCmd
static CLI::EXPORT_SCH_PYTHONBOM_COMMAND exportSchPythonBomCmd
static CLI::SCH_COMMAND schCmd
static CLI::PCB_COMMAND pcbCmd
static std::vector< COMMAND_ENTRY > commandStack
static CLI::SYM_EXPORT_COMMAND symExportCmd
static CLI::SYM_EXPORT_SVG_COMMAND symExportSvgCmd
static COMMAND_ENTRY * recurseArgParserSubCommandUsed(argparse::ArgumentParser &aArgParser, COMMAND_ENTRY &aEntry)
static CLI::EXPORT_SCH_PDF_COMMAND exportSchPdfCmd
PGM_BASE & Pgm()
The global Program "get" accessor.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static CLI::VERSION_COMMAND versionCmd
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
static CLI::EXPORT_SCH_SVG_COMMAND exportSchSvgCmd
static void recurseArgParserBuild(argparse::ArgumentParser &aArgParser, COMMAND_ENTRY &aEntry)
static CLI::FP_COMMAND fpCmd
#define KFCTL_CPP_PROJECT_SUITE
Running under C++ project mgr, possibly with others.
#define KFCTL_CLI
Running as CLI app.
This file contains miscellaneous commonly used macros and functions.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
static const int ERR_ARGS
static const int AVOID_CLOSING
Not publicly visible because most of the action is in PGM_KICAD these days.
int FilterEvent(wxEvent &aEvent) override
void InitSettings(APP_SETTINGS_BASE *aPtr)
Takes ownership of a new application settings object.
COMMAND_ENTRY(CLI::COMMAND *aHandler)
COMMAND_ENTRY(CLI::COMMAND *aHandler, std::vector< COMMAND_ENTRY > aSub)
std::vector< COMMAND_ENTRY > subCommands
System directories search utilities.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.