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 <array>
99#include <atomic>
100#include <wx/defs.h>
101#include <wx/event.h>
102#include <import_export.h>
103#include <search_stack.h>
104#include <project.h>
105#include <frame_type.h>
106#include <mail_type.h>
107#include <ki_exception.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;
136class JOB;
137class REPORTER;
140class LOCAL_HISTORY;
141
142
155struct KIFACE
156{
157 // The order of functions establishes the vtable sequence, do not change the
158 // order of functions in this listing unless you recompile all clients of
159 // this interface.
160
161 virtual ~KIFACE() throw() {}
162
163#define KFCTL_STANDALONE ( 1 << 0 )
164#define KFCTL_CPP_PROJECT_SUITE ( 1 << 1 )
165#define KFCTL_CLI ( 1 << 2 )
166
167
182 virtual bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) = 0;
183
190 virtual void OnKifaceEnd() = 0;
191
195 virtual void Reset() = 0;
196
213 virtual wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId,
214 KIWAY* aKIWAY, int aCtlBits = 0 ) = 0;
215
221 virtual void SaveFileAs( const wxString& srcProjectBasePath,
222 const wxString& srcProjectName,
223 const wxString& newProjectBasePath,
224 const wxString& newProjectName,
225 const wxString& srcFilePath,
226 wxString& aErrors )
227 {
228 // If a KIFACE owns files then it needs to implement this....
229 }
230
242 virtual void* IfaceOrAddress( int aDataId ) = 0;
243
247 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const = 0;
248
249 virtual int HandleJob( JOB* aJob, REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter )
250 {
251 return 0;
252 }
253
254 virtual bool HandleJobConfig( JOB* aJob, wxWindow* aParent )
255 {
256 return 0;
257 }
258
259 virtual void PreloadLibraries( KIWAY* aKiway ) {}
260
261 virtual void CancelPreload( bool aBlock = true ) {}
262
263 virtual void ProjectChanged() {}
264};
265
266
294class KICOMMON_API KIWAY : public wxEvtHandler
295{
296 friend struct PGM_SINGLE_TOP; // can use set_kiface()
297
298public:
313
314 ~KIWAY();
315
322 static FACE_T KifaceType( FRAME_T aFrameType );
323
324 // If you change the vtable, recompile all of KiCad.
325
332 virtual KIFACE* KiFACE( FACE_T aFaceId, bool doLoad = true );
333
353 virtual KIWAY_PLAYER* Player( FRAME_T aFrameType, bool doCreate = true,
354 wxTopLevelWindow* aParent = nullptr );
355
364 virtual bool PlayerClose( FRAME_T aFrameType, bool doForce );
365
375 virtual bool PlayersClose( bool doForce );
376
380 void PlayerDidClose( FRAME_T aFrameType );
381
388 virtual void ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload,
389 wxWindow* aSource = nullptr, bool aFromOtherThread = false );
390
394 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const;
395
402 virtual PROJECT& Prj() const;
403
408
412 virtual void SetLanguage( int aLanguage );
413
419 virtual void CommonSettingsChanged( int aFlags = 0 );
420
425 void ClearFileHistory();
426
431 virtual void ProjectChanged();
432
433 KIWAY( int aCtlBits, wxFrame* aTop = nullptr );
434
439 void SetCtlBits( int aCtlBits ) { m_ctl = aCtlBits; }
440
447 void SetTop( wxFrame* aTop );
448 wxFrame* GetTop() { return m_top; }
449
450 void OnKiCadExit();
451
452 void OnKiwayEnd();
453
454 bool ProcessEvent( wxEvent& aEvent ) override;
455
456 void QueueEvent( wxEvent* aEvent ) override;
457
458 int ProcessJob( KIWAY::FACE_T aFace, JOB* aJob, REPORTER* aReporter = nullptr,
459 PROGRESS_REPORTER* aProgressReporter = nullptr );
460 bool ProcessJobConfigDialog( KIWAY::FACE_T aFace, JOB* aJob, wxWindow* aWindow );
461
466 wxWindow* GetBlockingDialog();
467 void SetBlockingDialog( wxWindow* aWin );
468
469private:
471 const wxString dso_search_path( FACE_T aFaceId );
472
473 bool set_kiface( FACE_T aFaceType, KIFACE* aKiface )
474 {
475 if( (unsigned) aFaceType < (unsigned) KIWAY_FACE_COUNT )
476 {
477 m_kiface[aFaceType] = aKiface;
478 return true;
479 }
480
481 return false;
482 }
483
488 KIWAY_PLAYER* GetPlayerFrame( FRAME_T aFrameType );
489
490 static std::array<KIFACE*,KIWAY_FACE_COUNT> m_kiface;
491 static std::array<int,KIWAY_FACE_COUNT> m_kiface_version;
492
493 int m_ctl;
494
495 wxFrame* m_top; // Usually m_top is the Project manager
496
498
499 // An array to store the window ID of PLAYER frames which were run.
500 // A non empty name means only a PLAYER was run at least one time.
501 // Empty entries are represented by wxID_NONE.
502 // They can be closed, and the stored window ID may be invalid.
503 // Call: wxWindow::FindWindowById( m_playerFrameId[aFrameType] )
504 // to know if still exists (or GetPlayerFrame( FRAME_T aFrameType )
505 std::atomic<wxWindowID> m_playerFrameId[KIWAY_PLAYER_COUNT];
506
508};
509
510
511#ifndef SWIG
512// provided by single_top.cpp and kicad.cpp;
513extern KIWAY Kiway;
514// whereas python launchers: single_top.py and project manager instantiate as a python object
515#endif
516
517
530typedef KIFACE* KIFACE_GETTER_FUNC( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
531
532
533#ifndef SWIG
534
536extern "C" {
537#if defined(BUILD_KIWAY_DLL)
538 KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
539#else
540 KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
541#endif
542}
543
544#endif // SWIG
545
546#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:295
void SetCtlBits(int aCtlBits)
Overwrites previously set ctl bits, only for use in kicad.cpp to flip between standalone and manager ...
Definition kiway.h:439
LOCAL_HISTORY * m_local_history
Definition kiway.h:507
wxWindowID m_blockingDialog
Definition kiway.h:497
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition kiway.h:473
static std::array< KIFACE *, KIWAY_FACE_COUNT > m_kiface
Definition kiway.h:490
wxFrame * m_top
Definition kiway.h:495
wxFrame * GetTop()
Definition kiway.h:448
friend struct PGM_SINGLE_TOP
Definition kiway.h:296
FACE_T
Known KIFACE implementations.
Definition kiway.h:301
@ KIWAY_FACE_COUNT
Definition kiway.h:311
@ FACE_SCH
eeschema DSO
Definition kiway.h:302
@ FACE_PL_EDITOR
Definition kiway.h:306
@ FACE_PYTHON
Definition kiway.h:309
@ FACE_PCB
pcbnew DSO
Definition kiway.h:303
@ FACE_CVPCB
Definition kiway.h:304
@ FACE_GERBVIEW
Definition kiway.h:305
@ FACE_BMP2CMP
Definition kiway.h:308
@ FACE_PCB_CALCULATOR
Definition kiway.h:307
static std::array< int, KIWAY_FACE_COUNT > m_kiface_version
Definition kiway.h:491
std::atomic< wxWindowID > m_playerFrameId[KIWAY_PLAYER_COUNT]
Definition kiway.h:505
KIWAY(int aCtlBits, wxFrame *aTop=nullptr)
Definition kiway.cpp:54
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
Definition kiway.h:407
int m_ctl
Definition kiway.h:493
Simple local history manager built on libgit2.
Container for data for KiCad programs.
Definition pgm_base.h:109
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.
void ProjectChanged() override
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:642
#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:530
#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
KIWAY Kiway(KFCTL_STANDALONE)
Implement a participant in the KIWAY alchemy.
Definition kiway.h:156
virtual bool HandleJobConfig(JOB *aJob, wxWindow *aParent)
Definition kiway.h:254
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:263
virtual void OnKifaceEnd()=0
Called just once just before the DSO is to be unloaded.
virtual void PreloadLibraries(KIWAY *aKiway)
Definition kiway.h:259
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:221
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 void CancelPreload(bool aBlock=true)
Definition kiway.h:261
virtual int HandleJob(JOB *aJob, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter)
Definition kiway.h:249
virtual ~KIFACE()
Definition kiway.h:161