25#include <nlohmann/json.hpp>
52 [&]() -> nlohmann::json
57 [&](
const nlohmann::json aObj )
61 if( !aObj.is_array() )
64 for(
const nlohmann::json& entry : aObj )
66 if( entry.empty() || !entry.is_object() )
69 DATABASE_LIB_TABLE table;
71 table.name = entry[
"name"].get<std::string>();
72 table.table = entry[
"table"].get<std::string>();
73 table.key_col = entry[
"key"].get<std::string>();
74 table.symbols_col = entry[
"symbols"].get<std::string>();
75 table.footprints_col = entry[
"footprints"].get<std::string>();
79 table.name.erase( std::remove( table.name.begin(), table.name.end(),
'/' ),
82 if( entry.contains(
"properties" ) && entry[
"properties"].is_object() )
84 const nlohmann::json& pj = entry[
"properties"];
86 table.properties.description = fetchOrDefault<std::string>( pj,
"description" );
88 table.properties.footprint_filters =
89 fetchOrDefault<std::string>( pj,
"footprint_filters" );
91 table.properties.keywords = fetchOrDefault<std::string>( pj,
"keywords" );
93 table.properties.exclude_from_bom =
94 fetchOrDefault<std::string>( pj,
"exclude_from_bom" );
96 table.properties.exclude_from_board =
97 fetchOrDefault<std::string>( pj,
"exclude_from_board" );
100 if( entry.contains(
"fields" ) && entry[
"fields"].is_array() )
102 for( const nlohmann::json& fieldJson : entry[
"fields"] )
104 if( fieldJson.empty() || !fieldJson.is_object() )
107 std::string column = fetchOrDefault<std::string>( fieldJson,
"column" );
108 std::string name = fetchOrDefault<std::string>( fieldJson,
"name" );
109 bool visible_on_add = fetchOrDefault<bool>( fieldJson,
"visible_on_add" );
110 bool visible_in_chooser =
111 fetchOrDefault<bool>( fieldJson,
"visible_in_chooser" );
112 bool show_name = fetchOrDefault<bool>( fieldJson,
"show_name" );
113 bool inherit = fetchOrDefault<bool>( fieldJson,
"inherit_properties" );
115 table.fields.emplace_back(
116 DATABASE_FIELD_MAPPING(
118 column, name, visible_on_add, visible_in_chooser, show_name,
124 m_Tables.emplace_back( std::move( table ) );
129 m_params.emplace_back(
new PARAM<int>(
"cache.max_size", &m_Cache.max_size, 256 ) );
131 m_params.emplace_back(
new PARAM<int>(
"cache.max_age", &m_Cache.max_age, 10 ) );
133 registerMigration( 0, 1,
141 if( !Contains(
"libraries" ) || !At(
"libraries" ).is_array() )
144 for( nlohmann::json&
library : At(
"libraries" ) )
146 if( !
library.contains(
"fields" ) )
149 for(
const nlohmann::json& field :
library[
"fields"] )
151 if( !field.contains(
"name" ) || !field.contains(
"column" ) )
154 std::string name = field[
"name"].get<std::string>();
155 std::string col = field[
"column"].get<std::string>();
157 if( name ==
"ki_description" )
158 library[
"properties"][
"description"] = col;
159 else if( name ==
"ki_fp_filters" )
160 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
const std::string DatabaseLibraryFileExtension
std::string connection_string
Definition of file extensions used in Kicad.