Load footprint info when there's no cache available.

Fixes https://gitlab.com/kicad/code/kicad/issues/8371
This commit is contained in:
Jeff Young 2021-05-14 22:23:40 +01:00
parent ebd53cd45c
commit ccaf9e11df
4 changed files with 28 additions and 18 deletions

View File

@ -144,9 +144,7 @@ FOOTPRINT_LIST* FOOTPRINT_LIST::GetInstance( KIWAY& aKiway )
return nullptr;
if( !footprintInfo->GetCount() )
{
footprintInfo->ReadCacheFromFile( aKiway.Prj().GetProjectPath() + "fp-info-cache" );
}
return footprintInfo;
}

View File

@ -23,14 +23,15 @@
#include <project.h>
#include <widgets/footprint_choice.h>
#include <widgets/footprint_select_widget.h>
#include <wx/wupdlock.h>
#include <widgets/progress_reporter.h>
#include <footprint_info_impl.h>
#include <wx/wupdlock.h>
extern FOOTPRINT_LIST_IMPL GFootprintList; // KIFACE scope.
wxDEFINE_EVENT( EVT_FOOTPRINT_SELECTED, wxCommandEvent );
FOOTPRINT_SELECT_WIDGET::FOOTPRINT_SELECT_WIDGET( EDA_DRAW_FRAME* aFrame, wxWindow* aParent,
FOOTPRINT_LIST* aFpList, bool aUpdate,
int aMaxItems ) :
@ -60,6 +61,15 @@ void FOOTPRINT_SELECT_WIDGET::Load( KIWAY& aKiway, PROJECT& aProject )
try
{
m_fp_list = FOOTPRINT_LIST::GetInstance( aKiway );
if( m_fp_list->GetCount() == 0 )
{
// If the fp-info-cache is empty (or, more likely, hasn't been created in a new
// project yet), load footprints the hard way.
FP_LIB_TABLE* fpTable = aProject.PcbFootprintLibs( aKiway );
static_cast<FOOTPRINT_LIST_IMPL*>( m_fp_list )->ReadFootprintFiles( fpTable );
}
m_fp_filter.SetList( *m_fp_list );
}
catch( ... )
@ -137,7 +147,7 @@ bool FOOTPRINT_SELECT_WIDGET::UpdateList()
if( !m_zero_filter )
{
for( auto& fpinfo : m_fp_filter )
for( FOOTPRINT_INFO& fpinfo : m_fp_filter )
{
wxString display_name( fpinfo.GetLibNickname() + ":" + fpinfo.GetFootprintName() );

View File

@ -811,10 +811,10 @@ void FOOTPRINT_EDIT_FRAME::initLibraryTree()
FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
if( GFootprintList.GetCount() == 0 )
{
GFootprintList.ReadCacheFromFile( Prj().GetProjectPath() + "fp-info-cache" );
}
GFootprintList.ReadFootprintFiles( fpTable, NULL, &progressReporter );
progressReporter.Show( false );

View File

@ -395,14 +395,16 @@ void FOOTPRINT_LIST_IMPL::ReadCacheFromFile( const wxString& aFilePath )
{
wxString libNickname = cacheFile.GetNextLine();
wxString name = cacheFile.GetNextLine();
wxString description = UnescapeString( cacheFile.GetNextLine() );
wxString desc = UnescapeString( cacheFile.GetNextLine() );
wxString keywords = UnescapeString( cacheFile.GetNextLine() );
int orderNum = wxAtoi( cacheFile.GetNextLine() );
unsigned int padCount = (unsigned) wxAtoi( cacheFile.GetNextLine() );
unsigned int uniquePadCount = (unsigned) wxAtoi( cacheFile.GetNextLine() );
auto* fpinfo = new FOOTPRINT_INFO_IMPL( libNickname, name, description, keywords,
orderNum, padCount, uniquePadCount );
FOOTPRINT_INFO_IMPL* fpinfo = new FOOTPRINT_INFO_IMPL( libNickname, name, desc,
keywords, orderNum,
padCount, uniquePadCount );
m_list.emplace_back( std::unique_ptr<FOOTPRINT_INFO>( fpinfo ) );
}
}