mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-11 16:10:10 +00:00
design blocks: move globals behind accessor functions
Prepare for lazy loading
This commit is contained in:
parent
b2dda11fae
commit
2eec2489ea
@ -672,6 +672,18 @@ bool DESIGN_BLOCK_LIB_TABLE::LoadGlobalTable( DESIGN_BLOCK_LIB_TABLE& aTable )
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK_LIB_TABLE& DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable()
|
||||
{
|
||||
return GDesignBlockTable;
|
||||
}
|
||||
|
||||
|
||||
DESIGN_BLOCK_LIST_IMPL& DESIGN_BLOCK_LIB_TABLE::GetGlobalList()
|
||||
{
|
||||
return GDesignBlockList;
|
||||
}
|
||||
|
||||
|
||||
wxString DESIGN_BLOCK_LIB_TABLE::GetGlobalTableFileName()
|
||||
{
|
||||
wxFileName fn;
|
||||
|
@ -1157,7 +1157,7 @@ size_t PANEL_DESIGN_BLOCK_LIB_TABLE::m_pageNdx = 0;
|
||||
|
||||
void InvokeEditDesignBlockLibTable( KIWAY* aKiway, wxWindow *aParent )
|
||||
{
|
||||
DESIGN_BLOCK_LIB_TABLE* globalTable = &GDesignBlockTable;
|
||||
DESIGN_BLOCK_LIB_TABLE* globalTable = &DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable();
|
||||
wxString globalTablePath = DESIGN_BLOCK_LIB_TABLE::GetGlobalTableFileName();
|
||||
DESIGN_BLOCK_LIB_TABLE* projectTable = aKiway->Prj().DesignBlockLibs();
|
||||
wxString projectTablePath = aKiway->Prj().DesignBlockLibTblName();
|
||||
|
@ -430,7 +430,7 @@ DESIGN_BLOCK_LIB_TABLE* PROJECT::DesignBlockLibs()
|
||||
{
|
||||
try
|
||||
{
|
||||
tbl = new DESIGN_BLOCK_LIB_TABLE( &GDesignBlockTable );
|
||||
tbl = new DESIGN_BLOCK_LIB_TABLE( &DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable() );
|
||||
tbl->Load( DesignBlockLibTblName() );
|
||||
|
||||
SetElem( ELEM::DESIGN_BLOCK_LIB_TABLE, tbl );
|
||||
|
@ -93,9 +93,9 @@ DESIGN_BLOCK_TREE_MODEL_ADAPTER::getDesignBlocks( EDA_BASE_FRAME* aParent,
|
||||
{
|
||||
std::vector<LIB_TREE_ITEM*> libList;
|
||||
|
||||
auto fullListStart = DESIGN_BLOCK_LIB_TABLE::GetGlobalList().GetList().begin();
|
||||
auto fullListEnd = DESIGN_BLOCK_LIB_TABLE::GetGlobalList().GetList().end();
|
||||
|
||||
auto fullListStart = GDesignBlockList.GetList().begin();
|
||||
auto fullListEnd = GDesignBlockList.GetList().end();
|
||||
std::unique_ptr<DESIGN_BLOCK_INFO> dummy =
|
||||
std::make_unique<DESIGN_BLOCK_INFO_IMPL>( aLibName, wxEmptyString );
|
||||
|
||||
|
@ -44,7 +44,7 @@ DESIGN_BLOCK_LIB_TABLE* SCH_EDIT_FRAME::selectDesignBlockLibTable( bool aOptiona
|
||||
// If no project is loaded, always work with the global table
|
||||
if( Prj().IsNullProject() )
|
||||
{
|
||||
DESIGN_BLOCK_LIB_TABLE* ret = &GDesignBlockTable;
|
||||
DESIGN_BLOCK_LIB_TABLE* ret = &DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable();
|
||||
|
||||
if( aOptional )
|
||||
{
|
||||
@ -76,7 +76,7 @@ DESIGN_BLOCK_LIB_TABLE* SCH_EDIT_FRAME::selectDesignBlockLibTable( bool aOptiona
|
||||
|
||||
switch( dlg.GetSelection() )
|
||||
{
|
||||
case 0: return &GDesignBlockTable;
|
||||
case 0: return &DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable();
|
||||
case 1: return Prj().DesignBlockLibs();
|
||||
default: return nullptr;
|
||||
}
|
||||
@ -99,7 +99,7 @@ wxString SCH_EDIT_FRAME::createNewDesignBlockLibrary( const wxString& aL
|
||||
|
||||
wxFileName fn;
|
||||
bool doAdd = false;
|
||||
bool isGlobal = ( aTable == &GDesignBlockTable );
|
||||
bool isGlobal = ( aTable == &DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable() );
|
||||
wxString initialPath = aProposedName;
|
||||
|
||||
if( initialPath.IsEmpty() )
|
||||
@ -196,7 +196,7 @@ bool SCH_EDIT_FRAME::AddDesignBlockLibrary( const wxString& aFilename,
|
||||
if( aTable == nullptr )
|
||||
return wxEmptyString;
|
||||
|
||||
bool isGlobal = ( aTable == &GDesignBlockTable );
|
||||
bool isGlobal = ( aTable == &DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable() );
|
||||
|
||||
wxFileName fn( aFilename );
|
||||
|
||||
@ -244,7 +244,8 @@ bool SCH_EDIT_FRAME::AddDesignBlockLibrary( const wxString& aFilename,
|
||||
aTable->InsertRow( row );
|
||||
|
||||
if( isGlobal )
|
||||
GDesignBlockTable.Save( DESIGN_BLOCK_LIB_TABLE::GetGlobalTableFileName() );
|
||||
DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable().Save(
|
||||
DESIGN_BLOCK_LIB_TABLE::GetGlobalTableFileName() );
|
||||
else
|
||||
Prj().DesignBlockLibs()->Save( Prj().DesignBlockLibTblName() );
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ PANEL_DESIGN_BLOCK_CHOOSER::PANEL_DESIGN_BLOCK_CHOOSER( SCH_EDIT_FRAME* aFrame,
|
||||
// Load design block files:
|
||||
WX_PROGRESS_REPORTER* progressReporter =
|
||||
new WX_PROGRESS_REPORTER( aParent, _( "Loading Design Block Libraries" ), 3 );
|
||||
GDesignBlockList.ReadDesignBlockFiles( libs, nullptr, progressReporter );
|
||||
DESIGN_BLOCK_LIB_TABLE::GetGlobalList().ReadDesignBlockFiles( libs, nullptr, progressReporter );
|
||||
|
||||
// Force immediate deletion of the WX_PROGRESS_REPORTER. Do not use Destroy(), or use
|
||||
// Destroy() followed by wxSafeYield() because on Windows, APP_PROGRESS_DIALOG and
|
||||
@ -78,7 +78,7 @@ PANEL_DESIGN_BLOCK_CHOOSER::PANEL_DESIGN_BLOCK_CHOOSER( SCH_EDIT_FRAME* aFrame,
|
||||
// WX_PROGRESS_REPORTER results in incorrect modal or quasi modal behavior.
|
||||
delete progressReporter;
|
||||
|
||||
if( GDesignBlockList.GetErrorCount() )
|
||||
if( DESIGN_BLOCK_LIB_TABLE::GetGlobalList().GetErrorCount() )
|
||||
displayErrors( aFrame );
|
||||
|
||||
m_adapter = DESIGN_BLOCK_TREE_MODEL_ADAPTER::Create( m_frame, libs );
|
||||
@ -260,12 +260,13 @@ void PANEL_DESIGN_BLOCK_CHOOSER::RefreshLibs( bool aProgress )
|
||||
if( aProgress )
|
||||
{
|
||||
WX_PROGRESS_REPORTER progressReporter( this, _( "Updating Design Block Libraries" ), 2 );
|
||||
GDesignBlockList.ReadDesignBlockFiles( fpTable, nullptr, &progressReporter );
|
||||
DESIGN_BLOCK_LIB_TABLE::GetGlobalList().ReadDesignBlockFiles( fpTable, nullptr,
|
||||
&progressReporter );
|
||||
progressReporter.Show( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
GDesignBlockList.ReadDesignBlockFiles( fpTable, nullptr, nullptr );
|
||||
DESIGN_BLOCK_LIB_TABLE::GetGlobalList().ReadDesignBlockFiles( fpTable, nullptr, nullptr );
|
||||
}
|
||||
|
||||
rebuildHistoryNode();
|
||||
@ -392,8 +393,8 @@ void PANEL_DESIGN_BLOCK_CHOOSER::rebuildHistoryNode()
|
||||
|
||||
for( const LIB_ID& lib : m_historyList )
|
||||
{
|
||||
LIB_TREE_ITEM* fp_info =
|
||||
GDesignBlockList.GetDesignBlockInfo( lib.GetLibNickname(), lib.GetLibItemName() );
|
||||
LIB_TREE_ITEM* fp_info = DESIGN_BLOCK_LIB_TABLE::GetGlobalList().GetDesignBlockInfo(
|
||||
lib.GetLibNickname(), lib.GetLibItemName() );
|
||||
|
||||
// this can be null, for example, if the design block has been deleted from a library.
|
||||
if( fp_info != nullptr )
|
||||
@ -416,7 +417,7 @@ void PANEL_DESIGN_BLOCK_CHOOSER::displayErrors( wxTopLevelWindow* aWindow )
|
||||
|
||||
wxString msg;
|
||||
|
||||
while( std::unique_ptr<IO_ERROR> error = GDesignBlockList.PopError() )
|
||||
while( std::unique_ptr<IO_ERROR> error = DESIGN_BLOCK_LIB_TABLE::GetGlobalList().PopError() )
|
||||
{
|
||||
wxString tmp = EscapeHTML( error->Problem() );
|
||||
|
||||
|
@ -266,6 +266,10 @@ public:
|
||||
*/
|
||||
static bool LoadGlobalTable( DESIGN_BLOCK_LIB_TABLE& aTable );
|
||||
|
||||
static DESIGN_BLOCK_LIB_TABLE& GetGlobalLibTable();
|
||||
|
||||
static DESIGN_BLOCK_LIST_IMPL& GetGlobalList();
|
||||
|
||||
/**
|
||||
* @return the platform specific global design block library path and file name.
|
||||
*/
|
||||
@ -285,7 +289,4 @@ private:
|
||||
friend class DESIGN_BLOCK_LIB_TABLE_GRID;
|
||||
};
|
||||
|
||||
KICOMMON_API extern DESIGN_BLOCK_LIB_TABLE GDesignBlockTable;
|
||||
KICOMMON_API extern DESIGN_BLOCK_LIST_IMPL GDesignBlockList;
|
||||
|
||||
#endif // DESIGN_BLOCK_LIB_TABLE_H_
|
||||
|
@ -357,7 +357,7 @@ bool PGM_KICAD::OnPgmInit()
|
||||
|
||||
try
|
||||
{
|
||||
DESIGN_BLOCK_LIB_TABLE::LoadGlobalTable( GDesignBlockTable );
|
||||
DESIGN_BLOCK_LIB_TABLE::LoadGlobalTable( DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable() );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
@ -372,9 +372,9 @@ bool PGM_KICAD::OnPgmInit()
|
||||
DisplayErrorMessage( nullptr, msg, ioe.What() );
|
||||
}
|
||||
|
||||
if( managerFrame->IsProjectActive() && GDesignBlockList.GetCount() == 0 )
|
||||
GDesignBlockList.ReadCacheFromFile( Prj().GetProjectPath()
|
||||
+ wxT( "design-block-info-cache" ) );
|
||||
if( managerFrame->IsProjectActive() && DESIGN_BLOCK_LIB_TABLE::GetGlobalList().GetCount() == 0 )
|
||||
DESIGN_BLOCK_LIB_TABLE::GetGlobalList().ReadCacheFromFile(
|
||||
Prj().GetProjectPath() + wxT( "design-block-info-cache" ) );
|
||||
|
||||
frame->Show( true );
|
||||
frame->Raise();
|
||||
|
Loading…
Reference in New Issue
Block a user