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

Public Member Functions

 IFACE (const char *aName, KIWAY::FACE_T aType)
 
bool OnKifaceStart (PGM_BASE *aProgram, int aCtlBits) override
 Function OnKifaceStart is called just once shortly after the DSO is loaded. More...
 
void OnKifaceEnd () override
 Function OnKifaceEnd is called just once just before the DSO is to be unloaded. More...
 
wxWindow * CreateWindow (wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
 Function CreateWindow creates a wxWindow for the current project. More...
 
void * IfaceOrAddress (int aDataId) override
 Function IfaceOrAddress 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
 Function SaveFileAs 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
 Function StartFlags returns whatever was passed as aCtlBits to OnKifaceStart() More...
 
bool IsSingle () const
 Function IsSingle is this KIFACE_I running under single_top? More...
 
const wxString & GetHelpFileName () const
 Function GetHelpFileName returns just the basename portion of the current help file. More...
 
FILE_HISTORYGetFileHistory ()
 
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 57 of file eeschema/eeschema.cpp.

Constructor & Destructor Documentation

◆ IFACE()

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

Definition at line 61 of file eeschema/eeschema.cpp.

61  :
62  KIFACE_I( aName, aType )
63  {}
KIFACE_I(const char *aKifaceName, KIWAY::FACE_T aId)
Constructor.
Definition: kiface_i.h:78

Member Function Documentation

◆ CreateWindow()

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

Function CreateWindow creates 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
wxWindow* - 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_I.

Definition at line 69 of file eeschema/eeschema.cpp.

70  {
71  switch( aClassId )
72  {
73  case FRAME_SCH:
74  {
75  SCH_EDIT_FRAME* frame = new SCH_EDIT_FRAME( aKiway, aParent );
76 
77  if( Kiface().IsSingle() )
78  {
79  // only run this under single_top, not under a project manager.
81  }
82 
83  return frame;
84  }
85 
87  {
88  LIB_EDIT_FRAME* frame = new LIB_EDIT_FRAME( aKiway, aParent );
89  return frame;
90  }
91 
92 #ifdef KICAD_SPICE
93  case FRAME_SIMULATOR:
94  {
95  SIM_PLOT_FRAME* frame = new SIM_PLOT_FRAME( aKiway, aParent );
96  return frame;
97  }
98 #endif
99  case FRAME_SCH_VIEWER:
101  {
102  LIB_VIEW_FRAME* frame = new LIB_VIEW_FRAME( aKiway, aParent, FRAME_T( aClassId ) );
103  return frame;
104  }
105 
107  InvokeSchEditSymbolLibTable( aKiway, aParent );
108  // Dialog has completed; nothing to return.
109  return nullptr;
110 
111  default:
112  return NULL;
113  }
114  }
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
void InvokeSchEditSymbolLibTable(KIWAY *aKiway, wxWindow *aParent)
Schematic editor (Eeschema) main window.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Symbol library viewer main window.
#define KICAD_SCH_PORT_SERVICE_NUMBER
Definition: eda_dde.h:42
#define NULL
bool IsSingle() const
Function IsSingle is this KIFACE_I running under single_top?
Definition: kiface_i.h:117
Implementing SIM_PLOT_FRAME_BASE.
The symbol library editor main window.
void CreateServer(int service, bool local=true)
Definition: eda_dde.cpp:49

References EDA_DRAW_FRAME::CreateServer(), DIALOG_SCH_LIBRARY_TABLE, FRAME_SCH, FRAME_SCH_LIB_EDITOR, FRAME_SCH_VIEWER, FRAME_SCH_VIEWER_MODAL, FRAME_SIMULATOR, InvokeSchEditSymbolLibTable(), KIFACE_I::IsSingle(), KICAD_SCH_PORT_SERVICE_NUMBER, Kiface(), and NULL.

◆ end_common()

void KIFACE_I::end_common ( )
protectedinherited

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

Definition at line 99 of file kiface_i.cpp.

100 {
101  m_bm.End();
102 }
BIN_MOD m_bm
Definition: kiface_i.h:134
void End()
Definition: bin_mod.cpp:61

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

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

◆ GetFileHistory()

◆ GetHelpFileName()

const wxString& KIFACE_I::GetHelpFileName ( ) const
inlineinherited

Function GetHelpFileName returns just the basename portion of the current help file.

Definition at line 123 of file kiface_i.h.

123 { return m_bm.m_help_file; }
BIN_MOD m_bm
Definition: kiface_i.h:134
wxString m_help_file
Definition: bin_mod.h:67

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

Referenced by EDA_BASE_FRAME::help_name().

◆ IfaceOrAddress()

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

Function IfaceOrAddress 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
void* - and must be cast into the know type.

Implements KIFACE_I.

Definition at line 124 of file eeschema/eeschema.cpp.

125  {
126  return NULL;
127  }
#define NULL

References NULL.

◆ InitSettings()

void KIFACE_I::InitSettings ( APP_SETTINGS_BASE aSettings)
inlineinherited

Definition at line 105 of file kiface_i.h.

105 { m_bm.InitSettings( aSettings ); }
BIN_MOD m_bm
Definition: kiface_i.h:134
void InitSettings(APP_SETTINGS_BASE *aPtr)
Takes ownership of a new application settings object.
Definition: bin_mod.h:61

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

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

◆ IsSingle()

bool KIFACE_I::IsSingle ( ) const
inlineinherited

◆ KifaceSearch()

SEARCH_STACK& KIFACE_I::KifaceSearch ( )
inlineinherited

Only for DSO specific 'non-library' files.

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

Definition at line 129 of file kiface_i.h.

129 { return m_bm.m_search; }
BIN_MOD m_bm
Definition: kiface_i.h:134
SEARCH_STACK m_search
Definition: bin_mod.h:69

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

Referenced by CVPCB_MAINFRAME::buildEquivalenceList(), WS_DATA_MODEL::MakeFullFileName(), WS_DATA_MODEL::MakeShortFileName(), and EDA_BASE_FRAME::sys_search().

◆ KifaceSettings()

◆ Name()

const wxString KIFACE_I::Name ( )
inlineinherited

Definition at line 101 of file kiface_i.h.

101 { return wxString::FromUTF8( m_bm.m_name ); }
BIN_MOD m_bm
Definition: kiface_i.h:134
const char * m_name
name of this binary module, static C string.
Definition: bin_mod.h:63

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

◆ OnKifaceEnd()

void IFACE::OnKifaceEnd ( )
overridevirtual

Function OnKifaceEnd is 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.

Implements KIFACE.

Definition at line 212 of file eeschema/eeschema.cpp.

213 {
215 
216  for( SCH_LAYER_ID layer = SCH_LAYER_ID_START; layer < SCH_LAYER_ID_END; ++layer )
217  {
218  cs->SetColor( layer, GetLayerColor( layer ) );
219  }
220 
221  end_common();
222 }
PGM_BASE & Pgm()
The global Program "get" accessor.
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
Definition: kiface_i.cpp:99
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Helper for all the old plotting/printing code while it still exists.
SCH_LAYER_ID
Eeschema drawing layers.
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
void SetColor(int aLayer, COLOR4D aColor)

References KIFACE_I::end_common(), SETTINGS_MANAGER::GetColorSettings(), GetLayerColor(), PGM_BASE::GetSettingsManager(), Pgm(), SCH_LAYER_ID_END, SCH_LAYER_ID_START, and COLOR_SETTINGS::SetColor().

◆ OnKifaceStart()

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

Function OnKifaceStart is called just once shortly after the DSO is loaded.

It is the second function called, immediately after the KIFACE_GETTER(). However before either of those, static C++ constructors are called. The DSO implementation should do process level initialization here, not project specific since there will be multiple projects open eventually.

Parameters
aProgramis the process block: PGM_BASE*
aCtlBitsconsists of bit flags from the set of KFCTL_* #defines above.
Returns
bool - true if DSO initialized OK, false if not. When returning false, the loader may optionally decide to terminate the process or not, but will not put out any UI because that is the duty of this function to say why it is returning false. Never return false without having reported to the UI why.

Implements KIFACE_I.

Definition at line 167 of file eeschema/eeschema.cpp.

168 {
169  // This is process-level-initialization, not project-level-initialization of the DSO.
170  // Do nothing in here pertinent to a project!
173 
174  start_common( aCtlBits );
175 
177 
178  if( !fn.FileExists() )
179  {
181 
182  fpDialog.ShowModal();
183  }
184  else
185  {
186  try
187  {
188  // The global table is not related to a specific project. All projects
189  // will use the same global table. So the KIFACE::OnKifaceStart() contract
190  // of avoiding anything project specific is not violated here.
192  return false;
193  }
194  catch( const IO_ERROR& ioe )
195  {
196  // if we are here, a incorrect global symbol library table was found.
197  // Incorrect global symbol library table is not a fatal error:
198  // the user just has to edit the (partially) loaded table.
199  wxString msg = _(
200  "An error occurred attempting to load the global symbol library table.\n"
201  "Please edit this global symbol library table in Preferences menu."
202  );
203 
204  DisplayErrorMessage( NULL, msg, ioe.What() );
205  }
206  }
207 
208  return true;
209 }
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Definition: kiface_i.cpp:89
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_i.h:103
int PGM_BASE * aProgram
static bool LoadGlobalTable(SYMBOL_LIB_TABLE &aTable)
Load the global symbol library table into aTable.
#define NULL
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
JSON_SETTINGS * RegisterSettings(JSON_SETTINGS *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
#define _(s)
Definition: 3d_actions.cpp:33
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition: kiface_i.h:105
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
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_I::InitSettings(), KIFACE_I::KifaceSettings(), SYMBOL_LIB_TABLE::LoadGlobalTable(), NULL, SETTINGS_MANAGER::RegisterSettings(), KIFACE_I::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 
)
override

Function SaveFileAs 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).

