KiCad PCB EDA Suite
Loading...
Searching...
No Matches
LIBRARY_MANAGER Class Reference

#include <library_manager.h>

Public Member Functions

 LIBRARY_MANAGER ()
 
 ~LIBRARY_MANAGER ()
 
 LIBRARY_MANAGER (const LIBRARY_MANAGER &)=delete
 
LIBRARY_MANAGERoperator= (const LIBRARY_MANAGER &)=delete
 
void LoadGlobalTables (std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
 (Re)loads the global library tables in the given list, or all tables if no list is given
 
void LoadProjectTables (std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
 (Re)loads the project library tables in the given list, or all tables if no list is given
 
void ReloadTables (LIBRARY_TABLE_SCOPE aScope, std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
 
void ProjectChanged ()
 Notify all adapters that the project has changed.
 
void AbortAsyncLoads ()
 Abort any async library loading operations in progress.
 
void RegisterAdapter (LIBRARY_TABLE_TYPE aType, std::unique_ptr< LIBRARY_MANAGER_ADAPTER > &&aAdapter)
 
bool RemoveAdapter (LIBRARY_TABLE_TYPE aType, LIBRARY_MANAGER_ADAPTER *aAdapter)
 
std::optional< LIBRARY_MANAGER_ADAPTER * > Adapter (LIBRARY_TABLE_TYPE aType) const
 
std::optional< LIBRARY_TABLE * > Table (LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope)
 Retrieves a given table; creating a new empty project table if a valid project is loaded and the given table type doesn't exist in the project.
 
std::vector< LIBRARY_TABLE_ROW * > Rows (LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH, bool aIncludeInvalid=false) const
 Returns a flattened list of libraries of the given type.
 
std::optional< LIBRARY_TABLE_ROW * > GetRow (LIBRARY_TABLE_TYPE aType, const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH)
 
std::optional< LIBRARY_TABLE_ROW * > FindRowByURI (LIBRARY_TABLE_TYPE aType, const wxString &aUri, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
 
void ReloadLibraryEntry (LIBRARY_TABLE_TYPE aType, const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH)
 
std::optional< LIB_STATUSLoadLibraryEntry (LIBRARY_TABLE_TYPE aType, const wxString &aNickname)
 Synchronously loads the named library to LOADED state for the given type.
 
void LoadProjectTables (const wxString &aProjectPath, std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
 
std::optional< wxString > GetFullURI (LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
 Return the full location specifying URI for the LIB, either in original UI form or in environment variable expanded form.
 

Static Public Member Functions

static wxString DefaultGlobalTablePath (LIBRARY_TABLE_TYPE aType)
 
static wxString StockTablePath (LIBRARY_TABLE_TYPE aType)
 
static bool IsTableValid (const wxString &aPath)
 
static bool GlobalTablesValid ()
 
static std::vector< LIBRARY_TABLE_TYPEInvalidGlobalTables ()
 
static bool CreateGlobalTable (LIBRARY_TABLE_TYPE aType, bool aPopulateDefaultLibraries)
 
static wxString GetFullURI (const LIBRARY_TABLE_ROW *aRow, bool aSubstituted=false)
 
static wxString ExpandURI (const wxString &aShortURI, const PROJECT &aProject)
 
static bool UrisAreEquivalent (const wxString &aURI1, const wxString &aURI2)
 

Private Types

typedef std::tuple< LIBRARY_TABLE_TYPE, LIBRARY_TABLE_SCOPE, wxString > ROW_CACHE_KEY
 

Private Member Functions

void loadTables (const wxString &aTablePath, LIBRARY_TABLE_SCOPE aScope, std::vector< LIBRARY_TABLE_TYPE > aTablesToLoad={})
 
void loadNestedTables (LIBRARY_TABLE &aTable)
 
void createEmptyTable (LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope)
 

Static Private Member Functions

static wxString tableFileName (LIBRARY_TABLE_TYPE aType)
 

Private Attributes

std::map< LIBRARY_TABLE_TYPE, std::unique_ptr< LIBRARY_TABLE > > m_tables
 
std::map< wxString, std::unique_ptr< LIBRARY_TABLE > > m_childTables
 Map of full URI to table object for tables that are referenced by global or project tables.
 
std::map< LIBRARY_TABLE_TYPE, std::unique_ptr< LIBRARY_TABLE > > m_projectTables
 
std::map< LIBRARY_TABLE_TYPE, std::unique_ptr< LIBRARY_MANAGER_ADAPTER > > m_adapters
 
std::mutex m_adaptersMutex
 
std::map< ROW_CACHE_KEY, LIBRARY_TABLE_ROW * > m_rowCache
 
std::mutex m_rowCacheMutex
 

Detailed Description

Definition at line 226 of file library_manager.h.

Member Typedef Documentation

◆ ROW_CACHE_KEY

Definition at line 359 of file library_manager.h.

Constructor & Destructor Documentation

◆ LIBRARY_MANAGER() [1/2]

LIBRARY_MANAGER::LIBRARY_MANAGER ( )

Definition at line 51 of file library_manager.cpp.

Referenced by LIBRARY_MANAGER(), and operator=().

◆ ~LIBRARY_MANAGER()

LIBRARY_MANAGER::~LIBRARY_MANAGER ( )
default

◆ LIBRARY_MANAGER() [2/2]

LIBRARY_MANAGER::LIBRARY_MANAGER ( const LIBRARY_MANAGER & )
delete

References LIBRARY_MANAGER().

Member Function Documentation

◆ AbortAsyncLoads()

void LIBRARY_MANAGER::AbortAsyncLoads ( )

Abort any async library loading operations in progress.

This should be called before modifying the project list to prevent race conditions with background threads that access Prj().

Definition at line 544 of file library_manager.cpp.

References m_adapters, and m_adaptersMutex.

Referenced by SCH_EDIT_FRAME::KiwayMailIn(), SETTINGS_MANAGER::LoadProject(), ProjectChanged(), ReloadTables(), and SETTINGS_MANAGER::UnloadProject().

◆ Adapter()

◆ createEmptyTable()

void LIBRARY_MANAGER::createEmptyTable ( LIBRARY_TABLE_TYPE aType,
LIBRARY_TABLE_SCOPE aScope )
private

◆ CreateGlobalTable()

◆ DefaultGlobalTablePath()

wxString LIBRARY_MANAGER::DefaultGlobalTablePath ( LIBRARY_TABLE_TYPE aType)
static

◆ ExpandURI()

◆ FindRowByURI()

std::optional< LIBRARY_TABLE_ROW * > LIBRARY_MANAGER::FindRowByURI ( LIBRARY_TABLE_TYPE aType,
const wxString & aUri,
LIBRARY_TABLE_SCOPE aScope = LIBRARY_TABLE_SCOPE::BOTH ) const

◆ GetFullURI() [1/2]

wxString LIBRARY_MANAGER::GetFullURI ( const LIBRARY_TABLE_ROW * aRow,
bool aSubstituted = false )
static

◆ GetFullURI() [2/2]

std::optional< wxString > LIBRARY_MANAGER::GetFullURI ( LIBRARY_TABLE_TYPE aType,
const wxString & aNickname,
bool aSubstituted = false )

Return the full location specifying URI for the LIB, either in original UI form or in environment variable expanded form.

Parameters
aTypedetermines which tables will be searched for the library
aNicknameis the library to look up
aSubstitutedTells if caller wanted the substituted form, else not.
Returns
the URI for the given library, or nullopt if the nickname is not a valid library

Definition at line 796 of file library_manager.cpp.

References GetFullURI(), GetRow(), and result.

Referenced by EXPORTER_STEP::buildFootprint3DShapes(), FOOTPRINT_EDIT_FRAME::DeleteFootprintFromLibrary(), SYMBOL_VIEWER_FRAME::DisplayLibInfos(), CVPCB_MAINFRAME::DisplayStatus(), FOOTPRINT_EDIT_FRAME::DuplicateFootprint(), SYMBOL_EDIT_FRAME::ExportSymbol(), SCH_EDITOR_CONTROL::ExportSymbolsToLibrary(), EXPORTER_PCB_VRML::ExportVrmlFootprint(), FindRowByURI(), FOOTPRINT_LIBRARY_ADAPTER::GenerateTimestamp(), GetFullURI(), SYMBOL_LIBRARY_MANAGER::GetLibraryHash(), idf_export_footprint(), SYMBOL_EDIT_FRAME::KiwayMailIn(), SYMBOL_VIEWER_FRAME::KiwayMailIn(), RENDER_3D_RAYTRACE_BASE::load3DModels(), RENDER_3D_OPENGL::load3dModels(), SCH_EDIT_FRAME::LoadSheetFromFile(), NETLIST_EXPORTER_XML::makeLibraries(), PANEL_FP_PROPERTIES_3D_MODEL::OnAdd3DModel(), FOOTPRINT_EDITOR_CONTROL::OpenDirectory(), SYMBOL_EDITOR_CONTROL::OpenDirectory(), FOOTPRINT_EDITOR_CONTROL::OpenWithTextEditor(), SYMBOL_EDITOR_CONTROL::OpenWithTextEditor(), DRC_TEST_PROVIDER_LIBRARY_PARITY::Run(), FOOTPRINT_EDITOR_CONTROL::SaveAs(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), SYMBOL_LIBRARY_MANAGER::SaveLibrary(), SYMBOL_EDIT_FRAME::saveLibrary(), PCB_BASE_FRAME::setFPWatcher(), SCH_BASE_FRAME::setSymWatcher(), ERC_TESTER::TestLibSymbolIssues(), FOOTPRINT_VIEWER_FRAME::UpdateTitle(), and PANEL_FP_PROPERTIES_3D_MODEL::validateModelExists().

◆ GetRow()

std::optional< LIBRARY_TABLE_ROW * > LIBRARY_MANAGER::GetRow ( LIBRARY_TABLE_TYPE aType,
const wxString & aNickname,
LIBRARY_TABLE_SCOPE aScope = LIBRARY_TABLE_SCOPE::BOTH )
Parameters
aTypedetermines which type of libraries to return (symbol, footprint, ...)
aScopedetermines whether to search project, global, or both library tables
aNicknameis the library nickname to retrieve
Returns
the row, or a nullopt if it does not exist

Definition at line 709 of file library_manager.cpp.

References m_rowCache, m_rowCacheMutex, and Rows().

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), GetFullURI(), SYMBOL_EDIT_FRAME::LoadSymbol(), SYMBOL_LIB_TABLE_RESCUER::OpenRescueLibrary(), ERC_TESTER::TestLibSymbolIssues(), and SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary().

◆ GlobalTablesValid()

bool LIBRARY_MANAGER::GlobalTablesValid ( )
static
Returns
true if all required global tables are present on disk and valid

Definition at line 375 of file library_manager.cpp.

References InvalidGlobalTables().

Referenced by STARTWIZARD_PROVIDER_LIBRARIES::NeedsUserInput(), and operator=().

◆ InvalidGlobalTables()

std::vector< LIBRARY_TABLE_TYPE > LIBRARY_MANAGER::InvalidGlobalTables ( )
static

◆ IsTableValid()

bool LIBRARY_MANAGER::IsTableValid ( const wxString & aPath)
static

◆ LoadGlobalTables()

◆ LoadLibraryEntry()

std::optional< LIB_STATUS > LIBRARY_MANAGER::LoadLibraryEntry ( LIBRARY_TABLE_TYPE aType,
const wxString & aNickname )

Synchronously loads the named library to LOADED state for the given type.

Returns the resulting status, or nullopt if the library is not found.

Definition at line 756 of file library_manager.cpp.

References Adapter().

Referenced by REMOTE_SYMBOL_IMPORT_JOB::Import(), and PANEL_REMOTE_SYMBOL::receiveFootprint().

◆ loadNestedTables()

void LIBRARY_MANAGER::loadNestedTables ( LIBRARY_TABLE & aTable)
private

◆ LoadProjectTables() [1/2]

void LIBRARY_MANAGER::LoadProjectTables ( const wxString & aProjectPath,
std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad = {} )

Definition at line 766 of file library_manager.cpp.

References loadTables(), m_projectTables, PROJECT, and traceLibraries.

◆ LoadProjectTables() [2/2]

void LIBRARY_MANAGER::LoadProjectTables ( std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad = {})

(Re)loads the project library tables in the given list, or all tables if no list is given

Definition at line 522 of file library_manager.cpp.

References LoadProjectTables(), Pgm(), and Prj().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), SCH_EDIT_FRAME::KiwayMailIn(), LoadProjectTables(), ProjectChanged(), and ReloadTables().

◆ loadTables()

void LIBRARY_MANAGER::loadTables ( const wxString & aTablePath,
LIBRARY_TABLE_SCOPE aScope,
std::vector< LIBRARY_TABLE_TYPE > aTablesToLoad = {} )
private

◆ operator=()

◆ ProjectChanged()

◆ RegisterAdapter()

void LIBRARY_MANAGER::RegisterAdapter ( LIBRARY_TABLE_TYPE aType,
std::unique_ptr< LIBRARY_MANAGER_ADAPTER > && aAdapter )

◆ ReloadLibraryEntry()

void LIBRARY_MANAGER::ReloadLibraryEntry ( LIBRARY_TABLE_TYPE aType,
const wxString & aNickname,
LIBRARY_TABLE_SCOPE aScope = LIBRARY_TABLE_SCOPE::BOTH )

◆ ReloadTables()

◆ RemoveAdapter()

bool LIBRARY_MANAGER::RemoveAdapter ( LIBRARY_TABLE_TYPE aType,
LIBRARY_MANAGER_ADAPTER * aAdapter )

Definition at line 564 of file library_manager.cpp.

References m_adapters, and m_adaptersMutex.

◆ Rows()

std::vector< LIBRARY_TABLE_ROW * > LIBRARY_MANAGER::Rows ( LIBRARY_TABLE_TYPE aType,
LIBRARY_TABLE_SCOPE aScope = LIBRARY_TABLE_SCOPE::BOTH,
bool aIncludeInvalid = false ) const

Returns a flattened list of libraries of the given type.

Parameters
aTypedetermines which type of libraries to return (symbol, footprint, ...)
aIncludeInvalidwill include the nicknames of libraries even if they could not be loaded for some reason (file not found, etc)
Returns
a list of library nicknames (the first part of a LIB_ID)

Definition at line 629 of file library_manager.cpp.

References BOTH, GLOBAL, m_childTables, m_projectTables, m_tables, PROJECT, table, LIBRARY_TABLE_ROW::TABLE_TYPE_NAME, and UNINITIALIZED.

Referenced by DESIGN_BLOCK_TREE_MODEL_ADAPTER::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), FindRowByURI(), SYMBOL_LIBRARY_MANAGER::GetLibraryNames(), GetRow(), and DIALOG_CONFIGURE_PATHS::TransferDataToWindow().

◆ StockTablePath()

◆ Table()

std::optional< LIBRARY_TABLE * > LIBRARY_MANAGER::Table ( LIBRARY_TABLE_TYPE aType,
LIBRARY_TABLE_SCOPE aScope )

◆ tableFileName()

◆ UrisAreEquivalent()

bool LIBRARY_MANAGER::UrisAreEquivalent ( const wxString & aURI1,
const wxString & aURI2 )
static

Definition at line 825 of file library_manager.cpp.

Referenced by LIBRARY_MANAGER_ADAPTER::FindLibraryByURI(), and FindRowByURI().

Member Data Documentation

◆ m_adapters

std::map<LIBRARY_TABLE_TYPE, std::unique_ptr<LIBRARY_MANAGER_ADAPTER> > LIBRARY_MANAGER::m_adapters
private

◆ m_adaptersMutex

std::mutex LIBRARY_MANAGER::m_adaptersMutex
mutableprivate

◆ m_childTables

std::map<wxString, std::unique_ptr<LIBRARY_TABLE> > LIBRARY_MANAGER::m_childTables
private

Map of full URI to table object for tables that are referenced by global or project tables.

Definition at line 350 of file library_manager.h.

Referenced by loadNestedTables(), and Rows().

◆ m_projectTables

std::map<LIBRARY_TABLE_TYPE, std::unique_ptr<LIBRARY_TABLE> > LIBRARY_MANAGER::m_projectTables
private

Definition at line 353 of file library_manager.h.

Referenced by createEmptyTable(), LoadProjectTables(), loadTables(), Rows(), and Table().

◆ m_rowCache

std::map<ROW_CACHE_KEY, LIBRARY_TABLE_ROW*> LIBRARY_MANAGER::m_rowCache
private

Definition at line 361 of file library_manager.h.

Referenced by GetRow(), and loadTables().

◆ m_rowCacheMutex

std::mutex LIBRARY_MANAGER::m_rowCacheMutex
mutableprivate

Definition at line 362 of file library_manager.h.

Referenced by GetRow(), and loadTables().

◆ m_tables

std::map<LIBRARY_TABLE_TYPE, std::unique_ptr<LIBRARY_TABLE> > LIBRARY_MANAGER::m_tables
private

Definition at line 347 of file library_manager.h.

Referenced by createEmptyTable(), loadTables(), Rows(), and Table().


The documentation for this class was generated from the following files: