27 #include <lib_table_lexer.h> 37 using namespace LIB_TABLE_T;
64 if( SCH_IO_MGR::SCH_FILE_T( -1 ) == type )
65 type = SCH_IO_MGR::SCH_LEGACY;
75 wxArrayString dummyList;
77 plugin.set( SCH_IO_MGR::FindPlugin( type ) );
79 plugin->EnumerateSymbolLib( dummyList, GetFullURI(
true ), GetProperties() );
109 if( in->CurTok() != T_sym_lib_table )
112 if( ( tok = in->NextTok() ) != T_sym_lib_table )
113 in->Expecting( T_sym_lib_table );
116 while( ( tok = in->NextTok() ) != T_RIGHT )
118 std::unique_ptr< SYMBOL_LIB_TABLE_ROW > row = std::make_unique<SYMBOL_LIB_TABLE_ROW>();
121 in->Expecting( T_RIGHT );
124 in->Expecting( T_LEFT );
127 int lineNum = in->CurLineNumber();
129 if( ( tok = in->NextTok() ) != T_lib )
130 in->Expecting( T_lib );
135 if( ( tok = in->NextTok() ) != T_name )
136 in->Expecting( T_name );
138 in->NeedSYMBOLorNUMBER();
140 row->SetNickName( in->FromUTF8() );
146 bool sawType =
false;
147 bool sawOpts =
false;
148 bool sawDesc =
false;
150 bool sawDisabled =
false;
152 while( ( tok = in->NextTok() ) != T_RIGHT )
155 in->Unexpected( T_EOF );
158 in->Expecting( T_LEFT );
160 tok = in->NeedSYMBOLorNUMBER();
166 in->Duplicate( tok );
168 in->NeedSYMBOLorNUMBER();
169 row->SetFullURI( in->FromUTF8() );
174 in->Duplicate( tok );
176 in->NeedSYMBOLorNUMBER();
177 row->SetType( in->FromUTF8() );
182 in->Duplicate( tok );
184 in->NeedSYMBOLorNUMBER();
185 row->SetOptions( in->FromUTF8() );
190 in->Duplicate( tok );
192 in->NeedSYMBOLorNUMBER();
193 row->SetDescr( in->FromUTF8() );
198 in->Duplicate( tok );
200 row->SetEnabled(
false );
204 in->Unexpected( tok );
211 in->Expecting( T_type );
214 in->Expecting( T_uri );
220 wxString nickname = row->GetNickName();
228 wxString msg =
wxString::Format(
_(
"Duplicate library nickname '%s' found in symbol " 229 "library table file line %d" ),
233 if( !errMsg.IsEmpty() )
240 if( !errMsg.IsEmpty() )
247 aOutput->
Print( aIndentLevel,
"(sym_lib_table\n" );
251 it->Format( aOutput, aIndentLevel+1 );
254 aOutput->
Print( aIndentLevel,
")\n" );
263 for(
const auto& libName : libNames )
267 if( !row || !row->
plugin )
273 hash += row->
plugin->GetModifyHash();
283 bool aPowerSymbolsOnly )
286 wxCHECK( row && row->
plugin, );
290 if( aPowerSymbolsOnly )
297 if( aPowerSymbolsOnly )
305 dynamic_cast< SYMBOL_LIB_TABLE_ROW* >(
findRow( aNickname, aCheckIfEnabled ) );
321 const wxString& aNickname,
bool aPowerSymbolsOnly )
324 wxCHECK( row && row->
plugin, );
328 if( aPowerSymbolsOnly )
335 if( aPowerSymbolsOnly )
344 LIB_ID id = part->GetLibId();
347 part->SetLibId(
id );
356 if( !row || !row->
plugin )
362 if( part ==
nullptr )
382 const LIB_PART* aSymbol,
bool aOverwrite )
397 std::unique_ptr< LIB_PART > symbol( row->
plugin->LoadSymbol( row->
GetFullURI(
true ),
421 wxCHECK( row && row->
plugin, );
430 wxCHECK( row && row->
plugin,
false );
437 wxCHECK( row,
false );
445 wxCHECK( row && row->
plugin, );
453 wxCHECK( row && row->
plugin, );
463 if( nickname.size() )
474 for(
unsigned i = 0; i < nicks.size(); ++i )
491 return "KICAD6_SYMBOL_DIR";
497 bool tableExists =
true;
500 if( !fn.FileExists() )
504 if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
507 _(
"Cannot create global library table path \"%s\"." ), fn.GetPath() ) );
516 wxString templatePath =
517 Pgm().GetLocalEnvVariables().at( wxT(
"KICAD6_TEMPLATE_DIR" ) ).GetValue();
519 if( !templatePath.IsEmpty() )
525 if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
529 emptyTable.
Save( fn.GetFullPath() );
533 aTable.
Load( fn.GetFullPath() );
546 return fn.GetFullPath();
SAVE_T SaveSymbol(const wxString &aNickname, const LIB_PART *aSymbol, bool aOverwrite=true)
Write aSymbol to an existing library given by aNickname.
static const wxString & GetSymbolLibTableFileName()
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
void EnumerateSymbolLib(const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
Return a list of symbol alias names contained within the library given by aNickname.
wxString FindValidPath(const wxString &aFileName) const
const UTF8 & GetLibItemName() const
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
LIB_ID GetLibId() const override
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
SYMBOL_LIB_TABLE(SYMBOL_LIB_TABLE *aFallBackTable=NULL)
Build a symbol library table by pre-pending this table fragment in front of aFallBackTable.
void CreateSymbolLib(const wxString &aNickname)
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
void DeleteSymbolLib(const wxString &aNickname)
void SetType(const wxString &aType) override
Change the schematic plugin type represented by this row.
LIB_PART * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_PART having aName from the library given by aNickname.
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
System directories search utilities.
Look for files in a number of paths.
static const wxString global_tbl_name("sym-lib-table")
A logical library item identifier and consists of various portions much like a URI.
bool IsSymbolLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
bool operator==(const LIB_TABLE_ROW &r) const
bool IsSymbolLibLoaded(const wxString &aNickname)
Return true if the library given by aNickname was successfully loaded.
bool operator==(const SYMBOL_LIB_TABLE_ROW &aRow) 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...
void SetLoaded(bool aLoaded)
Mark the row as being a loaded library.
const wxString & GetNickName() const
static bool LoadGlobalTable(SYMBOL_LIB_TABLE &aTable)
Load the global symbol library table into aTable.
bool Refresh()
Attempt to reload the library.
void LoadSymbolLib(std::vector< LIB_PART * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
Define a library symbol object.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
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,...
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.
void setPlugin(SCH_PLUGIN *aPlugin)
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
void DeleteSymbol(const wxString &aNickname, const wxString &aSymbolName)
Deletes the aSymbolName from the library given by aNickname.
static SCH_FILE_T EnumFromStr(const wxString &aFileType)
Return the #SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy",...
static int m_modifyHash
helper for GetModifyHash()
virtual void Parse(LIB_TABLE_LEXER *aLexer) override
Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objec...
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
void SetOptions(const wxString &aOptions)
Change the library options strings.
SAVE_T
The set of return values from SaveSymbol() below.
static const char * PropNonPowerSymsOnly
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).
LIB_PART * LoadSymbolWithOptionalNickname(const LIB_ID &aId)
Load a LIB_PART having aFootprintId with possibly an empty library nickname.
SYMBOL_LIB_TABLE g_symbolLibraryTable
The global symbol library table.
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
void SetLibId(const LIB_ID &aLibId)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
#define THROW_IO_ERROR(msg)
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
static const char * PropPowerSymsOnly
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.