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.release();
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 wxFAIL;
319 continue;
320 }
321
322 hash += row->plugin->GetModifyHash();
323 }
324
325 hash += m_modifyHash;
326
327 return hash;
328}
329
330
331void SYMBOL_LIB_TABLE::EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames,
332 bool aPowerSymbolsOnly )
333{
334 SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
335 wxCHECK( row && row->plugin, /* void */ );
336
337 wxString options = row->GetOptions();
338
339 if( aPowerSymbolsOnly )
340 row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly );
341
342 row->SetLoaded( false );
343 row->plugin->EnumerateSymbolLib( aAliasNames, row->GetFullURI( true ), row->GetProperties() );
344 row->SetLoaded( true );
345
346 if( aPowerSymbolsOnly )
347 row->SetOptions( options );
348}
349
350
351SYMBOL_LIB_TABLE_ROW* SYMBOL_LIB_TABLE::FindRow( const wxString& aNickname, bool aCheckIfEnabled )
352{
354 dynamic_cast< SYMBOL_LIB_TABLE_ROW* >( findRow( aNickname, aCheckIfEnabled ) );
355
356 if( !row )
357 return nullptr;
358
359 // We've been 'lazy' up until now, but it cannot be deferred any longer,
360 // instantiate a PLUGIN of the proper kind if it is not already in this
361 // SYMBOL_LIB_TABLE_ROW.
362 if( !row->plugin )
363 {
364 row->setPlugin( SCH_IO_MGR::FindPlugin( row->type ) );
365 row->plugin->SetLibTable( this );
366 }
367
368 return row;
369}
370
371
372void SYMBOL_LIB_TABLE::LoadSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
373 const wxString& aNickname, bool aPowerSymbolsOnly )
374{
375 SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
376
377 if( !row || !row->plugin )
378 return;
379
380 std::lock_guard<std::mutex> lock( row->GetMutex() );
381
382 wxString options = row->GetOptions();
383
384 if( aPowerSymbolsOnly )
385 row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly );
386
387 row->SetLoaded( false );
388 row->plugin->SetLibTable( this );
389 row->plugin->EnumerateSymbolLib( aSymbolList, row->GetFullURI( true ), row->GetProperties() );
390 row->SetLoaded( true );
391
392 if( aPowerSymbolsOnly )
393 row->SetOptions( options );
394
395 // The library cannot know its own name, because it might have been renamed or moved.
396 // Therefore footprints cannot know their own library nickname when residing in
397 // a symbol library.
398 // Only at this API layer can we tell the symbol about its actual library nickname.
399 for( LIB_SYMBOL* symbol : aSymbolList )
400 {
401 LIB_ID id = symbol->GetLibId();
402
403 id.SetLibNickname( row->GetNickName() );
404 symbol->SetLibId( id );
405 }
406}
407
408
409LIB_SYMBOL* SYMBOL_LIB_TABLE::LoadSymbol( const wxString& aNickname, const wxString& aSymbolName )
410{
411 SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
412
413 if( !row || !row->plugin )
414 return nullptr;
415
416 // If another thread is loading this library at the moment; continue
417 std::unique_lock<std::mutex> lock( row->GetMutex(), std::try_to_lock );
418
419 if( !lock.owns_lock() )
420 return nullptr;
421
422 LIB_SYMBOL* symbol = row->plugin->LoadSymbol( row->GetFullURI( true ), aSymbolName,
423 row->GetProperties() );
424
425 if( symbol )
426 {
427 // The library cannot know its own name, because it might have been renamed or moved.
428 // Therefore footprints cannot know their own library nickname when residing in
429 // a symbol library.
430 // Only at this API layer can we tell the symbol about its actual library nickname.
431 LIB_ID id = symbol->GetLibId();
432
433 id.SetLibNickname( row->GetNickName() );
434 symbol->SetLibId( id );
435
436 SIM_MODEL::MigrateSimModel<LIB_SYMBOL, LIB_FIELD>( *symbol, nullptr );
437 }
438
439 return symbol;
440}
441
442
444 const LIB_SYMBOL* aSymbol, bool aOverwrite )
445{
446 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
447 wxCHECK( row && row->plugin, SAVE_SKIPPED );
448
449 if( !row->plugin->IsLibraryWritable( row->GetFullURI( true ) ) )
450 return SAVE_SKIPPED;
451
452 if( !aOverwrite )
453 {
454 // Try loading the footprint to see if it already exists, caller wants overwrite
455 // protection, which is atypical, not the default.
456
457 wxString name = aSymbol->GetLibId().GetLibItemName();
458
459 std::unique_ptr<LIB_SYMBOL> symbol( row->plugin->LoadSymbol( row->GetFullURI( true ),
460 name, row->GetProperties() ) );
461
462 if( symbol.get() )
463 return SAVE_SKIPPED;
464 }
465
466 try
467 {
468 row->plugin->SaveSymbol( row->GetFullURI( true ), aSymbol, row->GetProperties() );
469 }
470 catch( const IO_ERROR& )
471 {
472 return SAVE_SKIPPED;
473 }
474
475 return SAVE_OK;
476}
477
478
479void SYMBOL_LIB_TABLE::DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName )
480{
481 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
482 wxCHECK( row && row->plugin, /* void */ );
483 return row->plugin->DeleteSymbol( row->GetFullURI( true ), aSymbolName, row->GetProperties() );
484}
485
486
487bool SYMBOL_LIB_TABLE::IsSymbolLibWritable( const wxString& aNickname )
488{
489 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
490 wxCHECK( row && row->plugin, false );
491 return row->plugin->IsLibraryWritable( row->GetFullURI( true ) );
492}
493
494bool SYMBOL_LIB_TABLE::IsSymbolLibLoaded( const wxString& aNickname )
495{
496 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
497 wxCHECK( row, false );
498 return row->GetIsLoaded();
499}
500
501
502void SYMBOL_LIB_TABLE::DeleteSymbolLib( const wxString& aNickname )
503{
504 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
505 wxCHECK( row && row->plugin, /* void */ );
506 row->plugin->DeleteLibrary( row->GetFullURI( true ), row->GetProperties() );
507}
508
509
510void SYMBOL_LIB_TABLE::CreateSymbolLib( const wxString& aNickname )
511{
512 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
513 wxCHECK( row && row->plugin, /* void */ );
514 row->plugin->CreateLibrary( row->GetFullURI( true ), row->GetProperties() );
515}
516
517
519{
520 wxString nickname = aLibId.GetLibNickname();
521 wxString name = aLibId.GetLibItemName();
522
523 if( nickname.size() )
524 {
525 return LoadSymbol( nickname, name );
526 }
527 else
528 {
529 // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
530 std::vector<wxString> nicks = GetLogicalLibs();
531
532 // Search each library going through libraries alphabetically.
533 for( unsigned i = 0; i < nicks.size(); ++i )
534 {
535 // FootprintLoad() returns NULL on not found, does not throw exception
536 // unless there's an IO_ERROR.
537 LIB_SYMBOL* ret = LoadSymbol( nicks[i], name );
538
539 if( ret )
540 return ret;
541 }
542
543 return nullptr;
544 }
545}
546
547
549{
550 return ENV_VAR::GetVersionedEnvVarName( wxS( "SYMBOL_DIR" ) );
551}
552
553
554class PCM_SYM_LIB_TRAVERSER final : public wxDirTraverser
555{
556public:
557 explicit PCM_SYM_LIB_TRAVERSER( const wxString& aPath, SYMBOL_LIB_TABLE& aTable,
558 const wxString& aPrefix ) :
559 m_lib_table( aTable ),
560 m_path_prefix( aPath ),
561 m_lib_prefix( aPrefix )
562 {
563 wxFileName f( aPath, "" );
564 m_prefix_dir_count = f.GetDirCount();
565 }
566
567 wxDirTraverseResult OnFile( const wxString& aFilePath ) override
568 {
569 wxFileName file = wxFileName::FileName( aFilePath );
570
571 // consider a file to be a lib if it's name ends with .kicad_sym and
572 // it is under $KICADn_3RD_PARTY/symbols/<pkgid>/ i.e. has nested level of at least +2
573 if( file.GetExt() == wxT( "kicad_sym" ) && file.GetDirCount() >= m_prefix_dir_count + 2 )
574 {
575 wxString versionedPath = wxString::Format( wxS( "${%s}" ),
576 ENV_VAR::GetVersionedEnvVarName( wxS( "3RD_PARTY" ) ) );
577
578 wxArrayString parts = file.GetDirs();
579 parts.RemoveAt( 0, m_prefix_dir_count );
580 parts.Insert( versionedPath, 0 );
581 parts.Add( file.GetFullName() );
582
583 wxString libPath = wxJoin( parts, '/' );
584
585 if( !m_lib_table.HasLibraryWithPath( libPath ) )
586 {
587 wxString name = parts.Last().substr( 0, parts.Last().length() - 10 );
588 wxString nickname = wxString::Format( "%s%s", m_lib_prefix, name );
589
590 if( m_lib_table.HasLibrary( nickname ) )
591 {
592 int increment = 1;
593 do
594 {
595 nickname = wxString::Format( "%s%s_%d", m_lib_prefix, name, increment );
596 increment++;
597 } while( m_lib_table.HasLibrary( nickname ) );
598 }
599
601 new SYMBOL_LIB_TABLE_ROW( nickname, libPath, wxT( "KiCad" ), wxEmptyString,
602 _( "Added by Plugin and Content Manager" ) ) );
603 }
604 }
605
606 return wxDIR_CONTINUE;
607 }
608
609 wxDirTraverseResult OnDir( const wxString& dirPath ) override { return wxDIR_CONTINUE; }
610
611private:
614 wxString m_lib_prefix;
616};
617
618
620{
621 bool tableExists = true;
622 wxFileName fn = GetGlobalTableFileName();
623
624 if( !fn.FileExists() )
625 {
626 tableExists = false;
627
628 if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
629 {
630 THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ),
631 fn.GetPath() ) );
632 }
633
634 // Attempt to copy the default global file table from the KiCad
635 // template folder to the user's home configuration path.
636 SEARCH_STACK ss;
637
638 SystemDirsAppend( &ss );
639
640 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
641 std::optional<wxString> v = ENV_VAR::GetVersionedEnvVarValue( envVars,
642 wxT( "TEMPLATE_DIR" ) );
643
644 if( v && !v->IsEmpty() )
645 ss.AddPaths( *v, 0 );
646
647 wxString fileName = ss.FindValidPath( global_tbl_name );
648
649 // The fallback is to create an empty global symbol table for the user to populate.
650 if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
651 {
652 SYMBOL_LIB_TABLE emptyTable;
653
654 emptyTable.Save( fn.GetFullPath() );
655 }
656 }
657
658 aTable.Clear();
659 aTable.Load( fn.GetFullPath() );
660
661 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
663
664 wxCHECK( settings, false );
665
666 wxString packagesPath;
667 const ENV_VAR_MAP& vars = Pgm().GetLocalEnvVariables();
668
669 if( std::optional<wxString> v = ENV_VAR::GetVersionedEnvVarValue( vars, wxT( "3RD_PARTY" ) ) )
670 packagesPath = *v;
671
672 if( settings->m_PcmLibAutoAdd )
673 {
674 // Scan for libraries in PCM packages directory
675 wxFileName d( packagesPath, "" );
676 d.AppendDir( "symbols" );
677
678 if( d.DirExists() )
679 {
680 PCM_SYM_LIB_TRAVERSER traverser( packagesPath, aTable, settings->m_PcmLibPrefix );
681 wxDir dir( d.GetPath() );
682
683 dir.Traverse( traverser );
684 }
685 }
686
687 if( settings->m_PcmLibAutoRemove )
688 {
689 // Remove PCM libraries that no longer exist
690 std::vector<wxString> to_remove;
691
692 for( size_t i = 0; i < aTable.GetCount(); i++ )
693 {
694 LIB_TABLE_ROW& row = aTable.At( i );
695 wxString path = row.GetFullURI( true );
696
697 if( path.StartsWith( packagesPath ) && !wxFile::Exists( path ) )
698 to_remove.push_back( row.GetNickName() );
699 }
700
701 for( const wxString& nickName : to_remove )
702 {
703 SYMBOL_LIB_TABLE_ROW* row = aTable.FindRow( nickName );
704
705 wxCHECK2( row, continue );
706
707 aTable.RemoveRow( row );
708 }
709 }
710
711 return tableExists;
712}
713
714
716{
717 if( m_rows.size() != aOther.m_rows.size() )
718 return false;
719
720 unsigned i;
721
722 for( i = 0; i < m_rows.size(); ++i )
723 {
724 const SYMBOL_LIB_TABLE_ROW& curr = static_cast<const SYMBOL_LIB_TABLE_ROW&>( m_rows[i] );
725 const SYMBOL_LIB_TABLE_ROW& curr_other = static_cast<const SYMBOL_LIB_TABLE_ROW&>( aOther.m_rows[i] );
726
727 if( curr != curr_other )
728 return false;
729 }
730
731 return true;
732}
733
734
736{
737 wxFileName fn;
738
739 fn.SetPath( PATHS::GetUserSettingsPath() );
740 fn.SetName( global_tbl_name );
741
742 return fn.GetFullPath();
743}
744
745
747{
748 return global_tbl_name;
749}
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:99
LIB_ID GetLibId() const override
Definition: lib_symbol.h:163
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:164
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:506
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)
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:106
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()
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
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
wxString GetVersionedEnvVarName(const wxString &aBaseName)
Constructs a versioned environment variable based on this KiCad major version.
Definition: env_vars.cpp:74
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
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.