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
53#include <git/git_backend.h>
54#include <git/libgit_backend.h>
55#include <cstdlib>
56
57#include "pgm_kicad.h"
58#include "kicad_manager_frame.h"
59#include "mergetool_frame.h"
60
61#include <wx/crt.h>
62#include <wx/evtloop.h>
63#include <wx/weakref.h>
64
65#include <kiplatform/app.h>
67
68// a dummy to quiet linking with EDA_BASE_FRAME::config();
69#include <kiface_base.h>
70
72
73
75{
76 // This function should never be called. It is only referenced from
77 // EDA_BASE_FRAME::config() and this is only provided to satisfy the
78 // linker, not to be actually called. Print the diagnostic to stderr
79 // and abort — throwing here lets wxApp's top-level exception handler
80 // pop a second modal dialog, which defeats the point of moving the
81 // diagnostic to the terminal in the first place.
82 wxFprintf( stderr,
83 wxT( "Unexpected call to Kiface() in kicad/kicad.cpp — a "
84 "project-manager-process code path is reaching into a "
85 "kiface stub. Re-run with KICAD_TRACE=KICAD for a "
86 "backtrace.\n" ) );
87 std::abort();
88}
89
90
92
94{
95 return program;
96}
97
98
100{
101 App().SetAppDisplayName( wxT( "KiCad" ) );
102
103#if defined(DEBUG)
104 wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
105
106 if( !wxIsAbsolutePath( absoluteArgv0 ) )
107 {
108 wxLogError( wxT( "No meaningful argv[0]" ) );
109 return false;
110 }
111#endif
112
113 // Initialize the git backend before trying to initialize individual programs
115 GetGitBackend()->Init();
116
117 static const wxCmdLineEntryDesc desc[] = {
118 { wxCMD_LINE_OPTION, "f", "frame", "Frame to load", wxCMD_LINE_VAL_STRING, 0 },
119 { wxCMD_LINE_SWITCH, "n", "new", "New instance of KiCad, does not attempt to load previously open files",
120 wxCMD_LINE_VAL_NONE, 0 },
121 { wxCMD_LINE_SWITCH, nullptr, "mergetool",
122 "Launch the 3-way merge tool. Expects four positional args: "
123 "ANCESTOR OURS THEIRS MERGED. Intended as a `git mergetool` driver.",
124 wxCMD_LINE_VAL_NONE, 0 },
125#ifndef __WXOSX__
126 { wxCMD_LINE_SWITCH, nullptr, "software-rendering", "Use software rendering instead of OpenGL",
127 wxCMD_LINE_VAL_NONE, 0 },
128#endif
129 { wxCMD_LINE_PARAM, nullptr, nullptr, "File to load", wxCMD_LINE_VAL_STRING,
130 wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
131 { wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 }
132 };
133
134 wxCmdLineParser parser( App().argc, App().argv );
135 parser.SetDesc( desc );
136 parser.Parse( false );
137
138 bool mergetoolMode = parser.FoundSwitch( "mergetool" ) == wxCMD_SWITCH_ON;
139
140 if( mergetoolMode && parser.GetParamCount() != 4 )
141 {
142 wxFprintf( stderr,
143 wxT( "kicad --mergetool expects four positional arguments: "
144 "ANCESTOR OURS THEIRS MERGED\n" ) );
145 return false;
146 }
147
148 FRAME_T appType = mergetoolMode ? FRAME_MERGETOOL : KICAD_MAIN_FRAME_T;
149
150 const struct
151 {
152 wxString name;
153 FRAME_T type;
154 } frameTypes[] = { { wxT( "pcb" ), FRAME_PCB_EDITOR },
155 { wxT( "fpedit" ), FRAME_FOOTPRINT_EDITOR },
156 { wxT( "sch" ), FRAME_SCH },
157 { wxT( "calc" ), FRAME_CALC },
158 { wxT( "bm2cmp" ), FRAME_BM2CMP },
159 { wxT( "ds" ), FRAME_PL_EDITOR },
160 { wxT( "gerb" ), FRAME_GERBER },
161 { wxT( "" ), FRAME_T_COUNT } };
162
163 wxString frameName;
164
165 if( parser.Found( "frame", &frameName ) )
166 {
167 appType = FRAME_T_COUNT;
168
169 for( const auto& it : frameTypes )
170 {
171 if( it.name == frameName )
172 appType = it.type;
173 }
174
175 if( appType == FRAME_T_COUNT )
176 {
177 wxLogError( wxT( "Unknown frame: %s" ), frameName );
178 // Clean up
179 OnPgmExit();
180 return false;
181 }
182 }
183
184 if( appType == KICAD_MAIN_FRAME_T )
185 {
186 Kiway.SetCtlBits( KFCTL_CPP_PROJECT_SUITE );
187 }
188 else
189 {
190 Kiway.SetCtlBits( KFCTL_STANDALONE );
191 }
192
193#ifndef __WXMAC__
194 if( parser.Found( "software-rendering" ) )
195 {
196 wxSetEnv( "KICAD_SOFTWARE_RENDERING", "1" );
197 }
198#endif
199
200 if( !InitPgm( false ) )
201 return false;
202
203
204 m_bm.InitSettings( new KICAD_SETTINGS );
207 m_bm.Init();
208
209 if( const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
210 {
211 if( cfg->m_Appearance.app_theme == APP_THEME::DARK )
213 else if( cfg->m_Appearance.app_theme == APP_THEME::AUTO )
215 }
216
217 // Add search paths to feed the PGM_KICAD::SysSearch() function,
218 // currently limited in support to only look for project templates
219 {
220 SEARCH_STACK bases;
221
222 SystemDirsAppend( &bases );
223
224 for( unsigned i = 0; i < bases.GetCount(); ++i )
225 {
226 wxFileName fn( bases[i], wxEmptyString );
227
228 // Add KiCad template file path to search path list.
229 fn.AppendDir( wxT( "template" ) );
230
231 // Only add path if exists and can be read by the user.
232 if( fn.DirExists() && fn.IsDirReadable() )
233 m_bm.m_search.AddPaths( fn.GetPath() );
234 }
235
236 auto insertExpanded = [&]( const wxString& aValue )
237 {
238 wxString resolved = ExpandEnvVarSubstitutions( aValue, nullptr );
239
240 // Skip values that still contain unresolved variable references so we don't
241 // pollute the search stack with paths like "${MISSING}/templates".
242 if( resolved.Contains( wxT( "${" ) ) || resolved.Contains( wxT( "$(" ) ) )
243 return;
244
245 m_bm.m_search.Insert( resolved, 0 );
246 };
247
248 // The versioned TEMPLATE_DIR takes precedence over the search stack template path.
249 if( std::optional<wxString> v = ENV_VAR::GetVersionedEnvVarValue( GetLocalEnvVariables(),
250 wxT( "TEMPLATE_DIR" ) ) )
251 {
252 if( !v->IsEmpty() )
253 insertExpanded( *v );
254 }
255
256 // We've been adding system (installed default) search paths so far, now for user paths
257 // The default user search path is inside KIPLATFORM::ENV::GetDocumentsPath()
258 m_bm.m_search.Insert( PATHS::GetUserTemplatesPath(), 0 );
259
260 // ...but the user can override that default with the KICAD_USER_TEMPLATE_DIR env var.
261 // The value may itself reference other KiCad path variables, so expand them here.
262 ENV_VAR_MAP_CITER it = GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
263
264 if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
265 insertExpanded( it->second.GetValue() );
266 }
267
268 wxFrame* frame = nullptr;
269 KIWAY_PLAYER* playerFrame = nullptr;
270 KICAD_MANAGER_FRAME* managerFrame = nullptr;
271 MERGETOOL_FRAME* mergetoolFrame = nullptr;
272
273 // Editor frames register their API handlers in their constructors, so the API server must
274 // be live before any frame is built. The short-lived --mergetool driver skips it to avoid
275 // contending for the singleton IPC socket.
276 if( appType != FRAME_MERGETOOL )
277 {
278 m_api_server = std::make_unique<KICAD_API_SERVER>();
279 m_api_common_handler = std::make_unique<API_HANDLER_COMMON>();
280 m_api_server->RegisterHandler( m_api_common_handler.get() );
281 }
282
283 if( appType == FRAME_MERGETOOL )
284 {
285 MERGETOOL_PATHS paths{ parser.GetParam( 0 ), parser.GetParam( 1 ),
286 parser.GetParam( 2 ), parser.GetParam( 3 ) };
287 mergetoolFrame = new MERGETOOL_FRAME( &Kiway, nullptr, paths );
288 frame = mergetoolFrame;
289 }
290 else if( appType == KICAD_MAIN_FRAME_T )
291 {
292 managerFrame = new KICAD_MANAGER_FRAME( nullptr, wxT( "KiCad" ), wxDefaultPosition,
293 wxWindow::FromDIP( wxSize( 775, -1 ), NULL ) );
294 frame = managerFrame;
295
296 STARTWIZARD startWizard;
297 startWizard.CheckAndRun( frame );
298 }
299 else
300 {
301 // Use KIWAY to create a top window, which registers its existence also.
302 // "TOP_FRAME" is a macro that is passed on compiler command line from CMake,
303 // and is one of the types in FRAME_T.
304 playerFrame = Kiway.Player( appType, true );
305 frame = playerFrame;
306
307 if( frame == nullptr )
308 {
309 return false;
310 }
311 }
312
313 App().SetTopWindow( frame );
314
315 if( playerFrame )
316 App().SetAppDisplayName( playerFrame->GetAboutTitle() );
317
318 Kiway.SetTop( frame );
319
320 KIPLATFORM::ENV::SetAppDetailsForWindow( frame, '"' + wxStandardPaths::Get().GetExecutablePath() + '"' + " -n",
321 frame->GetTitle() );
322
323 KICAD_SETTINGS* settings = static_cast<KICAD_SETTINGS*>( PgmSettings() );
324
326
327 wxString projToLoad;
328
329 HideSplash();
330
331 if( playerFrame && parser.GetParamCount() )
332 {
333 // Now after the frame processing, the rest of the positional args are files
334 std::vector<wxString> fileArgs;
335 /*
336 gerbview handles multiple project data files, i.e. gerber files on
337 cmd line. Others currently do not, they handle only one. For common
338 code simplicity we simply pass all the arguments in however, each
339 program module can do with them what they want, ignore, complain
340 whatever. We don't establish policy here, as this is a multi-purpose
341 launcher.
342 */
343
344 for( size_t i = 0; i < parser.GetParamCount(); i++ )
345 fileArgs.push_back( parser.GetParam( i ) );
346
347 // special attention to a single argument: argv[1] (==argSet[0])
348 if( fileArgs.size() == 1 )
349 {
350 wxFileName argv1( fileArgs[0] );
351
352#if defined( PGM_DATA_FILE_EXT )
353 // PGM_DATA_FILE_EXT, if present, may be different for each compile,
354 // it may come from CMake on the compiler command line, but often does not.
355 // This facility is mostly useful for those program footprints
356 // supporting a single argv[1].
357 if( !argv1.GetExt() )
358 argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
359#endif
360 argv1.MakeAbsolute();
361
362 fileArgs[0] = argv1.GetFullPath();
363 }
364
365 // Use the KIWAY_PLAYER::OpenProjectFiles() API function:
366 if( !playerFrame->OpenProjectFiles( fileArgs ) )
367 {
368 // OpenProjectFiles() API asks that it report failure to the UI.
369 // Nothing further to say here.
370
371 // We've already initialized things at this point, but wx won't call OnExit if
372 // we fail out. Call our own cleanup routine here to ensure the relevant resources
373 // are freed at the right time (if they aren't, segfaults will occur).
374 OnPgmExit();
375
376 // Fail the process startup if the file could not be opened,
377 // although this is an optional choice, one that can be reversed
378 // also in the KIFACE specific OpenProjectFiles() return value.
379 return false;
380 }
381 }
382 else if( managerFrame )
383 {
384 if( parser.GetParamCount() > 0 )
385 {
386 wxFileName tmp = parser.GetParam( 0 );
387
388 if( tmp.GetExt() != FILEEXT::ProjectFileExtension && tmp.GetExt() != FILEEXT::LegacyProjectFileExtension )
389 {
390 DisplayErrorMessage( nullptr, wxString::Format( _( "File '%s'\n"
391 "does not appear to be a KiCad project file." ),
392 tmp.GetFullPath() ) );
393 }
394 else
395 {
396 projToLoad = tmp.GetFullPath();
397 }
398 }
399
400 // If no file was given as an argument, check that there was a file open.
401 if( projToLoad.IsEmpty() && settings->m_OpenProjects.size() && !parser.FoundSwitch( "new" ) )
402 {
403 wxString last_pro = settings->m_OpenProjects.front();
404 settings->m_OpenProjects.erase( settings->m_OpenProjects.begin() );
405
406 if( wxFileExists( last_pro ) )
407 {
408 // Try to open the last opened project,
409 // if a project name is not given when starting Kicad
410 projToLoad = last_pro;
411 }
412 }
413
414 bool loaded = false;
415
416 // Do not attempt to load a non-existent project file.
417 if( !projToLoad.empty() )
418 {
419 wxFileName fn( projToLoad );
420
421 if( fn.Exists() && ( fn.GetExt() == FILEEXT::ProjectFileExtension
422 || fn.GetExt() == FILEEXT::LegacyProjectFileExtension ) )
423 {
424 fn.MakeAbsolute();
425
426 if( appType == KICAD_MAIN_FRAME_T )
427 loaded = managerFrame->LoadProject( fn );
428 }
429 }
430
431 if( !loaded && appType == KICAD_MAIN_FRAME_T )
432 managerFrame->PreloadAllLibraries();
433 }
434
435 if( mergetoolFrame )
436 {
437 // Stay hidden; the merge dialog is its own modal. The frame just needs
438 // to be the wxApp top window so the modal has a parent and the wxApp
439 // loop has something to drive. Defer the run via CallAfter so the
440 // event loop is up before ShowModal spins its nested loop. The
441 // wxWeakRef guards against the frame being destroyed (window-manager
442 // close, fatal init) before the callback fires.
443 wxWeakRef<MERGETOOL_FRAME> f( mergetoolFrame );
444
445 mergetoolFrame->CallAfter(
446 [f]() mutable
447 {
448 MERGETOOL_FRAME* frame = f.get();
449
450 if( !frame || frame->IsBeingDeleted() )
451 return;
452
453 int exitCode = frame->RunMerge();
454
455 // Propagate the merge JOB's exit code to the kicad
456 // process exit status so `git mergetool` sees a non-zero
457 // status on unresolved conflicts.
458 if( wxEventLoopBase* loop = wxTheApp->GetMainLoop() )
459 loop->ScheduleExit( exitCode );
460
461 frame->Close( true );
462 } );
463 }
464 else
465 {
466 frame->Show( true );
467 frame->Raise();
468 }
469
470 if( m_api_server )
471 m_api_server->SetReadyToReply();
472
473 return true;
474}
475
476
478{
479 return 0;
480}
481
482
484{
485 // Signal all background library preloads to abort before waiting for the thread pool.
486 // The design block preload runs on the global thread pool and checks this flag; without
487 // setting it here the pool wait below can block for up to 120 seconds.
488 m_libraryPreloadAbort.store( true );
489
490 // Abort and wait on any background jobs
491 GetKiCadThreadPool().purge();
492 GetKiCadThreadPool().wait();
493
494 Kiway.OnKiwayEnd();
495
496 m_api_server.reset();
497
499 {
501 m_settings_manager->Save();
502 }
503
504 // Destroy everything in PGM_KICAD,
505 // especially wxSingleInstanceCheckerImpl earlier than wxApp and earlier
506 // than static destruction would.
507 Destroy();
509 delete GetGitBackend();
510 SetGitBackend( nullptr );
511}
512
513
514void PGM_KICAD::MacOpenFile( const wxString& aFileName )
515{
516#if defined(__WXMAC__)
517
518 KICAD_MANAGER_FRAME* frame = (KICAD_MANAGER_FRAME*) App().GetTopWindow();
519
520 if( !aFileName.empty() && wxFileExists( aFileName ) )
521 frame->LoadProject( wxFileName( aFileName ) );
522
523#endif
524}
525
526
528{
529 // unlike a normal destructor, this is designed to be called more
530 // than once safely:
531
532 m_bm.End();
533
535}
536
537
539
540#ifdef NDEBUG
541// Define a custom assertion handler
542void CustomAssertHandler(const wxString& file,
543 int line,
544 const wxString& func,
545 const wxString& cond,
546 const wxString& msg)
547{
548 Pgm().HandleAssert( file, line, func, cond, msg );
549}
550#endif
551
555struct APP_KICAD : public wxApp
556{
557 APP_KICAD() : wxApp()
558 {
559 SetPgm( &program );
560
561 // Init the environment each platform wants
563 }
564
565
566 bool OnInit() override
567 {
568#ifdef NDEBUG
569 // These checks generate extra assert noise
570 wxSizerFlags::DisableConsistencyChecks();
571 wxDISABLE_DEBUG_SUPPORT();
572 wxSetAssertHandler( CustomAssertHandler );
573#endif
574
575 // Perform platform-specific init tasks
576 if( !KIPLATFORM::APP::Init() )
577 return false;
578
579#ifndef DEBUG
580 // Enable logging traces to the console in release build.
581 // This is usually disabled, but it can be useful for users to run to help
582 // debug issues and other problems.
583 if( wxGetEnv( wxS( "KICAD_ENABLE_WXTRACE" ), nullptr ) )
584 {
585 wxLog::EnableLogging( true );
586 wxLog::SetLogLevel( wxLOG_Trace );
587 }
588#endif
589
590 if( !program.OnPgmInit() )
591 {
592 program.OnPgmExit();
593 return false;
594 }
595
596 return true;
597 }
598
599 int OnExit() override
600 {
601 // Drain wxPendingDelete (frames deferred via Destroy()) before tearing down
602 // PGM_BASE singletons. On macOS the dock-quit path leaves frames in this
603 // queue at OnExit() time, and their canvas destructors call into
604 // Pgm().GetGLContextManager(). Running OnPgmExit() first would null that
605 // pointer out from under them. See https://gitlab.com/kicad/code/kicad/-/issues/23373
606 int ret = wxApp::OnExit();
607
608 // Avoid wxLog crashing when used in destructors invoked from OnPgmExit().
609 wxLog::EnableLogging( false );
610
611 program.OnPgmExit();
612 return ret;
613 }
614
615
616 int OnRun() override
617 {
618 try
619 {
620 return wxApp::OnRun();
621 }
622 catch(...)
623 {
624 Pgm().HandleException( std::current_exception() );
625 }
626
627 return -1;
628 }
629
630
631 void OnUnhandledException() override
632 {
633 Pgm().HandleException( std::current_exception(), true );
634 }
635
636
637 int FilterEvent( wxEvent& aEvent ) override
638 {
639 if( aEvent.GetEventType() == wxEVT_SHOW )
640 {
641 wxShowEvent& event = static_cast<wxShowEvent&>( aEvent );
642 wxDialog* dialog = dynamic_cast<wxDialog*>( event.GetEventObject() );
643
644 std::vector<void*>& dlgs = Pgm().m_ModalDialogs;
645
646 if( dialog )
647 {
648 if( event.IsShown() && dialog->IsModal() )
649 {
650 dlgs.push_back( dialog );
651 }
652 // Under GTK, sometimes the modal flag is cleared before hiding
653 else if( !event.IsShown() && !dlgs.empty() )
654 {
655 // If we close the expected dialog, remove it from our stack
656 if( dlgs.back() == dialog )
657 dlgs.pop_back();
658 // If an out-of-order, remove all dialogs added after the closed one
659 else if( auto it = std::find( dlgs.begin(), dlgs.end(), dialog ) ; it != dlgs.end() )
660 dlgs.erase( it, dlgs.end() );
661 }
662 }
663 }
664
665 return Event_Skip;
666 }
667
668#if defined( DEBUG )
672 bool ProcessEvent( wxEvent& aEvent ) override
673 {
674 if( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
675 {
676 wxKeyEvent* keyEvent = static_cast<wxKeyEvent*>( &aEvent );
677
678 if( keyEvent )
679 {
680 wxLogTrace( kicadTraceKeyEvent, "APP_KICAD::ProcessEvent %s", dump( *keyEvent ) );
681 }
682 }
683
684 aEvent.Skip();
685 return false;
686 }
687
695 bool OnExceptionInMainLoop() override
696 {
697 try
698 {
699 throw;
700 }
701 catch(...)
702 {
703 Pgm().HandleException( std::current_exception() );
704 }
705
706 return false; // continue on. Return false to abort program
707 }
708#endif
709
715#if defined( __WXMAC__ )
716 void MacOpenFile( const wxString& aFileName ) override
717 {
718 Pgm().MacOpenFile( aFileName );
719 }
720#endif
721};
722
723IMPLEMENT_APP( APP_KICAD )
724
725
726// The C++ project manager supports one open PROJECT, so Prj() calls within
727// this link image need this function.
729{
730 return Kiway.Prj();
731}
732
const char * name
wxString GetAboutTitle() const
virtual void Shutdown()=0
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:311
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
int RunMerge()
Run the merge synchronously.
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
Definition paths.cpp:71
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:553
virtual wxApp & App()
Return a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition pgm_base.cpp:204
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition pgm_base.cpp:799
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:403
void Destroy()
Definition pgm_base.cpp:183
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:814
std::atomic_bool m_libraryPreloadAbort
Definition pgm_base.h:446
std::vector< void * > m_ModalDialogs
Definition pgm_base.h:384
bool InitPgm(bool aHeadless=false, bool aIsUnitTest=false)
Initialize this program.
Definition pgm_base.cpp:320
std::unique_ptr< KICAD_API_SERVER > m_api_server
Definition pgm_base.h:412
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:851
virtual const wxString & GetExecutablePath() const
Definition pgm_base.cpp:879
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
void HideSplash()
Definition pgm_base.cpp:309
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:544
PGM_KICAD extends PGM_BASE to bring in FileHistory() and PdfBrowser() which were moved from EDA_APP i...
Definition pgm_kicad.h:35
bool OnPgmInit()
Definition kicad.cpp:99
void Destroy()
Definition kicad.cpp:527
std::unique_ptr< API_HANDLER_COMMON > m_api_common_handler
Definition pgm_kicad.h:69
void MacOpenFile(const wxString &aFileName) override
Specific to MacOSX (not used under Linux or Windows).
Definition kicad.cpp:514
void OnPgmExit()
Definition kicad.cpp:483
APP_SETTINGS_BASE * PgmSettings()
Definition pgm_kicad.h:52
int OnPgmRun()
Definition kicad.cpp:477
BIN_MOD m_bm
Definition pgm_kicad.h:65
Container for project specific data.
Definition project.h:62
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)
Replace any environment variable & text variable references with their values.
Definition common.cpp:721
The common library.
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:59
@ FRAME_BM2CMP
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:64
@ FRAME_T_COUNT
Definition frame_type.h:71
@ 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:69
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:93
PROJECT & Prj()
Definition kicad.cpp:728
static PGM_KICAD program
Definition kicad.cpp:91
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition kicad.cpp:74
KIWAY Kiway(KFCTL_CPP_PROJECT_SUITE)
#define KFCTL_CPP_PROJECT_SUITE
Running under C++ project mgr, possibly with others.
Definition kiway.h:160
#define KFCTL_STANDALONE
Running as a standalone Top.
Definition kiway.h:159
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:103
bool Init()
Perform application-specific initialization tasks.
Definition unix/app.cpp:40
void EnableDarkMode(bool aForce)
Definition unix/app.cpp:58
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:556
int OnRun() override
Definition kicad.cpp:616
APP_KICAD()
Definition kicad.cpp:557
bool OnInit() override
Definition kicad.cpp:566
int OnExit() override
Definition kicad.cpp:599
void OnUnhandledException() override
Definition kicad.cpp:631
int FilterEvent(wxEvent &aEvent) override
Definition kicad.cpp:637
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.