KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_database.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) 2022 Jon Evans <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <iostream>
22#include <unordered_set>
23#include <utility>
24#include <wx/datetime.h>
25#include <wx/log.h>
26
27#include <boost/algorithm/string.hpp>
28
32#include <fmt.h>
33#include <ki_exception.h>
34#include <lib_symbol.h>
35
36#include "sch_io_database.h"
37
39
40
42 SCH_IO( wxS( "Database library" ) ),
43 m_adapter( nullptr ),
44 m_settings(),
45 m_conn()
46{
49}
50
51
55
56
57void SCH_IO_DATABASE::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
58 const wxString& aLibraryPath,
59 const std::map<std::string, UTF8>* aProperties )
60{
61 std::vector<LIB_SYMBOL*> symbols;
62 EnumerateSymbolLib( symbols, aLibraryPath, aProperties );
63
64 for( LIB_SYMBOL* symbol : symbols )
65 aSymbolNameList.Add( symbol->GetName() );
66}
67
68
69void SCH_IO_DATABASE::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
70 const wxString& aLibraryPath,
71 const std::map<std::string, UTF8>* aProperties )
72{
73 wxCHECK_RET( m_adapter, "Database plugin missing library manager adapter handle!" );
74 ensureSettings( aLibraryPath );
76 cacheLib();
77
78 if( !m_conn )
80
81 bool powerSymbolsOnly = ( aProperties && aProperties->contains( SYMBOL_LIBRARY_ADAPTER::PropPowerSymsOnly ) );
82
83 for( auto const& pair : m_nameToSymbolcache )
84 {
85 LIB_SYMBOL* symbol = pair.second.get();
86
87 if( !powerSymbolsOnly || symbol->IsPower() )
88 aSymbolList.emplace_back( symbol );
89 }
90}
91
92
93LIB_SYMBOL* SCH_IO_DATABASE::LoadSymbol( const wxString& aLibraryPath,
94 const wxString& aAliasName,
95 const std::map<std::string, UTF8>* aProperties )
96{
97 wxCHECK_MSG( m_adapter, nullptr, "Database plugin missing library manager adapter handle!" );
98 ensureSettings( aLibraryPath );
100
101 if( !m_conn )
103
104 cacheLib();
105
106 /*
107 * Table names are tricky, in order to allow maximum flexibility to the user.
108 * The slash character is used as a separator between a table name and symbol name, but symbol
109 * names may also contain slashes and table names may now also be empty (which results in the
110 * slash being dropped in the symbol name when placing a new symbol). So, if a slash is found,
111 * we check if the string before the slash is a valid table name. If not, we assume the table
112 * name is blank if our config has an entry for the null table.
113 */
114
115 std::string tableName;
116 std::string symbolName( aAliasName.ToUTF8() );
117
118 auto sanitizedIt = m_sanitizedNameMap.find( aAliasName );
119
120 if( sanitizedIt != m_sanitizedNameMap.end() )
121 {
122 tableName = sanitizedIt->second.first;
123 symbolName = sanitizedIt->second.second;
124 }
125 else
126 {
127 tableName.clear();
128
129 if( aAliasName.Contains( '/' ) )
130 {
131 tableName = std::string( aAliasName.BeforeFirst( '/' ).ToUTF8() );
132 symbolName = std::string( aAliasName.AfterFirst( '/' ).ToUTF8() );
133 }
134 }
135
136 std::vector<const DATABASE_LIB_TABLE*> tablesToTry;
137
138 for( const DATABASE_LIB_TABLE& tableIter : m_settings->m_Tables )
139 {
140 // no table means globally unique keys, try all tables
141 if( tableName.empty() || tableIter.name == tableName )
142 tablesToTry.emplace_back( &tableIter );
143 }
144
145 if( tablesToTry.empty() )
146 {
147 wxLogTrace( traceDatabase, wxT( "LoadSymbol: table '%s' not found in config" ), tableName );
148 return nullptr;
149 }
150
151 const DATABASE_LIB_TABLE* foundTable = nullptr;
153
154 for( const DATABASE_LIB_TABLE* table : tablesToTry )
155 {
156 if( m_conn->SelectOne( table->table, std::make_pair( table->key_col, symbolName ),
157 result ) )
158 {
159 foundTable = table;
160 wxLogTrace( traceDatabase, wxT( "LoadSymbol: SelectOne (%s, %s) found in %s" ),
161 table->key_col, symbolName, table->table );
162 }
163 else
164 {
165 wxLogTrace( traceDatabase, wxT( "LoadSymbol: SelectOne (%s, %s) failed for table %s" ),
166 table->key_col, symbolName, table->table );
167 }
168 }
169
170 wxCHECK( foundTable, nullptr );
171
172 return loadSymbolFromRow( aAliasName, *foundTable, result ).release();
173}
174
175
176void SCH_IO_DATABASE::GetSubLibraryNames( std::vector<wxString>& aNames )
177{
178 ensureSettings( wxEmptyString );
179
180 aNames.clear();
181
182 std::set<wxString> tableNames;
183
184 for( const DATABASE_LIB_TABLE& tableIter : m_settings->m_Tables )
185 {
186 if( tableNames.count( tableIter.name ) )
187 continue;
188
189 aNames.emplace_back( tableIter.name );
190 tableNames.insert( tableIter.name );
191 }
192}
193
194
195void SCH_IO_DATABASE::GetAvailableSymbolFields( std::vector<wxString>& aNames )
196{
197 std::copy( m_customFields.begin(), m_customFields.end(), std::back_inserter( aNames ) );
198}
199
200
201void SCH_IO_DATABASE::GetDefaultSymbolFields( std::vector<wxString>& aNames )
202{
203 std::copy( m_defaultShownFields.begin(), m_defaultShownFields.end(),
204 std::back_inserter( aNames ) );
205}
206
207
208bool SCH_IO_DATABASE::TestConnection( wxString* aErrorMsg )
209{
210 if( m_conn && m_conn->IsConnected() )
211 return true;
212
213 connect();
214
215 if( aErrorMsg && ( !m_conn || !m_conn->IsConnected() ) )
216 *aErrorMsg = m_lastError;
217
218 return m_conn && m_conn->IsConnected();
219}
220
221
223{
224 long long currentTimestampSeconds = wxDateTime::Now().GetValue().GetValue() / 1000;
225
226 if( m_adapter->GetModifyHash() == m_cacheModifyHash
227 && ( currentTimestampSeconds - m_cacheTimestamp ) < m_settings->m_Cache.max_age )
228 {
229 return;
230 }
231
232 std::map<wxString, std::unique_ptr<LIB_SYMBOL>> newSymbolCache;
233 std::map<wxString, std::pair<std::string, std::string>> newSanitizedNameMap;
234
235 for( const DATABASE_LIB_TABLE& table : m_settings->m_Tables )
236 {
237 std::vector<DATABASE_CONNECTION::ROW> results;
238
239 if( !m_conn->SelectAll( table.table, table.key_col, results ) )
240 {
241 if( !m_conn->GetLastError().empty() )
242 {
243 wxString msg = wxString::Format( _( "Error reading database table %s: %s" ),
244 table.table, m_conn->GetLastError() );
245 THROW_IO_ERROR( msg );
246 }
247
248 continue;
249 }
250
251 for( DATABASE_CONNECTION::ROW& result : results )
252 {
253 if( !result.count( table.key_col ) )
254 continue;
255
256 std::string rawName = std::any_cast<std::string>( result[table.key_col] );
257 UTF8 sanitizedName = LIB_ID::FixIllegalChars( rawName, false );
258 std::string sanitizedKey = sanitizedName.c_str();
259 std::string prefix =
260 ( m_settings->m_GloballyUniqueKeys || table.name.empty() ) ? "" : fmt::format( "{}/", table.name );
261 std::string sanitizedDisplayName = fmt::format( "{}{}", prefix, sanitizedKey );
262 wxString name( sanitizedDisplayName );
263
264 newSanitizedNameMap[name] = std::make_pair( table.name, rawName );
265
266 std::unique_ptr<LIB_SYMBOL> symbol = loadSymbolFromRow( name, table, result );
267
268 if( symbol )
269 newSymbolCache[symbol->GetName()] = std::move( symbol );
270 }
271 }
272
273 m_nameToSymbolcache = std::move( newSymbolCache );
274 m_sanitizedNameMap = std::move( newSanitizedNameMap );
275
276 m_cacheTimestamp = currentTimestampSeconds;
277 m_cacheModifyHash = m_adapter->GetModifyHash();
278}
279
280void SCH_IO_DATABASE::ensureSettings( const wxString& aSettingsPath )
281{
282 auto tryLoad =
283 [&]()
284 {
285 if( !m_settings->LoadFromFile() )
286 {
287 wxString msg = wxString::Format(
288 _( "Could not load database library: settings file %s missing or invalid" ),
289 aSettingsPath );
290
291 THROW_IO_ERROR( msg );
292 }
293 };
294
295 if( !m_settings && !aSettingsPath.IsEmpty() )
296 {
297 std::string path( aSettingsPath.ToUTF8() );
298 m_settings = std::make_unique<DATABASE_LIB_SETTINGS>( path );
299 m_settings->SetReadOnly( true );
300
301 tryLoad();
302 }
303 else if( !m_conn && m_settings )
304 {
305 // If we have valid settings but no connection yet; reload settings in case user is editing
306 tryLoad();
307 }
308 else if( m_conn && m_settings && !aSettingsPath.IsEmpty() )
309 {
310 wxASSERT_MSG( aSettingsPath == m_settings->GetFilename(),
311 "Path changed for database library without re-initializing plugin!" );
312 }
313 else if( !m_settings )
314 {
315 wxLogTrace( traceDatabase, wxT( "ensureSettings: no settings but no valid path!" ) );
316 }
317}
318
319
321{
322 wxCHECK_RET( m_settings, "Call ensureSettings before ensureConnection!" );
323
324 connect();
325
326 if( !m_conn || !m_conn->IsConnected() )
327 {
328 wxString msg = wxString::Format(
329 _( "Could not load database library: could not connect to database %s (%s)" ),
330 m_settings->m_Source.dsn, m_lastError );
331
332 THROW_IO_ERROR( msg );
333 }
334}
335
336
338{
339 wxCHECK_RET( m_settings, "Call ensureSettings before connect()!" );
340
341 if( m_conn && !m_conn->IsConnected() )
342 m_conn.reset();
343
344 if( !m_conn )
345 {
346 if( m_settings->m_Source.connection_string.empty() )
347 {
348 m_conn = std::make_unique<DATABASE_CONNECTION>( m_settings->m_Source.dsn,
349 m_settings->m_Source.username,
350 m_settings->m_Source.password,
351 m_settings->m_Source.timeout );
352 }
353 else
354 {
355 std::string cs = m_settings->m_Source.connection_string;
356 std::string basePath( wxFileName( m_settings->GetFilename() ).GetPath().ToUTF8() );
357
358 // Database drivers that use files operate on absolute paths, so provide a mechanism
359 // for specifying on-disk databases that live next to the kicad_dbl file
360 boost::replace_all( cs, "${CWD}", basePath );
361
362 m_conn = std::make_unique<DATABASE_CONNECTION>( cs, m_settings->m_Source.timeout );
363 }
364
365 if( !m_conn->IsConnected() )
366 {
367 m_lastError = m_conn->GetLastError();
368 m_conn.reset();
369 return;
370 }
371
372 for( const DATABASE_LIB_TABLE& tableIter : m_settings->m_Tables )
373 {
374 std::set<std::string> columns;
375
376 columns.insert( boost::to_lower_copy( tableIter.key_col ) );
377 columns.insert( boost::to_lower_copy( tableIter.footprints_col ) );
378 columns.insert( boost::to_lower_copy( tableIter.symbols_col ) );
379
380 columns.insert( boost::to_lower_copy( tableIter.properties.description ) );
381 columns.insert( boost::to_lower_copy( tableIter.properties.footprint_filters ) );
382 columns.insert( boost::to_lower_copy( tableIter.properties.keywords ) );
383 columns.insert( boost::to_lower_copy( tableIter.properties.exclude_from_sim ) );
384 columns.insert( boost::to_lower_copy( tableIter.properties.exclude_from_bom ) );
385 columns.insert( boost::to_lower_copy( tableIter.properties.exclude_from_board ) );
386
387 for( const DATABASE_FIELD_MAPPING& field : tableIter.fields )
388 columns.insert( boost::to_lower_copy( field.column ) );
389
390 m_conn->CacheTableInfo( tableIter.table, columns );
391 }
392
393 m_conn->SetCacheParams( m_settings->m_Cache.max_size, m_settings->m_Cache.max_age );
394 }
395}
396
397
398std::optional<bool> SCH_IO_DATABASE::boolFromAny( const std::any& aVal )
399{
400 try
401 {
402 bool val = std::any_cast<bool>( aVal );
403 return val;
404 }
405 catch( const std::bad_any_cast& )
406 {
407 }
408
409 try
410 {
411 int val = std::any_cast<int>( aVal );
412 return static_cast<bool>( val );
413 }
414 catch( const std::bad_any_cast& )
415 {
416 }
417
418 try
419 {
420 wxString strval( std::any_cast<std::string>( aVal ).c_str(), wxConvUTF8 );
421
422 if( strval.IsEmpty() )
423 return std::nullopt;
424
425 strval.MakeLower();
426
427 for( const auto& trueVal : { wxS( "true" ), wxS( "yes" ), wxS( "y" ), wxS( "1" ) } )
428 {
429 if( strval.Matches( trueVal ) )
430 return true;
431 }
432
433 for( const auto& falseVal : { wxS( "false" ), wxS( "no" ), wxS( "n" ), wxS( "0" ) } )
434 {
435 if( strval.Matches( falseVal ) )
436 return false;
437 }
438 }
439 catch( const std::bad_any_cast& )
440 {
441 }
442
443 return std::nullopt;
444}
445
446
447std::unique_ptr<LIB_SYMBOL> SCH_IO_DATABASE::loadSymbolFromRow( const wxString& aSymbolName,
448 const DATABASE_LIB_TABLE& aTable,
449 const DATABASE_CONNECTION::ROW& aRow )
450{
451 std::unique_ptr<LIB_SYMBOL> symbol = nullptr;
452
453 if( aRow.count( aTable.symbols_col ) )
454 {
455 LIB_SYMBOL* originalSymbol = nullptr;
456
457 // TODO: Support multiple options for symbol
458 std::string symbolIdStr = std::any_cast<std::string>( aRow.at( aTable.symbols_col ) );
459 LIB_ID symbolId;
460 symbolId.Parse( std::any_cast<std::string>( aRow.at( aTable.symbols_col ) ) );
461
462 if( symbolId.IsValid() )
463 originalSymbol = m_adapter->LoadSymbol( symbolId );
464
465 if( originalSymbol )
466 {
467 wxLogTrace( traceDatabase, wxT( "loadSymbolFromRow: found original symbol '%s'" ),
468 symbolIdStr );
469 symbol.reset( originalSymbol->Duplicate() );
470 symbol->SetSourceLibId( symbolId );
471 }
472 else if( !symbolId.IsValid() )
473 {
474 wxLogTrace( traceDatabase, wxT( "loadSymboFromRow: source symbol id '%s' is invalid, "
475 "will create empty symbol" ), symbolIdStr );
476 }
477 else
478 {
479 wxLogTrace( traceDatabase, wxT( "loadSymboFromRow: source symbol '%s' not found, "
480 "will create empty symbol" ), symbolIdStr );
481 }
482 }
483
484 if( !symbol )
485 {
486 // Actual symbol not found: return metadata only; error will be indicated in the
487 // symbol chooser
488 symbol.reset( new LIB_SYMBOL( aSymbolName ) );
489 }
490 else
491 {
492 symbol->SetName( aSymbolName );
493 }
494
495 LIB_ID libId = symbol->GetLibId();
496 libId.SetSubLibraryName( aTable.name );;
497 symbol->SetLibId( libId );
498 wxArrayString footprintsList;
499
500 if( aRow.count( aTable.footprints_col ) )
501 {
502 std::string footprints = std::any_cast<std::string>( aRow.at( aTable.footprints_col ) );
503
504 wxString footprintsStr = wxString( footprints.c_str(), wxConvUTF8 );
505 wxStringTokenizer tokenizer( footprintsStr, ";\t\r\n", wxTOKEN_STRTOK );
506
507 while( tokenizer.HasMoreTokens() )
508 footprintsList.Add( tokenizer.GetNextToken() );
509
510 if( footprintsList.size() > 0 )
511 symbol->GetFootprintField().SetText( footprintsList[0] );
512 }
513 else
514 {
515 wxLogTrace( traceDatabase, wxT( "loadSymboFromRow: footprint field %s not found." ),
516 aTable.footprints_col );
517 }
518
519 if( !aTable.properties.description.empty() && aRow.count( aTable.properties.description ) )
520 {
521 wxString value(
522 std::any_cast<std::string>( aRow.at( aTable.properties.description ) ).c_str(),
523 wxConvUTF8 );
524 symbol->SetDescription( value );
525 }
526
527 if( !aTable.properties.keywords.empty() && aRow.count( aTable.properties.keywords ) )
528 {
529 wxString value( std::any_cast<std::string>( aRow.at( aTable.properties.keywords ) ).c_str(),
530 wxConvUTF8 );
531 symbol->SetKeyWords( value );
532 }
533
534 if( !aTable.properties.footprint_filters.empty()
535 && aRow.count( aTable.properties.footprint_filters ) )
536 {
537 wxString value( std::any_cast<std::string>( aRow.at( aTable.properties.footprint_filters ) )
538 .c_str(),
539 wxConvUTF8 );
540 footprintsList.push_back( value );
541 }
542
543 symbol->SetFPFilters( footprintsList );
544
545 if( !aTable.properties.exclude_from_sim.empty()
546 && aRow.count( aTable.properties.exclude_from_sim ) )
547 {
548 std::optional<bool> val = boolFromAny( aRow.at( aTable.properties.exclude_from_sim ) );
549
550 if( val )
551 {
552 symbol->SetExcludedFromSim( *val );
553 }
554 else
555 {
556 wxLogTrace( traceDatabase, wxT( "loadSymbolFromRow: exclude_from_sim value for %s "
557 "could not be cast to a boolean" ), aSymbolName );
558 }
559 }
560
561 if( !aTable.properties.exclude_from_board.empty()
562 && aRow.count( aTable.properties.exclude_from_board ) )
563 {
564 std::optional<bool> val = boolFromAny( aRow.at( aTable.properties.exclude_from_board ) );
565
566 if( val )
567 {
568 symbol->SetExcludedFromBoard( *val );
569 }
570 else
571 {
572 wxLogTrace( traceDatabase, wxT( "loadSymbolFromRow: exclude_from_board value for %s "
573 "could not be cast to a boolean" ), aSymbolName );
574 }
575 }
576
577 if( !aTable.properties.exclude_from_bom.empty()
578 && aRow.count( aTable.properties.exclude_from_bom ) )
579 {
580 std::optional<bool> val = boolFromAny( aRow.at( aTable.properties.exclude_from_bom ) );
581
582 if( val )
583 {
584 symbol->SetExcludedFromBOM( *val );
585 }
586 else
587 {
588 wxLogTrace( traceDatabase, wxT( "loadSymbolFromRow: exclude_from_bom value for %s "
589 "could not be cast to a boolean" ), aSymbolName );
590 }
591 }
592
593 std::vector<SCH_FIELD*> fields;
594 symbol->GetFields( fields );
595
596 std::unordered_map<wxString, SCH_FIELD*> fieldsMap;
597
598 for( SCH_FIELD* field : fields )
599 fieldsMap[field->GetName()] = field;
600
601 static const wxString c_valueFieldName( wxS( "Value" ) );
602 static const wxString c_datasheetFieldName( wxS( "Datasheet" ) );
603
604 for( const DATABASE_FIELD_MAPPING& mapping : aTable.fields )
605 {
606 if( !aRow.count( mapping.column ) )
607 {
608 wxLogTrace( traceDatabase, wxT( "loadSymbolFromRow: field %s not found in result" ),
609 mapping.column );
610 continue;
611 }
612
613 std::string strValue;
614
615 try
616 {
617 strValue = std::any_cast<std::string>( aRow.at( mapping.column ) );
618 }
619 catch( std::bad_any_cast& )
620 {
621 }
622
623 wxString value( strValue.c_str(), wxConvUTF8 );
624
625 if( mapping.name_wx == c_valueFieldName )
626 {
627 SCH_FIELD& field = symbol->GetValueField();
628 field.SetText( value );
629
630 if( !mapping.inherit_properties )
631 {
632 field.SetVisible( mapping.visible_on_add );
633 field.SetNameShown( mapping.show_name );
634 }
635 continue;
636 }
637 else if( mapping.name_wx == c_datasheetFieldName )
638 {
639 SCH_FIELD& field = symbol->GetDatasheetField();
640 field.SetText( value );
641
642 if( !mapping.inherit_properties )
643 {
644 field.SetVisible( mapping.visible_on_add );
645 field.SetNameShown( mapping.show_name );
646
647 if( mapping.visible_on_add )
648 field.SetAutoAdded( true );
649 }
650
651 continue;
652 }
653
654 SCH_FIELD* field;
655 bool isNew = false;
656
657 if( fieldsMap.count( mapping.name_wx ) )
658 {
659 field = fieldsMap[mapping.name_wx];
660 }
661 else
662 {
663 field = new SCH_FIELD( nullptr, FIELD_T::USER );
664 field->SetName( mapping.name_wx );
665 isNew = true;
666 fieldsMap[mapping.name_wx] = field;
667 }
668
669 if( !mapping.inherit_properties || isNew )
670 {
671 field->SetVisible( mapping.visible_on_add );
672 field->SetAutoAdded( true );
673 field->SetNameShown( mapping.show_name );
674 }
675
676 field->SetText( value );
677
678 if( isNew )
679 symbol->AddDrawItem( field, false );
680
681 m_customFields.insert( mapping.name_wx );
682
683 if( mapping.visible_in_chooser )
684 m_defaultShownFields.insert( mapping.name_wx );
685 }
686
687 symbol->GetDrawItems().sort();
688
689 return symbol;
690}
691
692
694{
695 return new DIALOG_DATABASE_LIB_SETTINGS( aParent, this );
696}
const char * name
std::map< std::string, std::any > ROW
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:68
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:395
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:52
bool IsValid() const
Check if this LID_ID is valid.
Definition lib_id.h:172
void SetSubLibraryName(const UTF8 &aName)
Definition lib_id.h:131
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition lib_id.cpp:192
Define a library symbol object.
Definition lib_symbol.h:83
bool IsPower() const override
virtual LIB_SYMBOL * Duplicate() const
Create a copy of a LIB_SYMBOL and assigns unique KIIDs to the copy and its children.
Definition lib_symbol.h:98
void SetAutoAdded(bool aAutoAdded)
Definition sch_field.h:227
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
void SetNameShown(bool aShown=true)
Definition sch_field.h:209
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
std::unique_ptr< DATABASE_CONNECTION > m_conn
Generally will be null if no valid connection is established.
void GetDefaultSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that should be shown by default for this library in the symb...
void ensureSettings(const wxString &aSettingsPath)
bool TestConnection(wxString *aErrorMsg=nullptr)
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > m_nameToSymbolcache
std::map< wxString, std::pair< std::string, std::string > > m_sanitizedNameMap
std::set< wxString > m_defaultShownFields
virtual ~SCH_IO_DATABASE()
void GetSubLibraryNames(std::vector< wxString > &aNames) override
Retrieves a list of sub-libraries in this library.
std::unique_ptr< DATABASE_LIB_SETTINGS > m_settings
static std::optional< bool > boolFromAny(const std::any &aVal)
SYMBOL_LIBRARY_ADAPTER * m_adapter
long long m_cacheTimestamp
DIALOG_SHIM * CreateConfigurationDialog(wxWindow *aParent) override
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.
std::unique_ptr< LIB_SYMBOL > loadSymbolFromRow(const wxString &aSymbolName, const DATABASE_LIB_TABLE &aTable, const DATABASE_CONNECTION::ROW &aRow)
std::set< wxString > m_customFields
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
SCH_IO(const wxString &aName)
Definition sch_io.h:375
static const char * PropPowerSymsOnly
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition utf8.h:71
const char * c_str() const
Definition utf8.h:108
const char *const traceDatabase
#define _(s)
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
static std::string strValue(double aValue)
bool visible_in_chooser
Whether the column is shown by default in the chooser.
std::string column
Database column name.
bool inherit_properties
Whether or not to inherit properties from symbol field.
bool visible_on_add
Whether to show the field when placing the symbol.
bool show_name
Whether or not to show the field name as well as its value.
wxString name_wx
KiCad field name (converted)
A database library table will be mapped to a sub-library provided by the database library entry in th...
std::string key_col
Unique key column name (will form part of the LIB_ID)
std::string name
KiCad library nickname (will form part of the LIB_ID)
std::string symbols_col
Column name containing KiCad symbol refs.
std::string footprints_col
Column name containing KiCad footprint refs.
std::vector< DATABASE_FIELD_MAPPING > fields
std::string table
Database table to pull content from.
MAPPABLE_SYMBOL_PROPERTIES properties
@ USER
The field ID hasn't been set yet; field is invalid.
std::string path
wxString result
Test unit parsing edge cases and error handling.