21#ifndef SCH_IO_DATABASE_H_
22#define SCH_IO_DATABASE_H_
29#include <condition_variable>
32#include <shared_mutex>
34#include <unordered_set>
68 const wxString& aLibraryPath,
69 const std::map<std::string, UTF8>* aProperties =
nullptr )
override;
72 const wxString& aLibraryPath,
73 const std::map<std::string, UTF8>* aProperties =
nullptr )
override;
76 const std::map<std::string, UTF8>* aProperties =
nullptr )
override;
79 const std::map<std::string, UTF8>* aProperties =
nullptr )
override;
115 bool aConnectNow =
true,
116 const wxString& aBaseDir = wxEmptyString );
143 static std::vector<std::unique_ptr<LIB_SYMBOL>>
145 const std::vector<DATABASE_CONNECTION::ROW>& aRows,
PREVIEW_ISSUES* aIssues );
148 typedef std::vector<std::pair<const DATABASE_LIB_TABLE*, std::vector<DATABASE_CONNECTION::ROW>>>
TABLE_RESULT_LIST;
155 std::map<wxString, std::unique_ptr<LIB_SYMBOL>>& aSymbolCache,
156 std::map<wxString, std::pair<std::string, std::string>>& aSanitizedNameMap );
168 static std::optional<bool>
boolFromAny(
const std::any& aVal );
187 std::unique_ptr<DATABASE_CONNECTION>
m_conn;
std::map< std::string, std::any > ROW
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
The interface used by the classes that actually can load IO plugins for the different parts of KiCad ...
A logical library item identifier and consists of various portions much like a URI.
Define a library symbol object.
void reportIssue(PREVIEW_ISSUE::FIELD aField, const wxString &aMessage, SEVERITY aSeverity) const
Reports to the preview's issue list when there is one, otherwise to the reporter.
static std::unique_ptr< DATABASE_CONNECTION > CreateConnection(const DATABASE_LIB_SETTINGS &aSettings, bool aConnectNow=true, const wxString &aBaseDir=wxEmptyString)
Opens a connection described by aSettings, expanding ${CWD} in a connection string to the directory h...
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
DIALOG_SHIM * CreateConfigurationDialog(wxWindow *aParent, const wxString &aLibraryPath) override
std::shared_mutex m_cacheMutex
PREVIEW_ISSUES * m_previewIssues
Collects the problems found while building a preview; null outside BuildPreviewSymbols()
DATABASE_LIB_SETTINGS * Settings() const
std::unique_ptr< DATABASE_CONNECTION > m_conn
Generally will be null if no valid connection is established.
friend class SCH_IO_DATABASE_CYCLE_DETECTION_FIXTURE
static wxString SymbolNameForRow(const DATABASE_LIB_TABLE &aTable, bool aGloballyUniqueKeys, const DATABASE_CONNECTION::ROW &aRow, std::string *aRawKey=nullptr)
void GetDefaultSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that should be shown by default for this library in the symb...
void ensureSettings(const wxString &aSettingsPath)
static thread_local std::unordered_set< wxString > s_inProgressLoads
LIB_IDs whose resolution is in flight on the calling thread, used to break self-referential cycles wh...
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void backgroundRefreshWorker()
bool SupportsSubLibraries() const override
static std::vector< std::unique_ptr< LIB_SYMBOL > > BuildPreviewSymbols(SYMBOL_LIBRARY_ADAPTER *aLibs, const DATABASE_LIB_TABLE &aTable, bool aGloballyUniqueKeys, const std::vector< DATABASE_CONNECTION::ROW > &aRows, PREVIEW_ISSUES *aIssues)
Builds symbols from already-fetched rows exactly as the library would name and load them,...
std::atomic< bool > m_cachePopulated
True once the LIB_SYMBOL cache has been materialized at least once.
void stopBackgroundRefresh()
bool m_inCacheLib
Re-entrancy guard for cacheLib(), tripped when a self-referential load routes back through the adapte...
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > m_nameToSymbolcache
std::map< wxString, std::pair< std::string, std::string > > m_sanitizedNameMap
std::set< wxString > m_defaultShownFields
void SetLibraryManagerAdapter(SYMBOL_LIBRARY_ADAPTER *aAdapter) override
Some library plugins need to interface with other loaded libraries.
virtual ~SCH_IO_DATABASE()
size_t m_cacheSignature
Signature of the raw database rows at last materialization; used to skip rebuilding the LIB_SYMBOL ca...
std::vector< std::pair< const DATABASE_LIB_TABLE *, std::vector< DATABASE_CONNECTION::ROW > > > TABLE_RESULT_LIST
void GetSubLibraryNames(std::vector< wxString > &aNames) override
Retrieves a list of sub-libraries in this library.
std::unique_ptr< DATABASE_LIB_SETTINGS > m_settings
bool SupportsConfigurationDialog() const override
static std::optional< bool > boolFromAny(const std::any &aVal)
size_t computeSignature(const TABLE_RESULT_LIST &aTableResults) const
void CheckLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Validate that the library at aLibraryPath is reachable and well-formed, without necessarily loading s...
SYMBOL_LIBRARY_ADAPTER * m_adapter
void startBackgroundRefresh()
std::thread m_refreshThread
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
long long m_cacheTimestamp
std::condition_variable m_refreshCV
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.
std::atomic< bool > m_refreshRunning
bool m_previewMode
Set on the throwaway instance behind BuildPreviewSymbols()
int GetModifyHash() const override
Return the modification hash from the library cache.
bool materializeCache(const TABLE_RESULT_LIST &aTableResults, std::map< wxString, std::unique_ptr< LIB_SYMBOL > > &aSymbolCache, std::map< wxString, std::pair< std::string, std::string > > &aSanitizedNameMap)
std::unique_ptr< LIB_SYMBOL > loadSymbolFromRow(const wxString &aSymbolName, const DATABASE_LIB_TABLE &aTable, const DATABASE_CONNECTION::ROW &aRow)
std::set< wxString > m_customFields
std::mutex m_symbolLoadMutex
LIB_SYMBOL * resolveSourceSymbol(const LIB_ID &aId)
Resolves one entry of a row's symbols column through the library adapter.
std::vector< PREVIEW_ISSUE > PREVIEW_ISSUES
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
std::mutex m_refreshMutex
SCH_IO(const wxString &aName)
An interface to the global shared library manager that is schematic-specific and linked to one projec...
static const std::string DatabaseLibraryFileExtension
A database library table will be mapped to a sub-library provided by the database library entry in th...
Container that describes file type info.
A problem found while previewing, tagged with the setting that caused it.
@ KEY
The row as a whole, such as colliding keys or a row that could not be loaded.
@ PIN_MAP
The pin map column.
@ REPEATED_KEY
A key that more than one row has.
@ SYMBOLS
The symbols column.
Definition of file extensions used in Kicad.