Definition at line 237 of file eeschema/eeschema.cpp.

240 {
241  wxFileName destFile( aSrcFilePath );
242  wxString destPath = destFile.GetPathWithSep();
243  wxUniChar pathSep = wxFileName::GetPathSeparator();
244  wxString ext = destFile.GetExt();
245 
246  if( destPath.StartsWith( aProjectBasePath + pathSep ) )
247  destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
248 
249 #if 0
250  // WAYNE STAMBAUGH TODO:
251  // If we end up with a symbol equivalent to ".pretty" we'll want to handle it here....
252  wxString srcProjectSymbolLib = pathSep + aProjectName + ".sym_lib_dir_extension" + pathSep;
253  wxString newProjectSymbolLib = pathSep + aNewProjectName + ".sym_lib_dir_extension" + pathSep;
254 
255  destPath.Replace( srcProjectSymbolLib, newProjectSymbolLib, true );
256 #endif
257 
258  destFile.SetPath( destPath );
259 
260  if( ext == "sch" || ext == "sch-bak" )
261  {
262  if( destFile.GetName() == aProjectName )
263  destFile.SetName( aNewProjectName );
264 
265  // Sheet paths when auto-generated are relative to the root, so those will stay
266  // pointing to whatever they were pointing at.
267  // The author can create their own absolute and relative sheet paths. Absolute
268  // sheet paths aren't an issue, and relative ones will continue to work as long
269  // as the author didn't include any '..'s. If they did, it's still not clear
270  // whether they should be adjusted or not (as the author may be duplicating an
271  // entire tree with several projects within it), so we leave this as an exercise
272  // to the author.
273 
274  CopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
275  }
276  else if( ext == "sym" )
277  {
278  // Symbols are not project-specific. Keep their source names.
279  CopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
280  }
281  else if( ext == "lib" )
282  {
283  if( destFile.GetName() == aProjectName )
284  destFile.SetName( aNewProjectName );
285  else if( destFile.GetName() == aProjectName + "-cache" )
286  destFile.SetName( aNewProjectName + "-cache" );
287  else if( destFile.GetName() == aProjectName + "-rescue" )
288  destFile.SetName( aNewProjectName + "-rescue" );
289 
290  CopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
291  }
292  else if( ext == "net" )
293  {
294  bool success = false;
295 
296  if( destFile.GetName() == aProjectName )
297  destFile.SetName( aNewProjectName );
298 
299  try
300  {
301  SEXPR::PARSER parser;
302  std::unique_ptr<SEXPR::SEXPR> sexpr( parser.ParseFromFile( TO_UTF8( aSrcFilePath ) ) );
303 
304  traverseSEXPR( sexpr.get(), [&]( SEXPR::SEXPR* node )
305  {
306  if( node->IsList() && node->GetNumberOfChildren() > 1
307  && node->GetChild( 0 )->IsSymbol()
308  && node->GetChild( 0 )->GetSymbol() == "source" )
309  {
310  auto pathNode = dynamic_cast<SEXPR::SEXPR_STRING*>( node->GetChild( 1 ) );
311  auto symNode = dynamic_cast<SEXPR::SEXPR_SYMBOL*>( node->GetChild( 1 ) );
312  wxString path;
313 
314  if( pathNode )
315  path = pathNode->m_value;
316  else if( symNode )
317  path = symNode->m_value;
318 
319  if( path == aProjectName + ".sch" )
320  path = aNewProjectName + ".sch";
321  else if( path == aProjectBasePath + "/" + aProjectName + ".sch" )
322  path = aNewProjectBasePath + "/" + aNewProjectName + ".sch";
323  else if( path.StartsWith( aProjectBasePath ) )
324  path.Replace( aProjectBasePath, aNewProjectBasePath, false );
325 
326  if( pathNode )
327  pathNode->m_value = path;
328  else if( symNode )
329  symNode->m_value = path;
330  }
331  } );
332 
333  wxFile destNetList( destFile.GetFullPath(), wxFile::write );
334 
335  if( destNetList.IsOpened() )
336  success = destNetList.Write( sexpr->AsString( 0 ) );
337 
338  // wxFile dtor will close the file
339  }
340  catch( ... )
341  {
342  success = false;
343  }
344 
345  if( !success )
346  {
347  wxString msg;
348 
349  if( !aErrors.empty() )
350  aErrors += "\n";
351 
352  msg.Printf( _( "Cannot copy file \"%s\"." ), destFile.GetFullPath() );
353  aErrors += msg;
354  }
355  }
356  else if( destFile.GetName() == "sym-lib-table" )
357  {
358  SYMBOL_LIB_TABLE symbolLibTable;
359  symbolLibTable.Load( aSrcFilePath );
360 
361  for( unsigned i = 0; i < symbolLibTable.GetCount(); i++ )
362  {
363  LIB_TABLE_ROW& row = symbolLibTable.At( i );
364  wxString uri = row.GetFullURI();
365 
366  uri.Replace( "/" + aProjectName + "-cache.lib", "/" + aNewProjectName + "-cache.lib" );
367  uri.Replace( "/" + aProjectName + "-rescue.lib", "/" + aNewProjectName + "-rescue.lib" );
368  uri.Replace( "/" + aProjectName + ".lib", "/" + aNewProjectName + ".lib" );
369 
370  row.SetFullURI( uri );
371  }
372 
373  try
374  {
375  symbolLibTable.Save( destFile.GetFullPath() );
376  }
377  catch( ... )
378  {
379  wxString msg;
380 
381  if( !aErrors.empty() )
382  aErrors += "\n";
383 
384  msg.Printf( _( "Cannot copy file \"%s\"." ), destFile.GetFullPath() );
385  aErrors += msg;
386  }
387  }
388  else
389  {
390  wxFAIL_MSG( "Unexpected filetype for Eeschema::SaveFileAs()" );
391  }
392 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
unsigned GetCount() const
Get the number of rows contained in the table.
void CopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Function CopyFile.
Definition: gestfich.cpp:363
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)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
static void traverseSEXPR(SEXPR::SEXPR *aNode, const std::function< void(SEXPR::SEXPR *)> &aVisitor)
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
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.
#define _(s)
Definition: 3d_actions.cpp:33
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
std::unique_ptr< SEXPR > ParseFromFile(const std::string &aFilename)

◆ start_common()

bool KIFACE_I::start_common ( int  aCtlBits)
protectedinherited

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

Definition at line 89 of file kiface_i.cpp.

90 {
91  m_start_flags = aCtlBits;
92  m_bm.Init();
94 
95  return true;
96 }
KIWAY::FACE_T m_id
Definition: kiface_i.h:132
void Init()
Definition: bin_mod.cpp:43
BIN_MOD m_bm
Definition: kiface_i.h:134
int m_start_flags
flags provided in OnKifaceStart()
Definition: kiface_i.h:136
SEARCH_STACK m_search
Definition: bin_mod.h:69
static void setSearchPaths(SEARCH_STACK *aDst, KIWAY::FACE_T aId)
Initialize aDst SEARCH_STACK with KIFACE (DSO) specific settings.
Definition: kiface_i.cpp:37

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

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

◆ StartFlags()

int KIFACE_I::StartFlags ( ) const
inlineinherited

Function StartFlags returns whatever was passed as aCtlBits to OnKifaceStart()

Definition at line 111 of file kiface_i.h.

111 { return m_start_flags; }
int m_start_flags
flags provided in OnKifaceStart()
Definition: kiface_i.h:136

References KIFACE_I::m_start_flags.


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