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_LeftWinWidth( 200 ),
43 m_ShowHistoryPanel( false ),
45{
46 m_params.emplace_back( new PARAM<int>( "appearance.left_frame_width", &m_LeftWinWidth, 200 ) );
47 m_params.emplace_back( new PARAM<bool>( "aui.show_history_panel", &m_ShowHistoryPanel, false ) );
48 m_params.emplace_back( new PARAM<bool>( "aui.show_git_commit_panel", &m_ShowGitCommitPanel, true ) );
49
50 m_params.emplace_back( new PARAM_LIST<wxString>( "system.open_projects", &m_OpenProjects, {} ) );
51
52 m_params.emplace_back( new PARAM<wxString>( "system.last_design_block_lib_dir", &m_lastDesignBlockLibDir, "" ) );
53
54 m_params.emplace_back( new PARAM<wxString>( "system.last_update_check_time", &m_lastUpdateCheckTime, "" ) );
55 m_params.emplace_back( new PARAM<wxString>( "system.last_received_update", &m_lastReceivedUpdate, "" ) );
56 m_params.emplace_back( new PARAM<bool>( "system.check_for_kicad_updates", &m_KiCadUpdateCheck, true ) );
57
58 m_params.emplace_back( new PARAM<wxPoint>( "template.window.pos", &m_TemplateWindowPos, wxDefaultPosition ) );
59 m_params.emplace_back( new PARAM<wxSize>( "template.window.size", &m_TemplateWindowSize, wxDefaultSize ) );
60 m_params.emplace_back( new PARAM<wxString>( "template.last_used", &m_LastUsedTemplate, "" ) );
61 m_params.emplace_back( new PARAM_LIST<wxString>( "template.recent_templates", &m_RecentTemplates, {} ) );
62 m_params.emplace_back( new PARAM_LIST<wxString>( "template.pinned_templates", &m_PinnedTemplates, {} ) );
63
64 m_params.emplace_back( new PARAM<int>( "template.filter", &m_TemplateFilterChoice, 0 ) );
65
66 m_params.emplace_back( new PARAM<wxString>( "template.browsed_path", &m_BrowsedTemplatesPath, "" ) );
67
68 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
69 "pcm.repositories",
70 [&]() -> nlohmann::json
71 {
72 nlohmann::json js = nlohmann::json::array();
73
74 for( const auto& pair : m_PcmRepositories )
75 {
76 js.push_back( nlohmann::json( { { "name", pair.first.ToUTF8() },
77 { "url", pair.second.ToUTF8() } } ) );
78 }
79
80 return js;
81 },
82 [&]( const nlohmann::json aObj )
83 {
84 m_PcmRepositories.clear();
85
86 if( !aObj.is_array() )
87 return;
88
89 for( const auto& entry : aObj )
90 {
91 if( entry.empty() || !entry.is_object() )
92 continue;
93
94 m_PcmRepositories.emplace_back(
95 std::make_pair( wxString( entry["name"].get<std::string>() ),
96 wxString( entry["url"].get<std::string>() ) ) );
97 }
98 },
100
101 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
102 "libraries.overrides",
103 [&]() -> nlohmann::json
104 {
105 nlohmann::json js = nlohmann::json::object();
106
107 for( const auto& [tablePath, libs] : m_LibOverrides )
108 {
109 nlohmann::json tableJs = nlohmann::json::object();
110
111 for( const auto& [nickname, override_] : libs )
112 {
113 nlohmann::json entry = nlohmann::json::object();
114
115 if( override_.disabled )
116 entry["disabled"] = true;
117
118 if( override_.hidden )
119 entry["hidden"] = true;
120
121 if( !entry.empty() )
122 tableJs[std::string( nickname.ToUTF8() )] = entry;
123 }
124
125 if( !tableJs.empty() )
126 js[std::string( tablePath.ToUTF8() )] = tableJs;
127 }
128
129 return js;
130 },
131 [&]( const nlohmann::json& aObj )
132 {
133 m_LibOverrides.clear();
134
135 if( !aObj.is_object() )
136 return;
137
138 for( const auto& [tablePath, tableObj] : aObj.items() )
139 {
140 if( !tableObj.is_object() )
141 continue;
142
143 std::map<wxString, LIB_OVERRIDE>& libs =
144 m_LibOverrides[wxString::FromUTF8( tablePath )];
145
146 for( const auto& [nickname, entry] : tableObj.items() )
147 {
148 if( !entry.is_object() )
149 continue;
150
151 LIB_OVERRIDE override_;
152
153 if( entry.contains( "disabled" ) && entry["disabled"].is_boolean() )
154 override_.disabled = entry["disabled"].get<bool>();
155
156 if( entry.contains( "hidden" ) && entry["hidden"].is_boolean() )
157 override_.hidden = entry["hidden"].get<bool>();
158
159 libs[wxString::FromUTF8( nickname )] = override_;
160 }
161 }
162 },
163 nlohmann::json::object() ) );
164
165 // The getter omits an override once both flags clear, so the save has to delete the key
166 m_params.back()->SetClearUnknownKeys();
167
168 m_params.emplace_back(
169 new PARAM<wxString>( "pcm.last_download_dir", &m_PcmLastDownloadDir, "" ) );
170
171 m_params.emplace_back( new PARAM<bool>( "pcm.check_for_updates", &m_PcmUpdateCheck, true ) );
172
173 m_params.emplace_back( new PARAM<bool>( "pcm.lib_auto_add", &m_PcmLibAutoAdd, true ) );
174
175 m_params.emplace_back( new PARAM<bool>( "pcm.lib_auto_remove", &m_PcmLibAutoRemove, true ) );
176
177 m_params.emplace_back( new PARAM<wxString>( "pcm.lib_prefix", &m_PcmLibPrefix,
178 wxS( "PCM_" ) ) );
179
180 m_params.emplace_back( new PARAM<wxString>( "pcm.last_selected_repo_id", &m_PcmLastSelectedRepoId, "" ) );
181}
182
183
184bool KICAD_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
185{
186 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
187
188 ret &= fromLegacy<int>( aCfg, "LeftWinWidth", "appearance.left_frame_width" );
189
190 // Override the size parameters to ensure the new PCM button is always shown.
191 // This will make the window take the default size instead of the migrated one.
192 Set( "window.size_x", 0 );
193 Set( "window.size_y", 0 );
194
195 return ret;
196}
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
std::vector< wxString > m_PinnedTemplates
wxString m_lastReceivedUpdate
wxString m_LastUsedTemplate
Like a normal param, but with custom getter and setter functions.
Definition parameters.h:299
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.