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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef KIWAY_H_
22#define KIWAY_H_
23
92
93
94#include <array>
95#include <atomic>
96#include <wx/defs.h>
97#include <wx/event.h>
98#include <import_export.h>
99#include <search_stack.h>
100#include <project.h>
101#include <frame_type.h>
102#include <mail_type.h>
103#include <ki_exception.h>
104#include <lib_id.h>
105
106class KICAD_API_SERVER;
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#if defined(__linux__) || defined(__FreeBSD__)
117 #define LIB_ENV_VAR wxT( "LD_LIBRARY_PATH" )
118#elif defined(__WXMAC__)
119 #define LIB_ENV_VAR wxT( "DYLD_LIBRARY_PATH" )
120#elif defined(_WIN32)
121 #define LIB_ENV_VAR wxT( "PATH" )
122#else
123 #error Platform support missing
124#endif
125
126class wxConfigBase;
127class wxWindow;
128class PGM_BASE;
129class KIWAY;
130class KIWAY_PLAYER;
131class wxTopLevelWindow;
132class TOOL_ACTION;
133class JOB;
134class REPORTER;
137class LOCAL_HISTORY;
138
139
152struct KIFACE
153{
167
168 // The order of functions establishes the vtable sequence, do not change the
169 // order of functions in this listing unless you recompile all clients of
170 // this interface.
171
172 virtual ~KIFACE() throw() {}
173
174#define KFCTL_STANDALONE ( 1 << 0 )
175#define KFCTL_CPP_PROJECT_SUITE ( 1 << 1 )
176#define KFCTL_CLI ( 1 << 2 )
177
178
193 virtual bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) = 0;
194
201 virtual void OnKifaceEnd() = 0;
202
206 virtual void Reset() = 0;
207
224 virtual wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId,
225 KIWAY* aKIWAY, int aCtlBits = 0 ) = 0;
226
232 virtual void SaveFileAs( const wxString& srcProjectBasePath,
233 const wxString& srcProjectName,
234 const wxString& newProjectBasePath,
235 const wxString& newProjectName,
236 const wxString& srcFilePath,
237 wxString& aErrors )
238 {
239 // If a KIFACE owns files then it needs to implement this....
240 }
241
253 virtual void* IfaceOrAddress( int aDataId ) = 0;
254
258 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const = 0;
259
260 virtual int HandleJob( JOB* aJob, REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter )
261 {
262 return 0;
263 }
264
265 virtual bool HandleJobConfig( JOB* aJob, wxWindow* aParent )
266 {
267 return 0;
268 }
269
270 virtual bool HandleApiOpenDocument( const DOCUMENT_SPEC& aSpec,
271 KICAD_API_SERVER* aServer,
272 wxString* aError )
273 {
274 if( aError )
275 *aError = wxS( "OpenDocument is not implemented for this face" );
276
277 return false;
278 }
279
280 virtual bool HandleApiCloseDocument( const wxString& aBoardFileName,
281 KICAD_API_SERVER* aServer,
282 wxString* aError )
283 {
284 if( aError )
285 *aError = wxS( "CloseDocument is not implemented for this face" );
286
287 return false;
288 }
289
290 virtual void PreloadLibraries( KIWAY* aKiway ) {}
291
292 virtual void CancelPreload( bool aBlock = true ) {}
293
294 virtual void ProjectChanged() {}
295
301 virtual void RegisterLibraryHandlers( KICAD_API_SERVER* aServer ) {}
302
308 virtual bool LoadAllLibraries() { return false; }
309};
310
311
339class KICOMMON_API KIWAY : public wxEvtHandler
340{
341 friend struct PGM_SINGLE_TOP; // can use set_kiface()
342
343public:
357
358 ~KIWAY();
359
366 static FACE_T KifaceType( FRAME_T aFrameType );
367
368 // If you change the vtable, recompile all of KiCad.
369
376 virtual KIFACE* KiFACE( FACE_T aFaceId, bool doLoad = true );
377
397 virtual KIWAY_PLAYER* Player( FRAME_T aFrameType, bool doCreate = true,
398 wxTopLevelWindow* aParent = nullptr );
399
408 virtual bool PlayerClose( FRAME_T aFrameType, bool doForce );
409
419 virtual bool PlayersClose( bool doForce );
420
424 void PlayerDidClose( FRAME_T aFrameType );
425
432 virtual void ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload,
433 wxWindow* aSource = nullptr, bool aFromOtherThread = false );
434
438 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const;
439
446 virtual PROJECT& Prj() const;
447
452
456 virtual void SetLanguage( int aLanguage );
457
463 virtual void CommonSettingsChanged( int aFlags = 0 );
464
469 void ClearFileHistory();
470
475 virtual void ProjectChanged();
476
477 KIWAY( int aCtlBits, wxFrame* aTop = nullptr );
478
483 void SetCtlBits( int aCtlBits ) { m_ctl = aCtlBits; }
484
491 void SetTop( wxFrame* aTop );
492 wxFrame* GetTop() { return m_top; }
493
494 void OnKiCadExit();
495
496 void OnKiwayEnd();
497
498 bool ProcessEvent( wxEvent& aEvent ) override;
499
500 void QueueEvent( wxEvent* aEvent ) override;
501
502 int ProcessJob( KIWAY::FACE_T aFace, JOB* aJob, REPORTER* aReporter = nullptr,
503 PROGRESS_REPORTER* aProgressReporter = nullptr );
504 bool ProcessJobConfigDialog( KIWAY::FACE_T aFace, JOB* aJob, wxWindow* aWindow );
505
506 bool ProcessApiOpenDocument( KIWAY::FACE_T aFace, const KIFACE::DOCUMENT_SPEC& aSpec,
507 KICAD_API_SERVER* aServer,
508 wxString* aError = nullptr );
509
510 bool ProcessApiCloseDocument( KIWAY::FACE_T aFace, const wxString& aPath,
511 KICAD_API_SERVER* aServer,
512 wxString* aError = nullptr );
513
518 wxWindow* GetBlockingDialog();
519 bool HasBlockingDialog() const { return m_blockingDialog != wxID_NONE; }
520 void SetBlockingDialog( wxWindow* aWin );
521
522private:
524 const wxString dso_search_path( FACE_T aFaceId );
525
526 bool set_kiface( FACE_T aFaceType, KIFACE* aKiface )
527 {
528 if( (unsigned) aFaceType < (unsigned) KIWAY_FACE_COUNT )
529 {
530 m_kiface[aFaceType] = aKiface;
531 return true;
532 }
533
534 return false;
535 }
536
541 KIWAY_PLAYER* GetPlayerFrame( FRAME_T aFrameType );
542
543 static std::array<KIFACE*,KIWAY_FACE_COUNT> m_kiface;
544 static std::array<int,KIWAY_FACE_COUNT> m_kiface_version;
545
546 int m_ctl;
547
548 wxFrame* m_top; // Usually m_top is the Project manager
549
551
552 // An array to store the window ID of PLAYER frames which were run.
553 // A non empty name means only a PLAYER was run at least one time.
554 // Empty entries are represented by wxID_NONE.
555 // They can be closed, and the stored window ID may be invalid.
556 // Call: wxWindow::FindWindowById( m_playerFrameId[aFrameType] )
557 // to know if still exists (or GetPlayerFrame( FRAME_T aFrameType )
558 std::atomic<wxWindowID> m_playerFrameId[KIWAY_PLAYER_COUNT];
559
561};
562
563
564extern KIWAY Kiway;
565
566
579typedef KIFACE* KIFACE_GETTER_FUNC( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
580
581
583extern "C" {
584#if defined(BUILD_KIWAY_DLL)
585 KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
586#else
587 KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
588#endif
589}
590
591#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:340
void SetCtlBits(int aCtlBits)
Overwrites previously set ctl bits, only for use in kicad.cpp to flip between standalone and manager ...
Definition kiway.h:483
LOCAL_HISTORY * m_local_history
Definition kiway.h:560
wxWindowID m_blockingDialog
Definition kiway.h:550
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition kiway.h:526
static std::array< KIFACE *, KIWAY_FACE_COUNT > m_kiface
Definition kiway.h:543
bool HasBlockingDialog() const
Definition kiway.h:519
wxFrame * m_top
Definition kiway.h:548
wxFrame * GetTop()
Definition kiway.h:492
friend struct PGM_SINGLE_TOP
Definition kiway.h:341
FACE_T
Known KIFACE implementations.
Definition kiway.h:346
@ KIWAY_FACE_COUNT
Definition kiway.h:355
@ FACE_SCH
eeschema DSO
Definition kiway.h:347
@ FACE_PL_EDITOR
Definition kiway.h:351
@ FACE_PCB
pcbnew DSO
Definition kiway.h:348
@ FACE_CVPCB
Definition kiway.h:349
@ FACE_GERBVIEW
Definition kiway.h:350
@ FACE_BMP2CMP
Definition kiway.h:353
@ FACE_PCB_CALCULATOR
Definition kiway.h:352
static std::array< int, KIWAY_FACE_COUNT > m_kiface_version
Definition kiway.h:544
std::atomic< wxWindowID > m_playerFrameId[KIWAY_PLAYER_COUNT]
Definition kiway.h:558
KIWAY(int aCtlBits, wxFrame *aTop=nullptr)
Definition kiway.cpp:50
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
Definition kiway.h:451
int m_ctl
Definition kiway.h:546
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
Simple local history manager built on libgit2.
Container for data for KiCad programs.
Definition pgm_base.h:101
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition project.h:63
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:29
@ KIWAY_PLAYER_COUNT
Definition frame_type.h:66
#define KIFACE_API
PROJECT & Prj()
Definition kicad.cpp:727
#define KICOMMON_API
Definition kicommon.h:27
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Point to the one and only KIFACE export.
Definition kiway.h:579
#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:34
KIWAY Kiway(KFCTL_STANDALONE)
wxString path
File path (KIND::FILE_KIND) or project path (KIND::FPID_KIND).
Definition kiway.h:164
LIB_ID libId
Library identifier; valid when kind == KIND::FPID_KIND.
Definition kiway.h:165
@ FPID_KIND
Open the library element named by libId.
Definition kiway.h:159
@ FILE_KIND
Open the file at path.
Definition kiway.h:158
@ CREATE_KIND
Create a new document at path and open it (in memory, not persisted)
Definition kiway.h:160
Implement a participant in the KIWAY alchemy.
Definition kiway.h:153
virtual bool HandleJobConfig(JOB *aJob, wxWindow *aParent)
Definition kiway.h:265
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:294
virtual void OnKifaceEnd()=0
Called just once just before the DSO is to be unloaded.
virtual void PreloadLibraries(KIWAY *aKiway)
Definition kiway.h:290
virtual void RegisterLibraryHandlers(KICAD_API_SERVER *aServer)
Register this face's library API handlers on the given server.
Definition kiway.h:301
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:232
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 bool HandleApiCloseDocument(const wxString &aBoardFileName, KICAD_API_SERVER *aServer, wxString *aError)
Definition kiway.h:280
virtual bool HandleApiOpenDocument(const DOCUMENT_SPEC &aSpec, KICAD_API_SERVER *aServer, wxString *aError)
Definition kiway.h:270
virtual void CancelPreload(bool aBlock=true)
Definition kiway.h:292
virtual int HandleJob(JOB *aJob, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter)
Definition kiway.h:260
virtual ~KIFACE()
Definition kiway.h:172
virtual bool LoadAllLibraries()
Starts a background load of all libraries of the type owned by this face.
Definition kiway.h:308