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;
139class LOCAL_HISTORY;
140
141
154struct KIFACE
155{
156 // The order of functions establishes the vtable sequence, do not change the
157 // order of functions in this listing unless you recompile all clients of
158 // this interface.
159
160 virtual ~KIFACE() throw() {}
161
162#define KFCTL_STANDALONE ( 1 << 0 )
163#define KFCTL_CPP_PROJECT_SUITE ( 1 << 1 )
164#define KFCTL_CLI ( 1 << 2 )
165
166
181 virtual bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) = 0;
182
189 virtual void OnKifaceEnd() = 0;
190
194 virtual void Reset() = 0;
195
212 virtual wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId,
213 KIWAY* aKIWAY, int aCtlBits = 0 ) = 0;
214
220 virtual void SaveFileAs( const wxString& srcProjectBasePath,
221 const wxString& srcProjectName,
222 const wxString& newProjectBasePath,
223 const wxString& newProjectName,
224 const wxString& srcFilePath,
225 wxString& aErrors )
226 {
227 // If a KIFACE owns files then it needs to implement this....
228 }
229
241 virtual void* IfaceOrAddress( int aDataId ) = 0;
242
246 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const = 0;
247
248 virtual int HandleJob( JOB* aJob, REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter )
249 {
250 return 0;
251 }
252
253 virtual bool HandleJobConfig( JOB* aJob, wxWindow* aParent )
254 {
255 return 0;
256 }
257
258 virtual void PreloadLibraries( KIWAY* aKiway ) {}
259
260 virtual void ProjectChanged() {}
261};
262
263
291class KICOMMON_API KIWAY : public wxEvtHandler
292{
293 friend struct PGM_SINGLE_TOP; // can use set_kiface()
294
295public:
310
311 ~KIWAY();
312
319 static FACE_T KifaceType( FRAME_T aFrameType );
320
321 // If you change the vtable, recompile all of KiCad.
322
329 virtual KIFACE* KiFACE( FACE_T aFaceId, bool doLoad = true );
330
350 virtual KIWAY_PLAYER* Player( FRAME_T aFrameType, bool doCreate = true,
351 wxTopLevelWindow* aParent = nullptr );
352
361 virtual bool PlayerClose( FRAME_T aFrameType, bool doForce );
362
372 virtual bool PlayersClose( bool doForce );
373
377 void PlayerDidClose( FRAME_T aFrameType );
378
385 virtual void ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload,
386 wxWindow* aSource = nullptr, bool aFromOtherThread = false );
387
391 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const;
392
399 virtual PROJECT& Prj() const;
400
405
409 virtual void SetLanguage( int aLanguage );
410
416 virtual void CommonSettingsChanged( int aFlags = 0 );
417
422 void ClearFileHistory();
423
428 virtual void ProjectChanged();
429
430 KIWAY( int aCtlBits, wxFrame* aTop = nullptr );
431
436 void SetCtlBits( int aCtlBits ) { m_ctl = aCtlBits; }
437
444 void SetTop( wxFrame* aTop );
445 wxFrame* GetTop() { return m_top; }
446
447 void OnKiCadExit();
448
449 void OnKiwayEnd();
450
451 bool ProcessEvent( wxEvent& aEvent ) override;
452
453 void QueueEvent( wxEvent* aEvent ) override;
454
455 int ProcessJob( KIWAY::FACE_T aFace, JOB* aJob, REPORTER* aReporter = nullptr,
456 PROGRESS_REPORTER* aProgressReporter = nullptr );
457 bool ProcessJobConfigDialog( KIWAY::FACE_T aFace, JOB* aJob, wxWindow* aWindow );
458
463 wxWindow* GetBlockingDialog();
464 void SetBlockingDialog( wxWindow* aWin );
465
466private:
468 const wxString dso_search_path( FACE_T aFaceId );
469
470 bool set_kiface( FACE_T aFaceType, KIFACE* aKiface )
471 {
472 if( (unsigned) aFaceType < (unsigned) KIWAY_FACE_COUNT )
473 {
474 m_kiface[aFaceType] = aKiface;
475 return true;
476 }
477
478 return false;
479 }
480
485 KIWAY_PLAYER* GetPlayerFrame( FRAME_T aFrameType );
486
489
490 int m_ctl;
491
492 wxFrame* m_top; // Usually m_top is the Project manager
493
495
496 // An array to store the window ID of PLAYER frames which were run.
497 // A non empty name means only a PLAYER was run at least one time.
498 // Empty entries are represented by wxID_NONE.
499 // They can be closed, and the stored window ID may be invalid.
500 // Call: wxWindow::FindWindowById( m_playerFrameId[aFrameType] )
501 // to know if still exists (or GetPlayerFrame( FRAME_T aFrameType )
502 std::atomic<wxWindowID> m_playerFrameId[KIWAY_PLAYER_COUNT];
503
505};
506
507
508#ifndef SWIG
509// provided by single_top.cpp and kicad.cpp;
510extern KIWAY Kiway;
511// whereas python launchers: single_top.py and project manager instantiate as a python object
512#endif
513
514
527typedef KIFACE* KIFACE_GETTER_FUNC( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
528
529
530#ifndef SWIG
531
533extern "C" {
534#if defined(BUILD_KIWAY_DLL)
535 KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
536#else
537 KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
538#endif
539}
540
541#endif // SWIG
542
543#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:292
void SetCtlBits(int aCtlBits)
Overwrites previously set ctl bits, only for use in kicad.cpp to flip between standalone and manager ...
Definition kiway.h:436
LOCAL_HISTORY * m_local_history
Definition kiway.h:504
wxWindowID m_blockingDialog
Definition kiway.h:494
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition kiway.h:470
static KIFACE * m_kiface[KIWAY_FACE_COUNT]
Definition kiway.h:487
wxFrame * m_top
Definition kiway.h:492
wxFrame * GetTop()
Definition kiway.h:445
friend struct PGM_SINGLE_TOP
Definition kiway.h:293
FACE_T
Known KIFACE implementations.
Definition kiway.h:298
@ KIWAY_FACE_COUNT
Definition kiway.h:308
@ FACE_SCH
eeschema DSO
Definition kiway.h:299
@ FACE_PL_EDITOR
Definition kiway.h:303
@ FACE_PYTHON
Definition kiway.h:306
@ FACE_PCB
pcbnew DSO
Definition kiway.h:300
@ FACE_CVPCB
Definition kiway.h:301
@ FACE_GERBVIEW
Definition kiway.h:302
@ FACE_BMP2CMP
Definition kiway.h:305
@ FACE_PCB_CALCULATOR
Definition kiway.h:304
static int m_kiface_version[KIWAY_FACE_COUNT]
Definition kiway.h:488
std::atomic< wxWindowID > m_playerFrameId[KIWAY_PLAYER_COUNT]
Definition kiway.h:502
KIWAY(int aCtlBits, wxFrame *aTop=nullptr)
Definition kiway.cpp:55
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
Definition kiway.h:404
int m_ctl
Definition kiway.h:490
Simple local history manager built on libgit2.
Container for data for KiCad programs.
Definition pgm_base.h:106
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition project.h:66
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:623
#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:527
#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:155
virtual bool HandleJobConfig(JOB *aJob, wxWindow *aParent)
Definition kiway.h:253
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:260
virtual void OnKifaceEnd()=0
Called just once just before the DSO is to be unloaded.
virtual void PreloadLibraries(KIWAY *aKiway)
Definition kiway.h:258
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:220
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:248
virtual ~KIFACE()
Definition kiway.h:160