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-2021 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 <config_params.h>
28 
29 #include <wx/app.h>
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 
130 static const wxChar MaxTangentTrackAngleDeviation[] = wxT( "MaxTangentTrackAngleDeviation" );
131 
136 static const wxChar MaxTrackLengthToKeep[] = wxT( "MaxTrackLengthToKeep" );
137 
141 static const wxChar StrokeTriangulation[] = wxT( "StrokeTriangulation" );
142 
147 static const wxChar ExtraZoneDisplayModes[] = wxT( "ExtraZoneDisplayModes" );
148 
153 static const wxChar MinPlotPenWidth[] = wxT( "MinPlotPenWidth" );
154 
155 static const wxChar DebugZoneFiller[] = wxT( "DebugZoneFiller" );
156 
157 static const wxChar DebugPDFWriter[] = wxT( "DebugPDFWriter" );
158 
163 static const wxChar SmallDrillMarkSize[] = wxT( "SmallDrillMarkSize" );
164 
165 static const wxChar HotkeysDumper[] = wxT( "HotkeysDumper" );
166 
167 static const wxChar DrawBoundingBoxes[] = wxT( "DrawBoundingBoxes" );
168 
169 static const wxChar ShowPcbnewExportNetlist[] = wxT( "ShowPcbnewExportNetlist" );
170 
171 static const wxChar Skip3DModelFileCache[] = wxT( "Skip3DModelFileCache" );
172 
173 static const wxChar Skip3DModelMemoryCache[] = wxT( "Skip3DModelMemoryCache" );
174 
175 static const wxChar HideVersionFromTitle[] = wxT( "HideVersionFromTitle" );
176 
177 } // namespace KEYS
178 
179 
180 /*
181  * Get a simple string for common parameters.
182  *
183  * This isn't exhaustive, but it covers most common types that might be
184  * used in the advance config
185  */
186 wxString dumpParamCfg( const PARAM_CFG& aParam )
187 {
188  wxString s = aParam.m_Ident + ": ";
189 
190  /*
191  * This implementation is rather simplistic, but it is
192  * effective enough for simple uses. A better implementation would be
193  * some kind of visitor, but that's somewhat more work.
194  */
195  switch( aParam.m_Type )
196  {
199  s << *static_cast<const PARAM_CFG_INT&>( aParam ).m_Pt_param;
200  break;
202  s << *static_cast<const PARAM_CFG_DOUBLE&>( aParam ).m_Pt_param;
203  break;
205  s << *static_cast<const PARAM_CFG_WXSTRING&>( aParam ).m_Pt_param;
206  break;
208  s << *static_cast<const PARAM_CFG_FILENAME&>( aParam ).m_Pt_param;
209  break;
211  s << ( *static_cast<const PARAM_CFG_BOOL&>( aParam ).m_Pt_param ? "true" : "false" );
212  break;
213  default: s << "Unsupported PARAM_CFG variant: " << aParam.m_Type;
214  }
215 
216  return s;
217 }
218 
219 
223 static void dumpCfg( const std::vector<PARAM_CFG*>& aArray )
224 {
225  // only dump if we need to
226  if( !wxLog::IsAllowedTraceMask( AdvancedConfigMask ) )
227  return;
228 
229  for( const PARAM_CFG* param : aArray )
230  {
231  wxLogTrace( AdvancedConfigMask, dumpParamCfg( *param ) );
232  }
233 }
234 
235 
241 static wxFileName getAdvancedCfgFilename()
242 {
243  const static wxString cfg_filename{ "kicad_advanced" };
244  return wxFileName( SETTINGS_MANAGER::GetUserSettingsPath(), cfg_filename );
245 }
246 
247 
249 {
250  wxLogTrace( AdvancedConfigMask, "Init advanced config" );
251 
252  // Init defaults - this is done in case the config doesn't exist,
253  // then the values will remain as set here.
254  m_RealTimeConnectivity = true;
257  m_DrawArcAccuracy = 10.0;
260  m_MaxTrackLengthToKeep = 0.0001;
261  m_ExtraZoneDisplayModes = false;
263 
264  m_ExtraClearance = 0.0001;
265  m_DRCEpsilon = 0.0001; // 0.1um is small enough not to materially violate
266  // any constraints.
267 
268  m_HoleWallThickness = 0.020; // IPC-6012 says 15-18um; Cadence says at least
269  // 0.020 for a Class 2 board and at least 0.025
270  // for Class 3.
271 
272  m_MinPlotPenWidth = 0.0212; // 1 pixel at 1200dpi.
273 
274  m_DebugZoneFiller = false;
275  m_DebugPDFWriter = false;
276  m_SmallDrillMarkSize = 0.35;
277  m_HotkeysDumper = false;
278  m_DrawBoundingBoxes = false;
280  m_Skip3DModelFileCache = false;
281  m_Skip3DModelMemoryCache = false;
282  m_HideVersionFromTitle = false;
283 
285 }
286 
287 
289 {
290  static ADVANCED_CFG instance;
291  return instance;
292 }
293 
294 
296 {
297  const wxFileName k_advanced = getAdvancedCfgFilename();
298 
299  // If we are running headless, use the class defaults because we cannot instantiate wxConfig
300  if( !wxTheApp )
301  return;
302 
303  if( !k_advanced.FileExists() )
304  {
305  wxLogTrace( AdvancedConfigMask, "File does not exist %s", k_advanced.GetFullPath() );
306 
307  // load the defaults
308  wxConfig emptyConfig;
309  loadSettings( emptyConfig );
310 
311  return;
312  }
313 
314  wxLogTrace( AdvancedConfigMask, "Loading advanced config from: %s", k_advanced.GetFullPath() );
315 
316  wxFileConfig file_cfg( "", "", k_advanced.GetFullPath() );
317  loadSettings( file_cfg );
318 }
319 
320 
321 void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
322 {
323  std::vector<PARAM_CFG*> configParams;
324 
325  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::RealtimeConnectivity,
326  &m_RealTimeConnectivity, true ) );
327 
328  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::ExtraFillMargin,
329  &m_ExtraClearance, 0.0005, 0.0, 1.0 ) );
330 
331  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DRCEpsilon,
332  &m_DRCEpsilon, 0.0005, 0.0, 1.0 ) );
333 
334  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::HoleWallThickness,
335  &m_HoleWallThickness, 0.020, 0.0, 1.0 ) );
336 
337  configParams.push_back( new PARAM_CFG_INT( true, AC_KEYS::CoroutineStackSize,
340 
341  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowRouterDebugGraphics,
342  &m_ShowRouterDebugGraphics, false ) );
343 
344  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::CompactFileSave,
345  &m_CompactSave, false ) );
346 
347  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DrawArcAccuracy,
348  &m_DrawArcAccuracy, 10.0, 0.0, 100000.0 ) );
349 
350  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DrawArcCenterStartEndMaxAngle,
351  &m_DrawArcCenterMaxAngle, 50.0, 0.0, 100000.0 ) );
352 
353  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::MaxTangentTrackAngleDeviation,
354  &m_MaxTangentAngleDeviation, 1.0, 0.0, 90.0 ) );
355 
356  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::MaxTrackLengthToKeep,
357  &m_MaxTrackLengthToKeep, 0.0005, 0.0, 1.0 ) );
358 
359  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ExtraZoneDisplayModes,
360  &m_ExtraZoneDisplayModes, false ) );
361 
362  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::StrokeTriangulation,
363  &m_DrawTriangulationOutlines, false ) );
364 
365  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::MinPlotPenWidth,
366  &m_MinPlotPenWidth, 0.0212, 0.0, 1.0 ) );
367 
368  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DebugZoneFiller,
369  &m_DebugZoneFiller, false ) );
370 
371  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DebugPDFWriter,
372  &m_DebugPDFWriter, false ) );
373 
374  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::SmallDrillMarkSize,
375  &m_SmallDrillMarkSize, 0.35, 0.0, 3.0 ) );
376 
377  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::HotkeysDumper,
378  &m_HotkeysDumper, false ) );
379 
380  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DrawBoundingBoxes,
381  &m_DrawBoundingBoxes, false ) );
382 
383  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowPcbnewExportNetlist,
384  &m_ShowPcbnewExportNetlist, false ) );
385 
386  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::Skip3DModelFileCache,
387  &m_Skip3DModelFileCache, false ) );
388 
389  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::Skip3DModelMemoryCache,
390  &m_Skip3DModelMemoryCache, false ) );
391 
392  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::HideVersionFromTitle,
393  &m_HideVersionFromTitle, false ) );
394 
395  wxConfigLoadSetups( &aCfg, configParams );
396 
397  dumpCfg( configParams );
398 
399  for( PARAM_CFG* param : configParams )
400  delete param;
401 }
402 
403 
static const wxChar Skip3DModelFileCache[]
Limits and default settings for the coroutine stack size allowed.
bool m_HideVersionFromTitle
Hides the build version from the KiCad manager frame title.
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)
Use aList of PARAM_CFG object to load configuration values from aCfg.
static const wxChar DrawArcAccuracy[]
For drawsegments - arcs.
wxString m_Ident
Keyword in config data.
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 object for double precision floating point numbers.
bool m_DrawTriangulationOutlines
When true, strokes the triangulations with visible color.
static const wxChar MaxTrackLengthToKeep[]
For arc track interactive drag-resizing Maximum track length to keep after doing an arc track resizin...
double m_DrawArcCenterMaxAngle
When drawing an arc, the angle ( center - start ) - ( start - end ) can be limited to avoid extremely...
static const wxChar DrawArcCenterStartEndMaxAngle[]
For drawsegments - arcs.
double m_MaxTrackLengthToKeep
Maximum track length to keep after doing an arc track resizing operation.
double m_DrawArcAccuracy
Distance from an arc end point and the estimated end point, when rotating from the start point to the...
bool m_ShowRouterDebugGraphics
Show PNS router debug graphics.
double m_SmallDrillMarkSize
The diameter of the drill marks on print and plot outputs (in mm), when the "Drill marks" option is s...
bool m_ShowPcbnewExportNetlist
Enable exporting board editor netlist to a file for troubleshooting purposes.
static const wxChar RealtimeConnectivity[]
Testing mode for new connectivity algorithm.
static const wxChar MaxTangentTrackAngleDeviation[]
For arc track interactive drag-resizing Maximum angle between the tangent line of an arc track and a ...
static const wxChar Skip3DModelMemoryCache[]
bool m_ExtraZoneDisplayModes
When true, adds zone-diaplay-modes for stroking the zone fracture boundaries and the zone triangulati...
static const wxChar DRCEpsilon[]
A fudge factor for DRC.
static const wxChar ShowPcbnewExportNetlist[]
static const wxChar DebugPDFWriter[]
static void dumpCfg(const std::vector< PARAM_CFG * > &aArray)
Dump the configs in the given array to trace.
void loadSettings(wxConfigBase &aCfg)
Configuration object for integers.
void loadFromConfigFile()
Load the config from the normal config file.
wxString dumpParamCfg(const PARAM_CFG &aParam)
Configuration object for booleans.
static const wxChar SmallDrillMarkSize[]
The diameter of the drill marks on print and plot outputs (in mm), when the "Drill marks" option is s...
bool m_Skip3DModelMemoryCache
Skip reading/writing 3d model memory caches This ensures 3d models are always reloaded from disk even...
static const wxChar DrawBoundingBoxes[]
static const wxChar ExtraZoneDisplayModes[]
When true, a third zone-display-mode is included which strokes the filled areas and fracture boundari...
double m_ExtraClearance
Extra fill clearance for zone fills.
double m_DRCEpsilon
Epsilon for DRC tests.
bool m_HotkeysDumper
Enable the hotkeys dumper feature, used for generating documentation.
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.
static wxFileName getAdvancedCfgFilename()
Get the filename for the advanced config file.
Class containing "advanced" configuration options.
double m_MaxTangentAngleDeviation
Maximum angle between the tangent line of an arc track and a connected straight track in order to com...
bool m_DrawBoundingBoxes
Draw GAL bounding boxes in painters.
int m_CoroutineStackSize
Set the stack size for coroutines.
bool m_DebugPDFWriter
A mode that writes PDFs without compression.
A base class which establishes the interface functions ReadParam and SaveParam, which are implemented...
Definition: config_params.h:81
static const wxChar CoroutineStackSize[]
Configure the coroutine stack size in bytes.
paramcfg_id m_Type
Type of parameter.
static const wxChar HotkeysDumper[]
static constexpr int default_stack
static const wxChar StrokeTriangulation[]
When true, GAL will stroke the triangulations (only used in OpenGL) with a visible color.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
static const wxChar DebugZoneFiller[]
static constexpr int max_stack
static const wxChar ShowRouterDebugGraphics[]
Show PNS router debug graphics while routing.
bool m_Skip3DModelFileCache
Skip reading/writing 3d model file caches This does not prevent the models from being cached in memor...
bool m_RealTimeConnectivity
Do real-time connectivity.
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 HideVersionFromTitle[]
static const wxChar AdvancedConfigMask[]
double m_HoleWallThickness
Hole wall plating thickness.