38 bool aVisibleOnAdd,
bool aVisibleInChooser,
39 bool aShowName,
bool aInheritProperties ) :
42 name_wx( aName.c_str(), wxConvUTF8 ),
43 visible_on_add( aVisibleOnAdd ),
44 visible_in_chooser( aVisibleInChooser ),
45 show_name( aShowName ),
46 inherit_properties( aInheritProperties )
68 [&]() -> nlohmann::json
73 [&](
const nlohmann::json aObj )
77 if( !aObj.is_array() )
80 for(
const nlohmann::json& entry : aObj )
82 if( entry.empty() || !entry.is_object() )
85 DATABASE_LIB_TABLE table;
87 table.name = entry[
"name"].get<std::string>();
88 table.table = entry[
"table"].get<std::string>();
89 table.key_col = entry[
"key"].get<std::string>();
90 table.symbols_col = entry[
"symbols"].get<std::string>();
91 table.footprints_col = entry[
"footprints"].get<std::string>();
95 std::erase( table.name,
'/' );
97 if( entry.contains(
"properties" ) && entry[
"properties"].is_object() )
99 const nlohmann::json& propJson = entry[
"properties"];
101 table.properties.description =
102 fetchOrDefault<std::string>( propJson,
"description" );
104 table.properties.footprint_filters =
105 fetchOrDefault<std::string>( propJson,
"footprint_filters" );
107 table.properties.keywords =
108 fetchOrDefault<std::string>( propJson,
"keywords" );
110 table.properties.exclude_from_bom =
111 fetchOrDefault<std::string>( propJson,
"exclude_from_bom" );
113 table.properties.exclude_from_board =
114 fetchOrDefault<std::string>( propJson,
"exclude_from_board" );
116 table.properties.exclude_from_sim =
117 fetchOrDefault<std::string>( propJson,
"exclude_from_sim" );
120 if( entry.contains(
"fields" ) && entry[
"fields"].is_array() )
122 for( const nlohmann::json& fieldJson : entry[
"fields"] )
124 if( fieldJson.empty() || !fieldJson.is_object() )
127 table.fields.emplace_back( DATABASE_FIELD_MAPPING(
128 fetchOrDefault<std::string>( fieldJson,
"column" ),
129 fetchOrDefault<std::string>( fieldJson,
"name" ),
130 fetchOrDefault<bool>( fieldJson,
"visible_on_add" ),
131 fetchOrDefault<bool>( fieldJson,
"visible_in_chooser" ),
132 fetchOrDefault<bool>( fieldJson,
"show_name" ),
133 fetchOrDefault<bool>( fieldJson,
"inherit_properties" ) ) );
142 m_params.emplace_back(
new PARAM<int>(
"cache.max_size", &m_Cache.max_size, 256 ) );
144 m_params.emplace_back(
new PARAM<int>(
"cache.max_age", &m_Cache.max_age, 10 ) );
146 registerMigration( 0, 1,
154 if( !Contains(
"libraries" ) || !At(
"libraries" ).is_array() )
157 for( nlohmann::json&
library : At(
"libraries" ) )
159 if( !
library.contains(
"fields" ) )
162 for(
const nlohmann::json& field :
library[
"fields"] )
164 if( !field.contains(
"name" ) || !field.contains(
"column" ) )
167 std::string name = field[
"name"].get<std::string>();
168 std::string col = field[
"column"].get<std::string>();
170 if( name ==
"ki_description" )
171 library[
"properties"][
"description"] = col;
172 else if( name ==
"ki_fp_filters" )
173 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
DATABASE_FIELD_MAPPING(const std::string &aColumn, const std::string &aName, bool aVisibleOnAdd, bool aVisibleInChooser, bool aShowName, bool aInheritProperties)
std::string connection_string
Definition of file extensions used in Kicad.