From 9c2ebf32f1dc080747b265c94a5d7b905bcbab4a Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sun, 5 Mar 2017 17:31:31 -0500 Subject: [PATCH] Initial symbol library table implementation prep work. Add loading symbol library table code to schematic PROJECT object. Fix minor issues with loading global symbol library table. Add default symbol library path environment variable to the environment variable list and change the variable name to KICAD_SYMBOL_DIR. Add code to SCH_SCREENS to test if all library nicknames of the symbol library IDs are empty. Remove unnecessary KICAD_USE_SCH_IO_MANAGER build option. --- CMakeLists.txt | 4 ---- common/pgm_base.cpp | 16 ++++++++++++++ eeschema/class_sch_screen.h | 13 +++++++++++ eeschema/eeschema_config.cpp | 41 +++++++++++++++++++++++++++++++++++ eeschema/files-io.cpp | 5 +++++ eeschema/sch_screen.cpp | 27 +++++++++++++++++++++++ eeschema/symbol_lib_table.cpp | 21 +++++++++++++++--- eeschema/symbol_lib_table.h | 8 +++---- include/project.h | 5 +++++ 9 files changed, 129 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d72dbef5e..687a250059 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,10 +67,6 @@ option( KICAD_SCRIPTING_ACTION_MENU "Build a tools menu with registred python plugins: actions plugins (default OFF)." ) -option( KICAD_USE_SCH_IO_MANAGER - "Build Eeschema with the I/O manager for handling schematic and symbol library I/O. (default OFF)" - ) - option( KICAD_USE_OCE "Build tools and plugins related to OpenCascade Community Edition (default OFF)" ) diff --git a/common/pgm_base.cpp b/common/pgm_base.cpp index 790d9792e2..3cad844e53 100644 --- a/common/pgm_base.cpp +++ b/common/pgm_base.cpp @@ -519,6 +519,22 @@ bool PGM_BASE::InitPgm() } envVarItem.SetValue( tmpFileName.GetFullPath() ); m_local_env_vars[ envVarName ] = envVarItem; + + // KICAD_SYMBOLS + envVarName = wxT( "KICAD_SYMBOL_DIR" ); + if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() ) + { + tmpFileName.AssignDir( envValue ); + envVarItem.SetDefinedExternally( true ); + } + else + { + tmpFileName = baseSharePath; + tmpFileName.AppendDir( wxT( "library" ) ); + envVarItem.SetDefinedExternally( false ); + } + envVarItem.SetValue( tmpFileName.GetFullPath() ); + m_local_env_vars[ envVarName ] = envVarItem; } ReadPdfBrowserInfos(); // needs m_common_settings diff --git a/eeschema/class_sch_screen.h b/eeschema/class_sch_screen.h index b9ef7fef87..0886c6a1f9 100644 --- a/eeschema/class_sch_screen.h +++ b/eeschema/class_sch_screen.h @@ -590,6 +590,19 @@ public: void UpdateSymbolLinks(); void TestDanglingEnds(); + /** + * Function HasNoFullyDefinedLibIds + * + * tests all of the schematic symbols to see if all #LIB_ID objects library nickname is not + * set. + * + * If none of the #LIB_ID object library nicknames are not set, this indicates that the + * project was created before the symbol library implementation. + * + * @return true if all of the #LIB_ID object library nick names are empty, otherwise false. + */ + bool HasNoFullyDefinedLibIds(); + private: void AddScreenToList( SCH_SCREEN* aScreen ); void BuildScreenList( EDA_ITEM* aItem ); diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 79b2321168..8f20a77845 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -830,3 +831,43 @@ void LIB_EDIT_FRAME::OnPreferencesOptions( wxCommandEvent& event ) m_canvas->Refresh( true ); } + +SYMBOL_LIB_TABLE* PROJECT::SchSymbolLibTable() +{ + // This is a lazy loading function, it loads the project specific table when + // that table is asked for, not before. + SYMBOL_LIB_TABLE* tbl = (SYMBOL_LIB_TABLE*) GetElem( ELEM_SYMBOL_LIB_TABLE ); + + // its gotta be NULL or a SYMBOL_LIB_TABLE, or a bug. + wxASSERT( !tbl || dynamic_cast( tbl ) ); + + if( !tbl ) + { + // Stack the project specific SYMBOL_LIB_TABLE overlay on top of the global table. + // ~SYMBOL_LIB_TABLE() will not touch the fallback table, so multiple projects may + // stack this way, all using the same global fallback table. + tbl = new SYMBOL_LIB_TABLE( &SYMBOL_LIB_TABLE::GetGlobalLibTable() ); + + SetElem( ELEM_SYMBOL_LIB_TABLE, tbl ); + + wxString prjPath; + + wxASSERT( wxGetEnv( PROJECT_VAR_NAME, &prjPath ) ); + + wxFileName fn( prjPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() ); + + try + { + tbl->Load( fn.GetFullPath() ); + } + catch( const IO_ERROR& ioe ) + { + wxString msg; + msg.Printf( _( "An error occurred loading the symbol library table.\n\n%s" ), + ioe.What() ); + DisplayError( NULL, msg ); + } + } + + return tbl; +} diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index cc5ffdb348..1683d7f600 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -300,6 +301,10 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in Prj().SchLibs(); } + // Load the symbol library table, this will be used forever more. + Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL ); + Prj().SchSymbolLibTable(); + if( is_new ) { // mark new, unsaved file as modified. diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index f6ee690a9a..e395feb6c3 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -1529,6 +1529,33 @@ void SCH_SCREENS::TestDanglingEnds() } +bool SCH_SCREENS::HasNoFullyDefinedLibIds() +{ + SCH_COMPONENT* symbol; + SCH_ITEM* item; + SCH_ITEM* nextItem; + SCH_SCREEN* screen; + + for( screen = GetFirst(); screen; screen = GetNext() ) + { + for( item = screen->GetDrawItems(); item; item = nextItem ) + { + nextItem = item->Next(); + + if( item->Type() != SCH_COMPONENT_T ) + continue; + + symbol = dynamic_cast< SCH_COMPONENT* >( item ); + + if( !symbol->GetLibId().GetLibNickname().empty() ) + return false; + } + } + + return true; +} + + #if defined(DEBUG) void SCH_SCREEN::Show( int nestLevel, std::ostream& os ) const { diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index 603bd46a6f..02c1ff1a97 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -37,10 +37,13 @@ using namespace LIB_TABLE_T; -static const wxChar global_tbl_name[] = wxT( "sym-lib-table" ); +static const wxString global_tbl_name( "sym-lib-table" ); -SYMBOL_LIB_TABLE SYMBOL_LIB_TABLE::m_globalLibTable; // There can be only one. +/// The global symbol library table. This is not dynamically allocated because +/// in a multiple project environment we must keep its address constant (since it is +/// the fallback table for multiple projects). +SYMBOL_LIB_TABLE g_symbolLibraryTable; bool SYMBOL_LIB_TABLE_ROW::operator==( const SYMBOL_LIB_TABLE_ROW& aRow ) const @@ -66,6 +69,12 @@ SYMBOL_LIB_TABLE::SYMBOL_LIB_TABLE( SYMBOL_LIB_TABLE* aFallBackTable ) : } +SYMBOL_LIB_TABLE& SYMBOL_LIB_TABLE::GetGlobalLibTable() +{ + return g_symbolLibraryTable; +} + + void SYMBOL_LIB_TABLE::Parse( LIB_TABLE_LEXER* in ) { T tok; @@ -364,7 +373,7 @@ LIB_ALIAS* SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname( const LIB_ID& aLibI const wxString SYMBOL_LIB_TABLE::GlobalPathEnvVariableName() { - return "KICAD_SYSTEM_SYMBOLS"; + return "KICAD_SYMBOL_DIR"; } @@ -412,3 +421,9 @@ wxString SYMBOL_LIB_TABLE::GetGlobalTableFileName() return fn.GetFullPath(); } + + +const wxString& SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() +{ + return global_tbl_name; +} diff --git a/eeschema/symbol_lib_table.h b/eeschema/symbol_lib_table.h index 03dc99d758..88dd603fbe 100644 --- a/eeschema/symbol_lib_table.h +++ b/eeschema/symbol_lib_table.h @@ -44,7 +44,8 @@ public: typedef SCH_IO_MGR::SCH_FILE_T LIB_T; SYMBOL_LIB_TABLE_ROW( const wxString& aNick, const wxString& aURI, const wxString& aType, - const wxString& aOptions, const wxString& aDescr = wxEmptyString ) : + const wxString& aOptions = wxEmptyString, + const wxString& aDescr = wxEmptyString ) : LIB_TABLE_ROW( aNick, aURI, aOptions, aDescr ) { SetType( aType ); @@ -290,10 +291,9 @@ public: */ static const wxString GlobalPathEnvVariableName(); - static SYMBOL_LIB_TABLE& GetGlobalLibTable() { return m_globalLibTable; } + static SYMBOL_LIB_TABLE& GetGlobalLibTable(); -private: - static SYMBOL_LIB_TABLE m_globalLibTable; // There can be only one. + static const wxString& GetSymbolLibTableFileName(); }; diff --git a/include/project.h b/include/project.h index 491abe4a2e..dd6648f103 100644 --- a/include/project.h +++ b/include/project.h @@ -39,6 +39,7 @@ class PART_LIBS; class SEARCH_STACK; class S3D_CACHE; class KIWAY; +class SYMBOL_LIB_TABLE; #define VTBL_ENTRY virtual @@ -193,6 +194,7 @@ public: ELEM_SCH_PART_LIBS, ELEM_SCH_SEARCH_STACK, ELEM_3DCACHE, + ELEM_SYMBOL_LIB_TABLE, ELEM_COUNT }; @@ -278,6 +280,9 @@ public: /// Accessor for Eeschema search stack. SEARCH_STACK* SchSearchS(); + + /// Accessor for project symbol library table. + SYMBOL_LIB_TABLE* SchSymbolLibTable(); #endif //----------------------------------------------------