From 88df49616873ba46bb7831a8e56747fb1bb61674 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Thu, 24 Nov 2016 12:57:53 -0500 Subject: [PATCH] Eeschema: implement loading of global symbol table. Add global symbol library storage and access to SYMBOL_LIB_TABLE object. Add code to Eeschema to load global symbol table on start up. --- eeschema/eeschema.cpp | 30 ++++++++++++++++++++++++++++++ eeschema/symbol_lib_table.cpp | 5 ++++- eeschema/symbol_lib_table.h | 5 +++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index c0baaf1cdf..2f05925e24 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,7 @@ #include #include #include +#include #include #include @@ -239,6 +241,34 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) wxConfigLoadSetups( KifaceSettings(), cfg_params() ); + try + { + // The global table is not related to a specific project. All projects + // will use the same global table. So the KIFACE::OnKifaceStart() contract + // of avoiding anything project specific is not violated here. + if( !SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE::GetGlobalLibTable() ) ) + { + DisplayInfoMessage( NULL, _( + "You have run Eeschema for the first time using the new symbol library table " + "method for finding symbols.\n\n" + "Eeschema has either copied the default table or created an empty table in the " + "kicad configuration folder.\n\n" + "You must first configure the library table to include all symbol libraries you " + "want to use.\n\n" + "See the \"Symbol Library Table\" section of Eeschema documentation for more " + "information." ) ); + } + } + catch( const IO_ERROR& ioe ) + { + wxString msg = wxString::Format( _( + "An error occurred attempting to load the global symbol library table:\n\n%s" ), + GetChars( ioe.What() ) + ); + DisplayError( NULL, msg ); + return false; + } + return true; } diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index 213079ca82..31ef534500 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -40,6 +40,9 @@ using namespace LIB_TABLE_T; static const wxChar global_tbl_name[] = wxT( "sym-lib-table" ); +SYMBOL_LIB_TABLE SYMBOL_LIB_TABLE::m_globalLibTable; // There can be only one. + + bool SYMBOL_LIB_TABLE_ROW::operator==( const SYMBOL_LIB_TABLE_ROW& aRow ) const { return LIB_TABLE_ROW::operator == ( aRow ) && type == aRow.type; @@ -386,7 +389,7 @@ bool SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE& aTable ) // template folder to the user's home configuration path. wxString fileName = Kiface().KifaceSearch().FindValidPath( global_tbl_name ); - // The fallback is to create an empty global footprint table for the user to populate. + // The fallback is to create an empty global symbol table for the user to populate. if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) ) { SYMBOL_LIB_TABLE emptyTable; diff --git a/eeschema/symbol_lib_table.h b/eeschema/symbol_lib_table.h index ac2a301efa..52c87882bc 100644 --- a/eeschema/symbol_lib_table.h +++ b/eeschema/symbol_lib_table.h @@ -289,6 +289,11 @@ public: * set already in the environment. */ static const wxString GlobalPathEnvVariableName(); + + static SYMBOL_LIB_TABLE& GetGlobalLibTable() { return m_globalLibTable; } + +private: + static SYMBOL_LIB_TABLE m_globalLibTable; // There can be only one. };