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
109class KICAD_API_SERVER;
110
111
112#define KIFACE_VERSION 1
113#define KIFACE_GETTER KIFACE_1
114
115// The KIFACE acquisition function is declared extern "C" so its name should not
116// be mangled.
117#define KIFACE_INSTANCE_NAME_AND_VERSION "KIFACE_1"
118
119#if defined(__linux__) || defined(__FreeBSD__)
120 #define LIB_ENV_VAR wxT( "LD_LIBRARY_PATH" )
121#elif defined(__WXMAC__)
122 #define LIB_ENV_VAR wxT( "DYLD_LIBRARY_PATH" )
123#elif defined(_WIN32)
124 #define LIB_ENV_VAR wxT( "PATH" )
125#else
126 #error Platform support missing
127#endif
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 bool HandleApiOpenDocument( const wxString& aPath,
260 KICAD_API_SERVER* aServer,
261 wxString* aError )
262 {
263 if( aError )
264 *aError = wxS( "OpenDocument is not implemented for this face" );
265
266 return false;
267 }
268
269 virtual bool HandleApiCloseDocument( const wxString& aBoardFileName,
270 KICAD_API_SERVER* aServer,
271 wxString* aError )
272 {
273 if( aError )
274 *aError = wxS( "CloseDocument is not implemented for this face" );
275
276 return false;
277 }
278
279 virtual void PreloadLibraries( KIWAY* aKiway ) {}
280
281 virtual void CancelPreload( bool aBlock = true ) {}
282
283 virtual void ProjectChanged() {}
284};
285
286
314class KICOMMON_API KIWAY : public wxEvtHandler
315{
316 friend struct PGM_SINGLE_TOP; // can use set_kiface()
317
318public:
332
333 ~KIWAY();
334
341 static FACE_T KifaceType( FRAME_T aFrameType );
342
343 // If you change the vtable, recompile all of KiCad.
344
351 virtual KIFACE* KiFACE( FACE_T aFaceId, bool doLoad = true );
352
372 virtual KIWAY_PLAYER* Player( FRAME_T aFrameType, bool doCreate = true,
373 wxTopLevelWindow* aParent = nullptr );
374
383 virtual bool PlayerClose( FRAME_T aFrameType, bool doForce );
384
394 virtual bool PlayersClose( bool doForce );
395
399 void PlayerDidClose( FRAME_T aFrameType );
400
407 virtual void ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload,
408 wxWindow* aSource = nullptr, bool aFromOtherThread = false );
409
413 virtual void GetActions( std::vector<TOOL_ACTION*>& aActions ) const;
414
421 virtual PROJECT& Prj() const;
422
427
431 virtual void SetLanguage( int aLanguage );
432
438 virtual void CommonSettingsChanged( int aFlags = 0 );
439
444 void ClearFileHistory();
445
450 virtual void ProjectChanged();
451
452 KIWAY( int aCtlBits, wxFrame* aTop = nullptr );
453
458 void SetCtlBits( int aCtlBits ) { m_ctl = aCtlBits; }
459
466 void SetTop( wxFrame* aTop );
467 wxFrame* GetTop() { return m_top; }
468
469 void OnKiCadExit();
470
471 void OnKiwayEnd();
472
473 bool ProcessEvent( wxEvent& aEvent ) override;
474
475 void QueueEvent( wxEvent* aEvent ) override;
476
477 int ProcessJob( KIWAY::FACE_T aFace, JOB* aJob, REPORTER* aReporter = nullptr,
478 PROGRESS_REPORTER* aProgressReporter = nullptr );
479 bool ProcessJobConfigDialog( KIWAY::FACE_T aFace, JOB* aJob, wxWindow* aWindow );
480
481 bool ProcessApiOpenDocument( KIWAY::FACE_T aFace, const wxString& aPath,
482 KICAD_API_SERVER* aServer,
483 wxString* aError = nullptr );
484
485 bool ProcessApiCloseDocument( KIWAY::FACE_T aFace, const wxString& aPath,
486 KICAD_API_SERVER* aServer,
487 wxString* aError = nullptr );
488
493 wxWindow* GetBlockingDialog();
494 void SetBlockingDialog( wxWindow* aWin );
495
496private:
498 const wxString dso_search_path( FACE_T aFaceId );
499
500 bool set_kiface( FACE_T aFaceType, KIFACE* aKiface )
501 {
502 if( (unsigned) aFaceType < (unsigned) KIWAY_FACE_COUNT )
503 {
504 m_kiface[aFaceType] = aKiface;
505 return true;
506 }
507
508 return false;
509 }
510
515 KIWAY_PLAYER* GetPlayerFrame( FRAME_T aFrameType );
516
517 static std::array<KIFACE*,KIWAY_FACE_COUNT> m_kiface;
518 static std::array<int,KIWAY_FACE_COUNT> m_kiface_version;
519
520 int m_ctl;
521
522 wxFrame* m_top; // Usually m_top is the Project manager
523
525
526 // An array to store the window ID of PLAYER frames which were run.
527 // A non empty name means only a PLAYER was run at least one time.
528 // Empty entries are represented by wxID_NONE.
529 // They can be closed, and the stored window ID may be invalid.
530 // Call: wxWindow::FindWindowById( m_playerFrameId[aFrameType] )
531 // to know if still exists (or GetPlayerFrame( FRAME_T aFrameType )
532 std::atomic<wxWindowID> m_playerFrameId[KIWAY_PLAYER_COUNT];
533
535};
536
537
538extern KIWAY Kiway;
539
540
553typedef KIFACE* KIFACE_GETTER_FUNC( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
554
555
557extern "C" {
558#if defined(BUILD_KIWAY_DLL)
559 KIFACE_API KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
560#else
561 KIFACE* KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram );
562#endif
563}
564
565#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:315
void SetCtlBits(int aCtlBits)
Overwrites previously set ctl bits, only for use in kicad.cpp to flip between standalone and manager ...
Definition kiway.h:458
LOCAL_HISTORY * m_local_history
Definition kiway.h:534
wxWindowID m_blockingDialog
Definition kiway.h:524
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition kiway.h:500
static std::array< KIFACE *, KIWAY_FACE_COUNT > m_kiface
Definition kiway.h:517
wxFrame * m_top
Definition kiway.h:522
wxFrame * GetTop()
Definition kiway.h:467
friend struct PGM_SINGLE_TOP
Definition kiway.h:316
FACE_T
Known KIFACE implementations.
Definition kiway.h:321
@ KIWAY_FACE_COUNT
Definition kiway.h:330
@ FACE_SCH
eeschema DSO
Definition kiway.h:322
@ FACE_PL_EDITOR
Definition kiway.h:326
@ FACE_PCB
pcbnew DSO
Definition kiway.h:323
@ FACE_CVPCB
Definition kiway.h:324
@ FACE_GERBVIEW
Definition kiway.h:325
@ FACE_BMP2CMP
Definition kiway.h:328
@ FACE_PCB_CALCULATOR
Definition kiway.h:327
static std::array< int, KIWAY_FACE_COUNT > m_kiface_version
Definition kiway.h:518
std::atomic< wxWindowID > m_playerFrameId[KIWAY_PLAYER_COUNT]
Definition kiway.h:532
KIWAY(int aCtlBits, wxFrame *aTop=nullptr)
Definition kiway.cpp:54
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
Definition kiway.h:426
int m_ctl
Definition kiway.h:520
Simple local history manager built on libgit2.
Container for data for KiCad programs.
Definition pgm_base.h:108
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:644
#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:553
#define KIFACE_GETTER
Definition kiway.h:113
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:283
virtual void OnKifaceEnd()=0
Called just once just before the DSO is to be unloaded.
virtual void PreloadLibraries(KIWAY *aKiway)
Definition kiway.h:279
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 bool HandleApiCloseDocument(const wxString &aBoardFileName, KICAD_API_SERVER *aServer, wxString *aError)
Definition kiway.h:269
virtual bool HandleApiOpenDocument(const wxString &aPath, KICAD_API_SERVER *aServer, wxString *aError)
Definition kiway.h:259
virtual void CancelPreload(bool aBlock=true)
Definition kiway.h:281
virtual int HandleJob(JOB *aJob, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter)
Definition kiway.h:249
virtual ~KIFACE()
Definition kiway.h:161