Pcbnew: minor Geda and KiCad plugin improvements.

* Make GPCB_PLUGIN::EnumerateFootprints() read the directory contents
  instead of loading the entire cache.
* Make KICAD_PLUGIN::EnumerateFootprints() read the directory contents
  instead of loading the entire cache.
This commit is contained in:
Wayne Stambaugh 2013-12-13 18:16:40 -05:00
commit efd9963750
2 changed files with 48 additions and 5 deletions

View File

@ -881,20 +881,41 @@ void GPCB_PLUGIN::cacheLib( const wxString& aLibraryPath, const wxString& aFootp
wxArrayString GPCB_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, wxArrayString GPCB_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath,
const PROPERTIES* aProperties ) const PROPERTIES* aProperties )
{ {
LOCALE_IO toggle; // toggles on, then off, the C locale. LOCALE_IO toggle; // toggles on, then off, the C locale.
wxArrayString ret;
wxDir dir( aLibraryPath );
if( !dir.IsOpened() )
{
THROW_IO_ERROR( wxString::Format( _( "footprint library path '%s' does not exist" ),
GetChars( aLibraryPath ) ) );
}
init( aProperties ); init( aProperties );
#if 1 // Set to 0 to only read directory contents, not load cache.
cacheLib( aLibraryPath ); cacheLib( aLibraryPath );
const MODULE_MAP& mods = m_cache->GetModules(); const MODULE_MAP& mods = m_cache->GetModules();
wxArrayString ret;
for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it ) for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
{ {
ret.Add( FROM_UTF8( it->first.c_str() ) ); ret.Add( FROM_UTF8( it->first.c_str() ) );
} }
#else
wxString fpFileName;
wxString wildcard = wxT( "*." ) + GedaPcbFootprintLibFileExtension;
if( dir.GetFirst( &fpFileName, wildcard, wxDIR_FILES ) )
{
do
{
wxFileName fn( aLibraryPath, fpFileName );
ret.Add( fn.GetName() );
} while( dir.GetNext( &fpFileName ) );
}
#endif
return ret; return ret;
} }

View File

@ -1688,22 +1688,44 @@ void PCB_IO::cacheLib( const wxString& aLibraryPath, const wxString& aFootprintN
} }
wxArrayString PCB_IO::FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties ) wxArrayString PCB_IO::FootprintEnumerate( const wxString& aLibraryPath,
const PROPERTIES* aProperties )
{ {
LOCALE_IO toggle; // toggles on, then off, the C locale. LOCALE_IO toggle; // toggles on, then off, the C locale.
wxArrayString ret;
wxDir dir( aLibraryPath );
if( !dir.IsOpened() )
{
THROW_IO_ERROR( wxString::Format( _( "footprint library path '%s' does not exist" ),
GetChars( aLibraryPath ) ) );
}
init( aProperties ); init( aProperties );
#if 1 // Set to 0 to only read directory contents, not load cache.
cacheLib( aLibraryPath ); cacheLib( aLibraryPath );
const MODULE_MAP& mods = m_cache->GetModules(); const MODULE_MAP& mods = m_cache->GetModules();
wxArrayString ret;
for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it ) for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
{ {
ret.Add( FROM_UTF8( it->first.c_str() ) ); ret.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; return ret;
} }