KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kicad.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 (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
25
26
27#include <wx/filename.h>
28#include <wx/log.h>
29#include <wx/app.h>
30#include <wx/stdpaths.h>
31#include <wx/msgdlg.h>
32#include <wx/cmdline.h>
33
34#include <api/api_server.h>
35#include <common.h>
36#include <env_vars.h>
37#include <file_history.h>
38#include <hotkeys_basic.h>
39#include <kiway.h>
40#include <macros.h>
41#include <paths.h>
42#include <richio.h>
47#include <systemdirsappend.h>
48#include <thread_pool.h>
49#include <trace_helpers.h>
51#include <confirm.h>
52#if defined( KICAD_NATIVE_MODEL_PREVIEW ) && defined( __WINDOWS__ )
54#endif
55
56#include <git/git_backend.h>
57#include <git/libgit_backend.h>
58#include <cstdlib>
59
60#include "pgm_kicad.h"
61#include "kicad_manager_frame.h"
62#include "mergetool_frame.h"
63
64#include <wx/crt.h>
65#include <wx/evtloop.h>
66#include <wx/weakref.h>
67
68#include <kiplatform/app.h>
70
71// a dummy to quiet linking with EDA_BASE_FRAME::config();
72#include <kiface_base.h>
73
75
76
78{
79 // This function should never be called. It is only referenced from
80 // EDA_BASE_FRAME::config() and this is only provided to satisfy the
81 // linker, not to be actually called. Print the diagnostic to stderr
82 // and abort — throwing here lets wxApp's top-level exception handler
83 // pop a second modal dialog, which defeats the point of moving the
84 // diagnostic to the terminal in the first place.
85 wxFprintf( stderr,
86 wxT( "Unexpected call to Kiface() in kicad/kicad.cpp — a "
87 "project-manager-process code path is reaching into a "
88 "kiface stub. Re-run with KICAD_TRACE=KICAD for a "
89 "backtrace.\n" ) );
90 std::abort();
91}
92
93
95
97{
98 return program;
99}
100
101
103{
104 App().SetAppDisplayName( wxT( "KiCad" ) );
105
106#if defined(DEBUG)
107 wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
108
109 if( !wxIsAbsolutePath( absoluteArgv0 ) )
110 {
111 wxLogError( wxT( "No meaningful argv[0]" ) );
112 return false;
113 }
114#endif
115
116 // Initialize the git backend before trying to initialize individual programs
118 GetGitBackend()->Init();
119
120 static const wxCmdLineEntryDesc desc[] = {
121 { wxCMD_LINE_OPTION, "f", "frame", "Frame to load", wxCMD_LINE_VAL_STRING, 0 },
122 { wxCMD_LINE_SWITCH, "n", "new", "New instance of KiCad, does not attempt to load previously open files",
123 wxCMD_LINE_VAL_NONE, 0 },
124 { wxCMD_LINE_SWITCH, nullptr, "mergetool",
125 "Launch the 3-way merge tool. Expects four positional args: "
126 "ANCESTOR OURS THEIRS MERGED. Intended as a `git mergetool` driver.",
127 wxCMD_LINE_VAL_NONE, 0 },
128#ifndef __WXOSX__
129 { wxCMD_LINE_SWITCH, nullptr, "software-rendering", "Use software rendering instead of OpenGL",
130 wxCMD_LINE_VAL_NONE, 0 },
131#endif
132 { wxCMD_LINE_PARAM, nullptr, nullptr, "File to load", wxCMD_LINE_VAL_STRING,
133 wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
134 { wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 }
135 };
136
137 wxCmdLineParser parser( App().argc, App().argv );
138 parser.SetDesc( desc );
139 parser.Parse( false );
140
141 bool mergetoolMode = parser.FoundSwitch( "mergetool" ) == wxCMD_SWITCH_ON;
142
143 if( mergetoolMode && parser.GetParamCount() != 4 )
144 {
145 wxFprintf( stderr,
146 wxT( "kicad --mergetool expects four positional arguments: "
147 "ANCESTOR OURS THEIRS MERGED\n" ) );
148 return false;
149 }
150
151 FRAME_T appType = mergetoolMode ? FRAME_MERGETOOL : KICAD_MAIN_FRAME_T;
152
153 const struct
154 {
155 wxString name;
156 FRAME_T type;
157 // clang-format off
158 } frameTypes[] = { { wxT( "pcb" ), FRAME_PCB_EDITOR },
159 { wxT( "fpedit" ), FRAME_FOOTPRINT_EDITOR },
160 { wxT( "sch" ), FRAME_SCH },
161 { wxT( "calc" ), FRAME_CALC },
162 { wxT( "ds" ), FRAME_PL_EDITOR },
163 { wxT( "gerb" ), FRAME_GERBER },
164 { wxT( "" ), FRAME_T_COUNT } };
165 // clang-format on
166
167 wxString frameName;
168
169 if( parser.Found( "frame", &frameName ) )
170 {
171 appType = FRAME_T_COUNT;
172
173 for( const auto& it : frameTypes )
174 {
175 if( it.name == frameName )
176 appType = it.type;
177 }
178
179 if( appType == FRAME_T_COUNT )
180 {
181 wxLogError( wxT( "Unknown frame: %s" ), frameName );
182 return false;
183 }
184 }
185
186 if( appType == KICAD_MAIN_FRAME_T )
187 {
188 Kiway.SetCtlBits( KFCTL_CPP_PROJECT_SUITE );
189 }
190 else
191 {
192 Kiway.SetCtlBits( KFCTL_STANDALONE );
193 }
194
195#ifndef __WXMAC__
196 if( parser.Found( "software-rendering" ) )
197 {
198 wxSetEnv( "KICAD_SOFTWARE_RENDERING", "1" );
199 }
200#endif
201
202 if( !InitPgm( false ) )
203 return false;
204
205
206 m_bm.InitSettings( new KICAD_SETTINGS );
209 m_bm.Init();
210
211 if( const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
212 {
213 if( cfg->m_Appearance.app_theme == APP_THEME::DARK )
215 else if( cfg->m_Appearance.app_theme == APP_THEME::AUTO )
217 }
218
219 // Add search paths to feed the PGM_KICAD::SysSearch() function,
220 // currently limited in support to only look for project templates
221 {
222 SEARCH_STACK bases;
223
224 SystemDirsAppend( &bases );
225
226 for( unsigned i = 0; i < bases.GetCount(); ++i )
227 {
228 wxFileName fn( bases[i], wxEmptyString );
229
230 // Add KiCad template file path to search path list.
231 fn.AppendDir( wxT( "template" ) );
232
233 // Only add path if exists and can be read by the user.
234 if( fn.DirExists() && fn.IsDirReadable() )
235 m_bm.m_search.AddPaths( fn.GetPath() );
236 }
237
238 auto insertExpanded = [&]( const wxString& aValue )
239 {
240 wxString resolved = ExpandEnvVarSubstitutions( aValue, nullptr );
241
242 // Skip values that still contain unresolved variable references so we don't
243 // pollute the search stack with paths like "${MISSING}/templates".
244 if( resolved.Contains( wxT( "${" ) ) || resolved.Contains( wxT( "$(" ) ) )
245 return;
246
247 m_bm.m_search.Insert( resolved, 0 );
248 };
249
250 // The versioned TEMPLATE_DIR takes precedence over the search stack template path.
251 if( std::optional<wxString> v = ENV_VAR::GetVersionedEnvVarValue( GetLocalEnvVariables(),
252 wxT( "TEMPLATE_DIR" ) ) )
253 {
254 if( !v->IsEmpty() )
255 insertExpanded( *v );
256 }
257
258 // We've been adding system (installed default) search paths so far, now for user paths
259 // The default user search path is inside KIPLATFORM::ENV::GetDocumentsPath()
260 m_bm.m_search.Insert( PATHS::GetUserTemplatesPath(), 0 );
261
262 // ...but the user can override that default with the KICAD_USER_TEMPLATE_DIR env var.
263 // The value may itself reference other KiCad path variables, so expand them here.
264 ENV_VAR_MAP_CITER it = GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
265
266 if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
267 insertExpanded( it->second.GetValue() );
268 }
269
270 wxFrame* frame = nullptr;
271 KIWAY_PLAYER* playerFrame = nullptr;
272 KICAD_MANAGER_FRAME* managerFrame = nullptr;
273 MERGETOOL_FRAME* mergetoolFrame = nullptr;
274
275 // Editor frames register their API handlers in their constructors, so the API server must
276 // be live before any frame is built. The short-lived --mergetool driver skips it to avoid
277 // contending for the singleton IPC socket.
278 if( appType != FRAME_MERGETOOL )
279 {
280 m_api_server = std::make_unique<KICAD_API_SERVER>();
281 m_api_common_handler = std::make_unique<API_HANDLER_COMMON>();
282 m_api_server->RegisterHandler( m_api_common_handler.get() );
283 m_api_libraries_handler = std::make_unique<API_HANDLER_LIBRARIES>(
285 m_api_server->RegisterHandler( m_api_libraries_handler.get() );
286 }
287
288 if( appType == FRAME_MERGETOOL )
289 {
290 // A later project load can change the working directory, so resolve git's relative paths now
291 auto absolute = [&]( size_t aIndex )
292 {
293 wxFileName fn( parser.GetParam( aIndex ) );
294 fn.MakeAbsolute();
295 return fn.GetFullPath();
296 };
297
298 MERGETOOL_PATHS paths{ absolute( 0 ), absolute( 1 ), absolute( 2 ), absolute( 3 ) };
299 mergetoolFrame = new MERGETOOL_FRAME( &Kiway, nullptr, paths );
300 frame = mergetoolFrame;
301 }
302 else if( appType == KICAD_MAIN_FRAME_T )
303 {
304 managerFrame = new KICAD_MANAGER_FRAME( nullptr, wxT( "KiCad" ), wxDefaultPosition,
305 wxWindow::FromDIP( wxSize( 775, -1 ), NULL ) );
306 frame = managerFrame;
307
308 STARTWIZARD startWizard;
309 startWizard.CheckAndRun( frame );
310 }
311 else
312 {
313 // Use KIWAY to create a top window, which registers its existence also.
314 // "TOP_FRAME" is a macro that is passed on compiler command line from CMake,
315 // and is one of the types in FRAME_T.
316 playerFrame = Kiway.Player( appType, true );
317 frame = playerFrame;
318
319 if( frame == nullptr )
320 {
321 return false;
322 }
323 }
324
325 App().SetTopWindow( frame );
326
327 if( playerFrame )
328 App().SetAppDisplayName( playerFrame->GetAboutTitle() );
329
330 Kiway.SetTop( frame );
331
332 KIPLATFORM::ENV::SetAppDetailsForWindow( frame, '"' + wxStandardPaths::Get().GetExecutablePath() + '"' + " -n",
333 frame->GetTitle() );
334
335 KICAD_SETTINGS* settings = static_cast<KICAD_SETTINGS*>( PgmSettings() );
336
338
339 wxString projToLoad;
340
341 HideSplash();
342
343 if( playerFrame && parser.GetParamCount() )
344 {
345 // Now after the frame processing, the rest of the positional args are files
346 std::vector<wxString> fileArgs;
347 /*
348 gerbview handles multiple project data files, i.e. gerber files on
349 cmd line. Others currently do not, they handle only one. For common
350 code simplicity we simply pass all the arguments in however, each
351 program module can do with them what they want, ignore, complain
352 whatever. We don't establish policy here, as this is a multi-purpose
353 launcher.
354 */
355
356 for( size_t i = 0; i < parser.GetParamCount(); i++ )
357 fileArgs.push_back( parser.GetParam( i ) );
358
359 // special attention to a single argument: argv[1] (==argSet[0])
360 if( fileArgs.size() == 1 )
361 {
362 wxFileName argv1( fileArgs[0] );
363
364#if defined( PGM_DATA_FILE_EXT )
365 // PGM_DATA_FILE_EXT, if present, may be different for each compile,
366 // it may come from CMake on the compiler command line, but often does not.
367 // This facility is mostly useful for those program footprints
368 // supporting a single argv[1].
369 if( !argv1.GetExt() )
370 argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
371#endif
372 argv1.MakeAbsolute();
373
374 fileArgs[0] = argv1.GetFullPath();
375 }
376
377 // Use the KIWAY_PLAYER::OpenProjectFiles() API function:
378 if( !playerFrame->OpenProjectFiles( fileArgs ) )
379 {
380 // OpenProjectFiles() API asks that it report failure to the UI.
381 // Nothing further to say here.
382
383 // Fail the process startup if the file could not be opened,
384 // although this is an optional choice, one that can be reversed
385 // also in the KIFACE specific OpenProjectFiles() return value.
386 return false;
387 }
388 }
389 else if( managerFrame )
390 {
391 if( parser.GetParamCount() > 0 )
392 {
393 wxFileName tmp = parser.GetParam( 0 );
394
395 if( tmp.GetExt() != FILEEXT::ProjectFileExtension && tmp.GetExt() != FILEEXT::LegacyProjectFileExtension )
396 {
397 DisplayErrorMessage( nullptr, wxString::Format( _( "File '%s'\n"
398 "does not appear to be a KiCad project file." ),
399 tmp.GetFullPath() ) );
400 }
401 else
402 {
403 projToLoad = tmp.GetFullPath();
404 }
405 }
406
407 // If no file was given as an argument, check that there was a file open.
408 if( projToLoad.IsEmpty() && settings->m_OpenProjects.size() && !parser.FoundSwitch( "new" ) )
409 {
410 wxString last_pro = settings->m_OpenProjects.front();
411 settings->m_OpenProjects.erase( settings->m_OpenProjects.begin() );
412
413 if( wxFileExists( last_pro ) )
414 {
415 // Try to open the last opened project,
416 // if a project name is not given when starting Kicad
417 projToLoad = last_pro;
418 }
419 }
420
421 bool loaded = false;
422
423 // Do not attempt to load a non-existent project file.
424 if( !projToLoad.empty() )
425 {
426 wxFileName fn( projToLoad );
427
428 if( fn.Exists() && ( fn.GetExt() == FILEEXT::ProjectFileExtension
429 || fn.GetExt() == FILEEXT::LegacyProjectFileExtension ) )
430 {
431 fn.MakeAbsolute();
432
433 if( appType == KICAD_MAIN_FRAME_T )
434 loaded = managerFrame->LoadProject( fn );
435 }
436 }
437
438 if( !loaded && appType == KICAD_MAIN_FRAME_T )
439 managerFrame->PreloadAllLibraries();
440 }
441
442 if( mergetoolFrame )
443 {
444 // Closing the host frame must not replace the merge result with an exit code of zero.
445 App().SetExitOnFrameDelete( false );
446
447 // Stay hidden; the merge dialog is its own modal. The frame just needs
448 // to be the wxApp top window so the modal has a parent and the wxApp
449 // loop has something to drive. Defer the run via CallAfter so the
450 // event loop is up before ShowModal spins its nested loop. The
451 // wxWeakRef guards against the frame being destroyed (window-manager
452 // close, fatal init) before the callback fires.
453 wxWeakRef<MERGETOOL_FRAME> mergeToolFrameRef( mergetoolFrame );
454
455 mergetoolFrame->CallAfter(
456 [mergeToolFrameRef]() mutable
457 {
458 if( !mergeToolFrameRef || mergeToolFrameRef->IsBeingDeleted() )
459 return;
460
461 int exitCode = mergeToolFrameRef->RunMerge();
462
463 // Propagate the merge JOB's exit code to the kicad
464 // process exit status so `git mergetool` sees a non-zero
465 // status on unresolved conflicts.
466 if( wxEventLoopBase* loop = wxTheApp->GetMainLoop() )
467 loop->ScheduleExit( exitCode );
468
469 mergeToolFrameRef->Close( true );
470 } );
471 }
472 else
473 {
474 frame->Show( true );
475 frame->Raise();
476
477#if defined( KICAD_NATIVE_MODEL_PREVIEW ) && defined( __WINDOWS__ )
478 frame->CallAfter( [frame] { MaybeShowModelPreviewSetupPrompt( frame ); } );
479#endif
480 }
481
482 if( m_api_server )
483 m_api_server->SetReadyToReply();
484
485 return true;
486}
487
488
490{
491 return 0;
492}
493
494
496{
497 // Signal all background library preloads to abort before waiting for the thread pool.
498 // The design block preload runs on the global thread pool and checks this flag; without
499 // setting it here the pool wait below can block for up to 120 seconds.
500 m_libraryPreloadAbort.store( true );
501
502 // Abort and wait on any background jobs, if InitPgm() got far enough to start the pool
503 if( m_singleton.m_ThreadPool )
504 {
505 GetKiCadThreadPool().purge();
506 GetKiCadThreadPool().wait();
507 }
508
509 Kiway.OnKiwayEnd();
510
511 m_api_server.reset();
512
514 {
516 m_settings_manager->Save();
517 }
518
519 // Destroy PGM_KICAD earlier than wxApp and static destruction would
520 Destroy();
521
522 if( GIT_BACKEND* backend = GetGitBackend() )
523 {
524 backend->Shutdown();
525 delete backend;
526 SetGitBackend( nullptr );
527 }
528}
529
530
531void PGM_KICAD::MacOpenFile( const wxString& aFileName )
532{
533#if defined(__WXMAC__)
534
535 KICAD_MANAGER_FRAME* frame = (KICAD_MANAGER_FRAME*) App().GetTopWindow();
536
537 if( !aFileName.empty() && wxFileExists( aFileName ) )
538 frame->LoadProject( wxFileName( aFileName ) );
539
540#endif
541}
542
543
545{
546 // unlike a normal destructor, this is designed to be called more
547 // than once safely:
548
549 m_bm.End();
550
552}
553
554
556
557#ifdef NDEBUG
558// Define a custom assertion handler
559void CustomAssertHandler(const wxString& file,
560 int line,
561 const wxString& func,
562 const wxString& cond,
563 const wxString& msg)
564{
565 Pgm().HandleAssert( file, line, func, cond, msg );
566}
567#endif
568
572struct APP_KICAD : public wxApp
573{
574 APP_KICAD() : wxApp()
575 {
576 SetPgm( &program );
577
578 // Init the environment each platform wants
580 }
581
582
583 bool OnInit() override
584 {
585#ifdef NDEBUG
586 // These checks generate extra assert noise
587 wxSizerFlags::DisableConsistencyChecks();
588 wxDISABLE_DEBUG_SUPPORT();
589 wxSetAssertHandler( CustomAssertHandler );
590#endif
591
592 // Perform platform-specific init tasks
593 if( !KIPLATFORM::APP::Init() )
594 return false;
595
596#ifndef DEBUG
597 // Enable logging traces to the console in release build.
598 // This is usually disabled, but it can be useful for users to run to help
599 // debug issues and other problems.
600 if( wxGetEnv( wxS( "KICAD_ENABLE_WXTRACE" ), nullptr ) )
601 {
602 wxLog::EnableLogging( true );
603 wxLog::SetLogLevel( wxLOG_Trace );
604 }
605#endif
606
607 // An escaping exception would skip OnPgmExit() and crash the static teardown
608 try
609 {
610 if( program.OnPgmInit() )
611 return true;
612 }
613 catch( ... )
614 {
615 Pgm().HandleException( std::current_exception() );
616 }
617
618 program.OnPgmExit();
619 return false;
620 }
621
622 int OnExit() override
623 {
624 // Drain wxPendingDelete (frames deferred via Destroy()) before tearing down
625 // PGM_BASE singletons. On macOS the dock-quit path leaves frames in this
626 // queue at OnExit() time, and their canvas destructors call into
627 // Pgm().GetGLContextManager(). Running OnPgmExit() first would null that
628 // pointer out from under them. See https://gitlab.com/kicad/code/kicad/-/issues/23373
629 int ret = wxApp::OnExit();
630
631 // Avoid wxLog crashing when used in destructors invoked from OnPgmExit().
632 wxLog::EnableLogging( false );
633
634 program.OnPgmExit();
635 program.ExitIfTeardownUnsafe();
636
637 return ret;
638 }
639
640
641 int OnRun() override
642 {
643 int ret = -1;
644
645 try
646 {
647 ret = wxApp::OnRun();
648 }
649 catch(...)
650 {
651 Pgm().HandleException( std::current_exception() );
652 }
653
654 program.SetRunResult( ret );
655
656 return ret;
657 }
658
659
660 void OnUnhandledException() override
661 {
662 Pgm().HandleException( std::current_exception(), true );
663 }
664
665
666 int FilterEvent( wxEvent& aEvent ) override
667 {
668 return Pgm().FilterAppEvent( aEvent );
669 }
670
671#if defined( DEBUG )
675 bool ProcessEvent( wxEvent& aEvent ) override
676 {
677 if( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
678 {
679 wxKeyEvent* keyEvent = static_cast<wxKeyEvent*>( &aEvent );
680
681 if( keyEvent )
682 {
683 wxLogTrace( kicadTraceKeyEvent, "APP_KICAD::ProcessEvent %s", dump( *keyEvent ) );
684 }
685 }
686
687 return wxApp::ProcessEvent( aEvent );
688 }
689
697 bool OnExceptionInMainLoop() override
698 {
699 try
700 {
701 throw;
702 }
703 catch(...)
704 {
705 Pgm().HandleException( std::current_exception() );
706 }
707
708 return false; // continue on. Return false to abort program
709 }
710#endif
711
717#if defined( __WXMAC__ )
718 void MacOpenFile( const wxString& aFileName ) override
719 {
720 Pgm().MacOpenFile( aFileName );
721 }
722#endif
723};
724
725IMPLEMENT_APP( APP_KICAD )
726
727
728// The C++ project manager supports one open PROJECT, so Prj() calls within
729// this link image need this function.
731{
732 return Kiway.Prj();
733}
const char * name
wxString GetAboutTitle() const
virtual void Init()=0
The main KiCad project manager frame.
bool LoadProject(const wxFileName &aProjectFileName)
Loads a new project.
std::vector< wxString > m_OpenProjects
A KIFACE implementation.
Definition kiface_base.h:35
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:348
void LoadGlobalTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the global library tables in the given list, or all tables if no list is given
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
Definition paths.cpp:71
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:600
virtual wxApp & App()
Return a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition pgm_base.cpp:236
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition pgm_base.cpp:846
virtual void MacOpenFile(const wxString &aFileName)=0
Specific to MacOSX (not used under Linux or Windows).
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition pgm_base.h:442
int FilterAppEvent(wxEvent &aEvent)
Handle events that must be seen once per application, before any window processes them.
void Destroy()
Definition pgm_base.cpp:190
void HandleException(std::exception_ptr aPtr, bool aUnhandled=false)
A exception handler to be used at the top level if exceptions bubble up that for.
Definition pgm_base.cpp:861
std::atomic_bool m_libraryPreloadAbort
Definition pgm_base.h:487
bool InitPgm(bool aHeadless=false, bool aIsUnitTest=false)
Initialize this program.
Definition pgm_base.cpp:373
std::unique_ptr< KICAD_API_SERVER > m_api_server
Definition pgm_base.h:448
void HandleAssert(const wxString &aFile, int aLine, const wxString &aFunc, const wxString &aCond, const wxString &aMsg)
A common assert handler to be used between single_top and kicad.
Definition pgm_base.cpp:898
virtual const wxString & GetExecutablePath() const
Definition pgm_base.cpp:926
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
void HideSplash()
Definition pgm_base.cpp:341
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:126
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition pgm_base.cpp:591
KICAD_SINGLETON m_singleton
Definition pgm_base.h:463
PGM_KICAD extends PGM_BASE to bring in FileHistory() and PdfBrowser() which were moved from EDA_APP i...
Definition pgm_kicad.h:37
bool OnPgmInit()
Definition kicad.cpp:102
void Destroy()
Definition kicad.cpp:544
std::unique_ptr< API_HANDLER_COMMON > m_api_common_handler
Definition pgm_kicad.h:71
void MacOpenFile(const wxString &aFileName) override
Specific to MacOSX (not used under Linux or Windows).
Definition kicad.cpp:531
void OnPgmExit()
Definition kicad.cpp:495
APP_SETTINGS_BASE * PgmSettings()
Definition pgm_kicad.h:54
std::unique_ptr< API_HANDLER_LIBRARIES > m_api_libraries_handler
Definition pgm_kicad.h:72
int OnPgmRun()
Definition kicad.cpp:489
BIN_MOD m_bm
Definition pgm_kicad.h:67
Container for project specific data.
Definition project.h:63
Look for files in a number of paths.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
void SetKiway(KIWAY *aKiway)
Associate this setting manager with the given Kiway.
void CheckAndRun(wxWindow *parent)
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject, bool aAllowEscapes)
Replace any environment variable & text variable references with their values.
Definition common.cpp:777
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
This file is part of the common library.
#define _(s)
Functions related to environment variables, including help functions.
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:29
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
@ FRAME_CALC
Definition frame_type.h:57
@ FRAME_SCH
Definition frame_type.h:30
@ FRAME_MERGETOOL
Top-level host for the 3-way merge resolution dialog.
Definition frame_type.h:62
@ FRAME_T_COUNT
Definition frame_type.h:69
@ FRAME_PL_EDITOR
Definition frame_type.h:55
@ FRAME_FOOTPRINT_EDITOR
Definition frame_type.h:39
@ FRAME_GERBER
Definition frame_type.h:53
@ KICAD_MAIN_FRAME_T
Definition frame_type.h:67
void SetGitBackend(GIT_BACKEND *aBackend)
GIT_BACKEND * GetGitBackend()
static const std::string ProjectFileExtension
static const std::string LegacyProjectFileExtension
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
PGM_KICAD & PgmTop()
Definition kicad.cpp:96
PROJECT & Prj()
Definition kicad.cpp:730
static PGM_KICAD program
Definition kicad.cpp:94
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition kicad.cpp:77
KIWAY Kiway(KFCTL_CPP_PROJECT_SUITE)
#define KFCTL_CPP_PROJECT_SUITE
Running under C++ project mgr, possibly with others.
Definition kiway.h:175
#define KFCTL_STANDALONE
Running as a standalone Top.
Definition kiway.h:174
This file contains miscellaneous commonly used macros and functions.
KICOMMON_API std::optional< wxString > GetVersionedEnvVarValue(const std::map< wxString, ENV_VAR_ITEM > &aMap, const wxString &aBaseName)
Attempt to retrieve the value of a versioned environment variable, such as KICAD8_TEMPLATE_DIR.
Definition env_vars.cpp:104
bool Init()
Perform application-specific initialization tasks.
Definition unix/app.cpp:46
void EnableDarkMode(bool aForce)
Definition unix/app.cpp:64
void Init()
Perform environment initialization tasks.
void SetAppDetailsForWindow(wxWindow *aWindow, const wxString &aRelaunchCommand, const wxString &aRelaunchDisplayName)
Sets the relaunch command for taskbar pins, this is intended for Windows.
void SetPgm(PGM_BASE *pgm)
PGM_BASE & Pgm()
The global program "get" accessor.
PGM_SINGLE_TOP program
KIWAY Kiway(KFCTL_STANDALONE)
Not publicly visible because most of the action is in PGM_KICAD these days.
Definition kicad.cpp:573
int OnRun() override
Definition kicad.cpp:641
APP_KICAD()
Definition kicad.cpp:574
bool OnInit() override
Definition kicad.cpp:583
int OnExit() override
Definition kicad.cpp:622
void OnUnhandledException() override
Definition kicad.cpp:660
int FilterEvent(wxEvent &aEvent) override
Definition kicad.cpp:666
Top-level host frame for the 3-way merge resolution dialog.
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
System directories search utilities.
VECTOR2I end
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.
Definition of file extensions used in Kicad.