KiCad PCB EDA Suite
KIWAY Class Reference

Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad process. More...

#include <kiway.h>

Inheritance diagram for KIWAY:

Public Types

enum  FACE_T {
  FACE_SCH, FACE_PCB, FACE_CVPCB, FACE_GERBVIEW,
  FACE_PL_EDITOR, FACE_PCB_CALCULATOR, FACE_BMP2CMP, KIWAY_FACE_COUNT
}
 Known KIFACE implementations. More...
 

Public Member Functions

 ~KIWAY () throw ()
 
VTBL_ENTRY KIFACEKiFACE (FACE_T aFaceId, bool doLoad=true)
 Function KiFACE returns the KIFACE* given a FACE_T. More...
 
VTBL_ENTRY KIWAY_PLAYERPlayer (FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
 Function Player returns the KIWAY_PLAYER* given a FRAME_T. More...
 
VTBL_ENTRY bool PlayerClose (FRAME_T aFrameType, bool doForce)
 Function PlayerClose calls the KIWAY_PLAYER::Close( bool force ) function on the window and if not vetoed, returns true, else false. More...
 
VTBL_ENTRY bool PlayersClose (bool doForce)
 Function PlayersClose calls the KIWAY_PLAYER::Close( bool force ) function on all the windows and if none are vetoed, returns true, else false. More...
 
VTBL_ENTRY void ExpressMail (FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=NULL)
 Function ExpressMail send aPayload to aDestination from aSource. More...
 
VTBL_ENTRY PROJECTPrj () const
 Function Prj returns the PROJECT associated with this KIWAY. More...
 
VTBL_ENTRY void SetLanguage (int aLanguage)
 Function SetLanguage changes the language and then calls ShowChangedLanguage() on all KIWAY_PLAYERs. More...
 
VTBL_ENTRY void CommonSettingsChanged (bool aEnvVarsChanged)
 Function CommonSettingsChanged Calls CommonSettingsChanged() on all KIWAY_PLAYERs. More...
 
 KIWAY (PGM_BASE *aProgram, int aCtlBits, wxFrame *aTop=NULL)
 
void SetTop (wxFrame *aTop)
 Function SetTop tells this KIWAY about the top most frame in the program and optionally allows it to play the role of one of the KIWAY_PLAYERs if launched from single_top.cpp. More...
 
void OnKiCadExit ()
 
void OnKiwayEnd ()
 
bool ProcessEvent (wxEvent &aEvent) override
 

Static Public Member Functions

static FACE_T KifaceType (FRAME_T aFrameType)
 Function KifaceType is a simple mapping function which returns the FACE_T which is known to implement aFrameType. More...
 

Private Member Functions

const wxString dso_search_path (FACE_T aFaceId)
 Get the [path &] name of the DSO holding the requested FACE_T. More...
 
bool set_kiface (FACE_T aFaceType, KIFACE *aKiface)
 
KIWAY_PLAYERGetPlayerFrame (FRAME_T aFrameType)
 

Private Attributes

PGM_BASEm_program
 
int m_ctl
 
wxFrame * m_top
 
wxArrayString m_playerFrameName
 
PROJECT m_project
 

Static Private Attributes

static KIFACEm_kiface [KIWAY_FACE_COUNT]
 
static int m_kiface_version [KIWAY_FACE_COUNT]
 

Friends

struct PGM_SINGLE_TOP
 

Detailed Description

Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad process.

It makes it possible to call between DSOs without having to link them together, and without having to link to the top process module which houses the KIWAY(s). More importantly it makes it possible to send custom wxEvents between DSOs and from the top process module down into the DSOs. The latter capability is thought useful for driving the lower DSOs from a python test rig or for demo (automation) purposes.

Most all calls are via virtual functions, which means C++ vtables are used to hold function pointers and eliminate the need to link to specific object code libraries, speeding development and encouraging clearly defined interface design. Unlike Microsoft COM, which is a multi-vendor design supporting DLL's built at various points in time, the KIWAY alchemy is single project, with all components being built at the same time. So one should expect solid compatibility between all KiCad components, as long at they are compiled at the same time.

There is one KIWAY in the launching portion of the process for each open KiCad project. Each project has its own KIWAY. Available to each KIWAY is an actual PROJECT data structure. If you have a KIWAY, you can get to the PROJECT using KIWAY::Prj().

In summary, a KIWAY facilitates communicating between DSOs, where the topic of the communication is project specific. Here a "project" means a BOARD and a SCHEMATIC and a NETLIST, (anything relating to production of a single BOARD and added to class PROJECT.)

Definition at line 274 of file kiway.h.

Member Enumeration Documentation

◆ FACE_T

Known KIFACE implementations.

Enumerator
FACE_SCH 

eeschema DSO

FACE_PCB 

pcbnew DSO

FACE_CVPCB 
FACE_GERBVIEW 
FACE_PL_EDITOR 
FACE_PCB_CALCULATOR 
FACE_BMP2CMP 
KIWAY_FACE_COUNT 

Definition at line 280 of file kiway.h.

Constructor & Destructor Documentation

◆ ~KIWAY()

KIWAY::~KIWAY ( )
throw (
)
inline

Definition at line 293 of file kiway.h.

293 {}

◆ KIWAY()

KIWAY::KIWAY ( PGM_BASE aProgram,
int  aCtlBits,
wxFrame *  aTop = NULL 
)

Definition at line 45 of file kiway.cpp.

45  :
46  m_program( aProgram ), m_ctl( aCtlBits ), m_top( 0 )
47 {
48  SetTop( aTop ); // hook player_destroy_handler() into aTop.
49 
50 
51  // Prepare the room to store the frame names, once they will be created
52  // with FRAME_T type as index in this table.
53  // (note this is a list of frame names, but a non empty entry
54  // does not mean the frame still exists. It means only the frame was created
55  // at least once. It can be destroyed after. These entries are not cleared.
56  // the purpose is just to allow a call to wxWindow::FindWindowByName(), from
57  // a FRAME_T frame type
58  m_playerFrameName.Add( wxEmptyString, KIWAY_PLAYER_COUNT );
59 }
PGM_BASE * m_program
Definition: kiway.h:433
int m_ctl
Definition: kiway.h:434
void SetTop(wxFrame *aTop)
Function SetTop tells this KIWAY about the top most frame in the program and optionally allows it to ...
Definition: kiway.cpp:77
wxArrayString m_playerFrameName
Definition: kiway.h:444
wxFrame * m_top
Definition: kiway.h:436
int PGM_BASE * aProgram
Definition: pcbnew.cpp:187

References KIWAY_PLAYER_COUNT, m_playerFrameName, and SetTop().

Member Function Documentation

◆ CommonSettingsChanged()

void KIWAY::CommonSettingsChanged ( bool  aEnvVarsChanged)

Function CommonSettingsChanged Calls CommonSettingsChanged() on all KIWAY_PLAYERs.

Used after changing suite-wide options such as panning, autosave interval, etc.

Definition at line 471 of file kiway.cpp.

472 {
473 #if 1
475  {
476  // A dynamic_cast could be better, but creates link issues
477  // (some basic_frame functions not found) on some platforms,
478  // so a static_cast is used.
479  EDA_BASE_FRAME* top = static_cast<EDA_BASE_FRAME*>( m_top );
480 
481  if( top )
482  top->CommonSettingsChanged( aEnvVarsChanged );
483  }
484 #endif
485 
486  for( unsigned i=0; i < KIWAY_PLAYER_COUNT; ++i )
487  {
488  KIWAY_PLAYER* frame = GetPlayerFrame( ( FRAME_T )i );
489 
490  if( frame )
491  frame->CommonSettingsChanged( aEnvVarsChanged );
492  }
493 }
#define KFCTL_CPP_PROJECT_SUITE
Am running under C++ project mgr, possibly with others.
Definition: kiway.h:160
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:59
KIWAY_PLAYER * GetPlayerFrame(FRAME_T aFrameType)
Definition: kiway.cpp:332
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
int m_ctl
Definition: kiway.h:434
virtual void CommonSettingsChanged(bool aEnvVarsChanged)
Notification event that some of the common (suite-wide) settings have changed.
The base frame for deriving all KiCad main window classes.
size_t i
Definition: json11.cpp:649
wxFrame * m_top
Definition: kiway.h:436

References EDA_BASE_FRAME::CommonSettingsChanged(), GetPlayerFrame(), i, KFCTL_CPP_PROJECT_SUITE, KIWAY_PLAYER_COUNT, m_ctl, and m_top.

Referenced by PCB::IFACE::CreateWindow(), and EDA_BASE_FRAME::OnPreferences().

◆ dso_search_path()

const wxString KIWAY::dso_search_path ( FACE_T  aFaceId)
private

Get the [path &] name of the DSO holding the requested FACE_T.

Definition at line 95 of file kiway.cpp.

96 {
97  const char* name;
98 
99  switch( aFaceId )
100  {
101  case FACE_SCH: name = KIFACE_PREFIX "eeschema"; break;
102  case FACE_PCB: name = KIFACE_PREFIX "pcbnew"; break;
103  case FACE_CVPCB: name = KIFACE_PREFIX "cvpcb"; break;
104  case FACE_GERBVIEW: name = KIFACE_PREFIX "gerbview"; break;
105  case FACE_PL_EDITOR: name = KIFACE_PREFIX "pl_editor"; break;
106  case FACE_PCB_CALCULATOR: name = KIFACE_PREFIX "pcb_calculator"; break;
107  case FACE_BMP2CMP: name = KIFACE_PREFIX "bitmap2component"; break;
108 
109  default:
110  wxASSERT_MSG( 0, wxT( "caller has a bug, passed a bad aFaceId" ) );
111  return wxEmptyString;
112  }
113 
114 #ifndef __WXMAC__
115  wxString path;
116 
118  {
119  // The 2 *.cpp program launchers: single_top.cpp and kicad.cpp expect
120  // the *.kiface's to reside in same directory as their binaries do.
121  // Not so for python launcher, identified by KFCTL_PY_PROJECT_SUITE
122  path = wxStandardPaths::Get().GetExecutablePath();
123  }
124 
125  wxFileName fn = path;
126 #else
127  // we have the dso's in main OSX bundle kicad.app/Contents/PlugIns
128  wxFileName fn = Pgm().GetExecutablePath();
129  fn.AppendDir( wxT( "Contents" ) );
130  fn.AppendDir( wxT( "PlugIns" ) );
131 #endif
132 
133  fn.SetName( name );
134 
135 #ifdef DEBUG
136  // To speed up development, it's sometimes nice to run kicad from inside
137  // the build path. In that case, each program will be in a subdirectory.
138  // To find the DSOs, we need to go up one directory and then enter a subdirectory.
139 
140  if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
141  {
142 #ifdef __WXMAC__
143  fn = wxStandardPaths::Get().GetExecutablePath();
144  fn.RemoveLastDir();
145  fn.AppendDir( wxT( "PlugIns" ) );
146  fn.SetName( name );
147 #else
148  const char* dirName;
149 
150  // The subdirectories usually have the same name as the kiface
151  switch( aFaceId )
152  {
153  case FACE_PL_EDITOR: dirName = "pagelayout_editor"; break;
154  default: dirName = name + 1; break;
155  }
156 
157  fn.RemoveLastDir();
158  fn.AppendDir( dirName );
159 #endif
160  }
161 #endif
162 
163  // Here a "suffix" == an extension with a preceding '.',
164  // so skip the preceding '.' to get an extension
165  fn.SetExt( KIFACE_SUFFIX + 1 ); // + 1 => &KIFACE_SUFFIX[1]
166 
167  return fn.GetFullPath();
168 }
#define KFCTL_CPP_PROJECT_SUITE
Am running under C++ project mgr, possibly with others.
Definition: kiway.h:160
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
int m_ctl
Definition: kiway.h:434
pcbnew DSO
Definition: kiway.h:283
eeschema DSO
Definition: kiway.h:282
const char * name
Definition: DXF_plotter.cpp:61
VTBL_ENTRY const wxString & GetExecutablePath() const
Definition: pgm_base.h:222
#define KFCTL_STANDALONE
Am running as a standalone Top.
Definition: kiway.h:159

References FACE_BMP2CMP, FACE_CVPCB, FACE_GERBVIEW, FACE_PCB, FACE_PCB_CALCULATOR, FACE_PL_EDITOR, FACE_SCH, PGM_BASE::GetExecutablePath(), KFCTL_CPP_PROJECT_SUITE, KFCTL_STANDALONE, m_ctl, name, and Pgm().

Referenced by KiFACE().

◆ ExpressMail()

void KIWAY::ExpressMail ( FRAME_T  aDestination,
MAIL_T  aCommand,
std::string &  aPayload,
wxWindow *  aSource = NULL 
)

Function ExpressMail send aPayload to aDestination from aSource.

Recipient receives this in its KIWAY_PLAYER::KiwayMailIn() function and can efficiently switch() based on aCommand in there.

Definition at line 427 of file kiway.cpp.

428 {
429  KIWAY_EXPRESS mail( aDestination, aCommand, aPayload, aSource );
430 
431  ProcessEvent( mail );
432 }
Class KIWAY_EXPRESS carries a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:39
bool ProcessEvent(wxEvent &aEvent) override
Definition: kiway.cpp:496

References ProcessEvent().

Referenced by TREEPROJECT_ITEM::Activate(), PCB_EDIT_FRAME::FetchNetlistFromSchematic(), KICAD_MANAGER_FRAME::OnImportEagleFiles(), SCH_EDIT_FRAME::OnUpdatePCB(), LIB_EDIT_FRAME::refreshSchematic(), CVPCB_MAINFRAME::SaveFootprintAssociation(), SCH_EDIT_FRAME::SendCrossProbeClearHighlight(), SCH_EDIT_FRAME::SendCrossProbeNetName(), PCB_EDIT_FRAME::SendCrossProbeNetName(), CVPCB_MAINFRAME::SendMessageToEESCHEMA(), PCB_EDIT_FRAME::SendMessageToEESCHEMA(), SCH_EDIT_FRAME::SendMessageToPCBNEW(), and SCH_EDIT_FRAME::sendNetlistToCvpcb().

◆ GetPlayerFrame()

KIWAY_PLAYER * KIWAY::GetPlayerFrame ( FRAME_T  aFrameType)
private
Returns
the reference of the KIWAY_PLAYER having the type aFrameType if exists, or NULL if this KIWAY_PLAYER was not yet created, or was closed

Definition at line 332 of file kiway.cpp.

333 {
334  if( m_playerFrameName[aFrameType].IsEmpty() )
335  return NULL;
336 
337  return static_cast<KIWAY_PLAYER*>( wxWindow::FindWindowByName( m_playerFrameName[aFrameType] ) );
338 }
wxArrayString m_playerFrameName
Definition: kiway.h:444

References m_playerFrameName.

Referenced by CommonSettingsChanged(), Player(), PlayerClose(), and SetLanguage().

◆ KiFACE()

KIFACE * KIWAY::KiFACE ( FACE_T  aFaceId,
bool  doLoad = true 
)

Function KiFACE returns the KIFACE* given a FACE_T.

If it is not already loaded, the KIFACE is loaded and initialized with a call to KIFACE::OnKifaceStart()

Definition at line 177 of file kiway.cpp.

178 {
179  // Since this will be called from python, cannot assume that code will
180  // not pass a bad aFaceId.
181  if( (unsigned) aFaceId >= arrayDim( m_kiface ) )
182  {
183  // @todo : throw an exception here for python's benefit, at least that
184  // way it gets some explanatory text.
185 
186  wxASSERT_MSG( 0, wxT( "caller has a bug, passed a bad aFaceId" ) );
187  return NULL;
188  }
189 
190  // return the previously loaded KIFACE, if it was.
191  if( m_kiface[aFaceId] )
192  return m_kiface[aFaceId];
193 
194  wxString msg;
195 
196  // DSO with KIFACE has not been loaded yet, does caller want to load it?
197  if( doLoad )
198  {
199  wxString dname = dso_search_path( aFaceId );
200 
201  wxDynamicLibrary dso;
202 
203  void* addr = NULL;
204 
205  // For some reason wxDynamicLibrary::Load() crashes in some languages
206  // (chinese for instance) when loading the dynamic library.
207  // The crash happens for Eeschema.
208  // So switch to "C" locale during loading (LC_COLLATE is enough).
209  int lc_new_type = LC_COLLATE;
210  std::string user_locale = setlocale( lc_new_type, nullptr );
211  setlocale( lc_new_type, "C" );
212 
213  bool success = dso.Load( dname, wxDL_VERBATIM | wxDL_NOW | wxDL_GLOBAL );
214 
215  setlocale( lc_new_type, user_locale.c_str() );
216 
217  if( !success )
218  {
219  // Failure: error reporting UI was done via wxLogSysError().
220  // No further reporting required here. Apparently this is not true on all
221  // platforms and/or wxWidgets builds and KiCad will crash. Throwing the exception
222  // here and catching it in the KiCad launcher resolves the crash issue. See bug
223  // report https://bugs.launchpad.net/kicad/+bug/1577786.
224 
225  msg.Printf( _( "Failed to load kiface library \"%s\"." ), dname );
226  THROW_IO_ERROR( msg );
227  }
228  else if( ( addr = dso.GetSymbol( wxT( KIFACE_INSTANCE_NAME_AND_VERSION ) ) ) == NULL )
229  {
230  // Failure: error reporting UI was done via wxLogSysError().
231  // No further reporting required here. Assume the same thing applies here as
232  // above with the Load() call. This has not been tested.
233  msg.Printf(
234  _( "Could not read instance name and version symbol form kiface library \"%s\"." ),
235  dname );
236  THROW_IO_ERROR( msg );
237  }
238  else
239  {
240  KIFACE_GETTER_FUNC* getter = (KIFACE_GETTER_FUNC*) addr;
241 
242  KIFACE* kiface = getter( &m_kiface_version[aFaceId], KIFACE_VERSION, m_program );
243 
244  // KIFACE_GETTER_FUNC function comment (API) says the non-NULL is unconditional.
245  wxASSERT_MSG( kiface,
246  wxT( "attempted DSO has a bug, failed to return a KIFACE*" ) );
247 
248  // Give the DSO a single chance to do its "process level" initialization.
249  // "Process level" specifically means stay away from any projects in there.
250  if( kiface->OnKifaceStart( m_program, m_ctl ) )
251  {
252  // Tell dso's wxDynamicLibrary destructor not to Unload() the program image.
253  (void) dso.Detach();
254 
255  return m_kiface[aFaceId] = kiface;
256  }
257  }
258 
259  // In any of the failure cases above, dso.Unload() should be called here
260  // by dso destructor.
261  // However:
262 
263  // There is a file installation bug. We only look for KIFACE_I's which we know
264  // to exist, and we did not find one. If we do not find one, this is an
265  // installation bug.
266 
267  msg = wxString::Format( _(
268  "Fatal Installation Bug. File:\n"
269  "\"%s\"\ncould not be loaded\n" ), dname );
270 
271  if( ! wxFileExists( dname ) )
272  msg << _( "It is missing.\n" );
273  else
274  msg << _( "Perhaps a shared library (.dll or .so) file is missing.\n" );
275 
276  msg << _( "From command line: argv[0]:\n'" );
277  msg << wxStandardPaths::Get().GetExecutablePath() << wxT( "'\n" );
278 
279  // This is a fatal error, one from which we cannot recover, nor do we want
280  // to protect against in client code which would require numerous noisy
281  // tests in numerous places. So we inform the user that the installation
282  // is bad. This exception will likely not get caught until way up in the
283  // wxApp derivative, at which point the process will exit gracefully.
284  THROW_IO_ERROR( msg );
285  }
286 
287  return NULL;
288 }
#define KIFACE_VERSION
Definition: kiway.h:111
PGM_BASE * m_program
Definition: kiway.h:433
#define KIFACE_INSTANCE_NAME_AND_VERSION
Definition: kiway.h:116
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Function Pointer KIFACE_GETTER_FUNC points to the one and only KIFACE export.
Definition: kiway.h:470
int m_ctl
Definition: kiway.h:434
#define THROW_IO_ERROR(msg)
const wxString dso_search_path(FACE_T aFaceId)
Get the [path &] name of the DSO holding the requested FACE_T.
Definition: kiway.cpp:95
#define _(s)
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:151
static int m_kiface_version[KIWAY_FACE_COUNT]
Definition: kiway.h:431
return & kiface
Definition: pcbnew.cpp:189
static KIFACE * m_kiface[KIWAY_FACE_COUNT]
Definition: kiway.h:430

References _, arrayDim(), dso_search_path(), Format(), kiface, KIFACE_INSTANCE_NAME_AND_VERSION, KIFACE_VERSION, m_ctl, m_kiface, m_kiface_version, m_program, and THROW_IO_ERROR.

Referenced by COMMON_CONTROL::ConfigurePaths(), FOOTPRINT_PREVIEW_PANEL_BASE::Create(), get_instance_from_id(), SAVE_AS_TRAVERSER::OnFile(), Player(), and COMMON_CONTROL::ShowLibraryTable().

◆ KifaceType()

KIWAY::FACE_T KIWAY::KifaceType ( FRAME_T  aFrameType)
static

Function KifaceType is a simple mapping function which returns the FACE_T which is known to implement aFrameType.

Returns
KIWAY::FACE_T - a valid value or FACE_T(-1) if given a bad aFrameType.

Definition at line 291 of file kiway.cpp.

292 {
293  switch( aFrameType )
294  {
295  case FRAME_SCH:
297  case FRAME_SCH_VIEWER:
299  case FRAME_SIMULATOR:
300  return FACE_SCH;
301 
302  case FRAME_PCB_EDITOR:
307  case FRAME_PCB_DISPLAY3D:
308  return FACE_PCB;
309 
310  case FRAME_CVPCB:
311  case FRAME_CVPCB_DISPLAY:
312  return FACE_CVPCB;
313 
314  case FRAME_GERBER:
315  return FACE_GERBVIEW;
316 
317  case FRAME_PL_EDITOR:
318  return FACE_PL_EDITOR;
319 
320  case FRAME_CALC:
321  return FACE_PCB_CALCULATOR;
322 
323  case FRAME_BM2CMP:
324  return FACE_BMP2CMP;
325 
326  default:
327  return FACE_T( -1 );
328  }
329 }
pcbnew DSO
Definition: kiway.h:283
FACE_T
Known KIFACE implementations.
Definition: kiway.h:280
eeschema DSO
Definition: kiway.h:282

References FACE_BMP2CMP, FACE_CVPCB, FACE_GERBVIEW, FACE_PCB, FACE_PCB_CALCULATOR, FACE_PL_EDITOR, FACE_SCH, FRAME_BM2CMP, FRAME_CALC, FRAME_CVPCB, FRAME_CVPCB_DISPLAY, FRAME_FOOTPRINT_EDITOR, FRAME_FOOTPRINT_VIEWER, FRAME_FOOTPRINT_VIEWER_MODAL, FRAME_FOOTPRINT_WIZARD, FRAME_GERBER, FRAME_PCB_DISPLAY3D, FRAME_PCB_EDITOR, FRAME_PL_EDITOR, FRAME_SCH, FRAME_SCH_LIB_EDITOR, FRAME_SCH_VIEWER, FRAME_SCH_VIEWER_MODAL, and FRAME_SIMULATOR.

Referenced by PGM_SINGLE_TOP::OnPgmInit(), and Player().

◆ OnKiCadExit()

void KIWAY::OnKiCadExit ( )

Definition at line 522 of file kiway.cpp.

523 {
525  {
526  // A dynamic_cast could be better, but creates link issues
527  // (some basic_frame functions not found) on some platforms,
528  // so a static_cast is used.
529  EDA_BASE_FRAME* top = static_cast<EDA_BASE_FRAME*>( m_top );
530 
531  if( top )
532  top->Close( false );
533  }
534 }
#define KFCTL_CPP_PROJECT_SUITE
Am running under C++ project mgr, possibly with others.
Definition: kiway.h:160
int m_ctl
Definition: kiway.h:434
The base frame for deriving all KiCad main window classes.
wxFrame * m_top
Definition: kiway.h:436

References KFCTL_CPP_PROJECT_SUITE, m_ctl, and m_top.

Referenced by PL_EDITOR_FRAME::OnExit(), SCH_EDIT_FRAME::OnExit(), FOOTPRINT_EDIT_FRAME::OnExitKiCad(), FOOTPRINT_VIEWER_FRAME::OnExitKiCad(), LIB_EDIT_FRAME::OnExitKiCad(), and PCB_EDIT_FRAME::OnQuit().

◆ OnKiwayEnd()

void KIWAY::OnKiwayEnd ( )

Definition at line 537 of file kiway.cpp.

538 {
539  for( KIFACE* i : m_kiface )
540  {
541  if( i )
542  i->OnKifaceEnd();
543  }
544 }
size_t i
Definition: json11.cpp:649
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:151
static KIFACE * m_kiface[KIWAY_FACE_COUNT]
Definition: kiway.h:430

References i, and m_kiface.

Referenced by PGM_KICAD::OnPgmExit(), and PGM_SINGLE_TOP::OnPgmExit().

◆ Player()

KIWAY_PLAYER * KIWAY::Player ( FRAME_T  aFrameType,
bool  doCreate = true,
wxTopLevelWindow *  aParent = NULL 
)

Function Player returns the KIWAY_PLAYER* given a FRAME_T.

If it is not already created, the required KIFACE is found and loaded and initialized if necessary, then the KIWAY_PLAYER window is created but not shown. Caller must Show() it. If it is already created, then the existing KIWAY_PLAYER* pointer is returned.

Parameters
aFrameTypeis from enum FRAME_T.
doCreatewhen true asks that the player be created if it is not already created, false means do not create and maybe return NULL.
aParentis a parent for modal KIWAY_PLAYER frames, otherwise NULL used only when doCreate = true and by KIWAY_PLAYER frames created in modal form because the are using the wxFLOAT_ON_PARENT style
Returns
KIWAY_PLAYER* - a valid opened KIWAY_PLAYER or NULL if there is something wrong or doCreate was false and the player has yet to be created.
Exceptions
IO_ERRORif the *.kiface file could not be found, filled with text saying what.

Definition at line 341 of file kiway.cpp.

342 {
343  // Since this will be called from python, cannot assume that code will
344  // not pass a bad aFrameType.
345  if( (unsigned) aFrameType >= KIWAY_PLAYER_COUNT )
346  {
347  // @todo : throw an exception here for python's benefit, at least that
348  // way it gets some explanatory text.
349 
350  wxASSERT_MSG( 0, wxT( "caller has a bug, passed a bad aFrameType" ) );
351  return NULL;
352  }
353 
354  // return the previously opened window
355  KIWAY_PLAYER* frame = GetPlayerFrame( aFrameType );
356 
357  if( frame )
358  return frame;
359 
360  if( doCreate )
361  {
362  FACE_T face_type = KifaceType( aFrameType );
363  wxASSERT( face_type != FACE_T(-1) );
364 
365  KIFACE* kiface = KiFACE( face_type );
366  wxASSERT( kiface );
367 
368  if( kiface )
369  {
370  frame = (KIWAY_PLAYER*) kiface->CreateWindow(
371  aParent, // Parent window of frame in modal mode, NULL in non modal mode
372  aFrameType,
373  this,
374  m_ctl // questionable need, these same flags where passed
375  // to the KIFACE::OnKifaceStart()
376  );
377  wxASSERT( frame );
378 
379  m_playerFrameName[aFrameType] = frame->GetName();
380 
381  return frame;
382  }
383  }
384 
385  return NULL;
386 }
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:59
static FACE_T KifaceType(FRAME_T aFrameType)
Function KifaceType is a simple mapping function which returns the FACE_T which is known to implement...
Definition: kiway.cpp:291
KIWAY_PLAYER * GetPlayerFrame(FRAME_T aFrameType)
Definition: kiway.cpp:332
int m_ctl
Definition: kiway.h:434
VTBL_ENTRY KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Function KiFACE returns the KIFACE* given a FACE_T.
Definition: kiway.cpp:177
FACE_T
Known KIFACE implementations.
Definition: kiway.h:280
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:151
wxArrayString m_playerFrameName
Definition: kiway.h:444
return & kiface
Definition: pcbnew.cpp:189

References GetPlayerFrame(), kiface, KiFACE(), KifaceType(), KIWAY_PLAYER_COUNT, m_ctl, and m_playerFrameName.

Referenced by FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB(), PCB_BASE_EDIT_FRAME::AddLibrary(), LIB_CONTROL::AddSymbolToSchematic(), FIELDS_GRID_TRICKS::doPopupSelection(), FIELDS_EDITOR_GRID_TRICKS::doPopupSelection(), EDIT_TOOL::EditFpInFpEditor(), SCH_EDITOR_CONTROL::EditWithLibEdit(), PCB_EDIT_FRAME::FetchNetlistFromSchematic(), FOOTPRINT_EDIT_FRAME::GetPlotSettings(), PCB_EDIT_FRAME::InstallFootprintPropertiesDialog(), InvokePcbLibTableEditor(), InvokeSchEditSymbolLibTable(), FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD(), FOOTPRINT_PREVIEW_PANEL::New(), TEXT_BUTTON_SYMBOL_CHOOSER::OnButtonClick(), TEXT_BUTTON_FP_CHOOSER::OnButtonClick(), SCH_EDIT_FRAME::OnCloseWindow(), KICAD_MANAGER_FRAME::OnImportEagleFiles(), SCH_EDIT_FRAME::OnOpenCvpcb(), SCH_EDIT_FRAME::OnOpenPcbnew(), PGM_SINGLE_TOP::OnPgmInit(), EDA_BASE_FRAME::OnPreferences(), DIALOG_SYMBOL_REMAP::OnRemapSymbols(), DIALOG_EDIT_ONE_FIELD::OnTextValueSelectButtonClick(), FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard(), FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard(), SCH_EDIT_FRAME::OnUpdatePCB(), FOOTPRINT_EDIT_FRAME::Process_Special_Functions(), ProcessEvent(), SCH_EDIT_FRAME::rescueProject(), PCB_EDIT_FRAME::RunEeschema(), EE_INSPECTION_TOOL::RunSimulation(), FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard(), SCH_BASE_FRAME::SelectComponentFromLibBrowser(), PCB_BASE_FRAME::SelectFootprintFromLibBrowser(), FOOTPRINT_EDIT_FRAME::SetPlotSettings(), CVPCB_CONTROL::ShowFootprintViewer(), FOOTPRINT_SELECT_WIDGET::ShowPicker(), COMMON_CONTROL::ShowPlayer(), KICAD_MANAGER_CONTROL::ShowPlayer(), SIM_PLOT_FRAME::SIM_PLOT_FRAME(), and DIALOG_EXCHANGE_FOOTPRINTS::ViewAndSelectFootprint().

◆ PlayerClose()

bool KIWAY::PlayerClose ( FRAME_T  aFrameType,
bool  doForce 
)

Function PlayerClose calls the KIWAY_PLAYER::Close( bool force ) function on the window and if not vetoed, returns true, else false.

If window actually closes, then this KIWAY marks it as not opened internally.

Returns
bool - true the window is closed and not vetoed, else false.

Definition at line 389 of file kiway.cpp.

390 {
391  // Since this will be called from python, cannot assume that code will
392  // not pass a bad aFrameType.
393  if( (unsigned) aFrameType >= KIWAY_PLAYER_COUNT )
394  {
395  // @todo : throw an exception here for python's benefit, at least that
396  // way it gets some explanatory text.
397 
398  wxASSERT_MSG( 0, wxT( "caller has a bug, passed a bad aFrameType" ) );
399  return false;
400  }
401 
402  KIWAY_PLAYER* frame = GetPlayerFrame( aFrameType );
403 
404  if( frame == NULL ) // Already closed
405  return true;
406 
407  if( frame->Close( doForce ) )
408  return true;
409 
410  return false;
411 }
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:59
KIWAY_PLAYER * GetPlayerFrame(FRAME_T aFrameType)
Definition: kiway.cpp:332

References GetPlayerFrame(), and KIWAY_PLAYER_COUNT.

Referenced by PlayersClose().

◆ PlayersClose()

bool KIWAY::PlayersClose ( bool  doForce)

Function PlayersClose calls the KIWAY_PLAYER::Close( bool force ) function on all the windows and if none are vetoed, returns true, else false.

If any window actually closes, then this KIWAY marks it as not opened internally.

Returns
bool - true indicates that all windows closed because none were vetoed, false means at least one cast a veto. Any that cast a veto are still open.

Definition at line 414 of file kiway.cpp.

415 {
416  bool ret = true;
417 
418  for( unsigned i=0; i < KIWAY_PLAYER_COUNT; ++i )
419  {
420  ret = ret && PlayerClose( FRAME_T( i ), doForce );
421  }
422 
423  return ret;
424 }
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
VTBL_ENTRY bool PlayerClose(FRAME_T aFrameType, bool doForce)
Function PlayerClose calls the KIWAY_PLAYER::Close( bool force ) function on the window and if not ve...
Definition: kiway.cpp:389
size_t i
Definition: json11.cpp:649

References i, KIWAY_PLAYER_COUNT, and PlayerClose().

Referenced by KICAD_MANAGER_FRAME::LoadProject().

◆ Prj()

PROJECT & KIWAY::Prj ( ) const

Function Prj returns the PROJECT associated with this KIWAY.

This is here as an accessor, so that there is freedom to put the actual PROJECT storage in a place decided by the implementation, and not known to the caller.

Definition at line 171 of file kiway.cpp.

172 {
173  return *(PROJECT*) &m_project; // strip const-ness, function really is const.
174 }
Class PROJECT holds project specific data.
Definition: project.h:58
PROJECT m_project
Definition: kiway.h:446

References m_project.

Referenced by PCB::IFACE::CreateWindow(), SYMBOL_PREVIEW_WIDGET::DisplaySymbol(), FOOTPRINT_LIST::GetInstance(), PCB_EDIT_FRAME::importFile(), SCH_EDIT_FRAME::importFile(), InvokePcbLibTableEditor(), InvokeSchEditSymbolLibTable(), SCH_LEGACY_PLUGIN::Load(), KIWAY_HOLDER::Prj(), and Prj().

◆ ProcessEvent()

bool KIWAY::ProcessEvent ( wxEvent &  aEvent)
override

Definition at line 496 of file kiway.cpp.

497 {
498  KIWAY_EXPRESS* mail = dynamic_cast<KIWAY_EXPRESS*>( &aEvent );
499 
500  if( mail )
501  {
502  FRAME_T dest = mail->Dest();
503 
504  // see if recipient is alive
505  KIWAY_PLAYER* alive = Player( dest, false );
506 
507  if( alive )
508  {
509 #if 1
510  return alive->ProcessEvent( aEvent );
511 #else
512  alive->KiwayMailIn( *mail );
513  return true;
514 #endif
515  }
516  }
517 
518  return false;
519 }
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:59
Class KIWAY_EXPRESS carries a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:39
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:341
virtual void KiwayMailIn(KIWAY_EXPRESS &aEvent)
Function KiwayMailIn receives KIWAY_EXPRESS messages from other players.
FRAME_T Dest()
Function Dest returns the destination player id of the message.
Definition: kiway_express.h:46
bool ProcessEvent(wxEvent &aEvent) override
Override the default process event handler to implement the auto save feature.

References KIWAY_EXPRESS::Dest(), KIWAY_PLAYER::KiwayMailIn(), Player(), and EDA_BASE_FRAME::ProcessEvent().

Referenced by ExpressMail().

◆ set_kiface()

bool KIWAY::set_kiface ( FACE_T  aFaceType,
KIFACE aKiface 
)
inlineprivate

Definition at line 414 of file kiway.h.

415  {
416  if( (unsigned) aFaceType < (unsigned) KIWAY_FACE_COUNT )
417  {
418  m_kiface[aFaceType] = aKiface;
419  return true;
420  }
421  return false;
422  }
static KIFACE * m_kiface[KIWAY_FACE_COUNT]
Definition: kiway.h:430

References KIWAY_FACE_COUNT, and m_kiface.

Referenced by PGM_SINGLE_TOP::OnPgmInit().

◆ SetLanguage()

void KIWAY::SetLanguage ( int  aLanguage)

Function SetLanguage changes the language and then calls ShowChangedLanguage() on all KIWAY_PLAYERs.

Definition at line 435 of file kiway.cpp.

436 {
437  Pgm().SetLanguageIdentifier( aLanguage );
438  Pgm().SetLanguage();
439 
440 #if 1
441  // This is a risky hack that goes away if we allow the language to be
442  // set only from the top most frame if !Kiface.IsSingle()
443 
444  // Only for the C++ project manager, and not for the python one and not for
445  // single_top do we look for the EDA_BASE_FRAME as the top level window.
446  // For single_top this is not needed because that window is registered in
447  // the array below.
449  {
450  // A dynamic_cast could be better, but creates link issues
451  // (some basic_frame functions not found) on some platforms,
452  // so a static_cast is used.
453  EDA_BASE_FRAME* top = static_cast<EDA_BASE_FRAME*>( m_top );
454 
455  if( top )
456  top->ShowChangedLanguage();
457  }
458 #endif
459 
460  for( unsigned i=0; i < KIWAY_PLAYER_COUNT; ++i )
461  {
462  KIWAY_PLAYER* frame = GetPlayerFrame( ( FRAME_T )i );
463 
464  if( frame )
465  {
466  frame->ShowChangedLanguage();
467  }
468  }
469 }
#define KFCTL_CPP_PROJECT_SUITE
Am running under C++ project mgr, possibly with others.
Definition: kiway.h:160
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:59
KIWAY_PLAYER * GetPlayerFrame(FRAME_T aFrameType)
Definition: kiway.cpp:332
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
VTBL_ENTRY void SetLanguageIdentifier(int menu_id)
Function SetLanguageIdentifier sets in .m_language_id member the wxWidgets language identifier Id fro...
Definition: pgm_base.cpp:725
int m_ctl
Definition: kiway.h:434
VTBL_ENTRY bool SetLanguage(bool first_time=false)
Function SetLanguage sets the dictionary file name for internationalization.
Definition: pgm_base.cpp:633
The base frame for deriving all KiCad main window classes.
size_t i
Definition: json11.cpp:649
wxFrame * m_top
Definition: kiway.h:436
virtual void ShowChangedLanguage()
Redraw the menus and what not in current language.

References GetPlayerFrame(), i, KFCTL_CPP_PROJECT_SUITE, KIWAY_PLAYER_COUNT, m_ctl, m_top, Pgm(), PGM_BASE::SetLanguage(), PGM_BASE::SetLanguageIdentifier(), and EDA_BASE_FRAME::ShowChangedLanguage().

Referenced by KICAD_MANAGER_FRAME::language_change(), and KIWAY_PLAYER::language_change().

◆ SetTop()

void KIWAY::SetTop ( wxFrame *  aTop)

Function SetTop tells this KIWAY about the top most frame in the program and optionally allows it to play the role of one of the KIWAY_PLAYERs if launched from single_top.cpp.

Parameters
aTopis the top most wxFrame in the entire program.

Definition at line 77 of file kiway.cpp.

78 {
79 #if 0
80  if( m_top )
81  {
82  m_top->Disconnect( wxEVT_DESTROY, wxWindowDestroyEventHandler( KIWAY::player_destroy_handler ), NULL, this );
83  }
84 
85  if( aTop )
86  {
87  aTop->Connect( wxEVT_DESTROY, wxWindowDestroyEventHandler( KIWAY::player_destroy_handler ), NULL, this );
88  }
89 #endif
90 
91  m_top = aTop;
92 }
wxFrame * m_top
Definition: kiway.h:436

References m_top.

Referenced by KIWAY(), PGM_KICAD::OnPgmInit(), and PGM_SINGLE_TOP::OnPgmInit().

Friends And Related Function Documentation

◆ PGM_SINGLE_TOP

friend struct PGM_SINGLE_TOP
friend

Definition at line 276 of file kiway.h.

Member Data Documentation

◆ m_ctl

int KIWAY::m_ctl
private

◆ m_kiface

KIFACE * KIWAY::m_kiface
staticprivate

Definition at line 430 of file kiway.h.

Referenced by KiFACE(), OnKiwayEnd(), and set_kiface().

◆ m_kiface_version

int KIWAY::m_kiface_version
staticprivate

Definition at line 431 of file kiway.h.

Referenced by KiFACE().

◆ m_playerFrameName

wxArrayString KIWAY::m_playerFrameName
private

Definition at line 444 of file kiway.h.

Referenced by GetPlayerFrame(), KIWAY(), and Player().

◆ m_program

PGM_BASE* KIWAY::m_program
private

Definition at line 433 of file kiway.h.

Referenced by KiFACE().

◆ m_project

PROJECT KIWAY::m_project
private

Definition at line 446 of file kiway.h.

Referenced by Prj().

◆ m_top

wxFrame* KIWAY::m_top
private

Definition at line 436 of file kiway.h.

Referenced by CommonSettingsChanged(), OnKiCadExit(), SetLanguage(), and SetTop().


The documentation for this class was generated from the following files: