KiCad PCB EDA Suite
advanced_config.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) 2019 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <advanced_config.h>
25 
26 #include <common.h>
27 #include <config_params.h>
29 
30 #include <wx/config.h>
31 #include <wx/filename.h>
32 #include <wx/log.h>
33 
34 /*
35  * Flag to enable advanced config debugging
36  *
37  * Use "KICAD_ADVANCED_CONFIG" to enable.
38  *
39  * @ingroup trace_env_vars
40  */
41 static const wxChar AdvancedConfigMask[] = wxT( "KICAD_ADVANCED_CONFIG" );
42 
48 namespace AC_STACK
49 {
50  static constexpr int min_stack = 32 * 4096;
51  static constexpr int default_stack = 256 * 4096;
52  static constexpr int max_stack = 4096 * 4096;
53 }
54 
61 namespace AC_KEYS
62 {
68 static const wxChar UsePadProperty[] = wxT( "UsePadProperty" );
69 
75 static const wxChar UsePinFunction[] = wxT( "UsePinFunction" );
76 
82 static const wxChar RealtimeConnectivity[] = wxT( "RealtimeConnectivity" );
83 
88 static const wxChar CoroutineStackSize[] = wxT( "CoroutineStackSize" );
89 
90 } // namespace KEYS
91 
92 
93 /*
94  * Get a simple string for common parameters.
95  *
96  * This isn't exhaustive, but it covers most common types that might be
97  * used in the advance config
98  */
99 wxString dumpParamCfg( const PARAM_CFG& aParam )
100 {
101  wxString s = aParam.m_Ident + ": ";
102 
103  /*
104  * This implementation is rather simplistic, but it is
105  * effective enough for simple uses. A better implementation would be
106  * some kind of visitor, but that's somewhat more work.
107  */
108  switch( aParam.m_Type )
109  {
112  s << *static_cast<const PARAM_CFG_INT&>( aParam ).m_Pt_param;
113  break;
115  s << *static_cast<const PARAM_CFG_DOUBLE&>( aParam ).m_Pt_param;
116  break;
118  s << *static_cast<const PARAM_CFG_WXSTRING&>( aParam ).m_Pt_param;
119  break;
121  s << *static_cast<const PARAM_CFG_FILENAME&>( aParam ).m_Pt_param;
122  break;
124  s << ( *static_cast<const PARAM_CFG_BOOL&>( aParam ).m_Pt_param ? "true" : "false" );
125  break;
126  default: s << "Unsupported PARAM_CFG variant: " << aParam.m_Type;
127  }
128 
129  return s;
130 }
131 
132 
136 static void dumpCfg( const std::vector<PARAM_CFG*>& aArray )
137 {
138  // only dump if we need to
139  if( !wxLog::IsAllowedTraceMask( AdvancedConfigMask ) )
140  return;
141 
142  for( const PARAM_CFG* param : aArray )
143  {
144  wxLogTrace( AdvancedConfigMask, dumpParamCfg( *param ) );
145  }
146 }
147 
148 
154 static wxFileName getAdvancedCfgFilename()
155 {
156  const static wxString cfg_filename{ "kicad_advanced" };
157  return wxFileName( SETTINGS_MANAGER::GetUserSettingsPath(), cfg_filename );
158 }
159 
160 
162 {
163  wxLogTrace( AdvancedConfigMask, "Init advanced config" );
164 
165  // Init defaults - this is done in case the config doesn't exist,
166  // then the values will remain as set here.
167  m_EnableUsePadProperty = false;
168  m_EnableUsePinFunction = false;
169  m_realTimeConnectivity = true;
171 
173 }
174 
175 
177 {
178  static ADVANCED_CFG instance;
179  return instance;
180 }
181 
182 
184 {
185  const auto k_advanced = getAdvancedCfgFilename();
186 
187  if( !k_advanced.FileExists() )
188  {
189  wxLogTrace( AdvancedConfigMask, "File does not exist %s", k_advanced.GetFullPath() );
190  return;
191  }
192 
193  wxLogTrace( AdvancedConfigMask, "Loading advanced config from: %s", k_advanced.GetFullPath() );
194 
195  wxFileConfig file_cfg( "", "", k_advanced.GetFullPath() );
196  loadSettings( file_cfg );
197 }
198 
199 
200 void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
201 {
202  std::vector<PARAM_CFG*> configParams;
203 
204  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::UsePadProperty,
205  &m_EnableUsePadProperty, false ) );
206 
207  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::UsePinFunction,
208  &m_EnableUsePinFunction, false ) );
209 
210  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::RealtimeConnectivity,
211  &m_realTimeConnectivity, false ) );
212 
213  configParams.push_back( new PARAM_CFG_INT( true, AC_KEYS::CoroutineStackSize,
216 
217  wxConfigLoadSetups( &aCfg, configParams );
218 
219  for( auto param : configParams )
220  delete param;
221 
222  dumpCfg( configParams );
223 }
224 
225 
Limits and default settings for the coroutine stack size allowed.
void wxConfigLoadSetups(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList)
Function wxConfigLoadSetups uses aList of PARAM_CFG to load configuration values from aCfg.
wxString m_Ident
Keyword in config data.
List of known keys for advanced configuration options.
static const wxChar UsePadProperty[]
In Pcbnew, pads can have a fabrication property Because this feature adds a new keyword in *....
bool m_EnableUsePadProperty
Enable pad property handling in pcbnew.
static const wxChar RealtimeConnectivity[]
Testing mode for new connectivity algorithm.
static std::string GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
static void dumpCfg(const std::vector< PARAM_CFG * > &aArray)
Dump the configs in the given array to trace.
void loadSettings(wxConfigBase &aCfg)
Configuration parameter - Integer Class.
void loadFromConfigFile()
Load the config from the normal config file.
wxString dumpParamCfg(const PARAM_CFG &aParam)
Configuration parameter - Boolean Class.
bool m_EnableUsePinFunction
Enable pad pin function handling in pcbnew.
int m_coroutineStackSize
Set the stack size for coroutines.
static wxFileName getAdvancedCfgFilename()
Get the filename for the advanced config file.
bool m_realTimeConnectivity
Do real-time connectivity.
Class containing "advanced" configuration options.
PARAM_CFG is a base class which establishes the interface functions ReadParam and SaveParam,...
Definition: config_params.h:98
static const wxChar CoroutineStackSize[]
Configure the coroutine stack size in bytes.
paramcfg_id m_Type
Type of parameter.
static constexpr int default_stack
The common library.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
static const wxChar UsePinFunction[]
In Pcbnew, pads can handle a pin function info (this is the schematic pin name) Because this feature ...
static constexpr int max_stack
static constexpr int min_stack
static const wxChar AdvancedConfigMask[]