KiCad PCB EDA Suite
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 <jon@craftyjon.com>
5  * Copyright (C) 2020 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 
21 #include "kicad_settings.h"
22 #include <nlohmann/json.hpp>
23 #include <settings/parameters.h>
24 
25 
27 const int kicadSchemaVersion = 0;
28 
29 
31  APP_SETTINGS_BASE( "kicad", kicadSchemaVersion ), m_LeftWinWidth( 200 )
32 {
33  m_params.emplace_back( new PARAM<int>( "appearance.left_frame_width", &m_LeftWinWidth, 200 ) );
34 
35  m_params.emplace_back(
36  new PARAM_LIST<wxString>( "system.open_projects", &m_OpenProjects, {} ) );
37 
38 #ifdef PCM
39  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
40  "pcm.repositories",
41  [&]() -> nlohmann::json
42  {
43  nlohmann::json js = nlohmann::json::array();
44 
45  for( const auto& pair : m_PcmRepositories )
46  {
47  js.push_back( nlohmann::json( { { "name", pair.first.ToUTF8() },
48  { "url", pair.second.ToUTF8() } } ) );
49  }
50 
51  return js;
52  },
53  [&]( const nlohmann::json aObj )
54  {
55  m_PcmRepositories.clear();
56 
57  if( !aObj.is_array() )
58  return;
59 
60  for( const auto& entry : aObj )
61  {
62  if( entry.empty() || !entry.is_object() )
63  continue;
64 
65  m_PcmRepositories.emplace_back(
66  std::make_pair( wxString( entry["name"].get<std::string>() ),
67  wxString( entry["url"].get<std::string>() ) ) );
68  }
69  },
70  R"([
71  {
72  "name": "KiCad official repository",
73  "url": "https://repository.kicad.org/repository.json"
74  }
75  ])"_json ) );
76 
77  m_params.emplace_back(
78  new PARAM<wxString>( "pcm.last_download_dir", &m_PcmLastDownloadDir, "" ) );
79 #endif
80 }
81 
82 
83 bool KICAD_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
84 {
85  bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
86 
87  ret &= fromLegacy<int>( aCfg, "LeftWinWidth", "appearance.left_frame_width" );
88 
89  return ret;
90 }
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
std::vector< wxString > m_OpenProjects
nlohmann::json json
Definition: gerbview.cpp:41
const int kicadSchemaVersion
! Update the schema version whenever a migration is required
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99