37 bool aVisibleOnAdd,
bool aVisibleInChooser,
38 bool aShowName,
bool aInheritProperties ) :
41 name_wx( aName.c_str(), wxConvUTF8 ),
42 visible_on_add( aVisibleOnAdd ),
43 visible_in_chooser( aVisibleInChooser ),
44 show_name( aShowName ),
45 inherit_properties( aInheritProperties )
67 [&]() -> nlohmann::json
72 [&](
const nlohmann::json aObj )
76 if( !aObj.is_array() )
79 for(
const nlohmann::json& entry : aObj )
81 if( entry.empty() || !entry.is_object() )
84 DATABASE_LIB_TABLE table;
86 table.name = entry[
"name"].get<std::string>();
87 table.table = entry[
"table"].get<std::string>();
88 table.key_col = entry[
"key"].get<std::string>();
89 table.symbols_col = entry[
"symbols"].get<std::string>();
90 table.footprints_col = entry[
"footprints"].get<std::string>();
94 alg::delete_matching( table.name,
'/' );
96 if( entry.contains(
"properties" ) && entry[
"properties"].is_object() )
98 const nlohmann::json& propJson = entry[
"properties"];
100 table.properties.description =
101 fetchOrDefault<std::string>( propJson,
"description" );
103 table.properties.footprint_filters =
104 fetchOrDefault<std::string>( propJson,
"footprint_filters" );
106 table.properties.keywords =
107 fetchOrDefault<std::string>( propJson,
"keywords" );
109 table.properties.exclude_from_bom =
110 fetchOrDefault<std::string>( propJson,
"exclude_from_bom" );
112 table.properties.exclude_from_board =
113 fetchOrDefault<std::string>( propJson,
"exclude_from_board" );
115 table.properties.exclude_from_sim =
116 fetchOrDefault<std::string>( propJson,
"exclude_from_sim" );
119 if( entry.contains(
"fields" ) && entry[
"fields"].is_array() )
121 for( const nlohmann::json& fieldJson : entry[
"fields"] )
123 if( fieldJson.empty() || !fieldJson.is_object() )
126 table.fields.emplace_back( DATABASE_FIELD_MAPPING(
127 fetchOrDefault<std::string>( fieldJson,
"column" ),
128 fetchOrDefault<std::string>( fieldJson,
"name" ),
129 fetchOrDefault<bool>( fieldJson,
"visible_on_add" ),
130 fetchOrDefault<bool>( fieldJson,
"visible_in_chooser" ),
131 fetchOrDefault<bool>( fieldJson,
"show_name" ),
132 fetchOrDefault<bool>( fieldJson,
"inherit_properties" ) ) );
136 m_Tables.emplace_back( std::move( table ) );
141 m_params.emplace_back(
new PARAM<int>(
"cache.max_size", &m_Cache.max_size, 256 ) );
143 m_params.emplace_back(
new PARAM<int>(
"cache.max_age", &m_Cache.max_age, 10 ) );
145 registerMigration( 0, 1,
153 if( !Contains(
"libraries" ) || !At(
"libraries" ).is_array() )
156 for( nlohmann::json&
library : At(
"libraries" ) )
158 if( !
library.contains(
"fields" ) )
161 for(
const nlohmann::json& field :
library[
"fields"] )
163 if( !field.contains(
"name" ) || !field.contains(
"column" ) )
166 std::string name = field[
"name"].get<std::string>();
167 std::string col = field[
"column"].get<std::string>();
169 if( name ==
"ki_description" )
170 library[
"properties"][
"description"] = col;
171 else if( name ==
"ki_fp_filters" )
172 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.