27#include <wx/filename.h>
32#include <lib_table_lexer.h>
39using namespace LIB_TABLE_T;
76 uri.Replace(
'\\',
'/' );
78 wxString extraOptions;
81 extraOptions +=
"(disabled)";
84 extraOptions +=
"(hidden)";
86 out->
Print( nestLevel,
"(lib (name %s)(type %s)(uri %s)(options %s)(descr %s)%s)\n",
89 out->
Quotew( uri ).c_str(),
92 extraOptions.ToStdString().c_str() );
117 m_fallBack( aFallBackTable ), m_version( 0 )
147 return wxEmptyString;
166 if( row.GetFullURI() == aPath )
198 for(
const std::pair<const wxString, int>& entry : cur->
m_nickIndex )
200 if( entry.first == aNickName )
202 row = &cur->
m_rows[entry.second];
211 for(
const std::pair<const wxString, int>& entry : cur->
m_nickIndex )
213 wxString legacyLibName = entry.first;
214 legacyLibName.Replace(
" ",
"_" );
216 if( legacyLibName == aNickName )
218 row = &cur->
m_rows[entry.second];
226 }
while( ( cur = cur->
m_fallBack ) !=
nullptr );
240 for(
unsigned i = 0; i < cur->
m_rows.size(); i++ )
242 wxString tmp = cur->
m_rows[i].GetFullURI(
true );
244 if( tmp.Find(
"://" ) != wxNOT_FOUND )
251 wxFileName fn = aURI;
256 if( fn == wxFileName( tmp ) )
262 }
while( ( cur = cur->
m_fallBack ) !=
nullptr );
273 std::set<wxString> unique;
274 std::vector<wxString> ret;
281 if( it->GetIsEnabled() )
282 unique.insert( it->GetNickName() );
285 }
while( ( cur = cur->
m_fallBack ) !=
nullptr );
287 ret.reserve( unique.size() );
290 for( std::set< wxString >::const_iterator it = unique.begin(); it!=unique.end(); ++it )
291 ret.push_back( *it );
294 std::sort( ret.begin(), ret.end(),
295 [](
const wxString& lhs,
const wxString& rhs )
297 return StrNumCmp( lhs, rhs, true ) < 0;
323 m_rows.replace( it->second, aRow );
333 bool table_updated =
false;
337 bool row_updated =
false;
338 wxString uri = row.GetFullURI(
true );
342 row_updated |= ( uri.Replace( wxS(
"${KICAD5_" ), wxS(
"${KICAD7_" ),
false ) > 0 );
343 row_updated |= ( uri.Replace( wxS(
"${KICAD6_" ), wxS(
"${KICAD7_" ), false ) > 0 );
347 row.SetFullURI( uri );
348 table_updated =
true;
352 return table_updated;
359 if( wxFileName::IsFileReadable( aFileName ) )
362 LIB_TABLE_LEXER lexer( &reader );
366 if(
m_version != 7 &&
migrate() && wxFileName::IsFileWritable( aFileName ) )
384 if( aOptionsList.size() )
386 const char* cp = &aOptionsList[0];
387 const char* end = cp + aOptionsList.size();
398 while( cp < end && isspace( *cp ) )
404 if( *cp ==
'\\' && cp + 1 < end && cp[1] ==
OPT_SEP )
424 size_t eqNdx = pair.find(
'=' );
426 if( eqNdx != pair.npos )
428 std::string
name = pair.substr( 0, eqNdx );
429 std::string value = pair.substr( eqNdx + 1 );
453 for( STRING_UTF8_MAP::const_iterator it = aProperties->begin(); it != aProperties->end(); ++it )
455 const std::string&
name = it->first;
457 const UTF8& value = it->second;
469 for( std::string::const_iterator si = value.
begin(); si != value.
end(); ++si )
A LINE_READER that reads from an open file.
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
void SetFullURI(const wxString &aFullURI)
Change the full URI for the library.
bool visible
Whether the LIB_TABLE_ROW is visible in choosers.
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
const wxString & GetDescr() const
Return the description of the library referenced by this row.
std::unique_ptr< STRING_UTF8_MAP > properties
wxString uri_user
what user entered from UI or loaded from disk
virtual const wxString GetType() const =0
Return the type of library represented by this row.
void Format(OUTPUTFORMATTER *out, int nestLevel) const
Serialize this object as utf8 text to an OUTPUTFORMATTER, and tries to make it look good using multip...
bool enabled
Whether the LIB_TABLE_ROW is enabled.
void SetParent(LIB_TABLE *aParent)
void setProperties(STRING_UTF8_MAP *aProperties)
const wxString & GetNickName() const
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
LIB_TABLE_ROW * clone() const
bool operator==(const LIB_TABLE_ROW &r) const
bool GetIsEnabled() const
void SetOptions(const wxString &aOptions)
Change the library options strings.
bool GetIsVisible() const
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
const wxString GetDescription(const wxString &aNickname)
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
int m_version
Versioning to handle importing old tables.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
bool migrate()
Updates the env vars from older version of KiCad, provided they do not currently resolve to anything.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
bool HasLibraryWithPath(const wxString &aPath) const
Test for the existence of aPath in the library table.
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const =0
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
INDEX m_nickIndex
this particular key is the nickName within each row.
INDEX::value_type INDEX_VALUE
wxString GetFullURI(const wxString &aLibNickname, bool aExpandEnvVars=true) const
Return the full URI of the library mapped to aLibNickname.
LIB_TABLE(LIB_TABLE *aFallBackTable=nullptr)
Build a library table by pre-pending this table fragment in front of aFallBackTable.
bool IsEmpty(bool aIncludeFallback=true)
Return true if the table is empty.
virtual void Parse(LIB_TABLE_LEXER *aLexer)=0
Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objec...
INDEX::const_iterator INDEX_CITER
const LIB_TABLE_ROW * FindRowByURI(const wxString &aURI)
std::shared_mutex m_nickIndexMutex
Mutex to protect access to the nickIndex variable.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
static STRING_UTF8_MAP * ParseOptions(const std::string &aOptionsList)
Parses aOptionsList and places the result into a #PROPERTIES object which is returned.
LIB_TABLE_ROW * findRow(const wxString &aNickname, bool aCheckIfEnabled=false) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment,...
static UTF8 FormatOptions(const STRING_UTF8_MAP *aProperties)
Returns a list of options from the aProperties parameter.
A name/value tuple with unique names and optional values.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
std::string::const_iterator begin() const
std::string::size_type size() const
std::string::const_iterator end() const
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
LIB_TABLE_ROW * new_clone(const LIB_TABLE_ROW &aRow)
Allows boost pointer containers to make clones of the data stored in them.
#define OPT_SEP
options separator character
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
This file contains miscellaneous commonly used macros and functions.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.