Pcbnew: plugin improvements.

Allow partial library reads in libraries that support footprint per file.
This includes the KiCad and GEDA footprint libraries.

Allow for partially cached libraries rather than ignoring all valid files
when an error occurs.
This commit is contained in:
Wayne Stambaugh 2017-06-11 16:20:44 -04:00
parent 44b118f8cc
commit 3cec63e9b9
19 changed files with 108 additions and 81 deletions

View File

@ -197,11 +197,12 @@ void FP_LIB_TABLE::Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const
}
wxArrayString FP_LIB_TABLE::FootprintEnumerate( const wxString& aNickname )
void FP_LIB_TABLE::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname )
{
const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
wxASSERT( (PLUGIN*) row->plugin );
return row->plugin->FootprintEnumerate( row->GetFullURI( true ), row->GetProperties() );
row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ),
row->GetProperties() );
}

View File

@ -150,7 +150,9 @@ static int guessNickname( FP_LIB_TABLE* aTbl, LIB_ID* aFootprintId )
// Search each library going through libraries alphabetically.
for( unsigned libNdx = 0; libNdx<nicks.size(); ++libNdx )
{
wxArrayString fpnames = aTbl->FootprintEnumerate( nicks[libNdx] );
wxArrayString fpnames;
aTbl->FootprintEnumerate( fpnames, nicks[libNdx] );
for( unsigned nameNdx = 0; nameNdx<fpnames.size(); ++nameNdx )
{

View File

@ -146,7 +146,7 @@ public:
*
* @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded.
*/
wxArrayString FootprintEnumerate( const wxString& aNickname );
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname );
/**
* Function PrefetchLib

View File

@ -4,7 +4,7 @@
* Copyright (C) 2015 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
* Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -177,7 +177,7 @@ bool WIZARD_FPLIB_TABLE::LIBRARY::Test()
try
{
footprints = p->FootprintEnumerate( m_path );
p->FootprintEnumerate( footprints, m_path );
}
catch( IO_ERROR& )
{
@ -656,7 +656,9 @@ bool WIZARD_FPLIB_TABLE::downloadGithubLibsFromList( wxArrayString& aUrlList,
PLUGIN::RELEASER src( IO_MGR::PluginFind( IO_MGR::GITHUB ) );
PLUGIN::RELEASER dst( IO_MGR::PluginFind( IO_MGR::KICAD ) );
wxArrayString footprints = src->FootprintEnumerate( libsrc_name );
wxArrayString footprints;
src->FootprintEnumerate( footprints, libsrc_name );
for( unsigned i = 0; i < footprints.size(); ++i )
{

View File

@ -2080,18 +2080,15 @@ void EAGLE_PLUGIN::cacheLib( const wxString& aLibPath )
}
wxArrayString EAGLE_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
void EAGLE_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties )
{
init( aProperties );
cacheLib( aLibraryPath );
wxArrayString ret;
for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it )
ret.Add( FROM_UTF8( it->first.c_str() ) );
return ret;
aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
}

View File

@ -5,7 +5,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012-2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2012-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -87,11 +87,13 @@ public:
//-----<PUBLIC PLUGIN API>--------------------------------------------------
const wxString PluginName() const override;
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties = NULL ) override;
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
const PROPERTIES* aProperties = NULL ) override;
const wxString GetFileExtension() const override;
wxArrayString FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL) override;
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL) override;
MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL ) override;

View File

@ -189,15 +189,35 @@ bool FOOTPRINT_LIST_IMPL::JoinWorkers()
while( this->m_queue_out.pop( nickname ) )
{
CatchErrors( [this, &queue_parsed, &nickname]() {
wxArrayString fpnames = this->m_lib_table->FootprintEnumerate( nickname );
wxArrayString fpnames;
for( auto const& fpname : fpnames )
try
{
this->m_lib_table->FootprintEnumerate( fpnames, nickname );
}
catch( const IO_ERROR& ioe )
{
m_errors.move_push( std::make_unique<IO_ERROR>( ioe ) );
}
catch( const std::exception& se )
{
// This is a round about way to do this, but who knows what THROW_IO_ERROR()
// may be tricked out to do someday, keep it in the game.
try
{
FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO_IMPL( this, nickname, fpname );
queue_parsed.move_push( std::unique_ptr<FOOTPRINT_INFO>( fpinfo ) );
THROW_IO_ERROR( se.what() );
}
} );
catch( const IO_ERROR& ioe )
{
m_errors.move_push( std::make_unique<IO_ERROR>( ioe ) );
}
}
for( auto const& fpname : fpnames )
{
FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO_IMPL( this, nickname, fpname );
queue_parsed.move_push( std::unique_ptr<FOOTPRINT_INFO>( fpinfo ) );
}
}
} ) );
}

View File

@ -131,7 +131,7 @@ const wxString GITHUB_PLUGIN::GetFileExtension() const
}
wxArrayString GITHUB_PLUGIN::FootprintEnumerate(
void GITHUB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames,
const wxString& aLibraryPath, const PROPERTIES* aProperties )
{
//D(printf("%s: this:%p aLibraryPath:'%s'\n", __func__, this, TO_UTF8(aLibraryPath) );)
@ -143,7 +143,9 @@ wxArrayString GITHUB_PLUGIN::FootprintEnumerate(
if( m_pretty_dir.size() )
{
wxArrayString locals = PCB_IO::FootprintEnumerate( m_pretty_dir );
wxArrayString locals;
PCB_IO::FootprintEnumerate( locals, m_pretty_dir );
for( unsigned i=0; i<locals.GetCount(); ++i )
unique.insert( locals[i] );
@ -154,14 +156,10 @@ wxArrayString GITHUB_PLUGIN::FootprintEnumerate(
unique.insert( FROM_UTF8( it->first.c_str() ) );
}
wxArrayString ret;
for( MYSET::const_iterator it = unique.begin(); it != unique.end(); ++it )
{
ret.Add( *it );
aFootprintNames.Add( *it );
}
return ret;
}
@ -283,7 +281,9 @@ void GITHUB_PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxStrin
// Does the PCB_IO base class have this footprint?
// We cannot write to github.
wxArrayString pretties = PCB_IO::FootprintEnumerate( m_pretty_dir, aProperties );
wxArrayString pretties;
PCB_IO::FootprintEnumerate( pretties, m_pretty_dir, aProperties );
if( pretties.Index( aFootprintName ) != wxNOT_FOUND )
{

View File

@ -167,7 +167,7 @@ public:
const wxString GetFileExtension() const override;
wxArrayString FootprintEnumerate( const wxString& aLibraryPath,
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ) override;
void PrefetchLib( const wxString& aLibraryPath,

View File

@ -971,11 +971,11 @@ void GPCB_PLUGIN::cacheLib( const wxString& aLibraryPath, const wxString& aFootp
}
wxArrayString GPCB_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath,
const PROPERTIES* aProperties )
void GPCB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames,
const wxString& aLibraryPath,
const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
wxArrayString ret;
wxDir dir( aLibraryPath );
if( !dir.IsOpened() )
@ -1003,13 +1003,11 @@ wxArrayString GPCB_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath,
for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
{
ret.Add( FROM_UTF8( it->first.c_str() ) );
aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
}
if( !errorMsg.IsEmpty() )
THROW_IO_ERROR( errorMsg );
return ret;
}

View File

@ -1,8 +1,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2012-2017 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -62,8 +62,8 @@ public:
return wxT( "fp" );
}
wxArrayString FootprintEnumerate( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL) override;
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL) override;
MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL ) override;
@ -71,7 +71,8 @@ public:
void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL ) override;
bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL ) override;
bool FootprintLibDelete( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ) override;
bool IsFootprintLibWritable( const wxString& aLibraryPath ) override;

View File

@ -279,8 +279,8 @@ public:
*
* @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded.
*/
virtual wxArrayString FootprintEnumerate( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL );
virtual void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL );
/**
* Function PrefetchLib

View File

@ -1833,11 +1833,11 @@ void PCB_IO::cacheLib( const wxString& aLibraryPath, const wxString& aFootprintN
}
wxArrayString PCB_IO::FootprintEnumerate( const wxString& aLibraryPath,
const PROPERTIES* aProperties )
void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames,
const wxString& aLibraryPath,
const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
wxArrayString ret;
wxDir dir( aLibraryPath );
if( !dir.IsOpened() )
@ -1848,31 +1848,28 @@ wxArrayString PCB_IO::FootprintEnumerate( const wxString& aLibraryPath,
init( aProperties );
#if 1 // Set to 0 to only read directory contents, not load cache.
cacheLib( aLibraryPath );
wxString errorMsg;
// Some of the files may have been parsed correctly so we want to add the valid files to
// the library.
try
{
cacheLib( aLibraryPath );
}
catch( const IO_ERROR& ioe )
{
errorMsg = ioe.What();
}
const MODULE_MAP& mods = m_cache->GetModules();
for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
{
ret.Add( FROM_UTF8( it->first.c_str() ) );
aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
}
#else
wxString fpFileName;
wxString wildcard = wxT( "*." ) + KiCadFootprintFileExtension;
if( dir.GetFirst( &fpFileName, wildcard, wxDIR_FILES ) )
{
do
{
wxFileName fn( aLibraryPath, fpFileName );
ret.Add( fn.GetName() );
} while( dir.GetNext( &fpFileName ) );
}
#endif
return ret;
if( !errorMsg.IsEmpty() )
THROW_IO_ERROR( errorMsg );
}

View File

@ -110,9 +110,10 @@ public:
void Save( const wxString& aFileName, BOARD* aBoard,
const PROPERTIES* aProperties = NULL ) override;
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties = NULL ) override;
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
const PROPERTIES* aProperties = NULL ) override;
wxArrayString FootprintEnumerate( const wxString& aLibraryPath,
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ) override;
MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
@ -121,7 +122,8 @@ public:
void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
const PROPERTIES* aProperties = NULL ) override;
void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL ) override;
void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL ) override;
void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL) override;

View File

@ -3388,7 +3388,9 @@ void LEGACY_PLUGIN::cacheLib( const wxString& aLibraryPath )
}
wxArrayString LEGACY_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
void LEGACY_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames,
const wxString& aLibraryPath,
const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
@ -3398,14 +3400,10 @@ wxArrayString LEGACY_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, c
const MODULE_MAP& mods = m_cache->m_modules;
wxArrayString ret;
for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
{
ret.Add( FROM_UTF8( it->first.c_str() ) );
aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
}
return ret;
}

View File

@ -5,7 +5,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -84,13 +84,14 @@ public:
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
const PROPERTIES* aProperties = NULL ) override;
wxArrayString FootprintEnumerate( const wxString& aLibraryPath,
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ) override;
MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL ) override;
bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL ) override;
bool FootprintLibDelete( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ) override;
bool IsFootprintLibWritable( const wxString& aLibraryPath ) override;

View File

@ -551,7 +551,9 @@ void FOOTPRINT_EDIT_FRAME::OnSaveLibraryAs( wxCommandEvent& aEvent )
PLUGIN::RELEASER cur( IO_MGR::PluginFind( curType ) );
PLUGIN::RELEASER dst( IO_MGR::PluginFind( dstType ) );
wxArrayString mods = cur->FootprintEnumerate( curLibPath );
wxArrayString mods;
cur->FootprintEnumerate( mods, curLibPath );
for( unsigned i = 0; i < mods.size(); ++i )
{

View File

@ -412,7 +412,11 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
if( fp_info_list->GetErrorCount() )
{
fp_info_list->DisplayErrors( this );
return;
// For footprint libraries that support one footprint per file, there may have been
// valid footprints read so show the footprints that loaded properly.
if( fp_info_list->GetList().size() == 0 )
return;
}
for( auto& footprint : fp_info_list->GetList() )

View File

@ -58,11 +58,11 @@ void PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* a
}
wxArrayString PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
void PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties )
{
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
not_implemented( this, __FUNCTION__ );
return wxArrayString();
}