25#include <nlohmann/json.hpp>
61 if( !aObj.is_array() )
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>();
77 if( entry.contains(
"properties" ) && entry[
"properties"].is_object() )
79 const nlohmann::json& pj = entry[
"properties"];
81 table.properties.description = fetchOrDefault<std::string>( pj,
"description" );
83 table.properties.footprint_filters =
84 fetchOrDefault<std::string>( pj,
"footprint_filters" );
86 table.properties.keywords = fetchOrDefault<std::string>( pj,
"keywords" );
88 table.properties.exclude_from_bom =
89 fetchOrDefault<std::string>( pj,
"exclude_from_bom" );
91 table.properties.exclude_from_board =
92 fetchOrDefault<std::string>( pj,
"exclude_from_board" );
95 if( entry.contains(
"fields" ) && entry[
"fields"].is_array() )
97 for( const nlohmann::json& fieldJson : entry[
"fields"] )
99 if( fieldJson.empty() || !fieldJson.is_object() )
102 std::string column = fetchOrDefault<std::string>( fieldJson,
"column" );
103 std::string name = fetchOrDefault<std::string>( fieldJson,
"name" );
104 bool visible_on_add = fetchOrDefault<bool>( fieldJson,
"visible_on_add" );
105 bool visible_in_chooser =
106 fetchOrDefault<bool>( fieldJson,
"visible_in_chooser" );
107 bool show_name = fetchOrDefault<bool>( fieldJson,
"show_name" );
108 bool inherit = fetchOrDefault<bool>( fieldJson,
"inherit_properties" );
110 table.fields.emplace_back(
111 DATABASE_FIELD_MAPPING(
113 column, name, visible_on_add, visible_in_chooser, show_name,
119 m_Tables.emplace_back( std::move( table ) );
124 m_params.emplace_back(
new PARAM<int>(
"cache.max_size", &m_Cache.max_size, 256 ) );
126 m_params.emplace_back(
new PARAM<int>(
"cache.max_age", &m_Cache.max_age, 10 ) );
128 registerMigration( 0, 1,
136 if( !Contains(
"libraries" ) || !At(
"libraries" ).is_array() )
141 if( !
library.contains(
"fields" ) )
146 if( !field.contains(
"name" ) || !field.contains(
"column" ) )
149 std::string name = field[
"name"].get<std::string>();
150 std::string col = field[
"column"].get<std::string>();
152 if( name ==
"ki_description" )
153 library[
"properties"][
"description"] = col;
154 else if( name ==
"ki_fp_filters" )
155 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)
const int dblibSchemaVersion
const std::string DatabaseLibraryFileExtension
std::string connection_string
Definition of file extensions used in Kicad.