36 bool aVisibleOnAdd,
bool aVisibleInChooser,
37 bool aShowName,
bool aInheritProperties ) :
39 name( aName ), name_wx( aName.c_str(), wxConvUTF8 ), visible_on_add( aVisibleOnAdd ),
40 visible_in_chooser( aVisibleInChooser ), show_name( aShowName ),
41 inherit_properties( aInheritProperties )
63 [&]() -> nlohmann::json
68 [&](
const nlohmann::json aObj )
72 if( !aObj.is_array() )
75 for(
const nlohmann::json& entry : aObj )
77 if( entry.empty() || !entry.is_object() )
80 DATABASE_LIB_TABLE table;
82 table.name = entry[
"name"].get<std::string>();
83 table.table = entry[
"table"].get<std::string>();
84 table.key_col = entry[
"key"].get<std::string>();
85 table.symbols_col = entry[
"symbols"].get<std::string>();
86 table.footprints_col = entry[
"footprints"].get<std::string>();
90 table.name.erase( std::remove( table.name.begin(), table.name.end(),
'/' ),
93 if( entry.contains(
"properties" ) && entry[
"properties"].is_object() )
95 const nlohmann::json& pj = entry[
"properties"];
97 table.properties.description = fetchOrDefault<std::string>( pj,
"description" );
99 table.properties.footprint_filters =
100 fetchOrDefault<std::string>( pj,
"footprint_filters" );
102 table.properties.keywords = fetchOrDefault<std::string>( pj,
"keywords" );
104 table.properties.exclude_from_bom =
105 fetchOrDefault<std::string>( pj,
"exclude_from_bom" );
107 table.properties.exclude_from_board =
108 fetchOrDefault<std::string>( pj,
"exclude_from_board" );
110 table.properties.exclude_from_sim =
111 fetchOrDefault<std::string>( pj,
"exclude_from_sim" );
114 if( entry.contains(
"fields" ) && entry[
"fields"].is_array() )
116 for( const nlohmann::json& fieldJson : entry[
"fields"] )
118 if( fieldJson.empty() || !fieldJson.is_object() )
121 std::string column = fetchOrDefault<std::string>( fieldJson,
"column" );
122 std::string name = fetchOrDefault<std::string>( fieldJson,
"name" );
123 bool visible_on_add = fetchOrDefault<bool>( fieldJson,
"visible_on_add" );
124 bool visible_in_chooser =
125 fetchOrDefault<bool>( fieldJson,
"visible_in_chooser" );
126 bool show_name = fetchOrDefault<bool>( fieldJson,
"show_name" );
127 bool inherit = fetchOrDefault<bool>( fieldJson,
"inherit_properties" );
129 table.fields.emplace_back(
130 DATABASE_FIELD_MAPPING( column, name, visible_on_add,
131 visible_in_chooser, show_name, inherit ) );
135 m_Tables.emplace_back( std::move( table ) );
140 m_params.emplace_back(
new PARAM<int>(
"cache.max_size", &m_Cache.max_size, 256 ) );
142 m_params.emplace_back(
new PARAM<int>(
"cache.max_age", &m_Cache.max_age, 10 ) );
144 registerMigration( 0, 1,
152 if( !Contains(
"libraries" ) || !At(
"libraries" ).is_array() )
155 for( nlohmann::json&
library : At(
"libraries" ) )
157 if( !
library.contains(
"fields" ) )
160 for(
const nlohmann::json& field :
library[
"fields"] )
162 if( !field.contains(
"name" ) || !field.contains(
"column" ) )
165 std::string name = field[
"name"].get<std::string>();
166 std::string col = field[
"column"].get<std::string>();
168 if( name ==
"ki_description" )
169 library[
"properties"][
"description"] = col;
170 else if( name ==
"ki_fp_filters" )
171 library[
"properties"][
"footprint_filters"] = col;
DATABASE_LIB_SETTINGS(const std::string &aFilename)
wxString getFileExt() const override
std::vector< DATABASE_LIB_TABLE > m_Tables
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
Like a normal param, but with custom getter and setter functions.
const int dblibSchemaVersion
static const std::string DatabaseLibraryFileExtension
@ NONE
No connection to this item.
DATABASE_FIELD_MAPPING(std::string aColumn, std::string aName, bool aVisibleOnAdd, bool aVisibleInChooser, bool aShowName, bool aInheritProperties)
std::string connection_string
Definition of file extensions used in Kicad.