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 (C) 2016-2020 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef KIWAY_H_
26#define KIWAY_H_
27
98#include <atomic>
99#include <wx/defs.h>
100#include <wx/event.h>
101#include <import_export.h>
102#include <search_stack.h>
103#include <project.h>
104#include <frame_type.h>
105#include <mail_type.h>
106#include <ki_exception.h>
107#include <jobs/job.h>
108
109
110#define KIFACE_VERSION 1
111#define KIFACE_GETTER KIFACE_1
112
113// The KIFACE acquisition function is declared extern "C" so its name should not
114// be mangled.
115#define KIFACE_INSTANCE_NAME_AND_VERSION "KIFACE_1"
116
117#ifndef SWIG
118#if defined(__linux__) || defined(__FreeBSD__)
119 #define LIB_ENV_VAR wxT( "LD_LIBRARY_PATH" )
120#elif defined(__WXMAC__)
121 #define LIB_ENV_VAR wxT( "DYLD_LIBRARY_PATH" )
122#elif defined(_WIN32)
123 #define LIB_ENV_VAR wxT( "PATH" )
124#else
125 #error Platform support missing
126#endif
127#endif // SWIG
128
129class wxConfigBase;
130class wxWindow;
131class PGM_BASE;
132class KIWAY;
133class KIWAY_PLAYER;
134class wxTopLevelWindow;
135class TOOL_ACTION;
136
137
150struct KIFACE
151{
152 // The order of functions establishes the vtable sequence, do not change the
153 // order of functions in this listing unless you recompile all clients of
154 // this interface.
155
156 virtual ~KIFACE() throw() {}
157
158#define KFCTL_STANDALONE ( 1 << 0 )
159#define KFCTL_CPP_PROJECT_SUITE ( 1 << 1 )
160#define KFCTL_CLI ( 1 << 2 )
161
162
177 virtual bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) = 0;
178
185 virtual void OnKifaceEnd() = 0;
186
190 virtual void Reset() = 0;
191
208 virtual wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId,
209 KIWAY* aKIWAY, int aCtlBits = 0 ) = 0;
210
216 virtual void SaveFileAs( const wxString& srcProjectBasePath,
217 const wxString& srcProjectName,
218 const wxString& newProjectBasePath,
219 const wxString& newProjectName,
220 const wxString& srcFilePath,
221 wxString& aErrors )
222 {
223 // If a KIFACE owns files then it needs to implement this....
224 }
225
237 virtual void* IfaceOrAddress( int aDataId ) = 0;
238
242 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const = 0;
243
244 virtual int HandleJob( JOB* aJob )
245 {
246 return 0;
247 }
248};
249
250
278class KIWAY : public wxEvtHandler
279{
280 friend struct PGM_SINGLE_TOP; // can use set_kiface()
281
282public:
285 {
294
296 };
297
298 ~KIWAY() throw () {}
299
306 static FACE_T KifaceType( FRAME_T aFrameType );
307
308 // If you change the vtable, recompile all of KiCad.
309
316 virtual KIFACE* KiFACE( FACE_T aFaceId, bool doLoad = true );
317
337 virtual KIWAY_PLAYER* Player( FRAME_T aFrameType, bool doCreate = true,
338 wxTopLevelWindow* aParent = nullptr );
339
348 virtual bool PlayerClose( FRAME_T aFrameType, bool doForce );
349
359 virtual bool PlayersClose( bool doForce );
360
364 void PlayerDidClose( FRAME_T aFrameType );
365
372 virtual void ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload,
373 wxWindow* aSource = nullptr );
374
378 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const;
379
386 virtual PROJECT& Prj() const;
387
391 virtual void SetLanguage( int aLanguage );
392
398 virtual void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged );
399
404 virtual void ProjectChanged();
405
406 KIWAY( PGM_BASE* aProgram, int aCtlBits, wxFrame* aTop = nullptr );
407
412 void SetCtlBits( int aCtlBits ) { m_ctl = aCtlBits; }
413
420 void SetTop( wxFrame* aTop );
421 wxFrame* GetTop() { return m_top; }
422
423 void OnKiCadExit();
424
425 void OnKiwayEnd();
426
427 bool ProcessEvent( wxEvent& aEvent ) override;
428
429 int ProcessJob( KIWAY::FACE_T aFace, JOB* job );
430
435 wxWindow* GetBlockingDialog();
436 void SetBlockingDialog( wxWindow* aWin );
437
438private:
440 const wxString dso_search_path( FACE_T aFaceId );
441
442 bool set_kiface( FACE_T aFaceType, KIFACE* aKiface )
443 {
444 if( (unsigned) aFaceType < (unsigned) KIWAY_FACE_COUNT )
445 {
446 m_kiface[aFaceType] = aKiface;
447 return true;
448 }
449
450 return false;
451 }
452
457 KIWAY_PLAYER* GetPlayerFrame( FRAME_T aFrameType );
458
461
463 int m_ctl;
464
465 wxFrame* m_top; // Usually m_top is the Project manager
466
468
469 // An array to store the window ID of PLAYER frames which were run.
470 // A non empty name means only a PLAYER was run at least one time.
471 // Empty entries are represented by wxID_NONE.
472 // They can be closed, and the stored window ID may be invalid.
473 // Call: wxWindow::FindWindowById( m_playerFrameId[aFrameType] )
474 // to know if still exists (or GetPlayerFrame( FRAME_T aFrameType )
475 std::atomic<wxWindowID> m_playerFrameId[KIWAY_PLAYER_COUNT];
476};
477
478
479#ifndef SWIG
480// provided by single_top.cpp and kicad.cpp;
481extern KIWAY Kiway;
482// whereas python launchers: single_top.py and project manager instantiate as a python object
483#endif
484
485
498typedef KIFACE* KIFACE_GETTER_FUNC( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
499
500
501#ifndef SWIG
502
504extern "C" {
505#if defined(BUILD_KIWAY_DLL)
506 KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
507#else
508 KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
509#endif
510}
511
512#endif // SWIG
513
514#endif // KIWAY_H_
An simple container class that lets us dispatch output jobs to kifaces.
Definition: job.h:32
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:67
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
void OnKiCadExit()
Definition: kiway.cpp:743
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:643
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:432
const wxString dso_search_path(FACE_T aFaceId)
Get the [path &] name of the DSO holding the requested FACE_T.
Definition: kiway.cpp:110
int ProcessJob(KIWAY::FACE_T aFace, JOB *job)
Definition: kiway.cpp:735
PGM_BASE * m_program
Definition: kiway.h:462
void SetCtlBits(int aCtlBits)
Overwrites previously set ctl bits, only for use in kicad.cpp to flip between standalone and manager ...
Definition: kiway.h:412
void SetBlockingDialog(wxWindow *aWin)
Definition: kiway.cpp:700
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:496
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:370
wxWindowID m_blockingDialog
Definition: kiway.h:467
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition: kiway.h:442
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition: kiway.cpp:695
static KIFACE * m_kiface[KIWAY_FACE_COUNT]
Definition: kiway.h:459
wxFrame * m_top
Definition: kiway.h:465
wxFrame * GetTop()
Definition: kiway.h:421
virtual void SetLanguage(int aLanguage)
Change the language and then calls ShowChangedLanguage() on all #KIWAY_PLAYERs.
Definition: kiway.cpp:569
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:202
FACE_T
Known KIFACE implementations.
Definition: kiway.h:285
@ KIWAY_FACE_COUNT
Definition: kiway.h:295
@ FACE_SCH
eeschema DSO
Definition: kiway.h:286
@ FACE_PL_EDITOR
Definition: kiway.h:290
@ FACE_PYTHON
Definition: kiway.h:293
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:287
@ FACE_CVPCB
Definition: kiway.h:288
@ FACE_GERBVIEW
Definition: kiway.h:289
@ FACE_BMP2CMP
Definition: kiway.h:292
@ FACE_PCB_CALCULATOR
Definition: kiway.h:291
static int m_kiface_version[KIWAY_FACE_COUNT]
Definition: kiway.h:460
KIWAY_PLAYER * GetPlayerFrame(FRAME_T aFrameType)
Definition: kiway.cpp:414
bool ProcessEvent(wxEvent &aEvent) override
Definition: kiway.cpp:709
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:536
std::atomic< wxWindowID > m_playerFrameId[KIWAY_PLAYER_COUNT]
Definition: kiway.h:475
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:553
void OnKiwayEnd()
Definition: kiway.cpp:758
~KIWAY()
Definition: kiway.h:298
void PlayerDidClose(FRAME_T aFrameType)
Notifies a Kiway that a player has been closed.
Definition: kiway.cpp:547
virtual void GetActions(std::vector< TOOL_ACTION * > &aActions) const
Append all registered actions to the given list.
Definition: kiway.cpp:562
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:88
virtual void ProjectChanged()
Calls ProjectChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:666
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition: kiway.cpp:196
int m_ctl
Definition: kiway.h:463
Container for data for KiCad programs.
Definition: pgm_base.h:96
Container for project specific data.
Definition: project.h:62
Represent a single user action.
Definition: tool_action.h:269
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
@ KIWAY_PLAYER_COUNT
Definition: frame_type.h:65
#define KIFACE_API
Definition: import_export.h:51
KIWAY Kiway
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Point to the one and only KIFACE export.
Definition: kiway.h:498
#define KIFACE_GETTER
Definition: kiway.h:111
MAIL_T
The set of mail types sendable via KIWAY::ExpressMail() and supplied as the aCommand parameter to tha...
Definition: mail_type.h:38
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151
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 OnKifaceEnd()=0
Called just once just before the DSO is to be unloaded.
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:216
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 int HandleJob(JOB *aJob)
Definition: kiway.h:244
virtual ~KIFACE()
Definition: kiway.h:156
Struct PGM_SINGLE_TOP implements PGM_BASE with its own OnPgmInit() and OnPgmExit().
Definition: single_top.cpp:73