KiCad PCB EDA Suite
fp_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) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright (C) 2012 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 2012-2021 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 <kiface_base.h>
28#include <footprint_info.h>
29#include <lib_id.h>
30#include <lib_table_lexer.h>
31#include <pgm_base.h>
32#include <search_stack.h>
35#include <systemdirsappend.h>
36#include <fp_lib_table.h>
37#include <footprint.h>
38
39#include <wx/dir.h>
40#include <wx/hash.h>
41
42#define OPT_SEP '|'
43
44using namespace LIB_TABLE_T;
45
46
47static const wxChar global_tbl_name[] = wxT( "fp-lib-table" );
48
49
51{
52 return LIB_TABLE_ROW::operator == ( aRow ) && type == aRow.type;
53}
54
55
56void FP_LIB_TABLE_ROW::SetType( const wxString& aType )
57{
58 type = IO_MGR::EnumFromStr( aType );
59
60 if( IO_MGR::PCB_FILE_T( -1 ) == type )
62
64}
65
66
68 LIB_TABLE( aFallBackTable )
69{
70 // not copying fall back, simply search aFallBackTable separately
71 // if "nickName not found".
72}
73
74
75void FP_LIB_TABLE::Parse( LIB_TABLE_LEXER* in )
76{
77 T tok;
78 wxString errMsg; // to collect error messages
79
80 // This table may be nested within a larger s-expression, or not.
81 // Allow for parser of that optional containing s-epression to have looked ahead.
82 if( in->CurTok() != T_fp_lib_table )
83 {
84 in->NeedLEFT();
85
86 if( ( tok = in->NextTok() ) != T_fp_lib_table )
87 in->Expecting( T_fp_lib_table );
88 }
89
90 while( ( tok = in->NextTok() ) != T_RIGHT )
91 {
92 std::unique_ptr<FP_LIB_TABLE_ROW> row = std::make_unique<FP_LIB_TABLE_ROW>();
93
94 if( tok == T_EOF )
95 in->Expecting( T_RIGHT );
96
97 if( tok != T_LEFT )
98 in->Expecting( T_LEFT );
99
100 // in case there is a "row integrity" error, tell where later.
101 int lineNum = in->CurLineNumber();
102
103 if( ( tok = in->NextTok() ) != T_lib )
104 in->Expecting( T_lib );
105
106 // (name NICKNAME)
107 in->NeedLEFT();
108
109 if( ( tok = in->NextTok() ) != T_name )
110 in->Expecting( T_name );
111
112 in->NeedSYMBOLorNUMBER();
113
114 row->SetNickName( in->FromUTF8() );
115
116 in->NeedRIGHT();
117
118 // After (name), remaining (lib) elements are order independent, and in
119 // some cases optional.
120 bool sawType = false;
121 bool sawOpts = false;
122 bool sawDesc = false;
123 bool sawUri = false;
124 bool sawDisabled = false;
125
126 while( ( tok = in->NextTok() ) != T_RIGHT )
127 {
128 if( tok == T_EOF )
129 in->Unexpected( T_EOF );
130
131 if( tok != T_LEFT )
132 in->Expecting( T_LEFT );
133
134 tok = in->NeedSYMBOLorNUMBER();
135
136 switch( tok )
137 {
138 case T_uri:
139 if( sawUri )
140 in->Duplicate( tok );
141 sawUri = true;
142 in->NeedSYMBOLorNUMBER();
143 row->SetFullURI( in->FromUTF8() );
144 break;
145
146 case T_type:
147 if( sawType )
148 in->Duplicate( tok );
149 sawType = true;
150 in->NeedSYMBOLorNUMBER();
151 row->SetType( in->FromUTF8() );
152 break;
153
154 case T_options:
155 if( sawOpts )
156 in->Duplicate( tok );
157 sawOpts = true;
158 in->NeedSYMBOLorNUMBER();
159 row->SetOptions( in->FromUTF8() );
160 break;
161
162 case T_descr:
163 if( sawDesc )
164 in->Duplicate( tok );
165 sawDesc = true;
166 in->NeedSYMBOLorNUMBER();
167 row->SetDescr( in->FromUTF8() );
168 break;
169
170 case T_disabled:
171 if( sawDisabled )
172 in->Duplicate( tok );
173 sawDisabled = true;
174 row->SetEnabled( false );
175 break;
176
177 default:
178 in->Unexpected( tok );
179 }
180
181 in->NeedRIGHT();
182 }
183
184 if( !sawType )
185 in->Expecting( T_type );
186
187 if( !sawUri )
188 in->Expecting( T_uri );
189
190 // all nickNames within this table fragment must be unique, so we do not
191 // use doReplace in InsertRow(). (However a fallBack table can have a
192 // conflicting nickName and ours will supercede that one since in
193 // FindLib() we search this table before any fall back.)
194 wxString nickname = row->GetNickName(); // store it to be able to used it
195 // after row deletion if an error occurs
196 LIB_TABLE_ROW* tmp = row.release();
197
198 if( !InsertRow( tmp ) )
199 {
200 delete tmp; // The table did not take ownership of the row.
201
202 wxString msg = wxString::Format( _( "Duplicate library nickname '%s' found in "
203 "footprint library table file line %d." ),
204 nickname,
205 lineNum );
206
207 if( !errMsg.IsEmpty() )
208 errMsg << '\n';
209
210 errMsg << msg;
211 }
212 }
213
214 if( !errMsg.IsEmpty() )
215 THROW_IO_ERROR( errMsg );
216}
217
218
219bool FP_LIB_TABLE::operator==( const FP_LIB_TABLE& aFpTable ) const
220{
221 if( rows.size() == aFpTable.rows.size() )
222 {
223 for( unsigned i = 0; i < rows.size(); ++i )
224 {
225 if( (FP_LIB_TABLE_ROW&)rows[i] != (FP_LIB_TABLE_ROW&)aFpTable.rows[i] )
226 return false;
227 }
228
229 return true;
230 }
231
232 return false;
233}
234
235
236void FP_LIB_TABLE::Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const
237{
238 aOutput->Print( aIndentLevel, "(fp_lib_table\n" );
239
240 for( LIB_TABLE_ROWS_CITER it = rows.begin(); it != rows.end(); ++it )
241 it->Format( aOutput, aIndentLevel+1 );
242
243 aOutput->Print( aIndentLevel, ")\n" );
244}
245
246
247long long FP_LIB_TABLE::GenerateTimestamp( const wxString* aNickname )
248{
249 long long hash = 0;
250
251 if( aNickname )
252 {
253 const FP_LIB_TABLE_ROW* row = FindRow( *aNickname, true );
254
255 wxCHECK( row && row->plugin, hash );
256
257 return row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) ) +
258 wxHashTable::MakeKey( *aNickname );
259 }
260
261 for( const wxString& nickname : GetLogicalLibs() )
262 {
263 const FP_LIB_TABLE_ROW* row = FindRow( nickname, true );
264
265 wxCHECK2( row && row->plugin, continue );
266
267 hash += row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) ) +
268 wxHashTable::MakeKey( nickname );
269 }
270
271 return hash;
272}
273
274
275void FP_LIB_TABLE::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname,
276 bool aBestEfforts )
277{
278 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
279 wxASSERT( (PLUGIN*) row->plugin );
280 row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ), aBestEfforts,
281 row->GetProperties() );
282}
283
284
285void FP_LIB_TABLE::PrefetchLib( const wxString& aNickname )
286{
287 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
288 wxASSERT( (PLUGIN*) row->plugin );
289 row->plugin->PrefetchLib( row->GetFullURI( true ), row->GetProperties() );
290}
291
292
293const FP_LIB_TABLE_ROW* FP_LIB_TABLE::FindRow( const wxString& aNickname, bool aCheckIfEnabled )
294{
295 // Do not optimize this code. Is done this way specifically to fix a runtime
296 // error with clang 4.0.1.
297 LIB_TABLE_ROW* ltrow = findRow( aNickname, aCheckIfEnabled );
298 FP_LIB_TABLE_ROW* row = dynamic_cast< FP_LIB_TABLE_ROW* >( ltrow );
299
300 if( !row )
301 {
302 wxString msg = wxString::Format( _( "fp-lib-table files contain no library named '%s'." ),
303 aNickname );
304
305 THROW_IO_ERROR( msg );
306 }
307
308 // We've been 'lazy' up until now, but it cannot be deferred any longer,
309 // instantiate a PLUGIN of the proper kind if it is not already in this
310 // FP_LIB_TABLE_ROW.
311 if( !row->plugin )
312 row->setPlugin( IO_MGR::PluginFind( row->type ) );
313
314 return row;
315}
316
317
318static void setLibNickname( FOOTPRINT* aModule, const wxString& aNickname,
319 const wxString& aFootprintName )
320{
321 // The library cannot know its own name, because it might have been renamed or moved.
322 // Therefore footprints cannot know their own library nickname when residing in
323 // a footprint library.
324 // Only at this API layer can we tell the footprint about its actual library nickname.
325 if( aModule )
326 {
327 // remove "const"-ness, I really do want to set nickname without
328 // having to copy the LIB_ID and its two strings, twice each.
329 LIB_ID& fpid = (LIB_ID&) aModule->GetFPID();
330
331 // Catch any misbehaving plugin, which should be setting internal footprint name properly:
332 wxASSERT( aFootprintName == fpid.GetLibItemName().wx_str() );
333
334 // and clearing nickname
335 wxASSERT( !fpid.GetLibNickname().size() );
336
337 fpid.SetLibNickname( aNickname );
338 }
339}
340
341
342const FOOTPRINT* FP_LIB_TABLE::GetEnumeratedFootprint( const wxString& aNickname,
343 const wxString& aFootprintName )
344{
345 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
346 wxASSERT( (PLUGIN*) row->plugin );
347
348 return row->plugin->GetEnumeratedFootprint( row->GetFullURI( true ), aFootprintName,
349 row->GetProperties() );
350}
351
352
353bool FP_LIB_TABLE::FootprintExists( const wxString& aNickname, const wxString& aFootprintName )
354{
355 try
356 {
357 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
358 wxASSERT( (PLUGIN*) row->plugin );
359
360 return row->plugin->FootprintExists( row->GetFullURI( true ), aFootprintName,
361 row->GetProperties() );
362 }
363 catch( ... )
364 {
365 return false;
366 }
367}
368
369
370FOOTPRINT* FP_LIB_TABLE::FootprintLoad( const wxString& aNickname,
371 const wxString& aFootprintName, bool aKeepUUID )
372{
373 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
374 wxASSERT( (PLUGIN*) row->plugin );
375
376 FOOTPRINT* ret = row->plugin->FootprintLoad( row->GetFullURI( true ), aFootprintName,
377 aKeepUUID, row->GetProperties() );
378
379 setLibNickname( ret, row->GetNickName(), aFootprintName );
380
381 return ret;
382}
383
384
386 const FOOTPRINT* aFootprint, bool aOverwrite )
387{
388 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
389 wxASSERT( (PLUGIN*) row->plugin );
390
391 if( !aOverwrite )
392 {
393 // Try loading the footprint to see if it already exists, caller wants overwrite
394 // protection, which is atypical, not the default.
395
396 wxString fpname = aFootprint->GetFPID().GetLibItemName();
397
398 std::unique_ptr<FOOTPRINT> footprint( row->plugin->FootprintLoad( row->GetFullURI( true ),
399 fpname,
400 row->GetProperties() ) );
401
402 if( footprint.get() )
403 return SAVE_SKIPPED;
404 }
405
406 row->plugin->FootprintSave( row->GetFullURI( true ), aFootprint, row->GetProperties() );
407
408 return SAVE_OK;
409}
410
411
412void FP_LIB_TABLE::FootprintDelete( const wxString& aNickname, const wxString& aFootprintName )
413{
414 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
415 wxASSERT( (PLUGIN*) row->plugin );
416 return row->plugin->FootprintDelete( row->GetFullURI( true ), aFootprintName,
417 row->GetProperties() );
418}
419
420
421bool FP_LIB_TABLE::IsFootprintLibWritable( const wxString& aNickname )
422{
423 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
424 wxASSERT( (PLUGIN*) row->plugin );
425 return row->plugin->IsFootprintLibWritable( row->GetFullURI( true ) );
426}
427
428
429void FP_LIB_TABLE::FootprintLibDelete( const wxString& aNickname )
430{
431 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
432 wxASSERT( (PLUGIN*) row->plugin );
433 row->plugin->FootprintLibDelete( row->GetFullURI( true ), row->GetProperties() );
434}
435
436
437void FP_LIB_TABLE::FootprintLibCreate( const wxString& aNickname )
438{
439 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
440 wxASSERT( (PLUGIN*) row->plugin );
441 row->plugin->FootprintLibCreate( row->GetFullURI( true ), row->GetProperties() );
442}
443
444
446 bool aKeepUUID )
447{
448 wxString nickname = aFootprintId.GetLibNickname();
449 wxString fpname = aFootprintId.GetLibItemName();
450
451 if( nickname.size() )
452 {
453 return FootprintLoad( nickname, fpname, aKeepUUID );
454 }
455
456 // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
457 else
458 {
459 std::vector<wxString> nicks = GetLogicalLibs();
460
461 // Search each library going through libraries alphabetically.
462 for( unsigned i = 0; i < nicks.size(); ++i )
463 {
464 // FootprintLoad() returns NULL on not found, does not throw exception
465 // unless there's an IO_ERROR.
466 FOOTPRINT* ret = FootprintLoad( nicks[i], fpname, aKeepUUID );
467
468 if( ret )
469 return ret;
470 }
471
472 return nullptr;
473 }
474}
475
476
478{
479 return "KICAD6_FOOTPRINT_DIR";
480}
481
482
483class PCM_FP_LIB_TRAVERSER final : public wxDirTraverser
484{
485public:
486 explicit PCM_FP_LIB_TRAVERSER( const wxString& aPath, FP_LIB_TABLE& aTable,
487 const wxString& aPrefix ) :
488 m_lib_table( aTable ),
489 m_path_prefix( aPath ),
490 m_lib_prefix( aPrefix )
491 {
492 wxFileName f( aPath, "" );
493 m_prefix_dir_count = f.GetDirCount();
494 }
495
496 wxDirTraverseResult OnFile( const wxString& aFilePath ) override { return wxDIR_CONTINUE; }
497
498 wxDirTraverseResult OnDir( const wxString& dirPath ) override
499 {
500 wxFileName dir = wxFileName::DirName( dirPath );
501
502 // consider a directory to be a lib if it's name ends with .pretty and
503 // it is under $KICAD6_3RD_PARTY/footprints/<pkgid>/ i.e. has nested level of at least +3
504 if( dirPath.EndsWith( ".pretty" ) && dir.GetDirCount() >= m_prefix_dir_count + 3 )
505 {
506 wxArrayString parts = dir.GetDirs();
507 parts.RemoveAt( 0, m_prefix_dir_count );
508 parts.Insert( "${KICAD6_3RD_PARTY}", 0 );
509
510 wxString libPath = wxJoin( parts, '/' );
511
512 if( !m_lib_table.HasLibraryWithPath( libPath ) )
513 {
514 wxString name = parts.Last().substr( 0, parts.Last().length() - 7 );
515 wxString nickname = wxString::Format( "%s%s", m_lib_prefix, name );
516
517 if( m_lib_table.HasLibrary( nickname ) )
518 {
519 int increment = 1;
520 do
521 {
522 nickname = wxString::Format( "%s%s_%d", m_lib_prefix, name, increment );
523 increment++;
524 } while( m_lib_table.HasLibrary( nickname ) );
525 }
526
528 new FP_LIB_TABLE_ROW( nickname, libPath, wxT( "KiCad" ), wxEmptyString,
529 _( "Added by Plugin and Content Manager" ) ) );
530 }
531 }
532
533 return wxDIR_CONTINUE;
534 }
535
536private:
539 wxString m_lib_prefix;
541};
542
543
545{
546 bool tableExists = true;
547 wxFileName fn = GetGlobalTableFileName();
548
549 if( !fn.FileExists() )
550 {
551 tableExists = false;
552
553 if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
554 {
555 THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ),
556 fn.GetPath() ) );
557 }
558
559 // Attempt to copy the default global file table from the KiCad
560 // template folder to the user's home configuration path.
561 SEARCH_STACK ss;
562
563 SystemDirsAppend( &ss );
564
565 wxString templatePath =
566 Pgm().GetLocalEnvVariables().at( wxT( "KICAD6_TEMPLATE_DIR" ) ).GetValue();
567
568 if( !templatePath.IsEmpty() )
569 ss.AddPaths( templatePath, 0 );
570
571 wxString fileName = ss.FindValidPath( global_tbl_name );
572
573 // The fallback is to create an empty global footprint table for the user to populate.
574 if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
575 {
576 FP_LIB_TABLE emptyTable;
577
578 emptyTable.Save( fn.GetFullPath() );
579 }
580 }
581
582 aTable.Load( fn.GetFullPath() );
583
584 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
586
587 wxString packagesPath = Pgm().GetLocalEnvVariables().at( wxT( "KICAD6_3RD_PARTY" ) ).GetValue();
588
589 if( settings->m_PcmLibAutoAdd )
590 {
591 // Scan for libraries in PCM packages directory
592
593 wxFileName d( packagesPath, "" );
594 d.AppendDir( "footprints" );
595
596 if( d.DirExists() )
597 {
598 PCM_FP_LIB_TRAVERSER traverser( packagesPath, aTable, settings->m_PcmLibPrefix );
599 wxDir dir( d.GetPath() );
600
601 dir.Traverse( traverser );
602 }
603 }
604
605 if( settings->m_PcmLibAutoRemove )
606 {
607 // Remove PCM libraries that no longer exist
608 std::vector<wxString> to_remove;
609
610 for( size_t i = 0; i < aTable.GetCount(); i++ )
611 {
612 LIB_TABLE_ROW& row = aTable.At( i );
613 wxString path = row.GetFullURI( true );
614
615 if( path.StartsWith( packagesPath ) && !wxDir::Exists( path ) )
616 to_remove.push_back( row.GetNickName() );
617 }
618
619 for( const wxString& nickName : to_remove )
620 aTable.RemoveRow( aTable.FindRow( nickName ) );
621 }
622
623 return tableExists;
624}
625
626
628{
629 wxFileName fn;
630
632 fn.SetName( global_tbl_name );
633
634 return fn.GetFullPath();
635}
const char * name
Definition: DXF_plotter.cpp:56
const LIB_ID & GetFPID() const
Definition: footprint.h:203
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
Definition: fp_lib_table.h:41
void SetType(const wxString &aType) override
Change the type represented by this row.
bool operator==(const FP_LIB_TABLE_ROW &aRow) const
void setPlugin(PLUGIN *aPlugin)
Definition: fp_lib_table.h:84
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:91
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an FP_LIB_TABLE_ROW if aNickName is found in this table or in any chained fall back table frag...
void FootprintDelete(const wxString &aNickname, const wxString &aFootprintName)
Delete the aFootprintName from the library given by aNickname.
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Load the global footprint library table into aTable.
bool operator==(const FP_LIB_TABLE &aFpTable) const
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aNickname, bool aBestEfforts)
Return a list of footprint names contained within the library given by aNickname.
void FootprintLibCreate(const wxString &aNickname)
FP_LIB_TABLE(FP_LIB_TABLE *aFallBackTable=nullptr)
Build a footprint library table by pre-pending this table fragment in front of aFallBackTable.
const FOOTPRINT * GetEnumeratedFootprint(const wxString &aNickname, const wxString &aFootprintName)
A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
FOOTPRINT * FootprintLoadWithOptionalNickname(const LIB_ID &aFootprintId, bool aKeepUUID=false)
Load a footprint having aFootprintId with possibly an empty nickname.
long long GenerateTimestamp(const wxString *aNickname)
Generate a hashed timestamp representing the last-mod-times of the library indicated by aNickname,...
void FootprintLibDelete(const wxString &aNickname)
bool FootprintExists(const wxString &aNickname, const wxString &aFootprintName)
Indicates whether or not the given footprint already exists in the given library.
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...
bool IsFootprintLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
void PrefetchLib(const wxString &aNickname)
If possible, prefetches the specified library (e.g.
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
SAVE_T
The set of return values from FootprintSave() below.
Definition: fp_lib_table.h:199
FOOTPRINT * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName, bool aKeepUUID=false)
Load a footprint having aFootprintName from the library given by aNickname.
SAVE_T FootprintSave(const wxString &aNickname, const FOOTPRINT *aFootprint, bool aOverwrite=true)
Write aFootprint to an existing library given by aNickname.
static wxString GetGlobalTableFileName()
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written.
Definition: io_mgr.h:54
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition: io_mgr.h:56
static PCB_FILE_T EnumFromStr(const wxString &aFileType)
Return the PCB_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc.
Definition: io_mgr.cpp:93
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Return a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
wxString m_PcmLibPrefix
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:98
const UTF8 & GetLibItemName() const
Definition: lib_id.h:101
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
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
const STRING_UTF8_MAP * GetProperties() const
Return the constant #PROPERTIES for this library (LIB_TABLE_ROW).
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
bool HasLibraryWithPath(const wxString &aPath) const
Test for the existence of aPath in the library table.
LIB_TABLE_ROWS rows
bool RemoveRow(const LIB_TABLE_ROW *aRow)
Removes a row from the table.
unsigned GetCount() const
Get the number of rows contained in the table.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
LIB_TABLE_ROW * findRow(const wxString &aNickname, bool aCheckIfEnabled=false) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment,...
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:310
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:431
PCM_FP_LIB_TRAVERSER(const wxString &aPath, FP_LIB_TABLE &aTable, const wxString &aPrefix)
wxDirTraverseResult OnFile(const wxString &aFilePath) override
wxDirTraverseResult OnDir(const wxString &dirPath) override
FP_LIB_TABLE & m_lib_table
void release()
Definition: io_mgr.h:585
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:270
virtual const FOOTPRINT * GetEnumeratedFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const STRING_UTF8_MAP *aProperties=nullptr)
A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.
Definition: plugin.cpp:80
virtual void FootprintLibCreate(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Create a new empty footprint library at aLibraryPath empty.
Definition: plugin.cpp:122
virtual bool FootprintLibDelete(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Delete an existing footprint library and returns true, or if library does not exist returns false,...
Definition: plugin.cpp:129
virtual void FootprintSave(const wxString &aLibraryPath, const FOOTPRINT *aFootprint, const STRING_UTF8_MAP *aProperties=nullptr)
Write aFootprint to an existing library located at aLibraryPath.
Definition: plugin.cpp:106
virtual void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const STRING_UTF8_MAP *aProperties=nullptr)
Delete aFootprintName from the library at aLibraryPath.
Definition: plugin.cpp:114
virtual bool FootprintExists(const wxString &aLibraryPath, const wxString &aFootprintName, const STRING_UTF8_MAP *aProperties=nullptr)
Check for the existence of a footprint.
Definition: plugin.cpp:89
virtual FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const STRING_UTF8_MAP *aProperties=nullptr)
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
Definition: plugin.cpp:97
virtual bool IsFootprintLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: plugin.cpp:137
virtual long long GetLibraryTimestamp(const wxString &aLibraryPath) const =0
Generate a timestamp representing all the files in the library (including the library directory).
virtual void PrefetchLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
If possible, prefetches the specified library (e.g.
Definition: plugin.cpp:75
virtual void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const STRING_UTF8_MAP *aProperties=nullptr)
Return a list of footprint names contained within the library at aLibraryPath.
Definition: plugin.cpp:67
Look for files in a number of paths.
Definition: search_stack.h:42
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
T * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
std::string::size_type size() const
Definition: utf8.h:110
wxString wx_str() const
Definition: utf8.cpp:46
#define _(s)
static const wxChar global_tbl_name[]
static void setLibNickname(FOOTPRINT *aModule, const wxString &aNickname, const wxString &aFootprintName)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
see class PGM_BASE
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
System directories search utilities.