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 (C) 2020, 2023 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
22#include <nlohmann/json.hpp>
23#include <settings/parameters.h>
24
25
27const int kicadSchemaVersion = 0;
28
29
30const nlohmann::json PCM_DEFAULT_REPOSITORIES = nlohmann::json::array( {
31 nlohmann::json( {
32 { "name", "KiCad official repository" },
34 } )
35} );
36
37
39 APP_SETTINGS_BASE( "kicad", kicadSchemaVersion ), m_LeftWinWidth( 200 )
40{
41 m_params.emplace_back( new PARAM<int>( "appearance.left_frame_width", &m_LeftWinWidth, 200 ) );
42
43 m_params.emplace_back(
44 new PARAM_LIST<wxString>( "system.open_projects", &m_OpenProjects, {} ) );
45
46 m_params.emplace_back(
47 new PARAM<wxString>( "system.last_update_check_time", &m_lastUpdateCheckTime, "" ) );
48
49 m_params.emplace_back(
50 new PARAM<wxString>( "system.last_received_update", &m_lastReceivedUpdate, "" ) );
51
52 m_params.emplace_back( new PARAM<bool>( "system.check_for_kicad_updates", &m_KiCadUpdateCheck,
53 true ) );
54
55 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
56 "pcm.repositories",
57 [&]() -> nlohmann::json
58 {
59 nlohmann::json js = nlohmann::json::array();
60
61 for( const auto& pair : m_PcmRepositories )
62 {
63 js.push_back( nlohmann::json( { { "name", pair.first.ToUTF8() },
64 { "url", pair.second.ToUTF8() } } ) );
65 }
66
67 return js;
68 },
69 [&]( const nlohmann::json aObj )
70 {
71 m_PcmRepositories.clear();
72
73 if( !aObj.is_array() )
74 return;
75
76 for( const auto& entry : aObj )
77 {
78 if( entry.empty() || !entry.is_object() )
79 continue;
80
81 m_PcmRepositories.emplace_back(
82 std::make_pair( wxString( entry["name"].get<std::string>() ),
83 wxString( entry["url"].get<std::string>() ) ) );
84 }
85 },
87
88 m_params.emplace_back(
89 new PARAM<wxString>( "pcm.last_download_dir", &m_PcmLastDownloadDir, "" ) );
90
91 m_params.emplace_back( new PARAM<bool>( "pcm.check_for_updates", &m_PcmUpdateCheck, true ) );
92
93 m_params.emplace_back( new PARAM<bool>( "pcm.lib_auto_add", &m_PcmLibAutoAdd, true ) );
94
95 m_params.emplace_back( new PARAM<bool>( "pcm.lib_auto_remove", &m_PcmLibAutoRemove, true ) );
96
97 m_params.emplace_back( new PARAM<wxString>( "pcm.lib_prefix", &m_PcmLibPrefix,
98 wxS( "PCM_" ) ) );
99}
100
101
102bool KICAD_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
103{
104 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
105
106 ret &= fromLegacy<int>( aCfg, "LeftWinWidth", "appearance.left_frame_width" );
107
108 // Override the size parameters to ensure the new PCM button is always shown.
109 // This will make the window take the default size instead of the migrated one.
110 Set( "window.size_x", 0 );
111 Set( "window.size_y", 0 );
112
113 return ret;
114}
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
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)
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
wxString m_PcmLibPrefix
wxString m_lastUpdateCheckTime
wxString m_PcmLastDownloadDir
std::vector< wxString > m_OpenProjects
std::vector< std::pair< wxString, wxString > > m_PcmRepositories
wxString m_lastReceivedUpdate
Like a normal param, but with custom getter and setter functions.
Definition: parameters.h:294
const nlohmann::json PCM_DEFAULT_REPOSITORIES
const int kicadSchemaVersion
! Update the schema version whenever a migration is required
#define PCM_DEFAULT_REPOSITORY_URL