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 along
18 * with this program. If not, see <http://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(
48 new PARAM_LIST<wxString>( "system.open_projects", &m_OpenProjects, {} ) );
49
50 m_params.emplace_back( new PARAM<wxString>( "system.last_design_block_lib_dir",
52
53 m_params.emplace_back(
54 new PARAM<wxString>( "system.last_update_check_time", &m_lastUpdateCheckTime, "" ) );
55
56 m_params.emplace_back(
57 new PARAM<wxString>( "system.last_received_update", &m_lastReceivedUpdate, "" ) );
58
59 m_params.emplace_back( new PARAM<bool>( "system.check_for_kicad_updates", &m_KiCadUpdateCheck,
60 true ) );
61
62 m_params.emplace_back( new PARAM<wxPoint>( "template.window.pos", &m_TemplateWindowPos,
63 wxDefaultPosition ) );
64
65 m_params.emplace_back( new PARAM<wxSize>( "template.window.size", &m_TemplateWindowSize,
66 wxDefaultSize ) );
67
68 m_params.emplace_back( new PARAM<wxString>( "template.last_used", &m_LastUsedTemplate, "" ) );
69
70 m_params.emplace_back(
71 new PARAM_LIST<wxString>( "template.recent_templates", &m_RecentTemplates, {} ) );
72
73 m_params.emplace_back( new PARAM<int>( "template.filter", &m_TemplateFilterChoice, 0 ) );
74
75 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
76 "pcm.repositories",
77 [&]() -> nlohmann::json
78 {
79 nlohmann::json js = nlohmann::json::array();
80
81 for( const auto& pair : m_PcmRepositories )
82 {
83 js.push_back( nlohmann::json( { { "name", pair.first.ToUTF8() },
84 { "url", pair.second.ToUTF8() } } ) );
85 }
86
87 return js;
88 },
89 [&]( const nlohmann::json aObj )
90 {
91 m_PcmRepositories.clear();
92
93 if( !aObj.is_array() )
94 return;
95
96 for( const auto& entry : aObj )
97 {
98 if( entry.empty() || !entry.is_object() )
99 continue;
100
101 m_PcmRepositories.emplace_back(
102 std::make_pair( wxString( entry["name"].get<std::string>() ),
103 wxString( entry["url"].get<std::string>() ) ) );
104 }
105 },
107
108 m_params.emplace_back(
109 new PARAM<wxString>( "pcm.last_download_dir", &m_PcmLastDownloadDir, "" ) );
110
111 m_params.emplace_back( new PARAM<bool>( "pcm.check_for_updates", &m_PcmUpdateCheck, true ) );
112
113 m_params.emplace_back( new PARAM<bool>( "pcm.lib_auto_add", &m_PcmLibAutoAdd, true ) );
114
115 m_params.emplace_back( new PARAM<bool>( "pcm.lib_auto_remove", &m_PcmLibAutoRemove, true ) );
116
117 m_params.emplace_back( new PARAM<wxString>( "pcm.lib_prefix", &m_PcmLibPrefix,
118 wxS( "PCM_" ) ) );
119}
120
121
122bool KICAD_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
123{
124 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
125
126 ret &= fromLegacy<int>( aCfg, "LeftWinWidth", "appearance.left_frame_width" );
127
128 // Override the size parameters to ensure the new PCM button is always shown.
129 // This will make the window take the default size instead of the migrated one.
130 Set( "window.size_x", 0 );
131 Set( "window.size_y", 0 );
132
133 return ret;
134}
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_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
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:296
const nlohmann::json PCM_DEFAULT_REPOSITORIES
const int kicadSchemaVersion
! Update the schema version whenever a migration is required
#define PCM_DEFAULT_REPOSITORY_URL