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.
This commit is contained in:
Wayne Stambaugh 2017-03-05 17:31:31 -05:00
parent dcaa0559de
commit 9c2ebf32f1
9 changed files with 129 additions and 11 deletions

View File

@ -67,10 +67,6 @@ option( KICAD_SCRIPTING_ACTION_MENU
"Build a tools menu with registred python plugins: actions plugins (default OFF)." "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 option( KICAD_USE_OCE
"Build tools and plugins related to OpenCascade Community Edition (default OFF)" "Build tools and plugins related to OpenCascade Community Edition (default OFF)"
) )

View File

@ -519,6 +519,22 @@ bool PGM_BASE::InitPgm()
} }
envVarItem.SetValue( tmpFileName.GetFullPath() ); envVarItem.SetValue( tmpFileName.GetFullPath() );
m_local_env_vars[ envVarName ] = envVarItem; 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 ReadPdfBrowserInfos(); // needs m_common_settings

View File

@ -590,6 +590,19 @@ public:
void UpdateSymbolLinks(); void UpdateSymbolLinks();
void TestDanglingEnds(); 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: private:
void AddScreenToList( SCH_SCREEN* aScreen ); void AddScreenToList( SCH_SCREEN* aScreen );
void BuildScreenList( EDA_ITEM* aItem ); void BuildScreenList( EDA_ITEM* aItem );

View File

@ -44,6 +44,7 @@
#include <class_libentry.h> #include <class_libentry.h>
#include <worksheet_shape_builder.h> #include <worksheet_shape_builder.h>
#include <class_library.h> #include <class_library.h>
#include <symbol_lib_table.h>
#include <dialog_hotkeys_editor.h> #include <dialog_hotkeys_editor.h>
@ -830,3 +831,43 @@ void LIB_EDIT_FRAME::OnPreferencesOptions( wxCommandEvent& event )
m_canvas->Refresh( true ); 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<SYMBOL_LIB_TABLE*>( 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;
}

View File

@ -35,6 +35,7 @@
#include <schframe.h> #include <schframe.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <kiface_i.h> #include <kiface_i.h>
#include <richio.h>
#include <eeschema_id.h> #include <eeschema_id.h>
#include <class_library.h> #include <class_library.h>
@ -300,6 +301,10 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
Prj().SchLibs(); 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 ) if( is_new )
{ {
// mark new, unsaved file as modified. // mark new, unsaved file as modified.

View File

@ -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) #if defined(DEBUG)
void SCH_SCREEN::Show( int nestLevel, std::ostream& os ) const void SCH_SCREEN::Show( int nestLevel, std::ostream& os ) const
{ {

View File

@ -37,10 +37,13 @@
using namespace LIB_TABLE_T; 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 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 ) void SYMBOL_LIB_TABLE::Parse( LIB_TABLE_LEXER* in )
{ {
T tok; T tok;
@ -364,7 +373,7 @@ LIB_ALIAS* SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname( const LIB_ID& aLibI
const wxString SYMBOL_LIB_TABLE::GlobalPathEnvVariableName() 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(); return fn.GetFullPath();
} }
const wxString& SYMBOL_LIB_TABLE::GetSymbolLibTableFileName()
{
return global_tbl_name;
}

View File

@ -44,7 +44,8 @@ public:
typedef SCH_IO_MGR::SCH_FILE_T LIB_T; typedef SCH_IO_MGR::SCH_FILE_T LIB_T;
SYMBOL_LIB_TABLE_ROW( const wxString& aNick, const wxString& aURI, const wxString& aType, 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 ) LIB_TABLE_ROW( aNick, aURI, aOptions, aDescr )
{ {
SetType( aType ); SetType( aType );
@ -290,10 +291,9 @@ public:
*/ */
static const wxString GlobalPathEnvVariableName(); static const wxString GlobalPathEnvVariableName();
static SYMBOL_LIB_TABLE& GetGlobalLibTable() { return m_globalLibTable; } static SYMBOL_LIB_TABLE& GetGlobalLibTable();
private: static const wxString& GetSymbolLibTableFileName();
static SYMBOL_LIB_TABLE m_globalLibTable; // There can be only one.
}; };

View File

@ -39,6 +39,7 @@ class PART_LIBS;
class SEARCH_STACK; class SEARCH_STACK;
class S3D_CACHE; class S3D_CACHE;
class KIWAY; class KIWAY;
class SYMBOL_LIB_TABLE;
#define VTBL_ENTRY virtual #define VTBL_ENTRY virtual
@ -193,6 +194,7 @@ public:
ELEM_SCH_PART_LIBS, ELEM_SCH_PART_LIBS,
ELEM_SCH_SEARCH_STACK, ELEM_SCH_SEARCH_STACK,
ELEM_3DCACHE, ELEM_3DCACHE,
ELEM_SYMBOL_LIB_TABLE,
ELEM_COUNT ELEM_COUNT
}; };
@ -278,6 +280,9 @@ public:
/// Accessor for Eeschema search stack. /// Accessor for Eeschema search stack.
SEARCH_STACK* SchSearchS(); SEARCH_STACK* SchSearchS();
/// Accessor for project symbol library table.
SYMBOL_LIB_TABLE* SchSymbolLibTable();
#endif #endif
//-----</KIFACE Specific APIs>----------------------------------------------- //-----</KIFACE Specific APIs>-----------------------------------------------