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 DRCEpsilon[] = wxT( "DRCEpsilon" );
76 
82 static const wxChar HoleWallThickness[] = wxT( "HoleWallPlatingThickness" );
83 
89 static const wxChar RealtimeConnectivity[] = wxT( "RealtimeConnectivity" );
90 
95 static const wxChar CoroutineStackSize[] = wxT( "CoroutineStackSize" );
96 
100 static const wxChar ShowRouterDebugGraphics[] = wxT( "ShowRouterDebugGraphics" );
101 
106 static const wxChar CompactFileSave[] = wxT( "CompactSave" );
107 
115 static const wxChar DrawArcAccuracy[] = wxT( "DrawArcAccuracy" );
116 
123 static const wxChar DrawArcCenterStartEndMaxAngle[] = wxT( "DrawArcCenterStartEndMaxAngle" );
124 
128 static const wxChar StrokeTriangulation[] = wxT( "StrokeTriangulation" );
129 
133 static const wxChar PluginAltiumSch[] = wxT( "PluginAltiumSch" );
134 
139 static const wxChar MinPlotPenWidth[] = wxT( "MinPlotPenWidth" );
140 
141 static const wxChar DebugZoneFiller[] = wxT( "DebugZoneFiller" );
142 
143 static const wxChar SkipBoundingBoxFpLoad[] = wxT( "SkipBoundingBoxFpLoad" );
144 
145 } // namespace KEYS
146 
147 
148 /*
149  * Get a simple string for common parameters.
150  *
151  * This isn't exhaustive, but it covers most common types that might be
152  * used in the advance config
153  */
154 wxString dumpParamCfg( const PARAM_CFG& aParam )
155 {
156  wxString s = aParam.m_Ident + ": ";
157 
158  /*
159  * This implementation is rather simplistic, but it is
160  * effective enough for simple uses. A better implementation would be
161  * some kind of visitor, but that's somewhat more work.
162  */
163  switch( aParam.m_Type )
164  {
167  s << *static_cast<const PARAM_CFG_INT&>( aParam ).m_Pt_param;
168  break;
170  s << *static_cast<const PARAM_CFG_DOUBLE&>( aParam ).m_Pt_param;
171  break;
173  s << *static_cast<const PARAM_CFG_WXSTRING&>( aParam ).m_Pt_param;
174  break;
176  s << *static_cast<const PARAM_CFG_FILENAME&>( aParam ).m_Pt_param;
177  break;
179  s << ( *static_cast<const PARAM_CFG_BOOL&>( aParam ).m_Pt_param ? "true" : "false" );
180  break;
181  default: s << "Unsupported PARAM_CFG variant: " << aParam.m_Type;
182  }
183 
184  return s;
185 }
186 
187 
191 static void dumpCfg( const std::vector<PARAM_CFG*>& aArray )
192 {
193  // only dump if we need to
194  if( !wxLog::IsAllowedTraceMask( AdvancedConfigMask ) )
195  return;
196 
197  for( const PARAM_CFG* param : aArray )
198  {
199  wxLogTrace( AdvancedConfigMask, dumpParamCfg( *param ) );
200  }
201 }
202 
203 
209 static wxFileName getAdvancedCfgFilename()
210 {
211  const static wxString cfg_filename{ "kicad_advanced" };
212  return wxFileName( SETTINGS_MANAGER::GetUserSettingsPath(), cfg_filename );
213 }
214 
215 
217 {
218  wxLogTrace( AdvancedConfigMask, "Init advanced config" );
219 
220  // Init defaults - this is done in case the config doesn't exist,
221  // then the values will remain as set here.
222  m_realTimeConnectivity = true;
225  m_drawArcAccuracy = 10.0;
228  m_PluginAltiumSch = false;
229 
230  m_ExtraClearance = 0.0005;
231  m_DRCEpsilon = 0.0005; // 500nm is small enough not to materially violate
232  // any constraints.
233 
234  m_HoleWallThickness = 0.020; // IPC-6012 says 15-18um; Cadence says at least
235  // 0.020 for a Class 2 board and at least 0.025
236  // for Class 3.
237 
238  m_MinPlotPenWidth = 0.0212; // 1 pixel at 1200dpi.
239 
240  m_DebugZoneFiller = false;
241 
243 
245 }
246 
247 
249 {
250  static ADVANCED_CFG instance;
251  return instance;
252 }
253 
254 
256 {
257  const wxFileName k_advanced = getAdvancedCfgFilename();
258 
259  if( !k_advanced.FileExists() )
260  {
261  wxLogTrace( AdvancedConfigMask, "File does not exist %s", k_advanced.GetFullPath() );
262 
263  // load the defaults
264  wxConfig emptyConfig;
265  loadSettings( emptyConfig );
266 
267  return;
268  }
269 
270  wxLogTrace( AdvancedConfigMask, "Loading advanced config from: %s", k_advanced.GetFullPath() );
271 
272  wxFileConfig file_cfg( "", "", k_advanced.GetFullPath() );
273  loadSettings( file_cfg );
274 }
275 
276 
277 void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
278 {
279  std::vector<PARAM_CFG*> configParams;
280 
281  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::RealtimeConnectivity,
282  &m_realTimeConnectivity, true ) );
283 
284  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::ExtraFillMargin,
285  &m_ExtraClearance, 0.0005, 0.0, 1.0 ) );
286 
287  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DRCEpsilon,
288  &m_DRCEpsilon, 0.0005, 0.0, 1.0 ) );
289 
290  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::HoleWallThickness,
291  &m_HoleWallThickness, 0.020, 0.0, 1.0 ) );
292 
293  configParams.push_back( new PARAM_CFG_INT( true, AC_KEYS::CoroutineStackSize,
296 
297  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowRouterDebugGraphics,
298  &m_ShowRouterDebugGraphics, false ) );
299 
300  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::CompactFileSave,
301  &m_CompactSave, false ) );
302 
303  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DrawArcAccuracy,
304  &m_drawArcAccuracy, 10.0, 0.0, 100000.0 ) );
305 
306  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DrawArcCenterStartEndMaxAngle,
307  &m_drawArcCenterMaxAngle, 50.0, 0.0, 100000.0 ) );
308 
309  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::StrokeTriangulation,
310  &m_DrawTriangulationOutlines, false ) );
311 
312  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::PluginAltiumSch,
313  &m_PluginAltiumSch, false ) );
314 
315  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::MinPlotPenWidth,
316  &m_MinPlotPenWidth, 0.0212, 0.0, 1.0 ) );
317 
318  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DebugZoneFiller,
319  &m_DebugZoneFiller, false ) );
320 
321  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::SkipBoundingBoxFpLoad,
322  &m_SkipBoundingBoxOnFpLoad, false ) );
323 
324  wxConfigLoadSetups( &aCfg, configParams );
325 
326  for( PARAM_CFG* param : configParams )
327  delete param;
328 
329  dumpCfg( configParams );
330 }
331 
332 
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.
bool m_SkipBoundingBoxOnFpLoad
Skip bounding box calculation when loading footprints.
bool m_PluginAltiumSch
When true, enable Altium Schematic import (*.SchDoc) the current implementation is highly incomplete.
void wxConfigLoadSetups(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList)
Function wxConfigLoadSetups uses aList of PARAM_CFG to load configuration values from aCfg.
static const wxChar DrawArcAccuracy[]
For drawsegments - arcs.
wxString m_Ident
Keyword in config data.
Definition: config_params.h:88
List of known keys for advanced configuration options.
static const wxChar HoleWallThickness[]
Used to calculate the actual hole size from the finish hole size.
Configuration parameter - Double Precision Class.
bool m_DrawTriangulationOutlines
When true, strokes the triangulations with visible color.
static const wxChar DrawArcCenterStartEndMaxAngle[]
For drawsegments - arcs.
bool m_ShowRouterDebugGraphics
Show PNS router debug graphics.
static const wxChar RealtimeConnectivity[]
Testing mode for new connectivity algorithm.
static const wxChar DRCEpsilon[]
A fudge factor for DRC.
double m_drawArcAccuracy
For drawsegments - arcs.
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 const wxChar SkipBoundingBoxFpLoad[]
double m_ExtraClearance
Extra fill clearance for zone fills.
double m_DRCEpsilon
Epsilon for DRC tests.
double m_MinPlotPenWidth
Sets an absolute minimum pen width for plotting.
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
static const wxChar MinPlotPenWidth[]
Absolute minimum pen width to send to the plotter.
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:85
static const wxChar CoroutineStackSize[]
Configure the coroutine stack size in bytes.
paramcfg_id m_Type
Type of parameter.
Definition: config_params.h:89
static constexpr int default_stack
static const wxChar StrokeTriangulation[]
When true, GAL will stroke the triangulations (only used in OpenGL) with a visible color.
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 DebugZoneFiller[]
static const wxChar PluginAltiumSch[]
When true, enable Altium Schematic import (*.SchDoc)
static constexpr int max_stack
static const wxChar ShowRouterDebugGraphics[]
Show PNS router debug graphics while routing.
double m_drawArcCenterMaxAngle
For drawsegments - arcs.
bool m_DebugZoneFiller
A mode that dumps the various stages of a F_Cu fill into In1_Cu through In9_Cu.
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[]
double m_HoleWallThickness
Hole wall plating thickness.