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
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;
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 )
246 {
247 return 0;
248 }
249
250 virtual bool HandleJobConfig( JOB* aJob, wxWindow* aParent )
251 {
252 return 0;
253 }
254};
255
256
284class KICOMMON_API KIWAY : public wxEvtHandler
285{
286 friend struct PGM_SINGLE_TOP; // can use set_kiface()
287
288public:
291 {
300
301 KIWAY_FACE_COUNT
302 };
303
304 ~KIWAY() throw () {}
305
312 static FACE_T KifaceType( FRAME_T aFrameType );
313
314 // If you change the vtable, recompile all of KiCad.
315
322 virtual KIFACE* KiFACE( FACE_T aFaceId, bool doLoad = true );
323
343 virtual KIWAY_PLAYER* Player( FRAME_T aFrameType, bool doCreate = true,
344 wxTopLevelWindow* aParent = nullptr );
345
354 virtual bool PlayerClose( FRAME_T aFrameType, bool doForce );
355
365 virtual bool PlayersClose( bool doForce );
366
370 void PlayerDidClose( FRAME_T aFrameType );
371
378 virtual void ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload,
379 wxWindow* aSource = nullptr );
380
384 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const;
385
392 virtual PROJECT& Prj() const;
393
397 virtual void SetLanguage( int aLanguage );
398
404 virtual void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged );
405
410 virtual void ProjectChanged();
411
412 KIWAY( int aCtlBits, wxFrame* aTop = nullptr );
413
418 void SetCtlBits( int aCtlBits ) { m_ctl = aCtlBits; }
419
426 void SetTop( wxFrame* aTop );
427 wxFrame* GetTop() { return m_top; }
428
429 void OnKiCadExit();
430
431 void OnKiwayEnd();
432
433 bool ProcessEvent( wxEvent& aEvent ) override;
434
435 int ProcessJob( KIWAY::FACE_T aFace, JOB* aJob, REPORTER* aReporter = nullptr );
436 bool ProcessJobConfigDialog( KIWAY::FACE_T aFace, JOB* aJob, wxWindow* aWindow );
437
442 wxWindow* GetBlockingDialog();
443 void SetBlockingDialog( wxWindow* aWin );
444
445private:
447 const wxString dso_search_path( FACE_T aFaceId );
448
449 bool set_kiface( FACE_T aFaceType, KIFACE* aKiface )
450 {
451 if( (unsigned) aFaceType < (unsigned) KIWAY_FACE_COUNT )
452 {
453 m_kiface[aFaceType] = aKiface;
454 return true;
455 }
456
457 return false;
458 }
459
464 KIWAY_PLAYER* GetPlayerFrame( FRAME_T aFrameType );
465
466 static KIFACE* m_kiface[KIWAY_FACE_COUNT];
467 static int m_kiface_version[KIWAY_FACE_COUNT];
468
469 int m_ctl;
470
471 wxFrame* m_top; // Usually m_top is the Project manager
472
474
475 // An array to store the window ID of PLAYER frames which were run.
476 // A non empty name means only a PLAYER was run at least one time.
477 // Empty entries are represented by wxID_NONE.
478 // They can be closed, and the stored window ID may be invalid.
479 // Call: wxWindow::FindWindowById( m_playerFrameId[aFrameType] )
480 // to know if still exists (or GetPlayerFrame( FRAME_T aFrameType )
481 std::atomic<wxWindowID> m_playerFrameId[KIWAY_PLAYER_COUNT];
482};
483
484
485#ifndef SWIG
486// provided by single_top.cpp and kicad.cpp;
487extern KIWAY Kiway;
488// whereas python launchers: single_top.py and project manager instantiate as a python object
489#endif
490
491
504typedef KIFACE* KIFACE_GETTER_FUNC( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
505
506
507#ifndef SWIG
508
510extern "C" {
511#if defined(BUILD_KIWAY_DLL)
512 KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
513#else
514 KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
515#endif
516}
517
518#endif // SWIG
519
520#endif // KIWAY_H_
An simple container class that lets us dispatch output jobs to kifaces.
Definition: job.h:182
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:65
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:285
void SetCtlBits(int aCtlBits)
Overwrites previously set ctl bits, only for use in kicad.cpp to flip between standalone and manager ...
Definition: kiway.h:418
wxWindowID m_blockingDialog
Definition: kiway.h:473
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition: kiway.h:449
wxFrame * m_top
Definition: kiway.h:471
wxFrame * GetTop()
Definition: kiway.h:427
FACE_T
Known KIFACE implementations.
Definition: kiway.h:291
@ FACE_SCH
eeschema DSO
Definition: kiway.h:292
@ FACE_PL_EDITOR
Definition: kiway.h:296
@ FACE_PYTHON
Definition: kiway.h:299
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:293
@ FACE_CVPCB
Definition: kiway.h:294
@ FACE_GERBVIEW
Definition: kiway.h:295
@ FACE_BMP2CMP
Definition: kiway.h:298
@ FACE_PCB_CALCULATOR
Definition: kiway.h:297
~KIWAY()
Definition: kiway.h:304
int m_ctl
Definition: kiway.h:469
Container for data for KiCad programs.
Definition: pgm_base.h:103
Container for project specific data.
Definition: project.h:64
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
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:61
PROJECT & Prj()
Definition: kicad.cpp:597
#define KICOMMON_API
Definition: kicommon.h:28
KIWAY Kiway
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Point to the one and only KIFACE export.
Definition: kiway.h:504
#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: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 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 int HandleJob(JOB *aJob, REPORTER *aReporter)
Definition: kiway.h:245
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 ~KIFACE()
Definition: kiway.h:157
Implement PGM_BASE with its own OnPgmInit() and OnPgmExit().
Definition: single_top.cpp:77