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 <config_params.h>
28 
29 #include <wx/config.h>
30 #include <wx/filename.h>
31 #include <wx/log.h>
32 
33 /*
34  * Flag to enable advanced config debugging
35  *
36  * Use "KICAD_ADVANCED_CONFIG" to enable.
37  *
38  * @ingroup trace_env_vars
39  */
40 static const wxChar AdvancedConfigMask[] = wxT( "KICAD_ADVANCED_CONFIG" );
41 
47 namespace AC_STACK
48 {
49  static constexpr int min_stack = 32 * 4096;
50  static constexpr int default_stack = 256 * 4096;
51  static constexpr int max_stack = 4096 * 4096;
52 }
53 
60 namespace AC_KEYS
61 {
62 
67 static const wxChar ExtraFillMargin[] = wxT( "ExtraFillMargin" );
68 
74 static const wxChar DRCEpsilon[] = wxT( "DRCEpsilon" );
75 
81 static const wxChar HoleWallThickness[] = wxT( "HoleWallPlatingThickness" );
82 
88 static const wxChar RealtimeConnectivity[] = wxT( "RealtimeConnectivity" );
89 
94 static const wxChar CoroutineStackSize[] = wxT( "CoroutineStackSize" );
95 
99 static const wxChar ShowRouterDebugGraphics[] = wxT( "ShowRouterDebugGraphics" );
100 
105 static const wxChar CompactFileSave[] = wxT( "CompactSave" );
106 
114 static const wxChar DrawArcAccuracy[] = wxT( "DrawArcAccuracy" );
115 
122 static const wxChar DrawArcCenterStartEndMaxAngle[] = wxT( "DrawArcCenterStartEndMaxAngle" );
123 
127 static const wxChar StrokeTriangulation[] = wxT( "StrokeTriangulation" );
128 
132 static const wxChar PluginAltiumSch[] = wxT( "PluginAltiumSch" );
133 
138 static const wxChar MinPlotPenWidth[] = wxT( "MinPlotPenWidth" );
139 
140 static const wxChar DebugZoneFiller[] = wxT( "DebugZoneFiller" );
141 
142 static const wxChar DebugPDFWriter[] = wxT( "DebugPDFWriter" );
143 
148 static const wxChar SmallDrillMarkSize[] = wxT( "SmallDrillMarkSize" );
149 
150 static const wxChar HotkeysDumper[] = wxT( "HotkeysDumper" );
151 
152 static const wxChar DrawBoundingBoxes[] = wxT( "DrawBoundingBoxes" );
153 
154 
155 } // namespace KEYS
156 
157 
158 /*
159  * Get a simple string for common parameters.
160  *
161  * This isn't exhaustive, but it covers most common types that might be
162  * used in the advance config
163  */
164 wxString dumpParamCfg( const PARAM_CFG& aParam )
165 {
166  wxString s = aParam.m_Ident + ": ";
167 
168  /*
169  * This implementation is rather simplistic, but it is
170  * effective enough for simple uses. A better implementation would be
171  * some kind of visitor, but that's somewhat more work.
172  */
173  switch( aParam.m_Type )
174  {
177  s << *static_cast<const PARAM_CFG_INT&>( aParam ).m_Pt_param;
178  break;
180  s << *static_cast<const PARAM_CFG_DOUBLE&>( aParam ).m_Pt_param;
181  break;
183  s << *static_cast<const PARAM_CFG_WXSTRING&>( aParam ).m_Pt_param;
184  break;
186  s << *static_cast<const PARAM_CFG_FILENAME&>( aParam ).m_Pt_param;
187  break;
189  s << ( *static_cast<const PARAM_CFG_BOOL&>( aParam ).m_Pt_param ? "true" : "false" );
190  break;
191  default: s << "Unsupported PARAM_CFG variant: " << aParam.m_Type;
192  }
193 
194  return s;
195 }
196 
197 
201 static void dumpCfg( const std::vector<PARAM_CFG*>& aArray )
202 {
203  // only dump if we need to
204  if( !wxLog::IsAllowedTraceMask( AdvancedConfigMask ) )
205  return;
206 
207  for( const PARAM_CFG* param : aArray )
208  {
209  wxLogTrace( AdvancedConfigMask, dumpParamCfg( *param ) );
210  }
211 }
212 
213 
219 static wxFileName getAdvancedCfgFilename()
220 {
221  const static wxString cfg_filename{ "kicad_advanced" };
222  return wxFileName( SETTINGS_MANAGER::GetUserSettingsPath(), cfg_filename );
223 }
224 
225 
227 {
228  wxLogTrace( AdvancedConfigMask, "Init advanced config" );
229 
230  // Init defaults - this is done in case the config doesn't exist,
231  // then the values will remain as set here.
232  m_RealTimeConnectivity = true;
235  m_DrawArcAccuracy = 10.0;
238  m_PluginAltiumSch = false;
239 
240  m_ExtraClearance = 0.0001;
241  m_DRCEpsilon = 0.0001; // 0.1um is small enough not to materially violate
242  // any constraints.
243 
244  m_HoleWallThickness = 0.020; // IPC-6012 says 15-18um; Cadence says at least
245  // 0.020 for a Class 2 board and at least 0.025
246  // for Class 3.
247 
248  m_MinPlotPenWidth = 0.0212; // 1 pixel at 1200dpi.
249 
250  m_DebugZoneFiller = false;
251  m_DebugPDFWriter = false;
252  m_SmallDrillMarkSize = 0.35;
253  m_HotkeysDumper = false;
254  m_DrawBoundingBoxes = false;
255 
257 }
258 
259 
261 {
262  static ADVANCED_CFG instance;
263  return instance;
264 }
265 
266 
268 {
269  const wxFileName k_advanced = getAdvancedCfgFilename();
270 
271  if( !k_advanced.FileExists() )
272  {
273  wxLogTrace( AdvancedConfigMask, "File does not exist %s", k_advanced.GetFullPath() );
274 
275  // load the defaults
276  wxConfig emptyConfig;
277  loadSettings( emptyConfig );
278 
279  return;
280  }
281 
282  wxLogTrace( AdvancedConfigMask, "Loading advanced config from: %s", k_advanced.GetFullPath() );
283 
284  wxFileConfig file_cfg( "", "", k_advanced.GetFullPath() );
285  loadSettings( file_cfg );
286 }
287 
288 
289 void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
290 {
291  std::vector<PARAM_CFG*> configParams;
292 
293  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::RealtimeConnectivity,
294  &m_RealTimeConnectivity, true ) );
295 
296  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::ExtraFillMargin,
297  &m_ExtraClearance, 0.0005, 0.0, 1.0 ) );
298 
299  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DRCEpsilon,
300  &m_DRCEpsilon, 0.0005, 0.0, 1.0 ) );
301 
302  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::HoleWallThickness,
303  &m_HoleWallThickness, 0.020, 0.0, 1.0 ) );
304 
305  configParams.push_back( new PARAM_CFG_INT( true, AC_KEYS::CoroutineStackSize,
308 
309  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowRouterDebugGraphics,
310  &m_ShowRouterDebugGraphics, false ) );
311 
312  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::CompactFileSave,
313  &m_CompactSave, false ) );
314 
315  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DrawArcAccuracy,
316  &m_DrawArcAccuracy, 10.0, 0.0, 100000.0 ) );
317 
318  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::DrawArcCenterStartEndMaxAngle,
319  &m_DrawArcCenterMaxAngle, 50.0, 0.0, 100000.0 ) );
320 
321  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::StrokeTriangulation,
322  &m_DrawTriangulationOutlines, false ) );
323 
324  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::PluginAltiumSch,
325  &m_PluginAltiumSch, false ) );
326 
327  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::MinPlotPenWidth,
328  &m_MinPlotPenWidth, 0.0212, 0.0, 1.0 ) );
329 
330  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DebugZoneFiller,
331  &m_DebugZoneFiller, false ) );
332 
333  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DebugPDFWriter,
334  &m_DebugPDFWriter, false ) );
335 
336  configParams.push_back( new PARAM_CFG_DOUBLE( true, AC_KEYS::SmallDrillMarkSize,
337  &m_SmallDrillMarkSize, 0.35, 0.0, 3.0 ) );
338 
339  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::HotkeysDumper,
340  &m_HotkeysDumper, false ) );
341 
342  configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DrawBoundingBoxes,
343  &m_DrawBoundingBoxes, false ) );
344 
345  wxConfigLoadSetups( &aCfg, configParams );
346 
347  for( PARAM_CFG* param : configParams )
348  delete param;
349 
350  dumpCfg( configParams );
351 }
352 
353 
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_PluginAltiumSch
When true, enable Altium Schematic import (*.SchDoc) the current implementation is highly incomplete.
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.
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_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...
static const wxChar RealtimeConnectivity[]
Testing mode for new connectivity algorithm.
static const wxChar DRCEpsilon[]
A fudge factor for DRC.
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...
static const wxChar DrawBoundingBoxes[]
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.
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 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.
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 AdvancedConfigMask[]
double m_HoleWallThickness
Hole wall plating thickness.