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