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