KiCad PCB EDA Suite
Loading...
Searching...
No Matches
database_lib_settings.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022 Jon Evans <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef KICAD_DATABASE_LIB_SETTINGS_H
22#define KICAD_DATABASE_LIB_SETTINGS_H
23
24#include <json_common.h>
25#include <functional>
27#include <wx/string.h>
28
29#include <map>
30#include <memory>
31
32
38
39
41{
43 std::string dsn;
44 std::string username;
45 std::string password;
47 std::string connection_string;
48};
49
50
52{
53 std::string column;
54 std::string name;
55 wxString name_wx;
58 bool show_name;
60 nlohmann::json source;
61
63
64 explicit DATABASE_FIELD_MAPPING( const std::string& aColumn, const std::string& aName,
65 bool aVisibleOnAdd, bool aVisibleInChooser, bool aShowName,
66 bool aInheritProperties );
67
68 void SetName( const std::string& aName );
69};
70
71
73{
74 std::string description;
75 std::string footprint_filters;
76 std::string keywords;
77 std::string exclude_from_sim;
78 std::string exclude_from_bom;
79 std::string exclude_from_board;
80
81 bool operator==( const MAPPABLE_SYMBOL_PROPERTIES& aOther ) const = default;
82};
83
84
99{
100 std::string name;
101 std::string table;
102 std::string key_col;
103 std::string symbols_col;
104 std::string footprints_col;
105 std::string pins_col;
106
108 std::vector<DATABASE_FIELD_MAPPING> fields;
109
110 nlohmann::json source;
111};
112
113
119
120
124using DATABASE_SECRET_LOOKUP = std::function<bool( const wxString& aService, const wxString& aKey, wxString& aSecret )>;
125
127{
128public:
129 DATABASE_LIB_SETTINGS( const std::string& aFilename );
130
132
134
135 std::vector<DATABASE_LIB_TABLE> m_Tables;
136
138
140
141 std::string m_Name;
142 std::string m_Description;
143
145 void Load() override;
146
151 bool Store() override;
152
157 void ResolvePassword( const DATABASE_SECRET_LOOKUP& aLookup = nullptr );
158
159protected:
160 wxString getFileExt() const override;
161
162private:
163 static nlohmann::json tableToJson( const DATABASE_LIB_TABLE& aTable );
165 static DATABASE_LIB_TABLE tableFromJson( const nlohmann::json& aEntry );
166 static nlohmann::json fieldToJson( const DATABASE_FIELD_MAPPING& aField );
167 static DATABASE_FIELD_MAPPING fieldFromJson( const nlohmann::json& aEntry );
168
178};
179
180
188KICOMMON_API std::unique_ptr<DATABASE_LIB_SETTINGS> LoadDatabaseLibSettingsReadOnly( const wxString& aPath,
189 bool* aLoaded = nullptr );
190
195KICOMMON_API wxString DefaultDatabaseLibFileName( const wxString& aLibName );
196
201
206
214KICOMMON_API bool GetDatabasePassword( const DATABASE_SOURCE& aSource, std::string& aPassword,
215 const DATABASE_SECRET_LOOKUP& aLookup = nullptr );
216
221 const DATABASE_SECRET_LOOKUP& aLookup = nullptr );
222
227KICOMMON_API bool StoreDatabasePassword( const DATABASE_SOURCE& aSource, const std::string& aPassword );
228
229#endif //KICAD_DATABASE_LIB_SETTINGS_H
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
Read a model file and creates a generic display structure.
static DATABASE_LIB_TABLE tableFromJson(const nlohmann::json &aEntry)
Missing or mistyped keys load as defaults so one incomplete entry cannot stop the others.
void ResolvePassword(const DATABASE_SECRET_LOOKUP &aLookup=nullptr)
Fills in the source password from the keyring when the file has none.
DATABASE_LIB_SETTINGS(const std::string &aFilename)
wxString getFileExt() const override
static DATABASE_FIELD_MAPPING fieldFromJson(const nlohmann::json &aEntry)
bool Store() override
Stores parameters, then restores the raw file value of every scalar the caller left unchanged so that...
std::vector< DATABASE_LIB_TABLE > m_Tables
static nlohmann::json tableToJson(const DATABASE_LIB_TABLE &aTable)
DATABASE_CACHE_SETTINGS m_Cache
static nlohmann::json fieldToJson(const DATABASE_FIELD_MAPPING &aField)
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
KICOMMON_API bool StoreDatabasePassword(const DATABASE_SOURCE &aSource, const std::string &aPassword)
Stores the password for the source's DSN login in the system keyring, or removes the entry when the p...
KICOMMON_API void ResolveDatabasePassword(DATABASE_SOURCE &aSource, const DATABASE_SECRET_LOOKUP &aLookup=nullptr)
Fills in the source password from the keyring, but only when the library file did not supply one.
KICOMMON_API wxString DefaultDatabaseLibFileName(const wxString &aLibName)
KICOMMON_API DATABASE_SECRET_LOOKUP DefaultDatabaseSecretLookup()
The lookup used when none is injected, which must never prompt to unlock the keyring.
DATABASE_SOURCE_TYPE
std::function< bool(const wxString &aService, const wxString &aKey, wxString &aSecret)> DATABASE_SECRET_LOOKUP
Keyring lookup signature, matching KIPLATFORM::SECRETS::GetSecretNoPrompt.
KICOMMON_API bool GetDatabasePassword(const DATABASE_SOURCE &aSource, std::string &aPassword, const DATABASE_SECRET_LOOKUP &aLookup=nullptr)
DSN passwords that are not saved in the (often shared) library file live in the system keyring,...
KICOMMON_API bool IsNoPromptSecretLookup(const DATABASE_SECRET_LOOKUP &aLookup)
KICOMMON_API std::unique_ptr< DATABASE_LIB_SETTINGS > LoadDatabaseLibSettingsReadOnly(const wxString &aPath, bool *aLoaded=nullptr)
Loads a database library settings file without allowing the load itself (e.g.
#define KICOMMON_API
Definition kicommon.h:27
int max_age
Max age of a cached table before it expires, in seconds.
int max_size
Maximum number of tables to cache, each holding the rows read from it.
bool visible_in_chooser
Whether the column is shown by default in the chooser.
std::string column
Database column name.
std::string name
KiCad field name.
void SetName(const std::string &aName)
bool inherit_properties
Whether or not to inherit properties from symbol field.
bool visible_on_add
Whether to show the field when placing the symbol.
bool show_name
Whether or not to show the field name as well as its value.
nlohmann::json source
Raw JSON as loaded; untouched keys are written back verbatim.
wxString name_wx
KiCad field name (converted)
Scalar settings as parsed at load, so Store() can tell which ones the caller changed.
A database library table will be mapped to a sub-library provided by the database library entry in th...
std::string key_col
Unique key column name (will form part of the LIB_ID)
std::string name
KiCad library nickname (will form part of the LIB_ID)
nlohmann::json source
Raw JSON as loaded; untouched keys are written back verbatim.
std::string symbols_col
Column name containing KiCad symbol refs.
std::string footprints_col
Column name containing KiCad footprint refs.
std::vector< DATABASE_FIELD_MAPPING > fields
std::string table
Database table to pull content from.
MAPPABLE_SYMBOL_PROPERTIES properties
std::string pins_col
Column name containing JSON pin assignments (optional)
std::string connection_string
DATABASE_SOURCE_TYPE type
bool operator==(const MAPPABLE_SYMBOL_PROPERTIES &aOther) const =default