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