KiCad PCB EDA Suite
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
108
109#define KIFACE_VERSION 1
110#define KIFACE_GETTER KIFACE_1
111
112// The KIFACE acquisition function is declared extern "C" so its name should not
113// be mangled.
114#define KIFACE_INSTANCE_NAME_AND_VERSION "KIFACE_1"
115
116#ifndef SWIG
117#if defined(__linux__) || defined(__FreeBSD__)
118 #define LIB_ENV_VAR wxT( "LD_LIBRARY_PATH" )
119#elif defined(__WXMAC__)
120 #define LIB_ENV_VAR wxT( "DYLD_LIBRARY_PATH" )
121#elif defined(_WIN32)
122 #define LIB_ENV_VAR wxT( "PATH" )
123#else
124 #error Platform support missing
125#endif
126#endif // SWIG
127
128class wxConfigBase;
129class wxWindow;
130class PGM_BASE;
131class KIWAY;
132class KIWAY_PLAYER;
133class wxTopLevelWindow;
134class TOOL_ACTION;
135
136
149struct KIFACE
150{
151 // The order of functions establishes the vtable sequence, do not change the
152 // order of functions in this listing unless you recompile all clients of
153 // this interface.
154
155 virtual ~KIFACE() throw() {}
156
157#define KFCTL_STANDALONE (1<<0)
158#define KFCTL_CPP_PROJECT_SUITE (1<<1)
159
160
175 virtual bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) = 0;
176
183 virtual void OnKifaceEnd() = 0;
184
201 virtual wxWindow* CreateWindow( wxWindow* aParent, int aClassId,
202 KIWAY* aKIWAY, int aCtlBits = 0 ) = 0;
203
209 virtual void SaveFileAs( const wxString& srcProjectBasePath,
210 const wxString& srcProjectName,
211 const wxString& newProjectBasePath,
212 const wxString& newProjectName,
213 const wxString& srcFilePath,
214 wxString& aErrors )
215 {
216 // If a KIFACE owns files then it needs to implement this....
217 }
218
230 virtual void* IfaceOrAddress( int aDataId ) = 0;
231
235 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const = 0;
236};
237
238
266class KIWAY : public wxEvtHandler
267{
268 friend struct PGM_SINGLE_TOP; // can use set_kiface()
269
270public:
273 {
282
284 };
285
286 ~KIWAY() throw () {}
287
294 static FACE_T KifaceType( FRAME_T aFrameType );
295
296 // If you change the vtable, recompile all of KiCad.
297
304 virtual KIFACE* KiFACE( FACE_T aFaceId, bool doLoad = true );
305
325 virtual KIWAY_PLAYER* Player( FRAME_T aFrameType, bool doCreate = true,
326 wxTopLevelWindow* aParent = nullptr );
327
336 virtual bool PlayerClose( FRAME_T aFrameType, bool doForce );
337
347 virtual bool PlayersClose( bool doForce );
348
355 virtual void ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload,
356 wxWindow* aSource = nullptr );
357
361 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const;
362
369 virtual PROJECT& Prj() const;
370
374 virtual void SetLanguage( int aLanguage );
375
381 virtual void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged );
382
387 virtual void ProjectChanged();
388
389 KIWAY( PGM_BASE* aProgram, int aCtlBits, wxFrame* aTop = nullptr );
390
397 void SetTop( wxFrame* aTop );
398 wxFrame* GetTop() { return m_top; }
399
400 void OnKiCadExit();
401
402 void OnKiwayEnd();
403
404 bool ProcessEvent( wxEvent& aEvent ) override;
405
410 wxWindow* GetBlockingDialog();
411 void SetBlockingDialog( wxWindow* aWin );
412
413private:
415 const wxString dso_search_path( FACE_T aFaceId );
416
417#if 0
419 void player_destroy_handler( wxWindowDestroyEvent& event );
420#endif
421
422 bool set_kiface( FACE_T aFaceType, KIFACE* aKiface )
423 {
424 if( (unsigned) aFaceType < (unsigned) KIWAY_FACE_COUNT )
425 {
426 m_kiface[aFaceType] = aKiface;
427 return true;
428 }
429
430 return false;
431 }
432
437 KIWAY_PLAYER* GetPlayerFrame( FRAME_T aFrameType );
438
441
443 int m_ctl;
444
445 wxFrame* m_top; // Usually m_top is the Project manager
446
448
449 // An array to store the window ID of PLAYER frames which were run.
450 // A non empty name means only a PLAYER was run at least one time.
451 // Empty entries are represented by wxID_NONE.
452 // They can be closed, and the stored window ID may be invalid.
453 // Call: wxWindow::FindWindowById( m_playerFrameId[aFrameType] )
454 // to know if still exists (or GetPlayerFrame( FRAME_T aFrameType )
455 std::atomic<wxWindowID> m_playerFrameId[KIWAY_PLAYER_COUNT];
456};
457
458
459#ifndef SWIG
460// provided by single_top.cpp and kicad.cpp;
461extern KIWAY Kiway;
462// whereas python launchers: single_top.py and project manager instantiate as a python object
463#endif
464
465
478typedef KIFACE* KIFACE_GETTER_FUNC( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
479
480
481#ifndef SWIG
482
484extern "C" {
485#if defined(BUILD_KIWAY_DLL)
486 MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
487#else
488 KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
489#endif
490}
491
492#endif // SWIG
493
494#endif // KIWAY_H_
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:66
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:267
void OnKiCadExit()
Definition: kiway.cpp:657
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:572
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:394
const wxString dso_search_path(FACE_T aFaceId)
Get the [path &] name of the DSO holding the requested FACE_T.
Definition: kiway.cpp:106
PGM_BASE * m_program
Definition: kiway.h:442
void SetBlockingDialog(wxWindow *aWin)
Definition: kiway.cpp:622
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:450
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:332
wxWindowID m_blockingDialog
Definition: kiway.h:447
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition: kiway.h:422
KIWAY(PGM_BASE *aProgram, int aCtlBits, wxFrame *aTop=nullptr)
Definition: kiway.cpp:53
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition: kiway.cpp:617
static KIFACE * m_kiface[KIWAY_FACE_COUNT]
Definition: kiway.h:439
wxFrame * m_top
Definition: kiway.h:445
wxFrame * GetTop()
Definition: kiway.h:398
virtual void SetLanguage(int aLanguage)
Change the language and then calls ShowChangedLanguage() on all #KIWAY_PLAYERs.
Definition: kiway.cpp:504
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:198
FACE_T
Known KIFACE implementations.
Definition: kiway.h:273
@ KIWAY_FACE_COUNT
Definition: kiway.h:283
@ FACE_SCH
eeschema DSO
Definition: kiway.h:274
@ FACE_PL_EDITOR
Definition: kiway.h:278
@ FACE_PYTHON
Definition: kiway.h:281
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:275
@ FACE_CVPCB
Definition: kiway.h:276
@ FACE_GERBVIEW
Definition: kiway.h:277
@ FACE_BMP2CMP
Definition: kiway.h:280
@ FACE_PCB_CALCULATOR
Definition: kiway.h:279
static int m_kiface_version[KIWAY_FACE_COUNT]
Definition: kiway.h:440
KIWAY_PLAYER * GetPlayerFrame(FRAME_T aFrameType)
Definition: kiway.cpp:376
bool ProcessEvent(wxEvent &aEvent) override
Definition: kiway.cpp:631
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:475
std::atomic< wxWindowID > m_playerFrameId[KIWAY_PLAYER_COUNT]
Definition: kiway.h:455
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:488
void OnKiwayEnd()
Definition: kiway.cpp:672
~KIWAY()
Definition: kiway.h:286
virtual void GetActions(std::vector< TOOL_ACTION * > &aActions) const
Append all registered actions to the given list.
Definition: kiway.cpp:497
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:84
virtual void ProjectChanged()
Calls ProjectChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:595
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition: kiway.cpp:192
int m_ctl
Definition: kiway.h:443
Container for data for KiCad programs.
Definition: pgm_base.h:94
Container for project specific data.
Definition: project.h:63
Represent a single user action.
Definition: tool_action.h:68
int aKIWAYversion
Definition: cvpcb.cpp:109
int PGM_BASE * aProgram
Definition: cvpcb.cpp:110
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:61
#define MY_API(rettype)
Definition: import_export.h:55
KIWAY Kiway
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Point to the one and only KIFACE export.
Definition: kiway.h:478
#define KIFACE_GETTER
Definition: kiway.h:110
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:150
virtual wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKIWAY, int aCtlBits=0)=0
Create a wxWindow for the current project.
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:209
virtual void GetActions(std::vector< TOOL_ACTION * > &aActions) const =0
Append this Kiface's registered actions to the given list.
virtual bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits)=0
Called just once shortly after the DSO is loaded.
virtual ~KIFACE()
Definition: kiway.h:155
Struct PGM_SINGLE_TOP implements PGM_BASE with its own OnPgmInit() and OnPgmExit().
Definition: single_top.cpp:67