KiCad PCB EDA Suite
symbol_lib_table.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 Wayne Stambaugh <[email protected]>
5 * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26#include <lib_id.h>
27#include <lib_table_lexer.h>
28#include <pgm_base.h>
29#include <search_stack.h>
32#include <systemdirsappend.h>
33#include <symbol_lib_table.h>
34#include <lib_symbol.h>
35
36#include <wx/dir.h>
37
38
39#define OPT_SEP '|'
40
41using namespace LIB_TABLE_T;
42
43
44static const wxString global_tbl_name( "sym-lib-table" );
45
46
47const char* SYMBOL_LIB_TABLE::PropPowerSymsOnly = "pwr_sym_only";
48const char* SYMBOL_LIB_TABLE::PropNonPowerSymsOnly = "non_pwr_sym_only";
49int SYMBOL_LIB_TABLE::m_modifyHash = 1; // starts at 1 and goes up
50
51
56
57
59{
60 return LIB_TABLE_ROW::operator == ( aRow ) && type == aRow.type;
61}
62
63
64void SYMBOL_LIB_TABLE_ROW::SetType( const wxString& aType )
65{
67
68 if( SCH_IO_MGR::SCH_FILE_T( -1 ) == type )
69 type = SCH_IO_MGR::SCH_LEGACY;
70
72}
73
74
76{
77 if( !plugin )
78 {
79 wxArrayString dummyList;
80
81 plugin.set( SCH_IO_MGR::FindPlugin( type ) );
82 SetLoaded( false );
83 plugin->SetLibTable( static_cast<SYMBOL_LIB_TABLE*>( GetParent() ) );
84 plugin->EnumerateSymbolLib( dummyList, GetFullURI( true ), GetProperties() );
85 SetLoaded( true );
86 return true;
87 }
88
89 return false;
90}
91
92
93void SYMBOL_LIB_TABLE_ROW::GetSubLibraryNames( std::vector<wxString>& aNames ) const
94{
95 if( !plugin )
96 return;
97
98 plugin->GetSubLibraryNames( aNames );
99}
100
101
103 LIB_TABLE( aFallBackTable )
104{
105 // not copying fall back, simply search aFallBackTable separately
106 // if "nickName not found".
107}
108
109
111{
113}
114
115
116void SYMBOL_LIB_TABLE::Parse( LIB_TABLE_LEXER* in )
117{
118 T tok;
119 wxString errMsg; // to collect error messages
120
121 // This table may be nested within a larger s-expression, or not.
122 // Allow for parser of that optional containing s-epression to have looked ahead.
123 if( in->CurTok() != T_sym_lib_table )
124 {
125 in->NeedLEFT();
126
127 if( ( tok = in->NextTok() ) != T_sym_lib_table )
128 in->Expecting( T_sym_lib_table );
129 }
130
131 while( ( tok = in->NextTok() ) != T_RIGHT )
132 {
133 std::unique_ptr< SYMBOL_LIB_TABLE_ROW > row = std::make_unique<SYMBOL_LIB_TABLE_ROW>();
134
135 if( tok == T_EOF )
136 in->Expecting( T_RIGHT );
137
138 if( tok != T_LEFT )
139 in->Expecting( T_LEFT );
140
141 // in case there is a "row integrity" error, tell where later.
142 int lineNum = in->CurLineNumber();
143
144 if( ( tok = in->NextTok() ) != T_lib )
145 in->Expecting( T_lib );
146
147 // (name NICKNAME)
148 in->NeedLEFT();
149
150 if( ( tok = in->NextTok() ) != T_name )
151 in->Expecting( T_name );
152
153 in->NeedSYMBOLorNUMBER();
154
155 row->SetNickName( in->FromUTF8() );
156
157 in->NeedRIGHT();
158
159 // After (name), remaining (lib) elements are order independent, and in
160 // some cases optional.
161 bool sawType = false;
162 bool sawOpts = false;
163 bool sawDesc = false;
164 bool sawUri = false;
165 bool sawDisabled = false;
166 bool sawHidden = false;
167
168 while( ( tok = in->NextTok() ) != T_RIGHT )
169 {
170 if( tok == T_EOF )
171 in->Unexpected( T_EOF );
172
173 if( tok != T_LEFT )
174 in->Expecting( T_LEFT );
175
176 tok = in->NeedSYMBOLorNUMBER();
177
178 switch( tok )
179 {
180 case T_uri:
181 if( sawUri )
182 in->Duplicate( tok );
183 sawUri = true;
184 in->NeedSYMBOLorNUMBER();
185 row->SetFullURI( in->FromUTF8() );
186 break;
187
188 case T_type:
189 if( sawType )
190 in->Duplicate( tok );
191 sawType = true;
192 in->NeedSYMBOLorNUMBER();
193 row->SetType( in->FromUTF8() );
194 break;
195
196 case T_options:
197 if( sawOpts )
198 in->Duplicate( tok );
199 sawOpts = true;
200 in->NeedSYMBOLorNUMBER();
201 row->SetOptions( in->FromUTF8() );
202 break;
203
204 case T_descr:
205 if( sawDesc )
206 in->Duplicate( tok );
207 sawDesc = true;
208 in->NeedSYMBOLorNUMBER();
209 row->SetDescr( in->FromUTF8() );
210 break;
211
212 case T_disabled:
213 if( sawDisabled )
214 in->Duplicate( tok );
215 sawDisabled = true;
216 row->SetEnabled( false );
217 break;
218
219 case T_hidden:
220 if( sawHidden )
221 in->Duplicate( tok );
222 sawHidden = true;
223 row->SetVisible( false );
224 break;
225
226 default:
227 in->Unexpected( tok );
228 }
229
230 in->NeedRIGHT();
231 }
232
233 if( !sawType )
234 in->Expecting( T_type );
235
236 if( !sawUri )
237 in->Expecting( T_uri );
238
239 // all nickNames within this table fragment must be unique, so we do not
240 // use doReplace in InsertRow(). (However a fallBack table can have a
241 // conflicting nickName and ours will supercede that one since in
242 // FindLib() we search this table before any fall back.)
243 wxString nickname = row->GetNickName(); // store it to be able to used it
244 // after row deletion if an error occurs
245 LIB_TABLE_ROW* tmp = row.release();
246
247 if( !InsertRow( tmp ) )
248 {
249 delete tmp; // The table did not take ownership of the row.
250
251 wxString msg = wxString::Format( _( "Duplicate library nickname '%s' found in symbol "
252 "library table file line %d" ),
253 nickname,
254 lineNum );
255
256 if( !errMsg.IsEmpty() )
257 errMsg << '\n';
258
259 errMsg << msg;
260 }
261 }
262
263 if( !errMsg.IsEmpty() )
264 THROW_IO_ERROR( errMsg );
265}
266
267
268void SYMBOL_LIB_TABLE::Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const
269{
270 aOutput->Print( aIndentLevel, "(sym_lib_table\n" );
271
272 for( LIB_TABLE_ROWS_CITER it = rows.begin(); it != rows.end(); ++it )
273 {
274 it->Format( aOutput, aIndentLevel+1 );
275 }
276
277 aOutput->Print( aIndentLevel, ")\n" );
278}
279
280
282{
283 int hash = 0;
284 std::vector< wxString > libNames = GetLogicalLibs();
285
286 for( const auto& libName : libNames )
287 {
288 const SYMBOL_LIB_TABLE_ROW* row = FindRow( libName, true );
289
290 if( !row || !row->plugin )
291 {
292 wxFAIL;
293 continue;
294 }
295
296 hash += row->plugin->GetModifyHash();
297 }
298
299 hash += m_modifyHash;
300
301 return hash;
302}
303
304
305void SYMBOL_LIB_TABLE::EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames,
306 bool aPowerSymbolsOnly )
307{
308 SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
309 wxCHECK( row && row->plugin, /* void */ );
310
311 wxString options = row->GetOptions();
312
313 if( aPowerSymbolsOnly )
314 row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly );
315
316 row->SetLoaded( false );
317 row->plugin->EnumerateSymbolLib( aAliasNames, row->GetFullURI( true ), row->GetProperties() );
318 row->SetLoaded( true );
319
320 if( aPowerSymbolsOnly )
321 row->SetOptions( options );
322}
323
324
325SYMBOL_LIB_TABLE_ROW* SYMBOL_LIB_TABLE::FindRow( const wxString& aNickname, bool aCheckIfEnabled )
326{
328 dynamic_cast< SYMBOL_LIB_TABLE_ROW* >( findRow( aNickname, aCheckIfEnabled ) );
329
330 if( !row )
331 return nullptr;
332
333 // We've been 'lazy' up until now, but it cannot be deferred any longer,
334 // instantiate a PLUGIN of the proper kind if it is not already in this
335 // SYMBOL_LIB_TABLE_ROW.
336 if( !row->plugin )
337 {
338 row->setPlugin( SCH_IO_MGR::FindPlugin( row->type ) );
339 row->plugin->SetLibTable( this );
340 }
341
342 return row;
343}
344
345
346void SYMBOL_LIB_TABLE::LoadSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
347 const wxString& aNickname, bool aPowerSymbolsOnly )
348{
349 SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
350 wxCHECK( row && row->plugin, /* void */ );
351
352 std::lock_guard<std::mutex> lock( row->GetMutex() );
353
354 wxString options = row->GetOptions();
355
356 if( aPowerSymbolsOnly )
357 row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly );
358
359 row->SetLoaded( false );
360 row->plugin->EnumerateSymbolLib( aSymbolList, row->GetFullURI( true ), row->GetProperties() );
361 row->SetLoaded( true );
362
363 if( aPowerSymbolsOnly )
364 row->SetOptions( options );
365
366 // The library cannot know its own name, because it might have been renamed or moved.
367 // Therefore footprints cannot know their own library nickname when residing in
368 // a symbol library.
369 // Only at this API layer can we tell the symbol about its actual library nickname.
370 for( LIB_SYMBOL* symbol : aSymbolList )
371 {
372 LIB_ID id = symbol->GetLibId();
373
374 id.SetLibNickname( row->GetNickName() );
375 symbol->SetLibId( id );
376 }
377}
378
379
380LIB_SYMBOL* SYMBOL_LIB_TABLE::LoadSymbol( const wxString& aNickname, const wxString& aSymbolName )
381{
382 SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
383
384 if( !row || !row->plugin )
385 return nullptr;
386
387 // If another thread is loading this library at the moment; continue
388 std::unique_lock<std::mutex> lock( row->GetMutex(), std::try_to_lock );
389
390 if( !lock.owns_lock() )
391 return nullptr;
392
393 LIB_SYMBOL* symbol = row->plugin->LoadSymbol( row->GetFullURI( true ), aSymbolName,
394 row->GetProperties() );
395
396 // The library cannot know its own name, because it might have been renamed or moved.
397 // Therefore footprints cannot know their own library nickname when residing in
398 // a symbol library.
399 // Only at this API layer can we tell the symbol about its actual library nickname.
400 if( symbol )
401 {
402 LIB_ID id = symbol->GetLibId();
403
404 id.SetLibNickname( row->GetNickName() );
405 symbol->SetLibId( id );
406 }
407
408 return symbol;
409}
410
411
413 const LIB_SYMBOL* aSymbol, bool aOverwrite )
414{
415 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
416 wxCHECK( row && row->plugin, SAVE_SKIPPED );
417
418 if( !row->plugin->IsSymbolLibWritable( row->GetFullURI( true ) ) )
419 return SAVE_SKIPPED;
420
421 if( !aOverwrite )
422 {
423 // Try loading the footprint to see if it already exists, caller wants overwrite
424 // protection, which is atypical, not the default.
425
426 wxString name = aSymbol->GetLibId().GetLibItemName();
427
428 std::unique_ptr<LIB_SYMBOL> symbol( row->plugin->LoadSymbol( row->GetFullURI( true ),
429 name, row->GetProperties() ) );
430
431 if( symbol.get() )
432 return SAVE_SKIPPED;
433 }
434
435 try
436 {
437 row->plugin->SaveSymbol( row->GetFullURI( true ), aSymbol, row->GetProperties() );
438 }
439 catch( const IO_ERROR& )
440 {
441 return SAVE_SKIPPED;
442 }
443
444 return SAVE_OK;
445}
446
447
448void SYMBOL_LIB_TABLE::DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName )
449{
450 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
451 wxCHECK( row && row->plugin, /* void */ );
452 return row->plugin->DeleteSymbol( row->GetFullURI( true ), aSymbolName, row->GetProperties() );
453}
454
455
456bool SYMBOL_LIB_TABLE::IsSymbolLibWritable( const wxString& aNickname )
457{
458 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
459 wxCHECK( row && row->plugin, false );
460 return row->plugin->IsSymbolLibWritable( row->GetFullURI( true ) );
461}
462
463bool SYMBOL_LIB_TABLE::IsSymbolLibLoaded( const wxString& aNickname )
464{
465 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
466 wxCHECK( row, false );
467 return row->GetIsLoaded();
468}
469
470
471void SYMBOL_LIB_TABLE::DeleteSymbolLib( const wxString& aNickname )
472{
473 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
474 wxCHECK( row && row->plugin, /* void */ );
475 row->plugin->DeleteSymbolLib( row->GetFullURI( true ), row->GetProperties() );
476}
477
478
479void SYMBOL_LIB_TABLE::CreateSymbolLib( const wxString& aNickname )
480{
481 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
482 wxCHECK( row && row->plugin, /* void */ );
483 row->plugin->CreateSymbolLib( row->GetFullURI( true ), row->GetProperties() );
484}
485
486
488{
489 wxString nickname = aLibId.GetLibNickname();
490 wxString name = aLibId.GetLibItemName();
491
492 if( nickname.size() )
493 {
494 return LoadSymbol( nickname, name );
495 }
496 else
497 {
498 // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
499 std::vector<wxString> nicks = GetLogicalLibs();
500
501 // Search each library going through libraries alphabetically.
502 for( unsigned i = 0; i < nicks.size(); ++i )
503 {
504 // FootprintLoad() returns NULL on not found, does not throw exception
505 // unless there's an IO_ERROR.
506 LIB_SYMBOL* ret = LoadSymbol( nicks[i], name );
507
508 if( ret )
509 return ret;
510 }
511
512 return nullptr;
513 }
514}
515
516
518{
519 return "KICAD6_SYMBOL_DIR";
520}
521
522
523class PCM_SYM_LIB_TRAVERSER final : public wxDirTraverser
524{
525public:
526 explicit PCM_SYM_LIB_TRAVERSER( const wxString& aPath, SYMBOL_LIB_TABLE& aTable,
527 const wxString& aPrefix ) :
528 m_lib_table( aTable ),
529 m_path_prefix( aPath ),
530 m_lib_prefix( aPrefix )
531 {
532 wxFileName f( aPath, "" );
533 m_prefix_dir_count = f.GetDirCount();
534 }
535
536 wxDirTraverseResult OnFile( const wxString& aFilePath ) override
537 {
538 wxFileName file = wxFileName::FileName( aFilePath );
539
540 // consider a file to be a lib if it's name ends with .kicad_sym and
541 // it is under $KICAD6_3RD_PARTY/symbols/<pkgid>/ i.e. has nested level of at least +2
542 if( file.GetExt() == wxT( "kicad_sym" ) && file.GetDirCount() >= m_prefix_dir_count + 2 )
543 {
544 wxArrayString parts = file.GetDirs();
545 parts.RemoveAt( 0, m_prefix_dir_count );
546 parts.Insert( "${KICAD6_3RD_PARTY}", 0 );
547 parts.Add( file.GetFullName() );
548
549 wxString libPath = wxJoin( parts, '/' );
550
551 if( !m_lib_table.HasLibraryWithPath( libPath ) )
552 {
553 wxString name = parts.Last().substr( 0, parts.Last().length() - 10 );
554 wxString nickname = wxString::Format( "%s%s", m_lib_prefix, name );
555
556 if( m_lib_table.HasLibrary( nickname ) )
557 {
558 int increment = 1;
559 do
560 {
561 nickname = wxString::Format( "%s%s_%d", m_lib_prefix, name, increment );
562 increment++;
563 } while( m_lib_table.HasLibrary( nickname ) );
564 }
565
567 new SYMBOL_LIB_TABLE_ROW( nickname, libPath, wxT( "KiCad" ), wxEmptyString,
568 _( "Added by Plugin and Content Manager" ) ) );
569 }
570 }
571
572 return wxDIR_CONTINUE;
573 }
574
575 wxDirTraverseResult OnDir( const wxString& dirPath ) override { return wxDIR_CONTINUE; }
576
577private:
580 wxString m_lib_prefix;
582};
583
584
586{
587 bool tableExists = true;
588 wxFileName fn = GetGlobalTableFileName();
589
590 if( !fn.FileExists() )
591 {
592 tableExists = false;
593
594 if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
595 {
596 THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ),
597 fn.GetPath() ) );
598 }
599
600 // Attempt to copy the default global file table from the KiCad
601 // template folder to the user's home configuration path.
602 SEARCH_STACK ss;
603
604 SystemDirsAppend( &ss );
605
606 wxString templatePath =
607 Pgm().GetLocalEnvVariables().at( wxT( "KICAD6_TEMPLATE_DIR" ) ).GetValue();
608
609 if( !templatePath.IsEmpty() )
610 ss.AddPaths( templatePath, 0 );
611
612 wxString fileName = ss.FindValidPath( global_tbl_name );
613
614 // The fallback is to create an empty global symbol table for the user to populate.
615 if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
616 {
617 SYMBOL_LIB_TABLE emptyTable;
618
619 emptyTable.Save( fn.GetFullPath() );
620 }
621 }
622
623 aTable.Load( fn.GetFullPath() );
624
625 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
627
628 wxString packagesPath = Pgm().GetLocalEnvVariables().at( wxT( "KICAD6_3RD_PARTY" ) ).GetValue();
629
630 if( settings->m_PcmLibAutoAdd )
631 {
632 // Scan for libraries in PCM packages directory
633 wxFileName d( packagesPath, "" );
634 d.AppendDir( "symbols" );
635
636 if( d.DirExists() )
637 {
638 PCM_SYM_LIB_TRAVERSER traverser( packagesPath, aTable, settings->m_PcmLibPrefix );
639 wxDir dir( d.GetPath() );
640
641 dir.Traverse( traverser );
642 }
643 }
644
645 if( settings->m_PcmLibAutoRemove )
646 {
647 // Remove PCM libraries that no longer exist
648 std::vector<wxString> to_remove;
649
650 for( size_t i = 0; i < aTable.GetCount(); i++ )
651 {
652 LIB_TABLE_ROW& row = aTable.At( i );
653 wxString path = row.GetFullURI( true );
654
655 if( path.StartsWith( packagesPath ) && !wxFile::Exists( path ) )
656 to_remove.push_back( row.GetNickName() );
657 }
658
659 for( const wxString& nickName : to_remove )
660 aTable.RemoveRow( aTable.FindRow( nickName ) );
661 }
662
663 return tableExists;
664}
665
666
668{
669 wxFileName fn;
670
672 fn.SetName( global_tbl_name );
673
674 return fn.GetFullPath();
675}
676
677
679{
680 return global_tbl_name;
681}
const char * name
Definition: DXF_plotter.cpp:56
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
wxString m_PcmLibPrefix
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:98
const UTF8 & GetLibItemName() const
Definition: lib_id.h:101
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
Define a library symbol object.
Definition: lib_symbol.h:98
LIB_ID GetLibId() const override
Definition: lib_symbol.h:139
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:140
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
std::mutex & GetMutex()
bool GetIsLoaded() const
LIB_TABLE * GetParent() const
void SetLoaded(bool aLoaded)
Mark the row as being a loaded library.
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...
bool operator==(const LIB_TABLE_ROW &r) const
void SetOptions(const wxString &aOptions)
Change the library options strings.
const STRING_UTF8_MAP * GetProperties() const
Return the constant #PROPERTIES for this library (LIB_TABLE_ROW).
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
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.
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
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.
LIB_TABLE_ROWS rows
bool RemoveRow(const LIB_TABLE_ROW *aRow)
Removes a row from the table.
unsigned GetCount() const
Get the number of rows contained in the table.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
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,...
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:310
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:431
wxDirTraverseResult OnFile(const wxString &aFilePath) override
wxDirTraverseResult OnDir(const wxString &dirPath) override
SYMBOL_LIB_TABLE & m_lib_table
PCM_SYM_LIB_TRAVERSER(const wxString &aPath, SYMBOL_LIB_TABLE &aTable, const wxString &aPrefix)
static SCH_FILE_T EnumFromStr(const wxString &aFileType)
Return the #SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy",...
Definition: sch_io_mgr.cpp:101
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:562
virtual void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
Definition: sch_plugin.cpp:67
virtual int GetModifyHash() const =0
Return the modification hash from the library cache.
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const STRING_UTF8_MAP *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:94
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const STRING_UTF8_MAP *aProperties=nullptr)
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
Definition: sch_plugin.cpp:102
virtual LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const STRING_UTF8_MAP *aProperties=nullptr)
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
Definition: sch_plugin.cpp:85
virtual void SetLibTable(SYMBOL_LIB_TABLE *aTable)
Some library plugins need to have access to their parent library table.
Definition: sch_io_mgr.h:515
virtual void CreateSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:110
virtual bool DeleteSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Delete an existing symbol library and returns true if successful, or if library does not exist return...
Definition: sch_plugin.cpp:117
virtual void GetSubLibraryNames(std::vector< wxString > &aNames)
Retrieves a list of sub-libraries in this library.
Definition: sch_io_mgr.h:463
virtual bool IsSymbolLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: sch_plugin.cpp:125
Look for files in a number of paths.
Definition: search_stack.h:42
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
T * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
bool operator==(const SYMBOL_LIB_TABLE_ROW &aRow) const
void SetType(const wxString &aType) override
Change the schematic plugin type represented by this row.
void GetSubLibraryNames(std::vector< wxString > &aNames) const
void setPlugin(SCH_PLUGIN *aPlugin)
bool Refresh()
Attempt to reload the library.
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
void LoadSymbolLib(std::vector< LIB_SYMBOL * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
void DeleteSymbol(const wxString &aNickname, const wxString &aSymbolName)
Deletes the aSymbolName from the library given by aNickname.
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
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...
static const wxString & GetSymbolLibTableFileName()
SYMBOL_LIB_TABLE(SYMBOL_LIB_TABLE *aFallBackTable=nullptr)
Build a symbol library table by pre-pending this table fragment in front of aFallBackTable.
static const char * PropPowerSymsOnly
bool IsSymbolLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
bool IsSymbolLibLoaded(const wxString &aNickname)
Return true if the library given by aNickname was successfully loaded.
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
void DeleteSymbolLib(const wxString &aNickname)
void CreateSymbolLib(const wxString &aNickname)
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
void EnumerateSymbolLib(const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
Return a list of symbol alias names contained within the library given by aNickname.
static bool LoadGlobalTable(SYMBOL_LIB_TABLE &aTable)
Load the global symbol library table into aTable.
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
LIB_SYMBOL * LoadSymbolWithOptionalNickname(const LIB_ID &aId)
Load a LIB_SYMBOL having aFootprintId with possibly an empty library nickname.
static const char * PropNonPowerSymsOnly
SAVE_T SaveSymbol(const wxString &aNickname, const LIB_SYMBOL *aSymbol, bool aOverwrite=true)
Write aSymbol to an existing library given by aNickname.
SAVE_T
The set of return values from SaveSymbol() below.
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...
static int m_modifyHash
helper for GetModifyHash()
#define _(s)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
see class PGM_BASE
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
SYMBOL_LIB_TABLE g_symbolLibraryTable
The global symbol library table.
static const wxString global_tbl_name("sym-lib-table")
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
System directories search utilities.