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 {
63 
68 static const wxChar ExtraFillMargin[] = wxT( "ExtraFillMargin" );
69 
75 static const wxChar RealtimeConnectivity[] = wxT( "RealtimeConnectivity" );
76 
81 static const wxChar CoroutineStackSize[] = wxT( "CoroutineStackSize" );
82 
86 static const wxChar ShowRouterDebugGraphics[] = wxT( "ShowRouterDebugGraphics" );
87 
92 static const wxChar CompactFileSave[] = wxT( "CompactSave" );
93 
94 } // namespace KEYS
95 
96 
97 /*
98  * Get a simple string for common parameters.
99  *
100  * This isn't exhaustive, but it covers most common types that might be
101  * used in the advance config
102  */
103 wxString dumpParamCfg( const PARAM_CFG& aParam )
104 {
105  wxString s = aParam.m_Ident + ": ";
106 
107  /*
108  * This implementation is rather simplistic, but it is
109  * effective enough for simple uses. A better implementation would be
110  * some kind of visitor, but that's somewhat more work.
111  */
112  switch( aParam.m_Type )
113  {
116  s << *static_cast<const PARAM_CFG_INT&>( aParam ).m_Pt_param;
117  break;
119  s << *static_cast<const PARAM_CFG_DOUBLE&>( aParam ).m_Pt_param;
120  break;
122  s << *static_cast<const PARAM_CFG_WXSTRING&>( aParam ).m_Pt_param;
123  break;
125  s << *static_cast<const PARAM_CFG_FILENAME&>( aParam ).m_Pt_param;
126  break;
128  s << ( *static_cast<const PARAM_CFG_BOOL&>( aParam ).m_Pt_param ? "true" : "false" );
129  break;
130  default: s << "Unsupported PARAM_CFG variant: " << aParam.m_Type;
131  }
132 
133  return s;
134 }
135 
136 
140 static void dumpCfg( const std::vector<PARAM_CFG*>& aArray )
141 {
142  // only dump if we need to
143  if( !wxLog::IsAllowedTraceMask( AdvancedConfigMask ) )
144  return;
145 
146  for( const PARAM_CFG* param : aArray )
147  {
148  wxLogTrace( AdvancedConfigMask, dumpParamCfg( *param ) );
149  }
150 }
151 
152 
158 static wxFileName getAdvancedCfgFilename()
159 {
160  const static wxString cfg_filename{ "kicad_advanced" };
161  return wxFileName( SETTINGS_MANAGER::GetUserSettingsPath(), cfg_filename );
162 }
163 
164 
166 {
167  wxLogTrace( AdvancedConfigMask, "Init advanced config" );
168 
169  // Init defaults - this is done in case the config doesn't exist,
170  // then the values will remain as set here.
171  m_realTimeConnectivity = true;
174 
176 }
177 
178 
180 {
181  static ADVANCED_CFG instance;
182  return instance;
183 }
184 
185 
187 {
188  const auto k_advanced = getAdvancedCfgFilename();
189 
190  if( !k_advanced.FileExists() )
191  {
192  wxLogTrace( AdvancedConfigMask, "File does not exist %s", k_advanced.GetFullPath() );
193  return;
194  }
195 
196  wxLogTrace( AdvancedConfigMask, "Loading advanced config from: %s", k_advanced.GetFullPath() );
197 
198  wxFileConfig file_cfg( "", "", k_advanced.GetFullPath() );
199  loadSettings( file_cfg );
200 }
201 
202 
203 void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
204 {
205  std::vector<PARAM_CFG*> configParams;
206 
207  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::RealtimeConnectivity,
208  &m_realTimeConnectivity, false ) );
209 
210  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::ExtraFillMargin,
211  &m_extraClearance, 0.002, 0.0, 1.0 ) );
212 
213  configParams.push_back( new PARAM_CFG_INT( true, AC_KEYS::CoroutineStackSize,
216 
217  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowRouterDebugGraphics,
218  &m_ShowRouterDebugGraphics, false ) );
219 
220  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::CompactFileSave,
221  &m_CompactSave, false ) );
222 
223  wxConfigLoadSetups( &aCfg, configParams );
224 
225  for( auto param : configParams )
226  delete param;
227 
228  dumpCfg( configParams );
229 }
230 
231 
double m_extraClearance
Extra fill clearance for zone fills.
Limits and default settings for the coroutine stack size allowed.
bool m_CompactSave
Save files in compact display mode When is is not specified, points are written one per line.
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.
Definition: config_params.h:84
List of known keys for advanced configuration options.
Configuration parameter - Double Precision Class.
bool m_ShowRouterDebugGraphics
Show PNS router debug graphics.
static const wxChar RealtimeConnectivity[]
Testing mode for new connectivity algorithm.
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.
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
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:81
static const wxChar CoroutineStackSize[]
Configure the coroutine stack size in bytes.
paramcfg_id m_Type
Type of parameter.
Definition: config_params.h:85
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 constexpr int max_stack
static const wxChar ShowRouterDebugGraphics[]
Show PNS router debug graphics while routing.
static const wxChar CompactFileSave[]
When set to true, this will wrap polygon point sets at 4 points per line rather than a single point p...
static constexpr int min_stack
static const wxChar ExtraFillMargin[]
When filling zones, we add an extra amount of clearance to each zone to ensure that rounding errors d...
static const wxChar AdvancedConfigMask[]