Implement shared FOOTPRINT_LIST.
While we already cache the loaded footprint files, parsing said files into the list is also time-intensive. Since the FOOTPRINT_LIST is already hash-stamped against the current timestamps of the files that make up the list, sharing a single copy of the list is quite straight-forward.
This commit is contained in:
parent
b24b0d5dfe
commit
f4ce8766e3
|
@ -109,7 +109,7 @@ void FOOTPRINT_LIST::DisplayErrors( wxTopLevelWindow* aWindow )
|
|||
}
|
||||
|
||||
|
||||
static std::unique_ptr<FOOTPRINT_LIST> get_instance_from_id( KIWAY& aKiway, int aId )
|
||||
static FOOTPRINT_LIST* get_instance_from_id( KIWAY& aKiway, int aId )
|
||||
{
|
||||
void* ptr = nullptr;
|
||||
|
||||
|
@ -130,11 +130,11 @@ static std::unique_ptr<FOOTPRINT_LIST> get_instance_from_id( KIWAY& aKiway, int
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
return std::unique_ptr<FOOTPRINT_LIST>( (FOOTPRINT_LIST*) ( ptr ) );
|
||||
return static_cast<FOOTPRINT_LIST*>( ptr );
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<FOOTPRINT_LIST> FOOTPRINT_LIST::GetInstance( KIWAY& aKiway )
|
||||
FOOTPRINT_LIST* FOOTPRINT_LIST::GetInstance( KIWAY& aKiway )
|
||||
{
|
||||
return get_instance_from_id( aKiway, KIFACE_NEW_FOOTPRINT_LIST );
|
||||
}
|
||||
|
|
|
@ -245,7 +245,6 @@ long long FP_LIB_TABLE::GenerateTimestamp( const wxString* aNickname )
|
|||
}
|
||||
|
||||
long long hash = 0;
|
||||
|
||||
for( wxString const& nickname : GetLogicalLibs() )
|
||||
{
|
||||
const FP_LIB_TABLE_ROW* row = FindRow( nickname );
|
||||
|
|
|
@ -61,7 +61,7 @@ wxDEFINE_EVENT( EVT_FOOTPRINT_SELECTED, wxCommandEvent );
|
|||
|
||||
|
||||
FOOTPRINT_SELECT_WIDGET::FOOTPRINT_SELECT_WIDGET( wxWindow* aParent,
|
||||
FOOTPRINT_ASYNC_LOADER& aLoader, std::unique_ptr<FOOTPRINT_LIST>& aFpList, bool aUpdate,
|
||||
FOOTPRINT_LIST* aFpList, bool aUpdate,
|
||||
int aMaxItems )
|
||||
: wxPanel( aParent ),
|
||||
m_kiway( nullptr ),
|
||||
|
@ -69,7 +69,6 @@ FOOTPRINT_SELECT_WIDGET::FOOTPRINT_SELECT_WIDGET( wxWindow* aParent,
|
|||
m_finished_loading( false ),
|
||||
m_max_items( aMaxItems ),
|
||||
m_last_item( 0 ),
|
||||
m_fp_loader( aLoader ),
|
||||
m_fp_list( aFpList )
|
||||
{
|
||||
m_zero_filter = true;
|
||||
|
|
|
@ -73,7 +73,8 @@ class CVPCB_MAINFRAME : public KIWAY_PLAYER
|
|||
public:
|
||||
wxArrayString m_ModuleLibNames;
|
||||
wxArrayString m_EquFilesNames;
|
||||
std::unique_ptr<FOOTPRINT_LIST> m_FootprintsList;
|
||||
|
||||
FOOTPRINT_LIST* m_FootprintsList;
|
||||
|
||||
protected:
|
||||
int m_undefinedComponentCnt;
|
||||
|
|
|
@ -45,9 +45,6 @@
|
|||
#include <widgets/footprint_select_widget.h>
|
||||
|
||||
|
||||
FOOTPRINT_ASYNC_LOADER DIALOG_CHOOSE_COMPONENT::m_fp_loader;
|
||||
std::unique_ptr<FOOTPRINT_LIST> DIALOG_CHOOSE_COMPONENT::m_fp_list;
|
||||
|
||||
wxSize DIALOG_CHOOSE_COMPONENT::m_last_dlg_size( -1, -1 );
|
||||
int DIALOG_CHOOSE_COMPONENT::m_tree_canvas_sash_position = 0;
|
||||
|
||||
|
@ -66,6 +63,8 @@ DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const
|
|||
{
|
||||
wxBusyCursor busy_while_loading;
|
||||
|
||||
m_fp_list = FOOTPRINT_LIST::GetInstance( Kiway() );
|
||||
|
||||
auto sizer = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
// Use a slightly different layout, with a details pane spanning the entire window,
|
||||
|
@ -161,7 +160,7 @@ wxPanel* DIALOG_CHOOSE_COMPONENT::ConstructRightPanel( wxWindow* aParent )
|
|||
if( m_show_footprints )
|
||||
{
|
||||
if( m_allow_field_edits )
|
||||
m_fp_sel_ctrl = new FOOTPRINT_SELECT_WIDGET( panel, m_fp_loader, m_fp_list, true );
|
||||
m_fp_sel_ctrl = new FOOTPRINT_SELECT_WIDGET( panel, m_fp_list, true );
|
||||
|
||||
m_fp_view_ctrl = new FOOTPRINT_PREVIEW_WIDGET( panel, Kiway() );
|
||||
|
||||
|
|
|
@ -208,9 +208,8 @@ protected:
|
|||
bool m_external_browser_requested;
|
||||
wxString m_fp_override;
|
||||
|
||||
static FOOTPRINT_ASYNC_LOADER m_fp_loader;
|
||||
static std::unique_ptr<FOOTPRINT_LIST> m_fp_list;
|
||||
std::vector<std::pair<int, wxString>> m_field_edits;
|
||||
FOOTPRINT_LIST* m_fp_list;
|
||||
std::vector<std::pair<int, wxString>> m_field_edits;
|
||||
|
||||
// Remember the dialog size during a session
|
||||
static wxSize m_last_dlg_size;
|
||||
|
|
|
@ -265,12 +265,12 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Factory function to return a new FOOTPRINT_LIST via Kiway. NOT guaranteed
|
||||
* Factory function to return a FOOTPRINT_LIST via Kiway. NOT guaranteed
|
||||
* to succeed; will return null if the kiface is not available.
|
||||
*
|
||||
* @param aKiway - active kiway instance
|
||||
*/
|
||||
static std::unique_ptr<FOOTPRINT_LIST> GetInstance( KIWAY& aKiway );
|
||||
static FOOTPRINT_LIST* GetInstance( KIWAY& aKiway );
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
|
|
@ -59,14 +59,13 @@ public:
|
|||
* loaded more than once.
|
||||
*
|
||||
* @param aParent - parent window
|
||||
* @param aLoader - FOOTPRINT_ASYNC_LOADER instance
|
||||
* @param aFpList - FOOTPRINT_LIST container
|
||||
* @param aUpdate - whether to call UpdateList() automatically when finished loading
|
||||
* @param aMaxItems - maximum number of filter items to display, in addition to
|
||||
* Default and Other
|
||||
*/
|
||||
FOOTPRINT_SELECT_WIDGET( wxWindow* aParent, FOOTPRINT_ASYNC_LOADER& aLoader,
|
||||
std::unique_ptr<FOOTPRINT_LIST>& aFpList, bool aUpdate = true, int aMaxItems = 400 );
|
||||
FOOTPRINT_SELECT_WIDGET( wxWindow* aParent, FOOTPRINT_LIST* aFpList,
|
||||
bool aUpdate = true, int aMaxItems = 400 );
|
||||
|
||||
virtual ~FOOTPRINT_SELECT_WIDGET()
|
||||
{
|
||||
|
@ -145,10 +144,10 @@ private:
|
|||
wxString m_other_footprint;
|
||||
int m_last_item;
|
||||
|
||||
FOOTPRINT_ASYNC_LOADER& m_fp_loader;
|
||||
std::unique_ptr<FOOTPRINT_LIST>& m_fp_list;
|
||||
FOOTPRINT_FILTER m_fp_filter;
|
||||
bool m_zero_filter;
|
||||
FOOTPRINT_ASYNC_LOADER m_fp_loader;
|
||||
FOOTPRINT_LIST* m_fp_list;
|
||||
FOOTPRINT_FILTER m_fp_filter;
|
||||
bool m_zero_filter;
|
||||
|
||||
void OnProgressTimer( wxTimerEvent& aEvent );
|
||||
void OnComboBox( wxCommandEvent& aEvent );
|
||||
|
|
|
@ -118,8 +118,7 @@ void FOOTPRINT_LIST_IMPL::loader_job()
|
|||
bool FOOTPRINT_LIST_IMPL::ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname,
|
||||
WX_PROGRESS_REPORTER* aProgressReporter )
|
||||
{
|
||||
long long libraryTimestamp = aTable->GenerateTimestamp( aNickname );
|
||||
if( m_list_timestamp == libraryTimestamp )
|
||||
if( m_list_timestamp == aTable->GenerateTimestamp( aNickname ) )
|
||||
return true;
|
||||
|
||||
m_progress_reporter = aProgressReporter;
|
||||
|
@ -167,7 +166,7 @@ bool FOOTPRINT_LIST_IMPL::ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxStri
|
|||
( _( "Loading incomplete; cancelled by user." ), nullptr, nullptr, 0 ) );
|
||||
}
|
||||
|
||||
m_list_timestamp = libraryTimestamp;
|
||||
m_list_timestamp = aTable->GenerateTimestamp( aNickname );;
|
||||
m_progress_reporter = nullptr;
|
||||
|
||||
return m_errors.empty();
|
||||
|
|
|
@ -93,4 +93,7 @@ public:
|
|||
WX_PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
|
||||
};
|
||||
|
||||
extern FOOTPRINT_LIST_IMPL GFootprintList; // KIFACE scope.
|
||||
|
||||
|
||||
#endif // FOOTPRINT_INFO_IMPL_H
|
||||
|
|
|
@ -405,7 +405,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
|
|||
return;
|
||||
}
|
||||
|
||||
auto fp_info_list( FOOTPRINT_LIST::GetInstance( Kiway() ) );
|
||||
auto fp_info_list = FOOTPRINT_LIST::GetInstance( Kiway() );
|
||||
|
||||
wxString nickname = getCurNickname();
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ wxString g_DocModulesFileName = wxT( "footprints_doc/footprints.pdf" );
|
|||
DLIST<TRACK> g_CurrentTrackList;
|
||||
|
||||
|
||||
|
||||
namespace PCB {
|
||||
|
||||
static struct IFACE : public KIFACE_I
|
||||
|
@ -167,7 +168,7 @@ static struct IFACE : public KIFACE_I
|
|||
switch( aDataId )
|
||||
{
|
||||
case KIFACE_NEW_FOOTPRINT_LIST:
|
||||
return (void*) static_cast<FOOTPRINT_LIST*>( new FOOTPRINT_LIST_IMPL() );
|
||||
return (void*) &GFootprintList;
|
||||
|
||||
case KIFACE_G_FOOTPRINT_TABLE:
|
||||
return (void*) new FP_LIB_TABLE( &GFootprintTable );
|
||||
|
@ -309,7 +310,13 @@ void PythonPluginsReloadBase()
|
|||
/// The global footprint 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).
|
||||
FP_LIB_TABLE GFootprintTable;
|
||||
FP_LIB_TABLE GFootprintTable;
|
||||
|
||||
/// The global footprint info table. This is performance-intensive to build so we
|
||||
/// keep a hash-stamped global version. Any deviation from the request vs. stored
|
||||
/// hash will result in it being rebuilt.
|
||||
FOOTPRINT_LIST_IMPL GFootprintList;
|
||||
|
||||
|
||||
|
||||
bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
|
||||
|
|
Loading…
Reference in New Issue