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