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, 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
96
97
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;
135class JOB;
136class REPORTER;
138
139
152struct KIFACE
153{
154 // The order of functions establishes the vtable sequence, do not change the
155 // order of functions in this listing unless you recompile all clients of
156 // this interface.
157
158 virtual ~KIFACE() throw() {}
159
160#define KFCTL_STANDALONE ( 1 << 0 )
161#define KFCTL_CPP_PROJECT_SUITE ( 1 << 1 )
162#define KFCTL_CLI ( 1 << 2 )
163
164
179 virtual bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) = 0;
180
187 virtual void OnKifaceEnd() = 0;
188
192 virtual void Reset() = 0;
193
210 virtual wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId,
211 KIWAY* aKIWAY, int aCtlBits = 0 ) = 0;
212
218 virtual void SaveFileAs( const wxString& srcProjectBasePath,
219 const wxString& srcProjectName,
220 const wxString& newProjectBasePath,
221 const wxString& newProjectName,
222 const wxString& srcFilePath,
223 wxString& aErrors )
224 {
225 // If a KIFACE owns files then it needs to implement this....
226 }
227
239 virtual void* IfaceOrAddress( int aDataId ) = 0;
240
244 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const = 0;
245
246 virtual int HandleJob( JOB* aJob, REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter )
247 {
248 return 0;
249 }
250
251 virtual bool HandleJobConfig( JOB* aJob, wxWindow* aParent )
252 {
253 return 0;
254 }
255};
256
257
285class KICOMMON_API KIWAY : public wxEvtHandler
286{
287 friend struct PGM_SINGLE_TOP; // can use set_kiface()
288
289public:
304
305 ~KIWAY() throw () {}
306
313 static FACE_T KifaceType( FRAME_T aFrameType );
314
315 // If you change the vtable, recompile all of KiCad.
316
323 virtual KIFACE* KiFACE( FACE_T aFaceId, bool doLoad = true );
324
344 virtual KIWAY_PLAYER* Player( FRAME_T aFrameType, bool doCreate = true,
345 wxTopLevelWindow* aParent = nullptr );
346
355 virtual bool PlayerClose( FRAME_T aFrameType, bool doForce );
356
366 virtual bool PlayersClose( bool doForce );
367
371 void PlayerDidClose( FRAME_T aFrameType );
372
379 virtual void ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload,
380 wxWindow* aSource = nullptr );
381
385 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const;
386
393 virtual PROJECT& Prj() const;
394
398 virtual void SetLanguage( int aLanguage );
399
405 virtual void CommonSettingsChanged( int aFlags = 0 );
406
411 void ClearFileHistory();
412
417 virtual void ProjectChanged();
418
419 KIWAY( int aCtlBits, wxFrame* aTop = nullptr );
420
425 void SetCtlBits( int aCtlBits ) { m_ctl = aCtlBits; }
426
433 void SetTop( wxFrame* aTop );
434 wxFrame* GetTop() { return m_top; }
435
436 void OnKiCadExit();
437
438 void OnKiwayEnd();
439
440 bool ProcessEvent( wxEvent& aEvent ) override;
441
442 int ProcessJob( KIWAY::FACE_T aFace, JOB* aJob, REPORTER* aReporter = nullptr,
443 PROGRESS_REPORTER* aProgressReporter = nullptr );
444 bool ProcessJobConfigDialog( KIWAY::FACE_T aFace, JOB* aJob, wxWindow* aWindow );
445
450 wxWindow* GetBlockingDialog();
451 void SetBlockingDialog( wxWindow* aWin );
452
453private:
455 const wxString dso_search_path( FACE_T aFaceId );
456
457 bool set_kiface( FACE_T aFaceType, KIFACE* aKiface )
458 {
459 if( (unsigned) aFaceType < (unsigned) KIWAY_FACE_COUNT )
460 {
461 m_kiface[aFaceType] = aKiface;
462 return true;
463 }
464
465 return false;
466 }
467
472 KIWAY_PLAYER* GetPlayerFrame( FRAME_T aFrameType );
473
476
477 int m_ctl;
478
479 wxFrame* m_top; // Usually m_top is the Project manager
480
482
483 // An array to store the window ID of PLAYER frames which were run.
484 // A non empty name means only a PLAYER was run at least one time.
485 // Empty entries are represented by wxID_NONE.
486 // They can be closed, and the stored window ID may be invalid.
487 // Call: wxWindow::FindWindowById( m_playerFrameId[aFrameType] )
488 // to know if still exists (or GetPlayerFrame( FRAME_T aFrameType )
489 std::atomic<wxWindowID> m_playerFrameId[KIWAY_PLAYER_COUNT];
490};
491
492
493#ifndef SWIG
494// provided by single_top.cpp and kicad.cpp;
495extern KIWAY Kiway;
496// whereas python launchers: single_top.py and project manager instantiate as a python object
497#endif
498
499
512typedef KIFACE* KIFACE_GETTER_FUNC( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
513
514
515#ifndef SWIG
516
518extern "C" {
519#if defined(BUILD_KIWAY_DLL)
520 KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
521#else
522 KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
523#endif
524}
525
526#endif // SWIG
527
528#endif // KIWAY_H_
An simple container class that lets us dispatch output jobs to kifaces.
Definition job.h:183
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:286
void SetCtlBits(int aCtlBits)
Overwrites previously set ctl bits, only for use in kicad.cpp to flip between standalone and manager ...
Definition kiway.h:425
wxWindowID m_blockingDialog
Definition kiway.h:481
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition kiway.h:457
static KIFACE * m_kiface[KIWAY_FACE_COUNT]
Definition kiway.h:474
wxFrame * m_top
Definition kiway.h:479
wxFrame * GetTop()
Definition kiway.h:434
friend struct PGM_SINGLE_TOP
Definition kiway.h:287
FACE_T
Known KIFACE implementations.
Definition kiway.h:292
@ KIWAY_FACE_COUNT
Definition kiway.h:302
@ FACE_SCH
eeschema DSO
Definition kiway.h:293
@ FACE_PL_EDITOR
Definition kiway.h:297
@ FACE_PYTHON
Definition kiway.h:300
@ FACE_PCB
pcbnew DSO
Definition kiway.h:294
@ FACE_CVPCB
Definition kiway.h:295
@ FACE_GERBVIEW
Definition kiway.h:296
@ FACE_BMP2CMP
Definition kiway.h:299
@ FACE_PCB_CALCULATOR
Definition kiway.h:298
static int m_kiface_version[KIWAY_FACE_COUNT]
Definition kiway.h:475
std::atomic< wxWindowID > m_playerFrameId[KIWAY_PLAYER_COUNT]
Definition kiway.h:489
KIWAY(int aCtlBits, wxFrame *aTop=nullptr)
Definition kiway.cpp:54
~KIWAY()
Definition kiway.h:305
int m_ctl
Definition kiway.h:477
Container for data for KiCad programs.
Definition pgm_base.h:103
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition project.h:65
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
Represent a single user action.
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
PROJECT & Prj()
Definition kicad.cpp:612
#define KICOMMON_API
Definition kicommon.h:28
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Point to the one and only KIFACE export.
Definition kiway.h:512
#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
KIWAY Kiway(KFCTL_STANDALONE)
Implement a participant in the KIWAY alchemy.
Definition kiway.h:153
virtual bool HandleJobConfig(JOB *aJob, wxWindow *aParent)
Definition kiway.h:251
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:218
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, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter)
Definition kiway.h:246
virtual ~KIFACE()
Definition kiway.h:158