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
195 virtual bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits, KIWAY* aKiway ) = 0;
196
203 virtual void OnKifaceEnd() = 0;
204
208 virtual void Reset() = 0;
209
226 virtual wxWindow* CreateKiWindow( wxWindow* aParent, int aClassId,
227 KIWAY* aKIWAY, int aCtlBits = 0 ) = 0;
228
234 virtual void SaveFileAs( const wxString& srcProjectBasePath,
235 const wxString& srcProjectName,
236 const wxString& newProjectBasePath,
237 const wxString& newProjectName,
238 const wxString& srcFilePath,
239 wxString& aErrors )
240 {
241 // If a KIFACE owns files then it needs to implement this....
242 }
243
255 virtual void* IfaceOrAddress( int aDataId ) = 0;
256
260 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const = 0;
261
262 virtual int HandleJob( JOB* aJob, REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter )
263 {
264 return 0;
265 }
266
267 virtual bool HandleJobConfig( JOB* aJob, wxWindow* aParent )
268 {
269 return 0;
270 }
271
272 virtual bool HandleApiOpenDocument( const DOCUMENT_SPEC& aSpec,
273 KICAD_API_SERVER* aServer,
274 wxString* aError )
275 {
276 if( aError )
277 *aError = wxS( "OpenDocument is not implemented for this face" );
278
279 return false;
280 }
281
290 virtual bool HandleApiCloseDocument( const DOCUMENT_SPEC& aSpec, KICAD_API_SERVER* aServer, wxString* aError )
291 {
292 if( aError )
293 *aError = wxS( "CloseDocument is not implemented for this face" );
294
295 return false;
296 }
297
298 virtual void PreloadLibraries( KIWAY* aKiway ) {}
299
300 virtual void CancelPreload( bool aBlock = true ) {}
301
302 virtual void ProjectChanged() {}
303
309 virtual void RegisterLibraryHandlers( KICAD_API_SERVER* aServer ) {}
310
316 virtual bool LoadAllLibraries() { return false; }
317};
318
319
347class KICOMMON_API KIWAY : public wxEvtHandler
348{
349 friend struct PGM_SINGLE_TOP; // can use set_kiface()
350
351public:
365
366 ~KIWAY();
367
374 static FACE_T KifaceType( FRAME_T aFrameType );
375
376 // If you change the vtable, recompile all of KiCad.
377
384 virtual KIFACE* KiFACE( FACE_T aFaceId, bool doLoad = true );
385
405 virtual KIWAY_PLAYER* Player( FRAME_T aFrameType, bool doCreate = true,
406 wxTopLevelWindow* aParent = nullptr );
407
416 virtual bool PlayerClose( FRAME_T aFrameType, bool doForce );
417
427 virtual bool PlayersClose( bool doForce );
428
432 void PlayerDidClose( FRAME_T aFrameType );
433
440 virtual void ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload,
441 wxWindow* aSource = nullptr, bool aFromOtherThread = false );
442
446 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const;
447
454 virtual PROJECT& Prj() const;
455
460
464 virtual void SetLanguage( int aLanguage );
465
471 virtual void CommonSettingsChanged( int aFlags = 0 );
472
477 void ClearFileHistory();
478
483 virtual void ProjectChanged();
484
485 KIWAY( int aCtlBits, wxFrame* aTop = nullptr );
486
491 void SetCtlBits( int aCtlBits ) { m_ctl = aCtlBits; }
492
499 void SetTop( wxFrame* aTop );
500 wxFrame* GetTop() { return m_top; }
501
502 void OnKiCadExit();
503
504 void OnKiwayEnd();
505
506 bool ProcessEvent( wxEvent& aEvent ) override;
507
508 void QueueEvent( wxEvent* aEvent ) override;
509
510 int ProcessJob( KIWAY::FACE_T aFace, JOB* aJob, REPORTER* aReporter = nullptr,
511 PROGRESS_REPORTER* aProgressReporter = nullptr );
512 bool ProcessApiCloseDocument( KIWAY::FACE_T aFace, const KIFACE::DOCUMENT_SPEC& aSpec,
513 KICAD_API_SERVER* aServer,
514 wxString* aError = nullptr );
515 bool ProcessJobConfigDialog( KIWAY::FACE_T aFace, JOB* aJob, wxWindow* aWindow );
516
517 bool ProcessApiOpenDocument( KIWAY::FACE_T aFace, const KIFACE::DOCUMENT_SPEC& aSpec,
518 KICAD_API_SERVER* aServer,
519 wxString* aError = nullptr );
520
525 wxWindow* GetBlockingDialog();
526 bool HasBlockingDialog() const { return m_blockingDialog != wxID_NONE; }
527 void SetBlockingDialog( wxWindow* aWin );
528
529private:
531 const wxString dso_search_path( FACE_T aFaceId );
532
533 bool set_kiface( FACE_T aFaceType, KIFACE* aKiface )
534 {
535 if( (unsigned) aFaceType < (unsigned) KIWAY_FACE_COUNT )
536 {
537 m_kiface[aFaceType] = aKiface;
538 return true;
539 }
540
541 return false;
542 }
543
548 KIWAY_PLAYER* GetPlayerFrame( FRAME_T aFrameType );
549
550 static std::array<KIFACE*,KIWAY_FACE_COUNT> m_kiface;
551 static std::array<int,KIWAY_FACE_COUNT> m_kiface_version;
552
553 int m_ctl;
554
555 wxFrame* m_top; // Usually m_top is the Project manager
556
558
559 // An array to store the window ID of PLAYER frames which were run.
560 // A non empty name means only a PLAYER was run at least one time.
561 // Empty entries are represented by wxID_NONE.
562 // They can be closed, and the stored window ID may be invalid.
563 // Call: wxWindow::FindWindowById( m_playerFrameId[aFrameType] )
564 // to know if still exists (or GetPlayerFrame( FRAME_T aFrameType )
565 std::atomic<wxWindowID> m_playerFrameId[KIWAY_PLAYER_COUNT];
566
568};
569
570
571extern KIWAY Kiway;
572
573
586typedef KIFACE* KIFACE_GETTER_FUNC( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
587
588
590extern "C" {
591#if defined(BUILD_KIWAY_DLL)
592 KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
593#else
594 KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
595#endif
596}
597
598#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:348
void SetCtlBits(int aCtlBits)
Overwrites previously set ctl bits, only for use in kicad.cpp to flip between standalone and manager ...
Definition kiway.h:491
LOCAL_HISTORY * m_local_history
Definition kiway.h:567
wxWindowID m_blockingDialog
Definition kiway.h:557
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition kiway.h:533
static std::array< KIFACE *, KIWAY_FACE_COUNT > m_kiface
Definition kiway.h:550
bool HasBlockingDialog() const
Definition kiway.h:526
wxFrame * m_top
Definition kiway.h:555
wxFrame * GetTop()
Definition kiway.h:500
friend struct PGM_SINGLE_TOP
Definition kiway.h:349
FACE_T
Known KIFACE implementations.
Definition kiway.h:354
@ KIWAY_FACE_COUNT
Definition kiway.h:363
@ FACE_SCH
eeschema DSO
Definition kiway.h:355
@ FACE_PL_EDITOR
Definition kiway.h:359
@ FACE_PCB
pcbnew DSO
Definition kiway.h:356
@ FACE_CVPCB
Definition kiway.h:357
@ FACE_GERBVIEW
Definition kiway.h:358
@ FACE_BMP2CMP
Definition kiway.h:361
@ FACE_PCB_CALCULATOR
Definition kiway.h:360
static std::array< int, KIWAY_FACE_COUNT > m_kiface_version
Definition kiway.h:551
std::atomic< wxWindowID > m_playerFrameId[KIWAY_PLAYER_COUNT]
Definition kiway.h:565
KIWAY(int aCtlBits, wxFrame *aTop=nullptr)
Definition kiway.cpp:50
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
Definition kiway.h:459
int m_ctl
Definition kiway.h:553
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:733
#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:586
#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::LIBID_KIND).
Definition kiway.h:164
LIB_ID libId
Library identifier; valid when kind == KIND::LIBID_KIND.
Definition kiway.h:165
@ LIBID_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:267
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:302
virtual void OnKifaceEnd()=0
Called just once just before the DSO is to be unloaded.
virtual void PreloadLibraries(KIWAY *aKiway)
Definition kiway.h:298
virtual void RegisterLibraryHandlers(KICAD_API_SERVER *aServer)
Register this face's library API handlers on the given server.
Definition kiway.h:309
virtual bool HandleApiCloseDocument(const DOCUMENT_SPEC &aSpec, KICAD_API_SERVER *aServer, wxString *aError)
Close the document identified by aSpec.
Definition kiway.h:290
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:234
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 HandleApiOpenDocument(const DOCUMENT_SPEC &aSpec, KICAD_API_SERVER *aServer, wxString *aError)
Definition kiway.h:272
virtual void CancelPreload(bool aBlock=true)
Definition kiway.h:300
virtual int HandleJob(JOB *aJob, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter)
Definition kiway.h:262
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:316