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 <lib_id.h>
28#include <lib_table_lexer.h>
29#include <paths.h>
30#include <pgm_base.h>
31#include <search_stack.h>
34#include <systemdirsappend.h>
35#include <symbol_lib_table.h>
36#include <lib_symbol.h>
39
40#include <wx/dir.h>
41#include "sim/sim_model.h"
42
43#define OPT_SEP '|'
44
45using namespace LIB_TABLE_T;
46
47
48static const wxString global_tbl_name( "sym-lib-table" );
49
50
51const char* SYMBOL_LIB_TABLE::PropPowerSymsOnly = "pwr_sym_only";
52const char* SYMBOL_LIB_TABLE::PropNonPowerSymsOnly = "non_pwr_sym_only";
53int SYMBOL_LIB_TABLE::m_modifyHash = 1; // starts at 1 and goes up
54
55
60
61
63{
64 return LIB_TABLE_ROW::operator == ( aRow ) && type == aRow.type;
65}
66
67
68void SYMBOL_LIB_TABLE_ROW::SetType( const wxString& aType )
69{
71
72 if( type == SCH_IO_MGR::SCH_FILE_UNKNOWN )
73 type = SCH_IO_MGR::SCH_KICAD;
74
76}
77
78
80{
81 if( !plugin )
82 {
83 wxArrayString dummyList;
84
85 plugin.set( SCH_IO_MGR::FindPlugin( type ) );
86 SetLoaded( false );
87 plugin->SetLibTable( static_cast<SYMBOL_LIB_TABLE*>( GetParent() ) );
88 plugin->EnumerateSymbolLib( dummyList, GetFullURI( true ), GetProperties() );
89 SetLoaded( true );
90 return true;
91 }
92
93 return false;
94}
95
96
97void SYMBOL_LIB_TABLE_ROW::GetSubLibraryNames( std::vector<wxString>& aNames ) const
98{
99 if( !plugin )
100 return;
101
102 plugin->GetSubLibraryNames( aNames );
103}
104
105
106void SYMBOL_LIB_TABLE_ROW::ShowSettingsDialog( wxWindow* aParent ) const
107{
108 wxCHECK( plugin, /* void */ );
109
110 if( type != SCH_IO_MGR::SCH_DATABASE )
111 return;
112
113 DIALOG_DATABASE_LIB_SETTINGS dlg( aParent,
114 static_cast<SCH_DATABASE_PLUGIN*>( ( SCH_PLUGIN* )plugin ) );
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->IsSymbolLibWritable( 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->IsSymbolLibWritable( 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->DeleteSymbolLib( 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->CreateSymbolLib( 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 "KICAD7_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 $KICAD7_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 wxArrayString parts = file.GetDirs();
576 parts.RemoveAt( 0, m_prefix_dir_count );
577 parts.Insert( "${KICAD7_3RD_PARTY}", 0 );
578 parts.Add( file.GetFullName() );
579
580 wxString libPath = wxJoin( parts, '/' );
581
582 if( !m_lib_table.HasLibraryWithPath( libPath ) )
583 {
584 wxString name = parts.Last().substr( 0, parts.Last().length() - 10 );
585 wxString nickname = wxString::Format( "%s%s", m_lib_prefix, name );
586
587 if( m_lib_table.HasLibrary( nickname ) )
588 {
589 int increment = 1;
590 do
591 {
592 nickname = wxString::Format( "%s%s_%d", m_lib_prefix, name, increment );
593 increment++;
594 } while( m_lib_table.HasLibrary( nickname ) );
595 }
596
598 new SYMBOL_LIB_TABLE_ROW( nickname, libPath, wxT( "KiCad" ), wxEmptyString,
599 _( "Added by Plugin and Content Manager" ) ) );
600 }
601 }
602
603 return wxDIR_CONTINUE;
604 }
605
606 wxDirTraverseResult OnDir( const wxString& dirPath ) override { return wxDIR_CONTINUE; }
607
608private:
611 wxString m_lib_prefix;
613};
614
615
617{
618 bool tableExists = true;
619 wxFileName fn = GetGlobalTableFileName();
620
621 if( !fn.FileExists() )
622 {
623 tableExists = false;
624
625 if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
626 {
627 THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ),
628 fn.GetPath() ) );
629 }
630
631 // Attempt to copy the default global file table from the KiCad
632 // template folder to the user's home configuration path.
633 SEARCH_STACK ss;
634
635 SystemDirsAppend( &ss );
636
637 wxString templatePath =
638 Pgm().GetLocalEnvVariables().at( wxT( "KICAD7_TEMPLATE_DIR" ) ).GetValue();
639
640 if( !templatePath.IsEmpty() )
641 ss.AddPaths( templatePath, 0 );
642
643 wxString fileName = ss.FindValidPath( global_tbl_name );
644
645 // The fallback is to create an empty global symbol table for the user to populate.
646 if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
647 {
648 SYMBOL_LIB_TABLE emptyTable;
649
650 emptyTable.Save( fn.GetFullPath() );
651 }
652 }
653
654 aTable.Clear();
655 aTable.Load( fn.GetFullPath() );
656
657 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
659
660 wxCHECK( settings, false );
661
662 wxString packagesPath = Pgm().GetLocalEnvVariables().at( wxT( "KICAD7_3RD_PARTY" ) ).GetValue();
663
664 if( settings->m_PcmLibAutoAdd )
665 {
666 // Scan for libraries in PCM packages directory
667 wxFileName d( packagesPath, "" );
668 d.AppendDir( "symbols" );
669
670 if( d.DirExists() )
671 {
672 PCM_SYM_LIB_TRAVERSER traverser( packagesPath, aTable, settings->m_PcmLibPrefix );
673 wxDir dir( d.GetPath() );
674
675 dir.Traverse( traverser );
676 }
677 }
678
679 if( settings->m_PcmLibAutoRemove )
680 {
681 // Remove PCM libraries that no longer exist
682 std::vector<wxString> to_remove;
683
684 for( size_t i = 0; i < aTable.GetCount(); i++ )
685 {
686 LIB_TABLE_ROW& row = aTable.At( i );
687 wxString path = row.GetFullURI( true );
688
689 if( path.StartsWith( packagesPath ) && !wxFile::Exists( path ) )
690 to_remove.push_back( row.GetNickName() );
691 }
692
693 for( const wxString& nickName : to_remove )
694 {
695 SYMBOL_LIB_TABLE_ROW* row = aTable.FindRow( nickName );
696
697 wxCHECK2( row, continue );
698
699 aTable.RemoveRow( row );
700 }
701 }
702
703 return tableExists;
704}
705
706
708{
709 if( m_rows.size() != aOther.m_rows.size() )
710 return false;
711
712 unsigned i;
713
714 for( i = 0; i < m_rows.size(); ++i )
715 {
716 const SYMBOL_LIB_TABLE_ROW& curr = static_cast<const SYMBOL_LIB_TABLE_ROW&>( m_rows[i] );
717 const SYMBOL_LIB_TABLE_ROW& curr_other = static_cast<const SYMBOL_LIB_TABLE_ROW&>( aOther.m_rows[i] );
718
719 if( curr != curr_other )
720 return false;
721 }
722
723 return true;
724}
725
726
728{
729 wxFileName fn;
730
731 fn.SetPath( PATHS::GetUserSettingsPath() );
732 fn.SetName( global_tbl_name );
733
734 return fn.GetFullPath();
735}
736
737
739{
740 return global_tbl_name;
741}
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: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: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:475
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
Definition: paths.cpp:485
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:116
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:557
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:145
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:139
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:165
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:173
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:157
virtual void SetLibTable(SYMBOL_LIB_TABLE *aTable)
Some library plugins need to have access to their parent library table.
Definition: sch_io_mgr.h:510
virtual void CreateSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:181
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:188
virtual void GetSubLibraryNames(std::vector< wxString > &aNames)
Retrieves a list of sub-libraries in this library.
Definition: sch_io_mgr.h:466
virtual bool IsSymbolLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: sch_plugin.cpp:195
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_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
bool Refresh() override
Attempt to reload the library.
void ShowSettingsDialog(wxWindow *aWindow) const override
void setPlugin(SCH_PLUGIN *aPlugin)
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
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)
static const wxChar global_tbl_name[]
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:115
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.