KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kiway.h
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#ifndef KIWAY_H_
22#define KIWAY_H_
23
92
93
94#include <array>
95#include <atomic>
96#include <wx/defs.h>
97#include <wx/event.h>
98#include <import_export.h>
99#include <search_stack.h>
100#include <project.h>
101#include <frame_type.h>
102#include <mail_type.h>
103#include <ki_exception.h>
104
105class KICAD_API_SERVER;
106
107
108#define KIFACE_VERSION 1
109#define KIFACE_GETTER KIFACE_1
110
111// The KIFACE acquisition function is declared extern "C" so its name should not
112// be mangled.
113#define KIFACE_INSTANCE_NAME_AND_VERSION "KIFACE_1"
114
115#if defined(__linux__) || defined(__FreeBSD__)
116 #define LIB_ENV_VAR wxT( "LD_LIBRARY_PATH" )
117#elif defined(__WXMAC__)
118 #define LIB_ENV_VAR wxT( "DYLD_LIBRARY_PATH" )
119#elif defined(_WIN32)
120 #define LIB_ENV_VAR wxT( "PATH" )
121#else
122 #error Platform support missing
123#endif
124
125class wxConfigBase;
126class wxWindow;
127class PGM_BASE;
128class KIWAY;
129class KIWAY_PLAYER;
130class wxTopLevelWindow;
131class TOOL_ACTION;
132class JOB;
133class REPORTER;
136class LOCAL_HISTORY;
137
138
151struct KIFACE
152{
153 // The order of functions establishes the vtable sequence, do not change the
154 // order of functions in this listing unless you recompile all clients of
155 // this interface.
156
157 virtual ~KIFACE() throw() {}
158
159#define KFCTL_STANDALONE ( 1 << 0 )
160#define KFCTL_CPP_PROJECT_SUITE ( 1 << 1 )
161#define KFCTL_CLI ( 1 << 2 )
162
163
178 virtual bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) = 0;
179
186 virtual void OnKifaceEnd() = 0;
187
191 virtual void Reset() = 0;
192
209 virtual wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId,
210 KIWAY* aKIWAY, int aCtlBits = 0 ) = 0;
211
217 virtual void SaveFileAs( const wxString& srcProjectBasePath,
218 const wxString& srcProjectName,
219 const wxString& newProjectBasePath,
220 const wxString& newProjectName,
221 const wxString& srcFilePath,
222 wxString& aErrors )
223 {
224 // If a KIFACE owns files then it needs to implement this....
225 }
226
238 virtual void* IfaceOrAddress( int aDataId ) = 0;
239
243 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const = 0;
244
245 virtual int HandleJob( JOB* aJob, REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter )
246 {
247 return 0;
248 }
249
250 virtual bool HandleJobConfig( JOB* aJob, wxWindow* aParent )
251 {
252 return 0;
253 }
254
255 virtual bool HandleApiOpenDocument( const wxString& aPath,
256 KICAD_API_SERVER* aServer,
257 wxString* aError )
258 {
259 if( aError )
260 *aError = wxS( "OpenDocument is not implemented for this face" );
261
262 return false;
263 }
264
265 virtual bool HandleApiCloseDocument( const wxString& aBoardFileName,
266 KICAD_API_SERVER* aServer,
267 wxString* aError )
268 {
269 if( aError )
270 *aError = wxS( "CloseDocument is not implemented for this face" );
271
272 return false;
273 }
274
275 virtual void PreloadLibraries( KIWAY* aKiway ) {}
276
277 virtual void CancelPreload( bool aBlock = true ) {}
278
279 virtual void ProjectChanged() {}
280};
281
282
310class KICOMMON_API KIWAY : public wxEvtHandler
311{
312 friend struct PGM_SINGLE_TOP; // can use set_kiface()
313
314public:
328
329 ~KIWAY();
330
337 static FACE_T KifaceType( FRAME_T aFrameType );
338
339 // If you change the vtable, recompile all of KiCad.
340
347 virtual KIFACE* KiFACE( FACE_T aFaceId, bool doLoad = true );
348
368 virtual KIWAY_PLAYER* Player( FRAME_T aFrameType, bool doCreate = true,
369 wxTopLevelWindow* aParent = nullptr );
370
379 virtual bool PlayerClose( FRAME_T aFrameType, bool doForce );
380
390 virtual bool PlayersClose( bool doForce );
391
395 void PlayerDidClose( FRAME_T aFrameType );
396
403 virtual void ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload,
404 wxWindow* aSource = nullptr, bool aFromOtherThread = false );
405
409 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const;
410
417 virtual PROJECT& Prj() const;
418
423
427 virtual void SetLanguage( int aLanguage );
428
434 virtual void CommonSettingsChanged( int aFlags = 0 );
435
440 void ClearFileHistory();
441
446 virtual void ProjectChanged();
447
448 KIWAY( int aCtlBits, wxFrame* aTop = nullptr );
449
454 void SetCtlBits( int aCtlBits ) { m_ctl = aCtlBits; }
455
462 void SetTop( wxFrame* aTop );
463 wxFrame* GetTop() { return m_top; }
464
465 void OnKiCadExit();
466
467 void OnKiwayEnd();
468
469 bool ProcessEvent( wxEvent& aEvent ) override;
470
471 void QueueEvent( wxEvent* aEvent ) override;
472
473 int ProcessJob( KIWAY::FACE_T aFace, JOB* aJob, REPORTER* aReporter = nullptr,
474 PROGRESS_REPORTER* aProgressReporter = nullptr );
475 bool ProcessJobConfigDialog( KIWAY::FACE_T aFace, JOB* aJob, wxWindow* aWindow );
476
477 bool ProcessApiOpenDocument( KIWAY::FACE_T aFace, const wxString& aPath,
478 KICAD_API_SERVER* aServer,
479 wxString* aError = nullptr );
480
481 bool ProcessApiCloseDocument( KIWAY::FACE_T aFace, const wxString& aPath,
482 KICAD_API_SERVER* aServer,
483 wxString* aError = nullptr );
484
489 wxWindow* GetBlockingDialog();
490 void SetBlockingDialog( wxWindow* aWin );
491
492private:
494 const wxString dso_search_path( FACE_T aFaceId );
495
496 bool set_kiface( FACE_T aFaceType, KIFACE* aKiface )
497 {
498 if( (unsigned) aFaceType < (unsigned) KIWAY_FACE_COUNT )
499 {
500 m_kiface[aFaceType] = aKiface;
501 return true;
502 }
503
504 return false;
505 }
506
511 KIWAY_PLAYER* GetPlayerFrame( FRAME_T aFrameType );
512
513 static std::array<KIFACE*,KIWAY_FACE_COUNT> m_kiface;
514 static std::array<int,KIWAY_FACE_COUNT> m_kiface_version;
515
516 int m_ctl;
517
518 wxFrame* m_top; // Usually m_top is the Project manager
519
521
522 // An array to store the window ID of PLAYER frames which were run.
523 // A non empty name means only a PLAYER was run at least one time.
524 // Empty entries are represented by wxID_NONE.
525 // They can be closed, and the stored window ID may be invalid.
526 // Call: wxWindow::FindWindowById( m_playerFrameId[aFrameType] )
527 // to know if still exists (or GetPlayerFrame( FRAME_T aFrameType )
528 std::atomic<wxWindowID> m_playerFrameId[KIWAY_PLAYER_COUNT];
529
531};
532
533
534extern KIWAY Kiway;
535
536
549typedef KIFACE* KIFACE_GETTER_FUNC( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
550
551
553extern "C" {
554#if defined(BUILD_KIWAY_DLL)
555 KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
556#else
557 KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
558#endif
559}
560
561#endif // KIWAY_H_
An simple container class that lets us dispatch output jobs to kifaces.
Definition job.h:184
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:311
void SetCtlBits(int aCtlBits)
Overwrites previously set ctl bits, only for use in kicad.cpp to flip between standalone and manager ...
Definition kiway.h:454
LOCAL_HISTORY * m_local_history
Definition kiway.h:530
wxWindowID m_blockingDialog
Definition kiway.h:520
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition kiway.h:496
static std::array< KIFACE *, KIWAY_FACE_COUNT > m_kiface
Definition kiway.h:513
wxFrame * m_top
Definition kiway.h:518
wxFrame * GetTop()
Definition kiway.h:463
friend struct PGM_SINGLE_TOP
Definition kiway.h:312
FACE_T
Known KIFACE implementations.
Definition kiway.h:317
@ KIWAY_FACE_COUNT
Definition kiway.h:326
@ FACE_SCH
eeschema DSO
Definition kiway.h:318
@ FACE_PL_EDITOR
Definition kiway.h:322
@ FACE_PCB
pcbnew DSO
Definition kiway.h:319
@ FACE_CVPCB
Definition kiway.h:320
@ FACE_GERBVIEW
Definition kiway.h:321
@ FACE_BMP2CMP
Definition kiway.h:324
@ FACE_PCB_CALCULATOR
Definition kiway.h:323
static std::array< int, KIWAY_FACE_COUNT > m_kiface_version
Definition kiway.h:514
std::atomic< wxWindowID > m_playerFrameId[KIWAY_PLAYER_COUNT]
Definition kiway.h:528
KIWAY(int aCtlBits, wxFrame *aTop=nullptr)
Definition kiway.cpp:50
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
Definition kiway.h:422
int m_ctl
Definition kiway.h:516
Simple local history manager built on libgit2.
Container for data for KiCad programs.
Definition pgm_base.h:102
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition project.h:62
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:71
Represent a single user action.
void ProjectChanged() override
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:29
@ KIWAY_PLAYER_COUNT
Definition frame_type.h:66
#define KIFACE_API
PROJECT & Prj()
Definition kicad.cpp:730
#define KICOMMON_API
Definition kicommon.h:27
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Point to the one and only KIFACE export.
Definition kiway.h:549
#define KIFACE_GETTER
Definition kiway.h:109
MAIL_T
The set of mail types sendable via KIWAY::ExpressMail() and supplied as the aCommand parameter to tha...
Definition mail_type.h:34
KIWAY Kiway(KFCTL_STANDALONE)
Implement a participant in the KIWAY alchemy.
Definition kiway.h:152
virtual bool HandleJobConfig(JOB *aJob, wxWindow *aParent)
Definition kiway.h:250
virtual wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKIWAY, int aCtlBits=0)=0
Create a wxWindow for the current project.
virtual bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway)=0
Called just once shortly after the DSO is loaded.
virtual void ProjectChanged()
Definition kiway.h:279
virtual void OnKifaceEnd()=0
Called just once just before the DSO is to be unloaded.
virtual void PreloadLibraries(KIWAY *aKiway)
Definition kiway.h:275
virtual void * IfaceOrAddress(int aDataId)=0
Return pointer to the requested object.
virtual void SaveFileAs(const wxString &srcProjectBasePath, const wxString &srcProjectName, const wxString &newProjectBasePath, const wxString &newProjectName, const wxString &srcFilePath, wxString &aErrors)
Saving a file under a different name is delegated to the various KIFACEs because the project doesn't ...
Definition kiway.h:217
virtual void Reset()=0
Reloads global state.
virtual void GetActions(std::vector< TOOL_ACTION * > &aActions) const =0
Append this Kiface's registered actions to the given list.
virtual bool HandleApiCloseDocument(const wxString &aBoardFileName, KICAD_API_SERVER *aServer, wxString *aError)
Definition kiway.h:265
virtual bool HandleApiOpenDocument(const wxString &aPath, KICAD_API_SERVER *aServer, wxString *aError)
Definition kiway.h:255
virtual void CancelPreload(bool aBlock=true)
Definition kiway.h:277
virtual int HandleJob(JOB *aJob, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter)
Definition kiway.h:245
virtual ~KIFACE()
Definition kiway.h:157