KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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) 2022 CERN
6 * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26
27#include <env_vars.h>
28#include <lib_id.h>
29#include <lib_table_lexer.h>
30#include <paths.h>
31#include <pgm_base.h>
32#include <search_stack.h>
35#include <systemdirsappend.h>
36#include <symbol_lib_table.h>
37#include <lib_symbol.h>
40
41#include <wx/dir.h>
42#include "sim/sim_model.h"
43
44#define OPT_SEP '|'
45
46using namespace LIB_TABLE_T;
47
48
49static const wxString global_tbl_name( "sym-lib-table" );
50
51
52const char* SYMBOL_LIB_TABLE::PropPowerSymsOnly = "pwr_sym_only";
53const char* SYMBOL_LIB_TABLE::PropNonPowerSymsOnly = "non_pwr_sym_only";
54int SYMBOL_LIB_TABLE::m_modifyHash = 1; // starts at 1 and goes up
55
56
61
62
64{
65 return LIB_TABLE_ROW::operator == ( aRow ) && type == aRow.type;
66}
67
68
69void SYMBOL_LIB_TABLE_ROW::SetType( const wxString& aType )
70{
72
73 if( type == SCH_IO_MGR::SCH_FILE_UNKNOWN )
74 type = SCH_IO_MGR::SCH_KICAD;
75
76 plugin.reset();
77}
78
79
81{
82 if( !plugin )
83 {
84 wxArrayString dummyList;
85
86 plugin.reset( SCH_IO_MGR::FindPlugin( type ) );
87 SetLoaded( false );
88 plugin->SetLibTable( static_cast<SYMBOL_LIB_TABLE*>( GetParent() ) );
89 plugin->EnumerateSymbolLib( dummyList, GetFullURI( true ), GetProperties() );
90 SetLoaded( true );
91 return true;
92 }
93
94 return false;
95}
96
97
98void SYMBOL_LIB_TABLE_ROW::GetSubLibraryNames( std::vector<wxString>& aNames ) const
99{
100 if( !plugin )
101 return;
102
103 plugin->GetSubLibraryNames( aNames );
104}
105
106
107void SYMBOL_LIB_TABLE_ROW::ShowSettingsDialog( wxWindow* aParent ) const
108{
109 wxCHECK( plugin, /* void */ );
110
111 if( type != SCH_IO_MGR::SCH_DATABASE )
112 return;
113
114 DIALOG_DATABASE_LIB_SETTINGS dlg( aParent, static_cast<SCH_IO_DATABASE*>( plugin.get() ) );
115 dlg.ShowModal();
116}
117
118
120 LIB_TABLE( aFallBackTable )
121{
122 // not copying fall back, simply search aFallBackTable separately
123 // if "nickName not found".
124}
125
126
128{
130}
131
132
133void SYMBOL_LIB_TABLE::Parse( LIB_TABLE_LEXER* in )
134{
135 T tok;
136 wxString errMsg; // to collect error messages
137
138 // This table may be nested within a larger s-expression, or not.
139 // Allow for parser of that optional containing s-epression to have looked ahead.
140 if( in->CurTok() != T_sym_lib_table )
141 {
142 in->NeedLEFT();
143
144 if( ( tok = in->NextTok() ) != T_sym_lib_table )
145 in->Expecting( T_sym_lib_table );
146 }
147
148 while( ( tok = in->NextTok() ) != T_RIGHT )
149 {
150 std::unique_ptr< SYMBOL_LIB_TABLE_ROW > row = std::make_unique<SYMBOL_LIB_TABLE_ROW>();
151
152 if( tok == T_EOF )
153 in->Expecting( T_RIGHT );
154
155 if( tok != T_LEFT )
156 in->Expecting( T_LEFT );
157
158 // in case there is a "row integrity" error, tell where later.
159 int lineNum = in->CurLineNumber();
160 tok = in->NextTok();
161
162 // Optionally parse the current version number
163 if( tok == T_version )
164 {
165 in->NeedNUMBER( "version" );
166 m_version = std::stoi( in->CurText() );
167 in->NeedRIGHT();
168 continue;
169 }
170
171 if( tok != T_lib )
172 in->Expecting( T_lib );
173
174 // (name NICKNAME)
175 in->NeedLEFT();
176
177 if( ( tok = in->NextTok() ) != T_name )
178 in->Expecting( T_name );
179
180 in->NeedSYMBOLorNUMBER();
181
182 row->SetNickName( in->FromUTF8() );
183
184 in->NeedRIGHT();
185
186 // After (name), remaining (lib) elements are order independent, and in
187 // some cases optional.
188 bool sawType = false;
189 bool sawOpts = false;
190 bool sawDesc = false;
191 bool sawUri = false;
192 bool sawDisabled = false;
193 bool sawHidden = false;
194
195 while( ( tok = in->NextTok() ) != T_RIGHT )
196 {
197 if( tok == T_EOF )
198 in->Unexpected( T_EOF );
199
200 if( tok != T_LEFT )
201 in->Expecting( T_LEFT );
202
203 tok = in->NeedSYMBOLorNUMBER();
204
205 switch( tok )
206 {
207 case T_uri:
208 if( sawUri )
209 in->Duplicate( tok );
210 sawUri = true;
211 in->NeedSYMBOLorNUMBER();
212 row->SetFullURI( in->FromUTF8() );
213 break;
214
215 case T_type:
216 if( sawType )
217 in->Duplicate( tok );
218 sawType = true;
219 in->NeedSYMBOLorNUMBER();
220 row->SetType( in->FromUTF8() );
221 break;
222
223 case T_options:
224 if( sawOpts )
225 in->Duplicate( tok );
226 sawOpts = true;
227 in->NeedSYMBOLorNUMBER();
228 row->SetOptions( in->FromUTF8() );
229 break;
230
231 case T_descr:
232 if( sawDesc )
233 in->Duplicate( tok );
234 sawDesc = true;
235 in->NeedSYMBOLorNUMBER();
236 row->SetDescr( in->FromUTF8() );
237 break;
238
239 case T_disabled:
240 if( sawDisabled )
241 in->Duplicate( tok );
242 sawDisabled = true;
243 row->SetEnabled( false );
244 break;
245
246 case T_hidden:
247 if( sawHidden )
248 in->Duplicate( tok );
249 sawHidden = true;
250 row->SetVisible( false );
251 break;
252
253 default:
254 in->Unexpected( tok );
255 }
256
257 in->NeedRIGHT();
258 }
259
260 if( !sawType )
261 in->Expecting( T_type );
262
263 if( !sawUri )
264 in->Expecting( T_uri );
265
266 // all nickNames within this table fragment must be unique, so we do not
267 // use doReplace in InsertRow(). (However a fallBack table can have a
268 // conflicting nickName and ours will supercede that one since in
269 // FindLib() we search this table before any fall back.)
270 wxString nickname = row->GetNickName(); // store it to be able to used it
271 // after row deletion if an error occurs
272 LIB_TABLE_ROW* tmp = row.release();
273
274 if( !InsertRow( tmp ) )
275 {
276 delete tmp; // The table did not take ownership of the row.
277
278 wxString msg = wxString::Format( _( "Duplicate library nickname '%s' found in symbol "
279 "library table file line %d" ),
280 nickname,
281 lineNum );
282
283 if( !errMsg.IsEmpty() )
284 errMsg << '\n';
285
286 errMsg << msg;
287 }
288 }
289
290 if( !errMsg.IsEmpty() )
291 THROW_IO_ERROR( errMsg );
292}
293
294
295void SYMBOL_LIB_TABLE::Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const
296{
297 aOutput->Print( aIndentLevel, "(sym_lib_table\n" );
298 aOutput->Print( aIndentLevel + 1, "(version %d)\n", m_version );
299
300 for( const LIB_TABLE_ROW& row : m_rows )
301 row.Format( aOutput, aIndentLevel + 1 );
302
303 aOutput->Print( aIndentLevel, ")\n" );
304}
305
306
308{
309 int hash = 0;
310 std::vector< wxString > libNames = GetLogicalLibs();
311
312 for( const auto& libName : libNames )
313 {
314 const SYMBOL_LIB_TABLE_ROW* row = FindRow( libName, true );
315
316 if( !row || !row->plugin )
317 {
318 continue;
319 }
320
321 hash += row->plugin->GetModifyHash();
322 }
323
324 hash += m_modifyHash;
325
326 return hash;
327}
328
329
330void SYMBOL_LIB_TABLE::EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames,
331 bool aPowerSymbolsOnly )
332{
333 SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
334 wxCHECK( row && row->plugin, /* void */ );
335
336 wxString options = row->GetOptions();
337
338 if( aPowerSymbolsOnly )
339 row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly );
340
341 row->SetLoaded( false );
342 row->plugin->EnumerateSymbolLib( aAliasNames, row->GetFullURI( true ), row->GetProperties() );
343 row->SetLoaded( true );
344
345 if( aPowerSymbolsOnly )
346 row->SetOptions( options );
347}
348
349
350SYMBOL_LIB_TABLE_ROW* SYMBOL_LIB_TABLE::FindRow( const wxString& aNickname, bool aCheckIfEnabled )
351{
353 dynamic_cast< SYMBOL_LIB_TABLE_ROW* >( findRow( aNickname, aCheckIfEnabled ) );
354
355 if( !row )
356 return nullptr;
357
358 // We've been 'lazy' up until now, but it cannot be deferred any longer,
359 // instantiate a PLUGIN of the proper kind if it is not already in this
360 // SYMBOL_LIB_TABLE_ROW.
361 if( !row->plugin )
362 {
363 row->setPlugin( SCH_IO_MGR::FindPlugin( row->type ) );
364 row->plugin->SetLibTable( this );
365 }
366
367 return row;
368}
369
370
371void SYMBOL_LIB_TABLE::LoadSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
372 const wxString& aNickname, bool aPowerSymbolsOnly )
373{
374 SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
375
376 if( !row || !row->plugin )
377 return;
378
379 std::lock_guard<std::mutex> lock( row->GetMutex() );
380
381 wxString options = row->GetOptions();
382
383 if( aPowerSymbolsOnly )
384 row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly );
385
386 row->SetLoaded( false );
387 row->plugin->SetLibTable( this );
388 row->plugin->EnumerateSymbolLib( aSymbolList, row->GetFullURI( true ), row->GetProperties() );
389 row->SetLoaded( true );
390
391 if( aPowerSymbolsOnly )
392 row->SetOptions( options );
393
394 // The library cannot know its own name, because it might have been renamed or moved.
395 // Therefore footprints cannot know their own library nickname when residing in
396 // a symbol library.
397 // Only at this API layer can we tell the symbol about its actual library nickname.
398 for( LIB_SYMBOL* symbol : aSymbolList )
399 {
400 LIB_ID id = symbol->GetLibId();
401
402 id.SetLibNickname( row->GetNickName() );
403 symbol->SetLibId( id );
404 }
405}
406
407
408LIB_SYMBOL* SYMBOL_LIB_TABLE::LoadSymbol( const wxString& aNickname, const wxString& aSymbolName )
409{
410 SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
411
412 if( !row || !row->plugin )
413 return nullptr;
414
415 // If another thread is loading this library at the moment; continue
416 std::unique_lock<std::mutex> lock( row->GetMutex(), std::try_to_lock );
417
418 if( !lock.owns_lock() )
419 return nullptr;
420
421 LIB_SYMBOL* symbol = row->plugin->LoadSymbol( row->GetFullURI( true ), aSymbolName,
422 row->GetProperties() );
423
424 if( symbol )
425 {
426 // The library cannot know its own name, because it might have been renamed or moved.
427 // Therefore footprints cannot know their own library nickname when residing in
428 // a symbol library.
429 // Only at this API layer can we tell the symbol about its actual library nickname.
430 LIB_ID id = symbol->GetLibId();
431
432 id.SetLibNickname( row->GetNickName() );
433 symbol->SetLibId( id );
434
435 SIM_MODEL::MigrateSimModel<LIB_SYMBOL>( *symbol, nullptr );
436 }
437
438 return symbol;
439}
440
441
443 const LIB_SYMBOL* aSymbol, bool aOverwrite )
444{
445 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
446 wxCHECK( row && row->plugin, SAVE_SKIPPED );
447
448 if( !row->plugin->IsLibraryWritable( row->GetFullURI( true ) ) )
449 return SAVE_SKIPPED;
450
451 if( !aOverwrite )
452 {
453 // Try loading the footprint to see if it already exists, caller wants overwrite
454 // protection, which is atypical, not the default.
455
456 wxString name = aSymbol->GetLibId().GetLibItemName();
457
458 std::unique_ptr<LIB_SYMBOL> symbol( row->plugin->LoadSymbol( row->GetFullURI( true ),
459 name, row->GetProperties() ) );
460
461 if( symbol.get() )
462 return SAVE_SKIPPED;
463 }
464
465 try
466 {
467 row->plugin->SaveSymbol( row->GetFullURI( true ), aSymbol, row->GetProperties() );
468 }
469 catch( const IO_ERROR& )
470 {
471 return SAVE_SKIPPED;
472 }
473
474 return SAVE_OK;
475}
476
477
478void SYMBOL_LIB_TABLE::DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName )
479{
480 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
481 wxCHECK( row && row->plugin, /* void */ );
482 return row->plugin->DeleteSymbol( row->GetFullURI( true ), aSymbolName, row->GetProperties() );
483}
484
485
486bool SYMBOL_LIB_TABLE::IsSymbolLibWritable( const wxString& aNickname )
487{
488 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
489 wxCHECK( row && row->plugin, false );
490 return row->plugin->IsLibraryWritable( row->GetFullURI( true ) );
491}
492
493bool SYMBOL_LIB_TABLE::IsSymbolLibLoaded( const wxString& aNickname )
494{
495 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
496 wxCHECK( row, false );
497 return row->GetIsLoaded();
498}
499
500
501void SYMBOL_LIB_TABLE::DeleteSymbolLib( const wxString& aNickname )
502{
503 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
504 wxCHECK( row && row->plugin, /* void */ );
505 row->plugin->DeleteLibrary( row->GetFullURI( true ), row->GetProperties() );
506}
507
508
509void SYMBOL_LIB_TABLE::CreateSymbolLib( const wxString& aNickname )
510{
511 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
512 wxCHECK( row && row->plugin, /* void */ );
513 row->plugin->CreateLibrary( row->GetFullURI( true ), row->GetProperties() );
514}
515
516
518{
519 wxString nickname = aLibId.GetLibNickname();
520 wxString name = aLibId.GetLibItemName();
521
522 if( nickname.size() )
523 {
524 return LoadSymbol( nickname, name );
525 }
526 else
527 {
528 // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
529 std::vector<wxString> nicks = GetLogicalLibs();
530
531 // Search each library going through libraries alphabetically.
532 for( unsigned i = 0; i < nicks.size(); ++i )
533 {
534 // FootprintLoad() returns NULL on not found, does not throw exception
535 // unless there's an IO_ERROR.
536 LIB_SYMBOL* ret = LoadSymbol( nicks[i], name );
537
538 if( ret )
539 return ret;
540 }
541
542 return nullptr;
543 }
544}
545
546
548{
549 return ENV_VAR::GetVersionedEnvVarName( wxS( "SYMBOL_DIR" ) );
550}
551
552
553class PCM_SYM_LIB_TRAVERSER final : public wxDirTraverser
554{
555public:
556 explicit PCM_SYM_LIB_TRAVERSER( const wxString& aPath, SYMBOL_LIB_TABLE& aTable,
557 const wxString& aPrefix ) :
558 m_lib_table( aTable ),
559 m_path_prefix( aPath ),
560 m_lib_prefix( aPrefix )
561 {
562 wxFileName f( aPath, "" );
563 m_prefix_dir_count = f.GetDirCount();
564 }
565
566 wxDirTraverseResult OnFile( const wxString& aFilePath ) override
567 {
568 wxFileName file = wxFileName::FileName( aFilePath );
569
570 // consider a file to be a lib if it's name ends with .kicad_sym and
571 // it is under $KICADn_3RD_PARTY/symbols/<pkgid>/ i.e. has nested level of at least +2
572 if( file.GetExt() == wxT( "kicad_sym" ) && file.GetDirCount() >= m_prefix_dir_count + 2 )
573 {
574 wxString versionedPath = wxString::Format( wxS( "${%s}" ),
575 ENV_VAR::GetVersionedEnvVarName( wxS( "3RD_PARTY" ) ) );
576
577 wxArrayString parts = file.GetDirs();
578 parts.RemoveAt( 0, m_prefix_dir_count );
579 parts.Insert( versionedPath, 0 );
580 parts.Add( file.GetFullName() );
581
582 wxString libPath = wxJoin( parts, '/' );
583
584 if( !m_lib_table.HasLibraryWithPath( libPath ) )
585 {
586 wxString name = parts.Last().substr( 0, parts.Last().length() - 10 );
587 wxString nickname = wxString::Format( "%s%s", m_lib_prefix, name );
588
589 if( m_lib_table.HasLibrary( nickname ) )
590 {
591 int increment = 1;
592 do
593 {
594 nickname = wxString::Format( "%s%s_%d", m_lib_prefix, name, increment );
595 increment++;
596 } while( m_lib_table.HasLibrary( nickname ) );
597 }
598
600 new SYMBOL_LIB_TABLE_ROW( nickname, libPath, wxT( "KiCad" ), wxEmptyString,
601 _( "Added by Plugin and Content Manager" ) ) );
602 }
603 }
604
605 return wxDIR_CONTINUE;
606 }
607
608 wxDirTraverseResult OnDir( const wxString& dirPath ) override { return wxDIR_CONTINUE; }
609
610private:
613 wxString m_lib_prefix;
615};
616
617
619{
620 bool tableExists = true;
621 wxFileName fn = GetGlobalTableFileName();
622
623 if( !fn.FileExists() )
624 {
625 tableExists = false;
626
627 if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
628 {
629 THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ),
630 fn.GetPath() ) );
631 }
632
633 // Attempt to copy the default global file table from the KiCad
634 // template folder to the user's home configuration path.
635 SEARCH_STACK ss;
636
637 SystemDirsAppend( &ss );
638
639 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
640 std::optional<wxString> v = ENV_VAR::GetVersionedEnvVarValue( envVars,
641 wxT( "TEMPLATE_DIR" ) );
642
643 if( v && !v->IsEmpty() )
644 ss.AddPaths( *v, 0 );
645
646 wxString fileName = ss.FindValidPath( global_tbl_name );
647
648 // The fallback is to create an empty global symbol table for the user to populate.
649 if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
650 {
651 SYMBOL_LIB_TABLE emptyTable;
652
653 emptyTable.Save( fn.GetFullPath() );
654 }
655 }
656
657 aTable.Clear();
658 aTable.Load( fn.GetFullPath() );
659
662
663 wxCHECK( settings, false );
664
665 wxString packagesPath;
666 const ENV_VAR_MAP& vars = Pgm().GetLocalEnvVariables();
667
668 if( std::optional<wxString> v = ENV_VAR::GetVersionedEnvVarValue( vars, wxT( "3RD_PARTY" ) ) )
669 packagesPath = *v;
670
671 if( settings->m_PcmLibAutoAdd )
672 {
673 // Scan for libraries in PCM packages directory
674 wxFileName d( packagesPath, "" );
675 d.AppendDir( "symbols" );
676
677 if( d.DirExists() )
678 {
679 PCM_SYM_LIB_TRAVERSER traverser( packagesPath, aTable, settings->m_PcmLibPrefix );
680 wxDir dir( d.GetPath() );
681
682 dir.Traverse( traverser );
683 }
684 }
685
686 if( settings->m_PcmLibAutoRemove )
687 {
688 // Remove PCM libraries that no longer exist
689 std::vector<wxString> to_remove;
690
691 for( size_t i = 0; i < aTable.GetCount(); i++ )
692 {
693 LIB_TABLE_ROW& row = aTable.At( i );
694 wxString path = row.GetFullURI( true );
695
696 if( path.StartsWith( packagesPath ) && !wxFile::Exists( path ) )
697 to_remove.push_back( row.GetNickName() );
698 }
699
700 for( const wxString& nickName : to_remove )
701 {
702 SYMBOL_LIB_TABLE_ROW* row = aTable.FindRow( nickName );
703
704 wxCHECK2( row, continue );
705
706 aTable.RemoveRow( row );
707 }
708 }
709
710 return tableExists;
711}
712
713
715{
716 if( m_rows.size() != aOther.m_rows.size() )
717 return false;
718
719 unsigned i;
720
721 for( i = 0; i < m_rows.size(); ++i )
722 {
723 const SYMBOL_LIB_TABLE_ROW& curr = static_cast<const SYMBOL_LIB_TABLE_ROW&>( m_rows[i] );
724 const SYMBOL_LIB_TABLE_ROW& curr_other = static_cast<const SYMBOL_LIB_TABLE_ROW&>( aOther.m_rows[i] );
725
726 if( curr != curr_other )
727 return false;
728 }
729
730 return true;
731}
732
733
735{
736 wxFileName fn;
737
738 fn.SetPath( PATHS::GetUserSettingsPath() );
739 fn.SetName( global_tbl_name );
740
741 return fn.GetFullPath();
742}
743
744
746{
747 return global_tbl_name;
748}
const char * name
Definition: DXF_plotter.cpp:57
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
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 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Definition: lib_id.cpp:99
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
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:78
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:143
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:144
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.
int m_version
Versioning to handle importing old tables.
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.
LIB_TABLE_ROWS m_rows
Owning set of rows.
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.
bool RemoveRow(const LIB_TABLE_ROW *aRow)
Removes a row from the table and frees the pointer.
void Clear()
Delete all rows.
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:322
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:458
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
Definition: paths.cpp:510
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)
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.cpp:923
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
A KiCad database library provides both symbol and footprint metadata, so there are "shim" plugins on ...
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:107
Look for files in a number of paths.
Definition: search_stack.h:43
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
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
bool Refresh() override
Attempt to reload the library.
void setPlugin(SCH_IO *aPlugin)
void ShowSettingsDialog(wxWindow *aWindow) const override
IO_RELEASER< SCH_IO > 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
bool operator==(const SYMBOL_LIB_TABLE &aOther) const
Compares this table against another.
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)
Functions related to environment variables, including help functions.
static const wxChar global_tbl_name[]
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
KICOMMON_API std::optional< wxString > GetVersionedEnvVarValue(const std::map< wxString, ENV_VAR_ITEM > &aMap, const wxString &aBaseName)
Attempts to retrieve the value of a versioned environment variable, such as KICAD8_TEMPLATE_DIR.
Definition: env_vars.cpp:83
KICOMMON_API wxString GetVersionedEnvVarName(const wxString &aBaseName)
Constructs a versioned environment variable based on this KiCad major version.
Definition: env_vars.cpp:74
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
SYMBOL_LIB_TABLE g_symbolLibraryTable
The global symbol library 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.