From 35a9deb3013ff03fc70022c86add439bf97fd2ad Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 13 Dec 2013 18:01:42 -0500 Subject: [PATCH 1/2] 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. --- pcbnew/gpcb_plugin.cpp | 25 +++++++++++++++++++++++-- pcbnew/kicad_plugin.cpp | 28 +++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/pcbnew/gpcb_plugin.cpp b/pcbnew/gpcb_plugin.cpp index 663c560f62..7115561959 100644 --- a/pcbnew/gpcb_plugin.cpp +++ b/pcbnew/gpcb_plugin.cpp @@ -881,20 +881,41 @@ void GPCB_PLUGIN::cacheLib( const wxString& aLibraryPath, const wxString& aFootp wxArrayString GPCB_PLUGIN::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 ); +#if 0 // Set to 0 to only read directory contents, not load cache. cacheLib( aLibraryPath ); const MODULE_MAP& mods = m_cache->GetModules(); - wxArrayString ret; for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it ) { 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; } diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index c60e409898..65bd8453ae 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -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 ); +#if 0 // Set to 0 to only read directory contents, not load cache. cacheLib( aLibraryPath ); const MODULE_MAP& mods = m_cache->GetModules(); - wxArrayString ret; for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it ) { 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; } From 5a9aa812e2450c0387a893efdfccf69241779fff Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 13 Dec 2013 18:14:30 -0500 Subject: [PATCH 2/2] Make old behavior the default in EnumerateFootprint() changes. --- pcbnew/gpcb_plugin.cpp | 2 +- pcbnew/kicad_plugin.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pcbnew/gpcb_plugin.cpp b/pcbnew/gpcb_plugin.cpp index 7115561959..7585aad4f9 100644 --- a/pcbnew/gpcb_plugin.cpp +++ b/pcbnew/gpcb_plugin.cpp @@ -893,7 +893,7 @@ wxArrayString GPCB_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, init( aProperties ); -#if 0 // Set to 0 to only read directory contents, not load cache. +#if 1 // Set to 0 to only read directory contents, not load cache. cacheLib( aLibraryPath ); const MODULE_MAP& mods = m_cache->GetModules(); diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index 65bd8453ae..5a2caa377b 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -1703,7 +1703,7 @@ wxArrayString PCB_IO::FootprintEnumerate( const wxString& aLibraryPath, init( aProperties ); -#if 0 // Set to 0 to only read directory contents, not load cache. +#if 1 // Set to 0 to only read directory contents, not load cache. cacheLib( aLibraryPath ); const MODULE_MAP& mods = m_cache->GetModules();