KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kiway.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) 2014 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
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
21#include <cstring>
22
23#include <app_monitor.h>
24#include <cli/exit_codes.h>
25#include <core/ignore.h>
26#include <macros.h>
27#include <kiway.h>
28#include <kiway_player.h>
29#include <kiway_mail.h>
30#include <paths.h>
31#include <reporter.h>
32#include <pgm_base.h>
33#include <config.h>
34#include <id.h>
35#include <kiplatform/app.h>
38#include <tool/action_manager.h>
39#include <logging.h>
40#include <local_history.h>
41
42#include <wx/dynlib.h>
43#include <wx/stdpaths.h>
44#include <wx/debug.h>
45#include <wx/utils.h>
46#include <confirm.h>
47
48std::array<KIFACE*, KIWAY::FACE_T::KIWAY_FACE_COUNT> KIWAY::m_kiface;
49std::array<int, KIWAY::FACE_T::KIWAY_FACE_COUNT> KIWAY::m_kiface_version;
50
51
52
53KIWAY::KIWAY( int aCtlBits, wxFrame* aTop ):
54 m_ctl( aCtlBits ), m_top( nullptr ), m_blockingDialog( wxID_NONE ), m_local_history( nullptr )
55{
57 SetTop( aTop ); // hook player_destroy_handler() into aTop.
58
59 // Set the array of all known frame window IDs to empty = wxID_NONE,
60 // once they are be created, they are added with FRAME_T as index to this array.
61 // Note: A non empty entry does not mean the frame still exists.
62 // It means only the frame was created at least once. It can be destroyed after.
63 // These entries are not cleared automatically on window closing. The purpose is just
64 // to allow a call to wxWindow::FindWindowById() using a FRAME_T frame type
65 for( int n = 0; n < KIWAY_PLAYER_COUNT; n++ )
66 m_playerFrameId[n] = wxID_NONE;
67}
68
69
71{
72 delete m_local_history;
73}
74
75
76#if 0
77// Any event types derived from wxCommandEvt, like wxWindowDestroyEvent, are
78// propagated upwards to parent windows if not handled below. Therefore the
79// m_top window should receive all wxWindowDestroyEvents originating from
80// KIWAY_PLAYERs. It does anyways, but now player_destroy_handler eavesdrops
81// on that event stream looking for KIWAY_PLAYERs being closed.
82
83void KIWAY::player_destroy_handler( wxWindowDestroyEvent& event )
84{
85 // Currently : do nothing
86 event.Skip(); // skip to who, the wxApp? I'm the top window.
87}
88#endif
89
90
91void KIWAY::SetTop( wxFrame* aTop )
92{
93#if 0
94 if( m_top )
95 {
96 m_top->Disconnect( wxEVT_DESTROY,
97 wxWindowDestroyEventHandler( KIWAY::player_destroy_handler ),
98 nullptr, this );
99 }
100
101 if( aTop )
102 {
103 aTop->Connect( wxEVT_DESTROY,
104 wxWindowDestroyEventHandler( KIWAY::player_destroy_handler ),
105 nullptr, this );
106 }
107#endif
108
109 m_top = aTop;
110}
111
112
113const wxString KIWAY::dso_search_path( FACE_T aFaceId )
114{
115 const char* name;
116
117 switch( aFaceId )
118 {
119 case FACE_SCH: name = KIFACE_PREFIX "eeschema"; break;
120 case FACE_PCB: name = KIFACE_PREFIX "pcbnew"; break;
121 case FACE_CVPCB: name = KIFACE_PREFIX "cvpcb"; break;
122 case FACE_GERBVIEW: name = KIFACE_PREFIX "gerbview"; break;
123 case FACE_PL_EDITOR: name = KIFACE_PREFIX "pl_editor"; break;
124 case FACE_PCB_CALCULATOR: name = KIFACE_PREFIX "pcb_calculator"; break;
125
126 default:
127 wxASSERT_MSG( 0, wxT( "caller has a bug, passed a bad aFaceId" ) );
128 return wxEmptyString;
129 }
130
131#ifndef __WXMAC__
132 wxString path;
133
135 {
136 // The 2 *.cpp program launchers: single_top.cpp and kicad.cpp expect
137 // the *.kiface's to reside in same directory as their binaries do.
138 wxString appDir;
139
140 // When running inside an AppImage, the bundled ld-linux is invoked as a wrapper
141 // which causes /proc/self/exe to resolve to the dynamic linker rather than the
142 // actual binary. Use APPDIR to construct the correct executable path.
143 if( wxGetEnv( wxT( "APPDIR" ), &appDir ) )
144 path = appDir + wxT( "/usr/bin/kicad" );
145 else
146 path = wxStandardPaths::Get().GetExecutablePath();
147 }
148
149 wxFileName fn = path;
150#else
151 // we have the dso's in main OSX bundle kicad.app/Contents/PlugIns
152 wxFileName fn = Pgm().GetExecutablePath();
153 fn.AppendDir( wxT( "Contents" ) );
154 fn.AppendDir( wxT( "PlugIns" ) );
155#endif
156
157 fn.SetName( name );
158
159 // To speed up development, it's sometimes nice to run kicad from inside
160 // the build path. In that case, each program will be in a subdirectory.
161 // To find the DSOs, we need to go up one directory and then enter a subdirectory.
163 {
164#ifdef __WXMAC__
165 // On Mac, all of the kifaces are placed in the kicad.app bundle, even though the individual
166 // standalone binaries are placed in separate bundles before the make install step runs.
167 // So, we have to jump up to the kicad directory, then the PlugIns section of the kicad
168 // bundle.
169 fn = wxStandardPaths::Get().GetExecutablePath();
170
171 fn.RemoveLastDir();
172 fn.RemoveLastDir();
173 fn.RemoveLastDir();
174 fn.RemoveLastDir();
175 fn.AppendDir( wxT( "kicad" ) );
176 fn.AppendDir( wxT( "kicad.app" ) );
177 fn.AppendDir( wxT( "Contents" ) );
178 fn.AppendDir( wxT( "PlugIns" ) );
179 fn.SetName( name );
180#else
181 const char* dirName;
182
183 // The subdirectories usually have the same name as the kiface
184 switch( aFaceId )
185 {
186 case FACE_PL_EDITOR: dirName = "pagelayout_editor"; break;
187 default: dirName = name + 1; break;
188 }
189
190 const wxString& buildRoot = PATHS::GetBuildRoot();
191
192 if( !buildRoot.IsEmpty() )
193 fn.AssignDir( buildRoot );
194 else
195 fn.RemoveLastDir();
196
197 fn.AppendDir( dirName );
198 fn.SetName( name );
199#endif
200 }
201
202 // Here a "suffix" == an extension with a preceding '.',
203 // so skip the preceding '.' to get an extension
204 fn.SetExt( &KIFACE_SUFFIX[1] );
205
206 return fn.GetFullPath();
207}
208
209
211{
212 return Pgm().GetSettingsManager().Prj();
213}
214
215
216KIFACE* KIWAY::KiFACE( FACE_T aFaceId, bool doLoad )
217{
218 // Since this will be called from python, cannot assume that code will
219 // not pass a bad aFaceId.
220 if( (unsigned) aFaceId >= m_kiface.size() )
221 {
222 wxASSERT_MSG( 0, wxT( "caller has a bug, passed a bad aFaceId" ) );
223 return nullptr;
224 }
225
226 // return the previously loaded KIFACE, if it was.
227 if( m_kiface[aFaceId] )
228 return m_kiface[aFaceId];
229
230 // A missing or broken DSO stays that way, so report it once per session
231 if( m_kifaceLoadFailed[aFaceId] )
232 return nullptr;
233
234 // DSO with KIFACE has not been loaded yet, does caller want to load it?
235 if( doLoad )
236 {
237 wxString dname = dso_search_path( aFaceId );
238
239 // Insert DLL search path for kicad_3dsg from build dir
240 const wxString& buildRoot = PATHS::GetBuildRoot();
241
243 {
244 wxFileName myPath;
245
246 if( !buildRoot.IsEmpty() )
247 myPath.AssignDir( buildRoot );
248 else
249 myPath.Assign( wxStandardPaths::Get().GetExecutablePath() );
250
251 if( !myPath.GetPath().EndsWith( wxT( "pcbnew" ) ) )
252 {
253 if( buildRoot.IsEmpty() )
254 myPath.RemoveLastDir();
255
256 myPath.AppendDir( wxT( "pcbnew" ) );
258 }
259 }
260
261#ifdef KICAD_WIN32_VERIFY_CODESIGN
262 bool codeSignOk = KIPLATFORM::ENV::VerifyFileSignature( dname );
263
264 if( !codeSignOk )
265 {
266 wxLogError( _( "Failed to verify kiface library '%s' signature." ), dname );
267 m_kifaceLoadFailed[aFaceId] = true;
268 return nullptr;
269 }
270#endif
271
272 wxDynamicLibrary dso;
273 void* addr = nullptr;
274
275 // For some reason wxDynamicLibrary::Load() crashes in some languages
276 // (chinese for instance) when loading the dynamic library.
277 // The crash happens for Eeschema.
278 // So switch to "C" locale during loading (LC_COLLATE is enough).
279 int lc_new_type = LC_COLLATE;
280 std::string user_locale = setlocale( lc_new_type, nullptr );
281 setlocale( lc_new_type, "C" );
282
283 bool success = dso.Load( dname, wxDL_VERBATIM | wxDL_NOW | wxDL_GLOBAL );
284
285 setlocale( lc_new_type, user_locale.c_str() );
286
287 APP_MONITOR::AddNavigationBreadcrumb( wxString::Format( "Loading kiface %d", aFaceId ), "kiway.kiface" );
288
289 // Return null instead of throwing, since an exception escaping an event handler or startup ends the program
290 if( !success )
291 {
292 wxLogError( _( "Failed to load kiface library '%s'." ), dname );
293 m_kifaceLoadFailed[aFaceId] = true;
294 return nullptr;
295 }
296 else if( ( addr = dso.GetSymbol( wxT( KIFACE_INSTANCE_NAME_AND_VERSION ) ) ) == nullptr )
297 {
298 wxLogError( _( "Could not read instance name and version from kiface library '%s'." ), dname );
299 m_kifaceLoadFailed[aFaceId] = true;
300 return nullptr;
301 }
302 else
303 {
304 KIFACE_GETTER_FUNC* ki_getter = (KIFACE_GETTER_FUNC*) addr;
305
306 KIFACE* kiface = ki_getter( &m_kiface_version[aFaceId], KIFACE_VERSION, &Pgm() );
307
308 // KIFACE_GETTER_FUNC function comment (API) says the non-NULL is unconditional.
309 wxASSERT_MSG( kiface, wxT( "attempted DSO has a bug, failed to return a KIFACE*" ) );
310
311 wxDllType dsoHandle = dso.Detach();
312
313 bool startSuccess = false;
314
315 // Give the DSO a single chance to do its "process level" initialization.
316 // "Process level" specifically means stay away from any projects in there.
317
318 try
319 {
320 startSuccess = kiface->OnKifaceStart( &Pgm(), m_ctl, this );
321 }
322 catch (...)
323 {
324 // OnKiFaceStart may generate an exception
325 // Before we continue and ultimately unload our module to retry we need
326 // to process the exception before we delete the free the memory space the
327 // exception resides in
328 Pgm().HandleException( std::current_exception() );
329 }
330
331 if( startSuccess )
332 {
333 return m_kiface[aFaceId] = kiface;
334 }
335 else
336 {
337 // Usually means canceled initial global library setup
338 // But it could have been an exception/failure
339 // Let the module go out of scope to unload
340 dso.Attach( dsoHandle );
341
342 return nullptr;
343 }
344 }
345 }
346
347 return nullptr;
348}
349
350
352{
353 switch( aFrameType )
354 {
355 case FRAME_SCH:
357 case FRAME_SCH_VIEWER:
359 case FRAME_SIMULATOR:
360 return FACE_SCH;
361
362 case FRAME_PCB_EDITOR:
368 return FACE_PCB;
369
370 case FRAME_CVPCB:
372 return FACE_CVPCB;
373
374 case FRAME_GERBER:
375 return FACE_GERBVIEW;
376
377 case FRAME_PL_EDITOR:
378 return FACE_PL_EDITOR;
379
380 case FRAME_CALC:
381 return FACE_PCB_CALCULATOR;
382
383 default:
384 return FACE_T( -1 );
385 }
386}
387
388
390{
391 wxWindowID storedId = m_playerFrameId[aFrameType];
392
393 if( storedId == wxID_NONE )
394 return nullptr;
395
396 wxWindow* frame = wxWindow::FindWindowById( storedId );
397
398 // Since wxWindow::FindWindow*() is not cheap (especially if the window does not exist),
399 // clear invalid entries to save CPU on repeated calls that do not lead to frame creation
400 if( !frame )
401 m_playerFrameId[aFrameType].compare_exchange_strong( storedId, wxID_NONE );
402
403 return static_cast<KIWAY_PLAYER*>( frame );
404}
405
406
407KIWAY_PLAYER* KIWAY::Player( FRAME_T aFrameType, bool doCreate, wxTopLevelWindow* aParent )
408{
409 // Since this will be called from python, cannot assume that code will
410 // not pass a bad aFrameType.
411 if( (unsigned) aFrameType >= KIWAY_PLAYER_COUNT )
412 {
413 wxASSERT_MSG( 0, wxT( "caller has a bug, passed a bad aFrameType" ) );
414 return nullptr;
415 }
416
417 // return the previously opened window
418 KIWAY_PLAYER* frame = GetPlayerFrame( aFrameType );
419
420 if( frame )
421 return frame;
422
423 if( doCreate )
424 {
425 try
426 {
427 wxString msg = wxString::Format( "Creating window type %d", aFrameType );
428 APP_MONITOR::AddNavigationBreadcrumb( msg, "kiway.player" );
429
430 FACE_T face_type = KifaceType( aFrameType );
431 KIFACE* kiface = KiFACE( face_type );
432
433 if( !kiface )
434 {
435 // KiFACE() reports a broken DSO only once, but every explicit open needs an answer
436 if( (unsigned) face_type < KIWAY_FACE_COUNT && m_kifaceLoadFailed[face_type] )
437 wxLogError( _( "Application cannot start." ) );
438
439 return nullptr;
440 }
441
442 frame = (KIWAY_PLAYER*) kiface->CreateKiWindow(
443 aParent, // Parent window of frame in modal mode,
444 // NULL in non modal mode
445 aFrameType,
446 this,
447 m_ctl // questionable need, these same flags
448 // were passed to KIFACE::OnKifaceStart()
449 );
450 if( frame )
451 m_playerFrameId[aFrameType].store( frame->GetId() );
452
453 return frame;
454 }
455 catch( ... )
456 {
457 Pgm().HandleException( std::current_exception() );
458 wxLogError( _( "Error loading editor." ) );
459 }
460 }
461
462 return nullptr;
463}
464
465
466bool KIWAY::PlayerClose( FRAME_T aFrameType, bool doForce )
467{
468 // Since this will be called from python, cannot assume that code will
469 // not pass a bad aFrameType.
470 if( (unsigned) aFrameType >= KIWAY_PLAYER_COUNT )
471 {
472 wxASSERT_MSG( 0, wxT( "caller has a bug, passed a bad aFrameType" ) );
473 return false;
474 }
475
476 KIWAY_PLAYER* frame = GetPlayerFrame( aFrameType );
477
478 if( frame == nullptr ) // Already closed
479 return true;
480
481 wxString msg = wxString::Format( "Closing window type %d", aFrameType );
482 APP_MONITOR::AddNavigationBreadcrumb( msg, "kiway.playerclose" );
483
484 if( frame->NonUserClose( doForce ) )
485 {
486 m_playerFrameId[aFrameType] = wxID_NONE;
487 return true;
488 }
489
490 return false;
491}
492
493
494bool KIWAY::PlayersClose( bool doForce )
495{
496 bool ret = true;
497
498 for( unsigned i=0; i < KIWAY_PLAYER_COUNT; ++i )
499 ret = ret && PlayerClose( FRAME_T( i ), doForce );
500
501 return ret;
502}
503
504
506{
507 m_playerFrameId[aFrameType] = wxID_NONE;
508}
509
510
511void KIWAY::ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload,
512 wxWindow* aSource, bool aFromOtherThread )
513{
514 std::unique_ptr<KIWAY_MAIL_EVENT> mail =
515 std::make_unique<KIWAY_MAIL_EVENT>( aDestination, aCommand, aPayload, aSource );
516
517 if( aFromOtherThread )
518 QueueEvent( mail.release() );
519 else
520 ProcessEvent( *mail );
521}
522
523
524void KIWAY::GetActions( std::vector<TOOL_ACTION*>& aActions ) const
525{
527 aActions.push_back( action );
528}
529
530
531void KIWAY::SetLanguage( int aLanguage )
532{
533 wxString errMsg;
534 bool ret = false;
535
536 {
537 // Only allow the traces to be logged by wx. We use our own system to log when the
538 // OS doesn't support the language, so we want to hide the wx error.
539 WX_LOG_TRACE_ONLY logtraceOnly;
540 Pgm().SetLanguageIdentifier( aLanguage );
541 ret = Pgm().SetLanguage( errMsg );
542 }
543
544 if( !ret )
545 {
546 wxString lang;
547
548 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
549 {
550 if( aLanguage == LanguagesList[ii].m_KI_Lang_Identifier )
551 {
552 if( LanguagesList[ii].m_DoNotTranslate )
553 lang = LanguagesList[ii].m_Lang_Label;
554 else
555 lang = wxGetTranslation( LanguagesList[ii].m_Lang_Label );
556
557 break;
558 }
559 }
560
561 DisplayErrorMessage( nullptr,
562 wxString::Format( _( "Unable to switch language to %s" ), lang ),
563 errMsg );
564 return;
565 }
566
567#if 1
568 // This is a risky hack that goes away if we allow the language to be
569 // set only from the top most frame if !Kiface.IsSingle()
570
571 // Only for the C++ project manager, and not for the python one and not for
572 // single_top do we look for the EDA_BASE_FRAME as the top level window.
573 // For single_top this is not needed because that window is registered in
574 // the array below.
576 {
577 // A dynamic_cast could be better, but creates link issues
578 // (some basic_frame functions not found) on some platforms,
579 // so a static_cast is used.
580 EDA_BASE_FRAME* top = static_cast<EDA_BASE_FRAME*>( m_top );
581
582 if ( top )
583 {
584 top->ShowChangedLanguage();
585 wxCommandEvent e( EDA_LANG_CHANGED );
586 top->GetEventHandler()->ProcessEvent( e );
587 }
588 }
589#endif
590
591 for( unsigned i=0; i < KIWAY_PLAYER_COUNT; ++i )
592 {
593 KIWAY_PLAYER* frame = GetPlayerFrame( ( FRAME_T )i );
594
595 if( frame )
596 {
597 frame->ShowChangedLanguage();
598 wxCommandEvent e( EDA_LANG_CHANGED );
599 frame->GetEventHandler()->ProcessEvent( e );
600 }
601 }
602}
603
604
606{
607 // Fieldname templates have both a project and a global half, so we need to update the global templates
608 // and then re-resolve the calculated templates (meaning figure out who's visibility settings win)
610
612 {
613 // A dynamic_cast could be better, but creates link issues
614 // (some basic_frame functions not found) on some platforms,
615 // so a static_cast is used.
616 EDA_BASE_FRAME* top = static_cast<EDA_BASE_FRAME*>( m_top );
617
618 if( top )
619 top->CommonSettingsChanged( aFlags );
620 }
621
622 if( aFlags & ENVVARS_CHANGED )
623 {
624 if( KIFACE* sch = KiFACE( FACE_SCH, false ) )
625 sch->PreloadLibraries( this );
626
627 if( KIFACE* pcb = KiFACE( FACE_PCB, false ) )
628 pcb->PreloadLibraries( this );
629 }
630
631 for( unsigned i=0; i < KIWAY_PLAYER_COUNT; ++i )
632 {
633 KIWAY_PLAYER* frame = GetPlayerFrame( ( FRAME_T )i );
634
635 if( frame )
636 frame->CommonSettingsChanged( aFlags );
637 }
638}
639
640
642{
644 {
645 // A dynamic_cast could be better, but creates link issues
646 // (some basic_frame functions not found) on some platforms,
647 // so a static_cast is used.
648 EDA_BASE_FRAME* top = static_cast<EDA_BASE_FRAME*>( m_top );
649
650 if( top )
651 top->ClearFileHistory();
652 }
653
654 for( unsigned i=0; i < KIWAY_PLAYER_COUNT; ++i )
655 {
656 KIWAY_PLAYER* frame = GetPlayerFrame( ( FRAME_T )i );
657
658 if( frame )
659 frame->ClearFileHistory();
660 }
661}
662
663
665{
666 // Skip project change notifications during application shutdown to avoid
667 // clearing savers and re-registering them unnecessarily
668 if( PgmOrNull() && Pgm().m_Quitting )
669 return;
670
671 APP_MONITOR::AddNavigationBreadcrumb( "Changing project", "kiway.projectchanged" );
672
674
676 {
677 // A dynamic_cast could be better, but creates link issues
678 // (some basic_frame functions not found) on some platforms,
679 // so a static_cast is used.
680 EDA_BASE_FRAME* top = static_cast<EDA_BASE_FRAME*>( m_top );
681
682 if( top )
683 top->ProjectChanged();
684 }
685
686 // Cancel an in-progress load of libraries; handled through the schematic and PCB ifaces.
687 // Use doLoad=false: only notify already-loaded kifaces, don't force-load absent ones
688 // (e.g. eeschema kiface isn't available in standalone pcbnew).
689 if ( KIFACE* schface = KiFACE( KIWAY::FACE_SCH, false ) )
690 schface->ProjectChanged();
691
692 if ( KIFACE* pcbface = KiFACE( KIWAY::FACE_PCB, false ) )
693 pcbface->ProjectChanged();
694
695 for( unsigned i=0; i < KIWAY_PLAYER_COUNT; ++i )
696 {
697 KIWAY_PLAYER* frame = GetPlayerFrame( ( FRAME_T )i );
698
699 if( frame )
700 frame->ProjectChanged();
701 }
702}
703
704
706{
707 return wxWindow::FindWindowById( m_blockingDialog );
708}
709
710
711void KIWAY::SetBlockingDialog( wxWindow* aWin )
712{
713 if( !aWin )
714 m_blockingDialog = wxID_NONE;
715 else
716 m_blockingDialog = aWin->GetId();
717}
718
719
720bool KIWAY::ProcessEvent( wxEvent& aEvent )
721{
722 KIWAY_MAIL_EVENT* mail = dynamic_cast<KIWAY_MAIL_EVENT*>( &aEvent );
723
724 if( mail )
725 {
726 FRAME_T dest = mail->Dest();
727
728 // see if recipient is alive
729 KIWAY_PLAYER* alive = Player( dest, false );
730
731 if( alive )
732 {
733#if 1
734 return alive->ProcessEvent( aEvent );
735#else
736 alive->KiwayMailIn( *mail );
737 return true;
738#endif
739 }
740 }
741
742 return false;
743}
744
745
746void KIWAY::QueueEvent( wxEvent* aEvent )
747{
748 KIWAY_MAIL_EVENT* mail = dynamic_cast<KIWAY_MAIL_EVENT*>( aEvent );
749
750 if( mail )
751 {
752 FRAME_T dest = mail->Dest();
753
754 // see if recipient is alive
755 KIWAY_PLAYER* alive = Player( dest, false );
756
757 if( alive )
758 {
759 alive->GetEventHandler()->QueueEvent( aEvent );
760 }
761 }
762}
763
764
765int KIWAY::ProcessJob( KIWAY::FACE_T aFace, JOB* job, REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter )
766{
767 KIFACE* kiface = KiFACE( aFace );
768
769 if( !kiface )
770 {
771 if( aReporter )
772 {
773 aReporter->Report( wxString::Format( _( "Failed to load kiface library '%s'." ), dso_search_path( aFace ) ),
775 }
776
778 }
779
780 return kiface->HandleJob( job, aReporter, aProgressReporter );
781}
782
783
784bool KIWAY::ProcessJobConfigDialog( KIWAY::FACE_T aFace, JOB* aJob, wxWindow* aWindow )
785{
786 KIFACE* kiface = KiFACE( aFace );
787
788 return kiface && kiface->HandleJobConfig( aJob, aWindow );
789}
790
791
793 KICAD_API_SERVER* aServer, wxString* aError )
794{
795 KIFACE* kiface = KiFACE( aFace );
796
797 if( !kiface )
798 {
799 if( aError )
800 *aError = wxS( "Failed to load requested face" );
801
802 return false;
803 }
804
805 return kiface->HandleApiOpenDocument( aSpec, aServer, aError );
806}
807
808
810 KICAD_API_SERVER* aServer, wxString* aError )
811{
812 KIFACE* kiface = KiFACE( aFace );
813
814 if( !kiface )
815 {
816 if( aError )
817 *aError = wxS( "Failed to load requested face" );
818
819 return false;
820 }
821
822 return kiface->HandleApiCloseDocument( aSpec, aServer, aError );
823}
824
825
827{
829 {
830 // A dynamic_cast could be better, but creates link issues
831 // (some basic_frame functions not found) on some platforms,
832 // so a static_cast is used.
833 EDA_BASE_FRAME* top = static_cast<EDA_BASE_FRAME*>( m_top );
834
835 if( top )
836 top->Close( false );
837 }
838}
839
840
842{
843 for( KIFACE* i : m_kiface )
844 {
845 if( i )
846 i->OnKifaceEnd();
847 }
848}
const char * name
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
The base frame for deriving all KiCad main window classes.
bool NonUserClose(bool aForce)
virtual void ProjectChanged()
Notification event that the project has changed.
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
bool ProcessEvent(wxEvent &aEvent) override
Override the default process event handler to implement the auto save feature.
virtual void ClearFileHistory()
Remove all files from the file history.
An simple container class that lets us dispatch output jobs to kifaces.
Definition job.h:184
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition kiway_mail.h:34
FRAME_T Dest()
Return the destination player id of the message.
Definition kiway_mail.h:39
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
virtual void KiwayMailIn(KIWAY_MAIL_EVENT &aEvent)
Receive KIWAY_MAIL_EVENT messages from other players.
void OnKiCadExit()
Definition kiway.cpp:826
bool ProcessJobConfigDialog(KIWAY::FACE_T aFace, JOB *aJob, wxWindow *aWindow)
Definition kiway.cpp:784
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition kiway.cpp:407
virtual const wxString dso_search_path(FACE_T aFaceId)
Get the [path &] name of the DSO holding the requested FACE_T.
Definition kiway.cpp:113
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:765
void SetBlockingDialog(wxWindow *aWin)
Definition kiway.cpp:711
LOCAL_HISTORY * m_local_history
Definition kiway.h:571
virtual bool PlayerClose(FRAME_T aFrameType, bool doForce)
Call the KIWAY_PLAYER::Close( bool force ) function on the window and if not vetoed,...
Definition kiway.cpp:466
static FACE_T KifaceType(FRAME_T aFrameType)
A simple mapping function which returns the FACE_T which is known to implement aFrameType.
Definition kiway.cpp:351
wxWindowID m_blockingDialog
Definition kiway.h:561
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr, bool aFromOtherThread=false)
Send aPayload to aDestination from aSource.
Definition kiway.cpp:511
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition kiway.cpp:705
static std::array< KIFACE *, KIWAY_FACE_COUNT > m_kiface
Definition kiway.h:552
std::array< bool, KIWAY_FACE_COUNT > m_kifaceLoadFailed
Definition kiway.h:555
void ClearFileHistory()
Clear the wxWidgets file history on each open frame.
Definition kiway.cpp:641
wxFrame * m_top
Definition kiway.h:559
bool ProcessApiOpenDocument(KIWAY::FACE_T aFace, const KIFACE::DOCUMENT_SPEC &aSpec, KICAD_API_SERVER *aServer, wxString *aError=nullptr)
Definition kiway.cpp:792
virtual void SetLanguage(int aLanguage)
Change the language and then calls ShowChangedLanguage() on all KIWAY_PLAYER objects.
Definition kiway.cpp:531
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition kiway.cpp:216
FACE_T
Known KIFACE implementations.
Definition kiway.h:354
@ KIWAY_FACE_COUNT
Definition kiway.h:361
@ FACE_SCH
eeschema DSO
Definition kiway.h:355
@ FACE_PL_EDITOR
Definition kiway.h:359
@ FACE_PCB
pcbnew DSO
Definition kiway.h:356
@ FACE_CVPCB
Definition kiway.h:357
@ FACE_GERBVIEW
Definition kiway.h:358
@ FACE_PCB_CALCULATOR
Definition kiway.h:360
KIWAY_PLAYER * GetPlayerFrame(FRAME_T aFrameType)
Definition kiway.cpp:389
bool ProcessEvent(wxEvent &aEvent) override
Definition kiway.cpp:720
static std::array< int, KIWAY_FACE_COUNT > m_kiface_version
Definition kiway.h:553
virtual bool PlayersClose(bool doForce)
Call the KIWAY_PLAYER::Close( bool force ) function on all the windows and if none are vetoed,...
Definition kiway.cpp:494
bool ProcessApiCloseDocument(KIWAY::FACE_T aFace, const KIFACE::DOCUMENT_SPEC &aSpec, KICAD_API_SERVER *aServer, wxString *aError=nullptr)
Definition kiway.cpp:809
std::atomic< wxWindowID > m_playerFrameId[KIWAY_PLAYER_COUNT]
Definition kiway.h:569
void OnKiwayEnd()
Definition kiway.cpp:841
KIWAY(int aCtlBits, wxFrame *aTop=nullptr)
Definition kiway.cpp:53
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
Definition kiway.h:460
virtual void CommonSettingsChanged(int aFlags=0)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition kiway.cpp:605
~KIWAY()
Definition kiway.cpp:70
void QueueEvent(wxEvent *aEvent) override
Definition kiway.cpp:746
void PlayerDidClose(FRAME_T aFrameType)
Notifies a Kiway that a player has been closed.
Definition kiway.cpp:505
virtual void GetActions(std::vector< TOOL_ACTION * > &aActions) const
Append all registered actions to the given list.
Definition kiway.cpp:524
void SetTop(wxFrame *aTop)
Tell this KIWAY about the top most frame in the program and optionally allows it to play the role of ...
Definition kiway.cpp:91
virtual void ProjectChanged()
Calls ProjectChanged() on all KIWAY_PLAYERs.
Definition kiway.cpp:664
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition kiway.cpp:210
int m_ctl
Definition kiway.h:557
Simple local history manager built on libgit2.
void ClearAllSavers()
Clear all registered savers.
static bool RunningFromBuildDir()
True when KiCad runs from its build tree or KICAD_RUN_FROM_BUILD_DIR is set.
Definition paths.cpp:743
static const wxString & GetBuildRoot()
The build root of the running executable, or empty outside a KiCad build tree.
Definition paths.cpp:735
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
virtual void SetLanguageIdentifier(int menu_id)
Set in .m_language_id member the wxWidgets language identifier ID from the KiCad menu id (internal me...
Definition pgm_base.cpp:748
virtual const wxString & GetExecutablePath() const
Definition pgm_base.cpp:926
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
virtual bool SetLanguage(wxString &aErrMsg, bool first_time=false)
Set the dictionary file name for internationalization.
Definition pgm_base.cpp:606
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition project.h:63
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
void SyncGlobalFieldNameTemplatesToProjects()
Synchronize the global field name templates into every loaded project.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
Represent a single user action.
A logger class that filters out all log messages that are not generated by wxLogTrace and ignores the...
Definition logging.h:28
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)
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_SYMBOL_EDITOR
Definition frame_type.h:31
@ FRAME_CVPCB_DISPLAY
Definition frame_type.h:49
@ FRAME_FOOTPRINT_VIEWER
Definition frame_type.h:41
@ FRAME_FOOTPRINT_WIZARD
Definition frame_type.h:42
@ FRAME_SCH_VIEWER
Definition frame_type.h:32
@ FRAME_SCH
Definition frame_type.h:30
@ FRAME_SIMULATOR
Definition frame_type.h:34
@ KIWAY_PLAYER_COUNT
Definition frame_type.h:64
@ FRAME_FOOTPRINT_CHOOSER
Definition frame_type.h:40
@ FRAME_PL_EDITOR
Definition frame_type.h:55
@ FRAME_FOOTPRINT_EDITOR
Definition frame_type.h:39
@ FRAME_GERBER
Definition frame_type.h:53
@ FRAME_PCB_DISPLAY3D
Definition frame_type.h:43
@ FRAME_CVPCB
Definition frame_type.h:48
@ FRAME_SYMBOL_CHOOSER
Definition frame_type.h:33
#define KFCTL_CPP_PROJECT_SUITE
Running under C++ project mgr, possibly with others.
Definition kiway.h:175
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Point to the one and only KIFACE export.
Definition kiway.h:590
#define KIFACE_INSTANCE_NAME_AND_VERSION
Definition kiway.h:114
#define KIFACE_VERSION
Definition kiway.h:109
#define KFCTL_STANDALONE
Running as a standalone Top.
Definition kiway.h:174
This file contains miscellaneous commonly used macros and functions.
MAIL_T
The set of mail types sendable via KIWAY::ExpressMail() and supplied as the aCommand parameter to tha...
Definition mail_type.h:34
void AddNavigationBreadcrumb(const wxString &aMsg, const wxString &aCategory)
Add a navigation breadcrumb.
static const int ERR_UNKNOWN
Definition exit_codes.h:32
void AddDynamicLibrarySearchPath(const wxString &aPath)
Inserts a search path for loading dynamic libraries.
Definition unix/app.cpp:118
bool VerifyFileSignature(const wxString &aPath)
Validates the code signing signature of a given file This is most likely only ever going to be applic...
PGM_BASE & Pgm()
The global program "get" accessor.
PGM_BASE * PgmOrNull()
Return a reference that can be nullptr when running a shared lib from a script, not from a kicad app.
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition pgm_base.cpp:92
see class PGM_BASE
@ RPT_SEVERITY_ERROR
Implement a participant in the KIWAY alchemy.
Definition kiway.h:153
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)
std::string path
KIBIS top(path, &reporter)
#define ENVVARS_CHANGED