KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kicad_settings.cpp
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) 2020 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#include <wx/aui/framemanager.h> // ensure class wxAuiPaneInfo is defined for other includes
21
23#include <json_common.h>
25#include <settings/parameters.h>
26
27
29const int kicadSchemaVersion = 0;
30
31
32const nlohmann::json PCM_DEFAULT_REPOSITORIES = nlohmann::json::array( {
33 nlohmann::json( {
34 { "name", "KiCad official repository" },
36 } )
37} );
38
39
42 m_ShowHistoryPanel( false )
43{
44 m_params.emplace_back( new PARAM<int>( "appearance.left_frame_width", &m_LeftWinWidth, 200 ) );
45 m_params.emplace_back( new PARAM<bool>( "aui.show_history_panel", &m_ShowHistoryPanel, false ) );
46
47 m_params.emplace_back( new PARAM_LIST<wxString>( "system.open_projects", &m_OpenProjects, {} ) );
48
49 m_params.emplace_back( new PARAM<wxString>( "system.last_design_block_lib_dir", &m_lastDesignBlockLibDir, "" ) );
50
51 m_params.emplace_back( new PARAM<wxString>( "system.last_update_check_time", &m_lastUpdateCheckTime, "" ) );
52 m_params.emplace_back( new PARAM<wxString>( "system.last_received_update", &m_lastReceivedUpdate, "" ) );
53 m_params.emplace_back( new PARAM<bool>( "system.check_for_kicad_updates", &m_KiCadUpdateCheck, true ) );
54
55 m_params.emplace_back( new PARAM<wxPoint>( "template.window.pos", &m_TemplateWindowPos, wxDefaultPosition ) );
56 m_params.emplace_back( new PARAM<wxSize>( "template.window.size", &m_TemplateWindowSize, wxDefaultSize ) );
57 m_params.emplace_back( new PARAM<wxString>( "template.last_used", &m_LastUsedTemplate, "" ) );
58 m_params.emplace_back( new PARAM_LIST<wxString>( "template.recent_templates", &m_RecentTemplates, {} ) );
59
60 m_params.emplace_back( new PARAM<int>( "template.filter", &m_TemplateFilterChoice, 0 ) );
61
62 m_params.emplace_back( new PARAM<wxString>( "template.browsed_path", &m_BrowsedTemplatesPath, "" ) );
63
64 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
65 "pcm.repositories",
66 [&]() -> nlohmann::json
67 {
68 nlohmann::json js = nlohmann::json::array();
69
70 for( const auto& pair : m_PcmRepositories )
71 {
72 js.push_back( nlohmann::json( { { "name", pair.first.ToUTF8() },
73 { "url", pair.second.ToUTF8() } } ) );
74 }
75
76 return js;
77 },
78 [&]( const nlohmann::json aObj )
79 {
80 m_PcmRepositories.clear();
81
82 if( !aObj.is_array() )
83 return;
84
85 for( const auto& entry : aObj )
86 {
87 if( entry.empty() || !entry.is_object() )
88 continue;
89
90 m_PcmRepositories.emplace_back(
91 std::make_pair( wxString( entry["name"].get<std::string>() ),
92 wxString( entry["url"].get<std::string>() ) ) );
93 }
94 },
96
97 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
98 "libraries.overrides",
99 [&]() -> nlohmann::json
100 {
101 nlohmann::json js = nlohmann::json::object();
102
103 for( const auto& [tablePath, libs] : m_LibOverrides )
104 {
105 nlohmann::json tableJs = nlohmann::json::object();
106
107 for( const auto& [nickname, override_] : libs )
108 {
109 nlohmann::json entry = nlohmann::json::object();
110
111 if( override_.disabled )
112 entry["disabled"] = true;
113
114 if( override_.hidden )
115 entry["hidden"] = true;
116
117 if( !entry.empty() )
118 tableJs[std::string( nickname.ToUTF8() )] = entry;
119 }
120
121 if( !tableJs.empty() )
122 js[std::string( tablePath.ToUTF8() )] = tableJs;
123 }
124
125 return js;
126 },
127 [&]( const nlohmann::json& aObj )
128 {
129 m_LibOverrides.clear();
130
131 if( !aObj.is_object() )
132 return;
133
134 for( const auto& [tablePath, tableObj] : aObj.items() )
135 {
136 if( !tableObj.is_object() )
137 continue;
138
139 std::map<wxString, LIB_OVERRIDE>& libs =
140 m_LibOverrides[wxString::FromUTF8( tablePath )];
141
142 for( const auto& [nickname, entry] : tableObj.items() )
143 {
144 if( !entry.is_object() )
145 continue;
146
147 LIB_OVERRIDE override_;
148
149 if( entry.contains( "disabled" ) && entry["disabled"].is_boolean() )
150 override_.disabled = entry["disabled"].get<bool>();
151
152 if( entry.contains( "hidden" ) && entry["hidden"].is_boolean() )
153 override_.hidden = entry["hidden"].get<bool>();
154
155 libs[wxString::FromUTF8( nickname )] = override_;
156 }
157 }
158 },
159 nlohmann::json::object() ) );
160
161 m_params.emplace_back(
162 new PARAM<wxString>( "pcm.last_download_dir", &m_PcmLastDownloadDir, "" ) );
163
164 m_params.emplace_back( new PARAM<bool>( "pcm.check_for_updates", &m_PcmUpdateCheck, true ) );
165
166 m_params.emplace_back( new PARAM<bool>( "pcm.lib_auto_add", &m_PcmLibAutoAdd, true ) );
167
168 m_params.emplace_back( new PARAM<bool>( "pcm.lib_auto_remove", &m_PcmLibAutoRemove, true ) );
169
170 m_params.emplace_back( new PARAM<wxString>( "pcm.lib_prefix", &m_PcmLibPrefix,
171 wxS( "PCM_" ) ) );
172
173 m_params.emplace_back( new PARAM<wxString>( "pcm.last_selected_repo_id", &m_PcmLastSelectedRepoId, "" ) );
174}
175
176
177bool KICAD_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
178{
179 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
180
181 ret &= fromLegacy<int>( aCfg, "LeftWinWidth", "appearance.left_frame_width" );
182
183 // Override the size parameters to ensure the new PCM button is always shown.
184 // This will make the window take the default size instead of the migrated one.
185 Set( "window.size_x", 0 );
186 Set( "window.size_y", 0 );
187
188 return ret;
189}
APP_SETTINGS_BASE(const std::string &aFilename, int aSchemaVersion)
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
bool fromLegacy(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig value to a given JSON pointer value.
void Set(const std::string &aPath, ValueType aVal)
Stores a value into the JSON document Will throw an exception if ValueType isn't something that the l...
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
wxString m_PcmLastSelectedRepoId
wxString m_lastDesignBlockLibDir
std::vector< wxString > m_RecentTemplates
wxSize m_TemplateWindowSize
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
wxString m_PcmLibPrefix
wxString m_BrowsedTemplatesPath
std::map< wxString, std::map< wxString, LIB_OVERRIDE > > m_LibOverrides
Overrides for libraries in read-only nested tables.
wxPoint m_TemplateWindowPos
wxString m_lastUpdateCheckTime
wxString m_PcmLastDownloadDir
std::vector< wxString > m_OpenProjects
std::vector< std::pair< wxString, wxString > > m_PcmRepositories
wxString m_lastReceivedUpdate
wxString m_LastUsedTemplate
Like a normal param, but with custom getter and setter functions.
Definition parameters.h:297
const nlohmann::json PCM_DEFAULT_REPOSITORIES
const int kicadSchemaVersion
! Update the schema version whenever a migration is required
#define PCM_DEFAULT_REPOSITORY_URL
Per-library override flags for libraries in read-only nested tables.