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 #include <wx/tokenzr.h>
34 
35 /*
36  * Flag to enable advanced config debugging
37  *
38  * Use "KICAD_ADVANCED_CONFIG" to enable.
39  *
40  * @ingroup trace_env_vars
41  */
42 static const wxChar AdvancedConfigMask[] = wxT( "KICAD_ADVANCED_CONFIG" );
43 
49 namespace AC_STACK
50 {
51  static constexpr int min_stack = 32 * 4096;
52  static constexpr int default_stack = 256 * 4096;
53  static constexpr int max_stack = 4096 * 4096;
54 }
55 
62 namespace AC_KEYS
63 {
64 
69 static const wxChar ExtraFillMargin[] = wxT( "ExtraFillMargin" );
70 
76 static const wxChar DRCEpsilon[] = wxT( "DRCEpsilon" );
77 
83 static const wxChar HoleWallThickness[] = wxT( "HoleWallPlatingThickness" );
84 
90 static const wxChar RealtimeConnectivity[] = wxT( "RealtimeConnectivity" );
91 
96 static const wxChar CoroutineStackSize[] = wxT( "CoroutineStackSize" );
97 
101 static const wxChar ShowRouterDebugGraphics[] = wxT( "ShowRouterDebugGraphics" );
102 
107 static const wxChar CompactFileSave[] = wxT( "CompactSave" );
108 
116 static const wxChar DrawArcAccuracy[] = wxT( "DrawArcAccuracy" );
117 
124 static const wxChar DrawArcCenterStartEndMaxAngle[] = wxT( "DrawArcCenterStartEndMaxAngle" );
125 
131 static const wxChar MaxTangentTrackAngleDeviation[] = wxT( "MaxTangentTrackAngleDeviation" );
132 
137 static const wxChar MaxTrackLengthToKeep[] = wxT( "MaxTrackLengthToKeep" );
138 
142 static const wxChar StrokeTriangulation[] = wxT( "StrokeTriangulation" );
143 
148 static const wxChar ExtraZoneDisplayModes[] = wxT( "ExtraZoneDisplayModes" );
149 
154 static const wxChar MinPlotPenWidth[] = wxT( "MinPlotPenWidth" );
155 
156 static const wxChar DebugZoneFiller[] = wxT( "DebugZoneFiller" );
157 
158 static const wxChar DebugPDFWriter[] = wxT( "DebugPDFWriter" );
159 
164 static const wxChar SmallDrillMarkSize[] = wxT( "SmallDrillMarkSize" );
165 
166 static const wxChar HotkeysDumper[] = wxT( "HotkeysDumper" );
167 
168 static const wxChar DrawBoundingBoxes[] = wxT( "DrawBoundingBoxes" );
169 
170 static const wxChar ShowPcbnewExportNetlist[] = wxT( "ShowPcbnewExportNetlist" );
171 
172 static const wxChar Skip3DModelFileCache[] = wxT( "Skip3DModelFileCache" );
173 
174 static const wxChar Skip3DModelMemoryCache[] = wxT( "Skip3DModelMemoryCache" );
175 
176 static const wxChar HideVersionFromTitle[] = wxT( "HideVersionFromTitle" );
177 
178 static const wxChar TraceMasks[] = wxT( "TraceMasks" );
179 
180 static const wxChar ShowRepairSchematic[] = wxT( "ShowRepairSchematic" );
181 
182 static const wxChar ShowEventCounters[] = wxT( "ShowEventCounters" );
183 
184 static const wxChar AllowManualCanvasScale[] = wxT( "AllowManualCanvasScale" );
185 
186 } // namespace KEYS
187 
188 
189 /*
190  * Get a simple string for common parameters.
191  *
192  * This isn't exhaustive, but it covers most common types that might be
193  * used in the advance config
194  */
195 wxString dumpParamCfg( const PARAM_CFG& aParam )
196 {
197  wxString s = aParam.m_Ident + wxT( ": " );
198 
199  /*
200  * This implementation is rather simplistic, but it is
201  * effective enough for simple uses. A better implementation would be
202  * some kind of visitor, but that's somewhat more work.
203  */
204  switch( aParam.m_Type )
205  {
208  s << *static_cast<const PARAM_CFG_INT&>( aParam ).m_Pt_param;
209  break;
211  s << *static_cast<const PARAM_CFG_DOUBLE&>( aParam ).m_Pt_param;
212  break;
214  s << *static_cast<const PARAM_CFG_WXSTRING&>( aParam ).m_Pt_param;
215  break;
217  s << *static_cast<const PARAM_CFG_FILENAME&>( aParam ).m_Pt_param;
218  break;
220  s << ( *static_cast<const PARAM_CFG_BOOL&>( aParam ).m_Pt_param ? wxT( "true" ) : wxT( "false" ) );
221  break;
222  default: s << wxT( "Unsupported PARAM_CFG variant: " ) << aParam.m_Type;
223  }
224 
225  return s;
226 }
227 
228 
232 static void dumpCfg( const std::vector<PARAM_CFG*>& aArray )
233 {
234  // only dump if we need to
235  if( !wxLog::IsAllowedTraceMask( AdvancedConfigMask ) )
236  return;
237 
238  for( const PARAM_CFG* param : aArray )
239  {
240  wxLogTrace( AdvancedConfigMask, dumpParamCfg( *param ) );
241  }
242 }
243 
244 
250 static wxFileName getAdvancedCfgFilename()
251 {
252  const static wxString cfg_filename{ wxT( "kicad_advanced" ) };
253  return wxFileName( SETTINGS_MANAGER::GetUserSettingsPath(), cfg_filename );
254 }
255 
256 
258 {
259  wxLogTrace( AdvancedConfigMask, wxT( "Init advanced config" ) );
260 
261  // Init defaults - this is done in case the config doesn't exist,
262  // then the values will remain as set here.
263  m_RealTimeConnectivity = true;
266  m_DrawArcAccuracy = 10.0;
269  m_MaxTrackLengthToKeep = 0.0005;
270  m_ExtraZoneDisplayModes = false;
272 
273  m_ExtraClearance = 0.0005;
274  m_DRCEpsilon = 0.0005; // 0.5um is small enough not to materially violate
275  // any constraints.
276 
277  m_HoleWallThickness = 0.020; // IPC-6012 says 15-18um; Cadence says at least
278  // 0.020 for a Class 2 board and at least 0.025
279  // for Class 3.
280 
281  m_MinPlotPenWidth = 0.0212; // 1 pixel at 1200dpi.
282 
283  m_DebugZoneFiller = false;
284  m_DebugPDFWriter = false;
285  m_SmallDrillMarkSize = 0.35;
286  m_HotkeysDumper = false;
287  m_DrawBoundingBoxes = false;
289  m_Skip3DModelFileCache = false;
290  m_Skip3DModelMemoryCache = false;
291  m_HideVersionFromTitle = false;
292  m_ShowEventCounters = false;
293  m_AllowManualCanvasScale = false;
294 
296 }
297 
298 
300 {
301  static ADVANCED_CFG instance;
302  return instance;
303 }
304 
305 
307 {
308  const wxFileName k_advanced = getAdvancedCfgFilename();
309 
310  // If we are running headless, use the class defaults because we cannot instantiate wxConfig
311  if( !wxTheApp )
312  return;
313 
314  if( !k_advanced.FileExists() )
315  {
316  wxLogTrace( AdvancedConfigMask, wxT( "File does not exist %s" ), k_advanced.GetFullPath() );
317 
318  // load the defaults
319  wxConfig emptyConfig;
320  loadSettings( emptyConfig );
321 
322  return;
323  }
324 
325  wxLogTrace( AdvancedConfigMask, wxT( "Loading advanced config from: %s" ), k_advanced.GetFullPath() );
326 
327  wxFileConfig file_cfg( wxEmptyString, wxEmptyString, k_advanced.GetFullPath() );
328  loadSettings( file_cfg );
329 }
330 
331 
332 void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
333 {
334  std::vector<PARAM_CFG*> configParams;
335 
336  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::RealtimeConnectivity,
338 
339  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::ExtraFillMargin,
340  &m_ExtraClearance, m_ExtraClearance, 0.0, 1.0 ) );
341 
342  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DRCEpsilon,
343  &m_DRCEpsilon, m_DRCEpsilon, 0.0, 1.0 ) );
344 
345  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::HoleWallThickness,
347 
348  configParams.push_back( new PARAM_CFG_INT( true, AC_KEYS::CoroutineStackSize,
351 
352  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowRouterDebugGraphics,
354 
355  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::CompactFileSave,
357 
358  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DrawArcAccuracy,
359  &m_DrawArcAccuracy, m_DrawArcAccuracy, 0.0, 100000.0 ) );
360 
361  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DrawArcCenterStartEndMaxAngle,
363 
364  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::MaxTangentTrackAngleDeviation,
366 
367  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::MaxTrackLengthToKeep,
369 
370  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ExtraZoneDisplayModes,
372 
373  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::StrokeTriangulation,
375 
376  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::MinPlotPenWidth,
377  &m_MinPlotPenWidth, m_MinPlotPenWidth, 0.0, 1.0 ) );
378 
379  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DebugZoneFiller,
381 
382  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DebugPDFWriter,
384 
385  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::SmallDrillMarkSize,
387 
388  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::HotkeysDumper,
390 
391  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DrawBoundingBoxes,
393 
394  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowPcbnewExportNetlist,
396 
397  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::Skip3DModelFileCache,
399 
400  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::Skip3DModelMemoryCache,
402 
403  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::HideVersionFromTitle,
405 
406  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowRepairSchematic,
408 
409  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowEventCounters,
411 
412  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::AllowManualCanvasScale,
414 
415  // Special case for trace mask setting...we just grab them and set them immediately
416  // Because we even use wxLogTrace inside of advanced config
417  wxString traceMasks = wxEmptyString;
418  configParams.push_back( new PARAM_CFG_WXSTRING( true, AC_KEYS::TraceMasks, &traceMasks, wxEmptyString ) );
419 
420  // Load the config from file
421  wxConfigLoadSetups( &aCfg, configParams );
422 
423  // Now actually set the trace masks
424  wxStringTokenizer traceMaskTokenizer( traceMasks, wxT( "," ) );
425 
426  while( traceMaskTokenizer.HasMoreTokens() )
427  {
428  wxString mask = traceMaskTokenizer.GetNextToken();
429  wxLog::AddTraceMask( mask );
430  }
431 
432  dumpCfg( configParams );
433 
434  for( PARAM_CFG* param : configParams )
435  delete param;
436 }
437 
438 
static const wxChar Skip3DModelFileCache[]
Limits and default settings for the coroutine stack size allowed.
bool m_ShowEventCounters
Shows debugging event counters in various places.
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.
static const wxChar ShowEventCounters[]
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[]
static const wxChar ShowRepairSchematic[]
static const wxChar TraceMasks[]
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.
static const wxChar AllowManualCanvasScale[]
Configuration object for wxString objects.
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.
bool m_AllowManualCanvasScale
bool m_ShowRepairSchematic
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.