KiCad PCB EDA Suite
SCH::IFACE Struct Reference
Inheritance diagram for SCH::IFACE:
KIFACE_BASE KIFACE

Public Member Functions

 IFACE (const char *aName, KIWAY::FACE_T aType)
 
bool OnKifaceStart (PGM_BASE *aProgram, int aCtlBits) override
 Typically start_common() is called from here. More...
 
void OnKifaceEnd () override
 Called just once just before the DSO is to be unloaded. More...
 
wxWindow * CreateWindow (wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
 Create a wxWindow for the current project. More...
 
void * IfaceOrAddress (int aDataId) override
 Return a pointer to the requested object. More...
 
void SaveFileAs (const wxString &aProjectBasePath, const wxString &aProjectName, const wxString &aNewProjectBasePath, const wxString &aNewProjectName, const wxString &aSrcFilePath, wxString &aErrors) override
 Saving a file under a different name is delegated to the various KIFACEs because the project doesn't know the internal format of the various files (which may have paths in them that need updating). More...
 
const wxString Name ()
 
APP_SETTINGS_BASEKifaceSettings () const
 
void InitSettings (APP_SETTINGS_BASE *aSettings)
 
int StartFlags () const
 Return whatever was passed as aCtlBits to OnKifaceStart(). More...
 
bool IsSingle () const
 Is this KIFACE running under single_top? More...
 
const wxString & GetHelpFileName () const
 Return just the basename portion of the current help file. More...
 
SEARCH_STACKKifaceSearch ()
 Only for DSO specific 'non-library' files. More...
 

Protected Member Functions

bool start_common (int aCtlBits)
 Common things to do for a top program module, during OnKifaceStart(). More...
 
void end_common ()
 Common things to do for a top program module, during OnKifaceEnd();. More...
 

Detailed Description

Definition at line 114 of file eeschema.cpp.

Constructor & Destructor Documentation

◆ IFACE()

SCH::IFACE::IFACE ( const char *  aName,
KIWAY::FACE_T  aType 
)
inline

Definition at line 118 of file eeschema.cpp.

118  :
119  KIFACE_BASE( aName, aType )
120  {}
KIFACE_BASE(const char *aKifaceName, KIWAY::FACE_T aId)
Definition: kiface_base.h:64

Member Function Documentation

◆ CreateWindow()

wxWindow* SCH::IFACE::CreateWindow ( wxWindow *  aParent,
int  aClassId,
KIWAY aKIWAY,
int  aCtlBits = 0 
)
inlineoverridevirtual

Create a wxWindow for the current project.

The caller must cast the return value into the known type.

Parameters
aParentmay be NULL or is otherwise the parent to connect under. If NULL then caller may want to connect the returned wxWindow into some hierarchy after this function returns.
aClassIdidentifies which wxFrame or wxDialog to retrieve, using a value known to the implementing KIFACE.
aKIWAYtells the window which KIWAY (and PROJECT) it is a participant in.
aCtlBitsconsists of bit flags from the set of KFCTL_* #defines above.
Returns
the window created and if not NULL, should be cast into the known type using and old school cast. dynamic_cast is problematic since it needs typeinfo probably not contained in the caller's link image.

Implements KIFACE_BASE.

Definition at line 126 of file eeschema.cpp.

128  {
129  switch( aClassId )
130  {
131  case FRAME_SCH:
132  {
133  SCH_EDIT_FRAME* frame = new SCH_EDIT_FRAME( aKiway, aParent );
134 
135  if( Kiface().IsSingle() )
136  {
137  // only run this under single_top, not under a project manager.
139  }
140 
141  return frame;
142  }
143 
145  {
146  SYMBOL_EDIT_FRAME* frame = new SYMBOL_EDIT_FRAME( aKiway, aParent );
147  return frame;
148  }
149 
150 #ifdef KICAD_SPICE
151  case FRAME_SIMULATOR:
152  {
153  SIM_PLOT_FRAME* frame = new SIM_PLOT_FRAME( aKiway, aParent );
154  return frame;
155  }
156 #endif
157  case FRAME_SCH_VIEWER:
159  {
160  SYMBOL_VIEWER_FRAME* frame = new SYMBOL_VIEWER_FRAME( aKiway, aParent,
161  FRAME_T( aClassId ) );
162  return frame;
163  }
164 
166  InvokeSchEditSymbolLibTable( aKiway, aParent );
167  // Dialog has completed; nothing to return.
168  return nullptr;
169 
170  default:
171  return nullptr;
172  }
173  }
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:32
void InvokeSchEditSymbolLibTable(KIWAY *aKiway, wxWindow *aParent)
Symbol library viewer main window.
Schematic editor (Eeschema) main window.
void CreateServer(int service, bool local=true)
Definition: eda_dde.cpp:43
#define KICAD_SCH_PORT_SERVICE_NUMBER
Scripting window listens for commands for other apps.
Definition: eda_dde.h:43
Implementing SIM_PLOT_FRAME_BASE.
bool IsSingle() const
Is this KIFACE running under single_top?
Definition: kiface_base.h:104
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition: eeschema.cpp:214
The symbol library editor main window.

References KIWAY_PLAYER::CreateServer(), DIALOG_SCH_LIBRARY_TABLE, FRAME_SCH, FRAME_SCH_SYMBOL_EDITOR, FRAME_SCH_VIEWER, FRAME_SCH_VIEWER_MODAL, FRAME_SIMULATOR, InvokeSchEditSymbolLibTable(), KIFACE_BASE::IsSingle(), KICAD_SCH_PORT_SERVICE_NUMBER, and Kiface().

◆ end_common()

void KIFACE_BASE::end_common ( )
protectedinherited

Common things to do for a top program module, during OnKifaceEnd();.

Definition at line 107 of file kiface_base.cpp.

108 {
109  m_bm.End();
110 }
BIN_MOD m_bm
Definition: kiface_base.h:118
void End()
Definition: bin_mod.cpp:50

References BIN_MOD::End(), and KIFACE_BASE::m_bm.

Referenced by PCBCALC::IFACE::OnKifaceEnd(), KIFACE_BASE::OnKifaceEnd(), CV::IFACE::OnKifaceEnd(), PGE::IFACE::OnKifaceEnd(), GERBV::IFACE::OnKifaceEnd(), PCB::IFACE::OnKifaceEnd(), and OnKifaceEnd().

◆ GetHelpFileName()

const wxString& KIFACE_BASE::GetHelpFileName ( ) const
inlineinherited

Return just the basename portion of the current help file.

Definition at line 109 of file kiface_base.h.

109 { return m_bm.m_help_file; }
BIN_MOD m_bm
Definition: kiface_base.h:118
wxString m_help_file
Definition: bin_mod.h:58

References KIFACE_BASE::m_bm, and BIN_MOD::m_help_file.

Referenced by EDA_BASE_FRAME::help_name().

◆ IfaceOrAddress()

void* SCH::IFACE::IfaceOrAddress ( int  aDataId)
inlineoverridevirtual

Return a pointer to the requested object.

The safest way to use this is to retrieve a pointer to a static instance of an interface, similar to how the KIFACE interface is exported. But if you know what you are doing use it to retrieve anything you want.

Parameters
aDataIdidentifies which object you want the address of.
Returns
the object requested and must be cast into the know type.

Implements KIFACE_BASE.

Definition at line 185 of file eeschema.cpp.

186  {
187  switch( aDataId )
188  {
190  return (void*) generateSchematicNetlist;
191  }
192 
193  return nullptr;
194  }
bool generateSchematicNetlist(const wxString &aFilename, wxString &aNetlist)
Definition: eeschema.cpp:101

References SCH::generateSchematicNetlist(), and KIFACE_NETLIST_SCHEMATIC.

◆ InitSettings()

void KIFACE_BASE::InitSettings ( APP_SETTINGS_BASE aSettings)
inlineinherited

Definition at line 94 of file kiface_base.h.

94 { m_bm.InitSettings( aSettings ); }
BIN_MOD m_bm
Definition: kiface_base.h:118
void InitSettings(APP_SETTINGS_BASE *aPtr)
Takes ownership of a new application settings object.
Definition: bin_mod.h:53

References BIN_MOD::InitSettings(), and KIFACE_BASE::m_bm.

Referenced by BMP2CMP::IFACE::CreateWindow(), PCBCALC::IFACE::OnKifaceStart(), CV::IFACE::OnKifaceStart(), PGE::IFACE::OnKifaceStart(), GERBV::IFACE::OnKifaceStart(), PCB::IFACE::OnKifaceStart(), and OnKifaceStart().

◆ IsSingle()

◆ KifaceSearch()

SEARCH_STACK& KIFACE_BASE::KifaceSearch ( )
inlineinherited

Only for DSO specific 'non-library' files.

(The library search path is in the PROJECT class.)

Definition at line 113 of file kiface_base.h.

113 { return m_bm.m_search; }
BIN_MOD m_bm
Definition: kiface_base.h:118
SEARCH_STACK m_search
Definition: bin_mod.h:60

References KIFACE_BASE::m_bm, and BIN_MOD::m_search.

Referenced by CVPCB_MAINFRAME::buildEquivalenceList(), DS_DATA_MODEL::ResolvePath(), and EDA_BASE_FRAME::sys_search().

◆ KifaceSettings()

◆ Name()

const wxString KIFACE_BASE::Name ( )
inlineinherited

Definition at line 87 of file kiface_base.h.

88  {
89  return wxString::FromUTF8( m_bm.m_name );
90  }
BIN_MOD m_bm
Definition: kiface_base.h:118
const char * m_name
name of this binary module, static C string.
Definition: bin_mod.h:55

References KIFACE_BASE::m_bm, and BIN_MOD::m_name.

◆ OnKifaceEnd()

void IFACE::OnKifaceEnd ( )
overridevirtual

Called just once just before the DSO is to be unloaded.

It is called before static C++ destructors are called. A default implementation is supplied.

Reimplemented from KIFACE_BASE.

Definition at line 285 of file eeschema.cpp.

286 {
287  end_common();
288 }
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.

References KIFACE_BASE::end_common().

◆ OnKifaceStart()

bool IFACE::OnKifaceStart ( PGM_BASE aProgram,
int  aCtlBits 
)
overridevirtual

Typically start_common() is called from here.

Implements KIFACE_BASE.

Definition at line 240 of file eeschema.cpp.

241 {
242  // This is process-level-initialization, not project-level-initialization of the DSO.
243  // Do nothing in here pertinent to a project!
246 
247  start_common( aCtlBits );
248 
250 
251  if( !fn.FileExists() )
252  {
253  DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG fpDialog( nullptr );
254 
255  fpDialog.ShowModal();
256  }
257  else
258  {
259  try
260  {
261  // The global table is not related to a specific project. All projects
262  // will use the same global table. So the KIFACE::OnKifaceStart() contract
263  // of avoiding anything project specific is not violated here.
265  return false;
266  }
267  catch( const IO_ERROR& ioe )
268  {
269  // if we are here, a incorrect global symbol library table was found.
270  // Incorrect global symbol library table is not a fatal error:
271  // the user just has to edit the (partially) loaded table.
272  wxString msg = _(
273  "An error occurred attempting to load the global symbol library table.\n"
274  "Please edit this global symbol library table in Preferences menu."
275  );
276 
277  DisplayErrorMessage( nullptr, msg, ioe.What() );
278  }
279  }
280 
281  return true;
282 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:129
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
int PGM_BASE * aProgram
Definition: eeschema.cpp:220
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition: kiface_base.h:94
static bool LoadGlobalTable(SYMBOL_LIB_TABLE &aTable)
Load the global symbol library table into aTable.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Definition: kiface_base.cpp:97
#define _(s)
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:92
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.

References _, aProgram, DisplayErrorMessage(), SYMBOL_LIB_TABLE::GetGlobalLibTable(), SYMBOL_LIB_TABLE::GetGlobalTableFileName(), PGM_BASE::GetSettingsManager(), KIFACE_BASE::InitSettings(), KIFACE_BASE::KifaceSettings(), SYMBOL_LIB_TABLE::LoadGlobalTable(), SETTINGS_MANAGER::RegisterSettings(), KIFACE_BASE::start_common(), and IO_ERROR::What().

◆ SaveFileAs()

void IFACE::SaveFileAs ( const wxString &  aProjectBasePath,
const wxString &  aProjectName,
const wxString &  aNewProjectBasePath,
const wxString &  aNewProjectName,
const wxString &  aSrcFilePath,
wxString &  aErrors 
)
overridevirtual

Saving a file under a different name is delegated to the various KIFACEs because the project doesn't know the internal format of the various files (which may have paths in them that need updating).

Reimplemented from KIFACE.

Definition at line 304 of file eeschema.cpp.

307 {
308  wxFileName destFile( aSrcFilePath );
309  wxString destPath = destFile.GetPathWithSep();
310  wxUniChar pathSep = wxFileName::GetPathSeparator();
311  wxString ext = destFile.GetExt();
312 
313  if( destPath.StartsWith( aProjectBasePath + pathSep ) )
314  destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
315 
316  destFile.SetPath( destPath );
317 
318  if( ext == LegacySchematicFileExtension ||
322  {
323  if( destFile.GetName() == aProjectName )
324  destFile.SetName( aNewProjectName );
325 
326  // Sheet paths when auto-generated are relative to the root, so those will stay
327  // pointing to whatever they were pointing at.
328  // The author can create their own absolute and relative sheet paths. Absolute
329  // sheet paths aren't an issue, and relative ones will continue to work as long
330  // as the author didn't include any '..'s. If they did, it's still not clear
331  // whether they should be adjusted or not (as the author may be duplicating an
332  // entire tree with several projects within it), so we leave this as an exercise
333  // to the author.
334 
335  KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
336  }
337  else if( ext == SchematicSymbolFileExtension )
338  {
339  // Symbols are not project-specific. Keep their source names.
340  KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
341  }
344  {
345  if( destFile.GetName() == aProjectName + "-cache" )
346  destFile.SetName( aNewProjectName + "-cache" );
347 
348  KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
349  }
350  else if( ext == NetlistFileExtension )
351  {
352  bool success = false;
353 
354  if( destFile.GetName() == aProjectName )
355  destFile.SetName( aNewProjectName );
356 
357  try
358  {
359  SEXPR::PARSER parser;
360  std::unique_ptr<SEXPR::SEXPR> sexpr( parser.ParseFromFile( TO_UTF8( aSrcFilePath ) ) );
361 
362  traverseSEXPR( sexpr.get(), [&]( SEXPR::SEXPR* node )
363  {
364  if( node->IsList() && node->GetNumberOfChildren() > 1
365  && node->GetChild( 0 )->IsSymbol()
366  && node->GetChild( 0 )->GetSymbol() == "source" )
367  {
368  auto pathNode = dynamic_cast<SEXPR::SEXPR_STRING*>( node->GetChild( 1 ) );
369  auto symNode = dynamic_cast<SEXPR::SEXPR_SYMBOL*>( node->GetChild( 1 ) );
370  wxString path;
371 
372  if( pathNode )
373  path = pathNode->m_value;
374  else if( symNode )
375  path = symNode->m_value;
376 
377  if( path == aProjectName + ".sch" )
378  path = aNewProjectName + ".sch";
379  else if( path == aProjectBasePath + "/" + aProjectName + ".sch" )
380  path = aNewProjectBasePath + "/" + aNewProjectName + ".sch";
381  else if( path.StartsWith( aProjectBasePath ) )
382  path.Replace( aProjectBasePath, aNewProjectBasePath, false );
383 
384  if( pathNode )
385  pathNode->m_value = path;
386  else if( symNode )
387  symNode->m_value = path;
388  }
389  } );
390 
391  wxFFile destNetList( destFile.GetFullPath(), "wb" );
392 
393  if( destNetList.IsOpened() )
394  success = destNetList.Write( sexpr->AsString( 0 ) );
395 
396  // wxFFile dtor will close the file
397  }
398  catch( ... )
399  {
400  success = false;
401  }
402 
403  if( !success )
404  {
405  wxString msg;
406 
407  if( !aErrors.empty() )
408  aErrors += "\n";
409 
410  msg.Printf( _( "Cannot copy file '%s'." ), destFile.GetFullPath() );
411  aErrors += msg;
412  }
413  }
414  else if( destFile.GetName() == "sym-lib-table" )
415  {
416  SYMBOL_LIB_TABLE symbolLibTable;
417  symbolLibTable.Load( aSrcFilePath );
418 
419  for( unsigned i = 0; i < symbolLibTable.GetCount(); i++ )
420  {
421  LIB_TABLE_ROW& row = symbolLibTable.At( i );
422  wxString uri = row.GetFullURI();
423 
424  uri.Replace( "/" + aProjectName + "-cache.lib", "/" + aNewProjectName + "-cache.lib" );
425  uri.Replace( "/" + aProjectName + "-rescue.lib", "/" + aNewProjectName +
426  "-rescue.lib" );
427  uri.Replace( "/" + aProjectName + ".lib", "/" + aNewProjectName + ".lib" );
428 
429  row.SetFullURI( uri );
430  }
431 
432  try
433  {
434  symbolLibTable.Save( destFile.GetFullPath() );
435  }
436  catch( ... )
437  {
438  wxString msg;
439 
440  if( !aErrors.empty() )
441  aErrors += "\n";
442 
443  msg.Printf( _( "Cannot copy file '%s'." ), destFile.GetFullPath() );
444  aErrors += msg;
445  }
446  }
447  else
448  {
449  wxFAIL_MSG( "Unexpected filetype for Eeschema::SaveFileAs()" );
450  }
451 }
const std::string NetlistFileExtension
static void traverseSEXPR(SEXPR::SEXPR *aNode, const std::function< void(SEXPR::SEXPR *)> &aVisitor)
Definition: eeschema.cpp:291
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
const std::string LegacySymbolLibFileExtension
std::unique_ptr< SEXPR > ParseFromFile(const std::string &aFilename)
const std::string BackupFileSuffix
unsigned GetCount() const
Get the number of rows contained in the table.
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition: gestfich.cpp:326
const std::string SchematicSymbolFileExtension
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
const std::string LegacySymbolDocumentFileExtension
#define _(s)
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
const std::string LegacySchematicFileExtension
void SetFullURI(const wxString &aFullURI)
Change the full URI for the library.
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
const std::string KiCadSchematicFileExtension
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
const std::string KiCadSymbolLibFileExtension

References _, LIB_TABLE::At(), BackupFileSuffix, LIB_TABLE::GetCount(), LIB_TABLE_ROW::GetFullURI(), KiCadSchematicFileExtension, KiCadSymbolLibFileExtension, KiCopyFile(), LegacySchematicFileExtension, LegacySymbolDocumentFileExtension, LegacySymbolLibFileExtension, LIB_TABLE::Load(), NetlistFileExtension, SEXPR::PARSER::ParseFromFile(), path, LIB_TABLE::Save(), SchematicSymbolFileExtension, LIB_TABLE_ROW::SetFullURI(), TO_UTF8, and traverseSEXPR().

◆ start_common()

bool KIFACE_BASE::start_common ( int  aCtlBits)
protectedinherited

Common things to do for a top program module, during OnKifaceStart().

Definition at line 97 of file kiface_base.cpp.

98 {
99  m_start_flags = aCtlBits;
100  m_bm.Init();
102 
103  return true;
104 }
BIN_MOD m_bm
Definition: kiface_base.h:118
void Init()
Definition: bin_mod.cpp:38
static void setSearchPaths(SEARCH_STACK *aDst, KIWAY::FACE_T aId)
Initialize aDst SEARCH_STACK with KIFACE (DSO) specific settings.
Definition: kiface_base.cpp:33
int m_start_flags
flags provided in OnKifaceStart()
Definition: kiface_base.h:120
SEARCH_STACK m_search
Definition: bin_mod.h:60
KIWAY::FACE_T m_id
Definition: kiface_base.h:116

References BIN_MOD::Init(), KIFACE_BASE::m_bm, KIFACE_BASE::m_id, BIN_MOD::m_search, KIFACE_BASE::m_start_flags, and setSearchPaths().

Referenced by BMP2CMP::IFACE::OnKifaceStart(), PCBCALC::IFACE::OnKifaceStart(), IFACE::OnKifaceStart(), CV::IFACE::OnKifaceStart(), PGE::IFACE::OnKifaceStart(), GERBV::IFACE::OnKifaceStart(), PCB::IFACE::OnKifaceStart(), and OnKifaceStart().

◆ StartFlags()

int KIFACE_BASE::StartFlags ( ) const
inlineinherited

Return whatever was passed as aCtlBits to OnKifaceStart().

Definition at line 99 of file kiface_base.h.

99 { return m_start_flags; }
int m_start_flags
flags provided in OnKifaceStart()
Definition: kiface_base.h:120

References KIFACE_BASE::m_start_flags.


The documentation for this struct was generated from the following file: