KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_calculator_settings.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 The 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 <array>
28#include <settings/parameters.h>
29#include <wx/config.h>
30
31
34
35
40{
41 // Build settings:
42 m_params.emplace_back( new PARAM<int>( "board_class_units", &m_BoardClassUnits, 0 ) );
43
44 m_params.emplace_back( new PARAM<int>( "color_code_tolerance", &m_ColorCodeTolerance, 0 ) );
45
46 m_params.emplace_back( new PARAM<int>( "last_page", &m_LastPage, 1 ) );
47
48 m_params.emplace_back( new PARAM<int>( "translines.type", &m_TransLine.type, 0 ) );
49
50 m_params.emplace_back( new PARAM<int>( "translines.dielectric_model",
51 &m_TransLine.dielectric_model, 0 ) );
52
53 m_params.emplace_back( new PARAM<wxString>( "translines.spec_frequency",
54 &m_TransLine.spec_frequency, wxT( "1" ) ) );
55
56 m_params.emplace_back( new PARAM<int>( "translines.spec_frequency_unit",
57 &m_TransLine.spec_frequency_unit, 0 ) );
58
59 m_params.emplace_back( new PARAM<int>( "translines.soldermask_present",
60 &m_TransLine.soldermask_present, 0 ) );
61
62 m_params.emplace_back( new PARAM<double>( "translines.soldermask_thickness",
63 &m_TransLine.soldermask_thickness, 20.0e-6 ) );
64
65 m_params.emplace_back( new PARAM<double>( "translines.soldermask_epsilonr",
66 &m_TransLine.soldermask_epsilonr, 3.5 ) );
67
68 m_params.emplace_back( new PARAM<double>( "translines.soldermask_tand",
69 &m_TransLine.soldermask_tand, 0.025 ) );
70
71 m_params.emplace_back( new PARAM<int>( "translines.soldermask_fills_gaps",
72 &m_TransLine.soldermask_fills_gaps, 1 ) );
73
74 m_params.emplace_back( new PARAM<int>( "attenuators.type", &m_Attenuators.type, 0 ) );
75
76 const std::array<std::string, 4> att_names = { "att_pi", "att_tee",
77 "att_bridge", "att_splitter" };
78
79 for( const auto& att_name : att_names )
80 {
81 std::string path = "attenuators." + att_name;
82 m_Attenuators.attenuators[ att_name ] = ATTENUATOR();
83 ATTENUATOR* att = &m_Attenuators.attenuators[ att_name ];
84
85 m_params.emplace_back( new PARAM<double>( path + ".attenuation", &att->attenuation, 6.0 ) );
86 m_params.emplace_back( new PARAM<double>( path + ".zin", &att->zin, 50.0 ) );
87 m_params.emplace_back( new PARAM<double>( path + ".zout", &att->zout, 50.0 ) );
88 }
89
90 // Electrical spacing params
91 m_params.emplace_back( new PARAM<int>( "electrical.spacing_units",
92 &m_Electrical.spacing_units, 0 ) );
93
94 m_params.emplace_back( new PARAM<wxString>( "electrical.spacing_voltage",
95 &m_Electrical.spacing_voltage, "500" ) );
96
97 m_params.emplace_back( new PARAM<double>( "electrical.iec60664_ratedVoltage",
98 &m_Electrical.iec60664_ratedVoltage, 230 ) );
99
100 m_params.emplace_back( new PARAM<int>( "electrical.iec60664_OVC",
101 &m_Electrical.iec60664_OVC, 0 ) );
102
103 m_params.emplace_back( new PARAM<double>( "electrical.iec60664_RMSvoltage",
104 &m_Electrical.iec60664_RMSvoltage, 230 ) );
105
106 m_params.emplace_back( new PARAM<double>( "electrical.iec60664_transientOV",
107 &m_Electrical.iec60664_transientOV, 1 ) );
108
109 m_params.emplace_back( new PARAM<double>( "electrical.iec60664_peakOV",
110 &m_Electrical.iec60664_peakOV, 0.5 ) );
111
112 m_params.emplace_back( new PARAM<int>( "electrical.iec60664_insulationType",
113 &m_Electrical.iec60664_insulationType, 0 ) );
114
115 m_params.emplace_back( new PARAM<int>( "electrical.iec60664_pollutionDegree",
116 &m_Electrical.iec60664_pollutionDegree, 0 ) );
117
118 m_params.emplace_back( new PARAM<int>( "electrical.iec60664_materialGroup",
119 &m_Electrical.iec60664_materialGroup, 0 ) );
120
121 m_params.emplace_back( new PARAM<int>( "electrical.iec60664_pcbMaterial",
122 &m_Electrical.iec60664_pcbMaterial, 1 ) );
123
124 m_params.emplace_back( new PARAM<double>( "electrical.iec60664_altitude",
125 &m_Electrical.iec60664_altitude, 2000 ) );
126
127 // Regulators params
128 m_params.emplace_back( new PARAM<wxString>( "regulators.resTol", &m_Regulators.resTol,
130
131 m_params.emplace_back(
132 new PARAM<wxString>( "regulators.r1", &m_Regulators.r1, DEFAULT_REGULATOR_R1 ) );
133
134 m_params.emplace_back(
135 new PARAM<wxString>( "regulators.r2", &m_Regulators.r2, DEFAULT_REGULATOR_R2 ) );
136
137 m_params.emplace_back( new PARAM<wxString>( "regulators.vrefMin", &m_Regulators.vrefMin,
139 m_params.emplace_back( new PARAM<wxString>( "regulators.vrefTyp", &m_Regulators.vrefTyp,
141 m_params.emplace_back( new PARAM<wxString>( "regulators.vrefMax", &m_Regulators.vrefMax,
143
144 m_params.emplace_back( new PARAM<wxString>( "regulators.voutTyp", &m_Regulators.voutTyp,
146
147 m_params.emplace_back( new PARAM<wxString>( "regulators.iadjTyp", &m_Regulators.iadjTyp,
149 m_params.emplace_back( new PARAM<wxString>( "regulators.iadjMax", &m_Regulators.iadjMax,
151
152 m_params.emplace_back( new PARAM<wxString>( "regulators.data_file",
153 &m_Regulators.data_file, "" ) );
154
155 m_params.emplace_back( new PARAM<wxString>( "regulators.selected_regulator",
156 &m_Regulators.selected_regulator, "" ) );
157
158 m_params.emplace_back( new PARAM<int>( "regulators.type", &m_Regulators.type, 1 ) );
159
160 m_params.emplace_back( new PARAM<int>( "regulators.last_param", &m_Regulators.last_param, 0 ) );
161
162 // cable_size params
163 m_params.emplace_back( new PARAM<wxString>( "cable_size.conductorMaterialResitivity",
164 &m_cableSize.conductorMaterialResitivity, "" ) );
165
166 m_params.emplace_back( new PARAM<wxString>( "cable_size.conductorTemperature",
167 &m_cableSize.conductorTemperature, "" ) );
168
169 m_params.emplace_back( new PARAM<wxString>( "cable_size.conductorThermalCoef",
170 &m_cableSize.conductorThermalCoef, "" ) );
171
172 m_params.emplace_back( new PARAM<int>( "cable_size.currentDensityChoice",
173 &m_cableSize.currentDensityChoice, 0 ) );
174
175 m_params.emplace_back(
176 new PARAM<int>( "cable_size.diameterUnit", &m_cableSize.diameterUnit, 0 ) );
177
178 m_params.emplace_back( new PARAM<int>( "cable_size.linResUnit", &m_cableSize.linResUnit, 0 ) );
179
180 m_params.emplace_back(
181 new PARAM<int>( "cable_size.frequencyUnit", &m_cableSize.frequencyUnit, 0 ) );
182
183 m_params.emplace_back( new PARAM<int>( "cable_size.lengthUnit", &m_cableSize.lengthUnit, 0 ) );
184
185 // wavelength params
186 m_params.emplace_back(
187 new PARAM<double>( "wavelength.frequency", &m_wavelength.frequency, 1e9 ) );
188
189 m_params.emplace_back(
190 new PARAM<double>( "wavelength.permeability", &m_wavelength.permeability, 1 ) );
191
192 m_params.emplace_back(
193 new PARAM<double>( "wavelength.permittivity", &m_wavelength.permittivity, 4.5 ) );
194
195 m_params.emplace_back(
196 new PARAM<int>( "wavelength.frequencyUnit", &m_wavelength.frequencyUnit, 0 ) );
197
198 m_params.emplace_back( new PARAM<int>( "wavelength.periodUnit", &m_wavelength.periodUnit, 0 ) );
199
200 m_params.emplace_back( new PARAM<int>( "wavelength.wavelengthVacuumUnit",
201 &m_wavelength.wavelengthVacuumUnit, 0 ) );
202
203 m_params.emplace_back( new PARAM<int>( "wavelength.wavelengthMediumUnit",
204 &m_wavelength.wavelengthMediumUnit, 0 ) );
205
206 m_params.emplace_back( new PARAM<int>( "wavelength.speedUnit", &m_wavelength.speedUnit, 0 ) );
207
208 m_params.emplace_back( new PARAM<wxString>( "track_width.current",
209 &m_TrackWidth.current, "1.0" ) );
210
211 m_params.emplace_back( new PARAM<wxString>( "track_width.delta_tc",
212 &m_TrackWidth.delta_tc, "10.0" ) );
213
214 m_params.emplace_back( new PARAM<wxString>( "track_width.track_len",
215 &m_TrackWidth.track_len, "20" ) );
216
217 m_params.emplace_back( new PARAM<int>( "track_width.track_len_units",
218 &m_TrackWidth.track_len_units, 0 ) );
219
220 m_params.emplace_back( new PARAM<wxString>( "track_width.resistivity",
221 &m_TrackWidth.resistivity, "1.72e-8" ) );
222
223 m_params.emplace_back( new PARAM<wxString>( "track_width.ext_track_width",
224 &m_TrackWidth.ext_track_width, "0.2" ) );
225
226 m_params.emplace_back( new PARAM<int>( "track_width.ext_track_width_units",
227 &m_TrackWidth.ext_track_width_units, 0 ) );
228
229 m_params.emplace_back( new PARAM<wxString>( "track_width.ext_track_thickness",
230 &m_TrackWidth.ext_track_thickness, "35" ) );
231
232 m_params.emplace_back( new PARAM<int>( "track_width.ext_track_thickness_units",
233 &m_TrackWidth.ext_track_thickness_units, 1 ) );
234
235 m_params.emplace_back( new PARAM<wxString>( "track_width.int_track_width",
236 &m_TrackWidth.int_track_width, "0.2" ) );
237
238 m_params.emplace_back( new PARAM<int>( "track_width.int_track_width_units",
239 &m_TrackWidth.int_track_width_units, 0 ) );
240
241 m_params.emplace_back( new PARAM<wxString>( "track_width.int_track_thickness",
242 &m_TrackWidth.int_track_thickness, "35" ) );
243
244 m_params.emplace_back( new PARAM<int>( "track_width.int_track_thickness_units",
245 &m_TrackWidth.int_track_thickness_units, 1 ) );
246
247 {
248 const std::array<std::string, 9> transline_names = { "MicroStrip", "CoPlanar", "GrCoPlanar",
249 "RectWaveGuide", "Coax", "Coupled_MicroStrip", "Coupled_Stripline", "StripLine",
250 "TwistedPair" };
251
252 for( const auto& name : transline_names )
253 {
254 m_TransLine.param_values[ name ] = TL_PARAM_MAP();
255 m_TransLine.param_units[ name ] = TL_PARAM_UNITS_MAP();
256
257 std::string path = "trans_line." + name + ".";
258
259 m_params.emplace_back( new PARAM_MAP<double>( path + "values",
260 &m_TransLine.param_values.at( name ), {} ) );
261
262 m_params.emplace_back( new PARAM_MAP<int>( path + "units",
263 &m_TransLine.param_units.at( name ), {} ) );
264 }
265 }
266
267 m_params.emplace_back( new PARAM<wxString>( "via_size.hole_diameter",
268 &m_ViaSize.hole_diameter, "0.4" ) );
269
270 m_params.emplace_back( new PARAM<int>( "via_size.hole_diameter_units",
271 &m_ViaSize.hole_diameter_units, 0 ) );
272
273 m_params.emplace_back( new PARAM<wxString>( "via_size.thickness",
274 &m_ViaSize.thickness, "0.035" ) );
275
276 m_params.emplace_back( new PARAM<int>( "via_size.thickness_units",
277 &m_ViaSize.thickness_units, 0 ) );
278
279 m_params.emplace_back( new PARAM<wxString>( "via_size.length",
280 &m_ViaSize.length, "1.6" ) );
281
282 m_params.emplace_back( new PARAM<int>( "via_size.length_units", &m_ViaSize.length_units, 0 ) );
283
284 m_params.emplace_back( new PARAM<wxString>( "via_size.pad_diameter",
285 &m_ViaSize.pad_diameter, "0.6" ) );
286
287 m_params.emplace_back( new PARAM<int>( "via_size.pad_diameter_units",
288 &m_ViaSize.pad_diameter_units, 0 ) );
289
290 m_params.emplace_back( new PARAM<wxString>( "via_size.clearance_diameter",
291 &m_ViaSize.clearance_diameter, "1.0" ) );
292
293 m_params.emplace_back( new PARAM<int>( "via_size.clearance_diameter_units",
294 &m_ViaSize.clearance_diameter_units, 0 ) );
295
296 m_params.emplace_back( new PARAM<wxString>( "via_size.characteristic_impedance",
297 &m_ViaSize.characteristic_impedance, "50" ) );
298
299 m_params.emplace_back( new PARAM<int>( "via_size.characteristic_impedance_units",
300 &m_ViaSize.characteristic_impedance_units, 0 ) );
301
302 m_params.emplace_back( new PARAM<wxString>( "via_size.applied_current",
303 &m_ViaSize.applied_current, "1" ) );
304
305 m_params.emplace_back( new PARAM<wxString>( "via_size.plating_resistivity",
306 &m_ViaSize.plating_resistivity, "1.72e-8" ) );
307
308 m_params.emplace_back( new PARAM<wxString>( "via_size.permittivity",
309 &m_ViaSize.permittivity, "4.5" ) );
310
311 m_params.emplace_back( new PARAM<wxString>( "via_size.temp_rise",
312 &m_ViaSize.temp_rise, "10" ) );
313
314 m_params.emplace_back( new PARAM<wxString>( "via_size.pulse_rise_time",
315 &m_ViaSize.pulse_rise_time, "1" ) );
316
317 m_params.emplace_back( new PARAM<wxString>( "corrosion_table.threshold_voltage",
318 &m_CorrosionTable.threshold_voltage, "0" ) );
319
320 m_params.emplace_back( new PARAM<bool>( "corrosion_table.show_symbols",
321 &m_CorrosionTable.show_symbols, true ) );
322}
323
324
326{
327 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
328
329 ret &= fromLegacy<int>( aCfg, "BrdClass_selection", "board_class_units" );
330 ret &= fromLegacy<int>( aCfg, "CC_selection", "color_code_tolerance" );
331 ret &= fromLegacy<int>( aCfg, "Page_selection", "last_page" );
332
333 ret &= fromLegacy<int>( aCfg, "Att_selection", "attenuators.type" );
334
335 {
336 nlohmann::json::json_pointer ptr =
338
339 const std::array<std::string, 4> att_names = { "att_pi", "att_tee",
340 "att_bridge", "att_splitter" };
341 double val = 0;
342
343 for( const auto& att : att_names )
344 {
345 aCfg->SetPath( "Attenuators/" + att );
346 ptr.push_back( att );
347
348 if( aCfg->Read( "Attenuation", &val ) )
349 ( *m_internals )[ptr]["attenuation"] = val;
350
351 if( aCfg->Read( "Zin", &val ) )
352 ( *m_internals )[ptr]["zin"] = val;
353
354 if( aCfg->Read( "Zout", &val ) )
355 ( *m_internals )[ptr]["zout"] = val;
356
357 ptr.pop_back();
358 aCfg->SetPath( "../.." );
359 }
360 }
361
362 ret &= fromLegacy<int>( aCfg, "ElectSpacing_selection", "electrical.spacing_units" );
363 ret &= fromLegacyString( aCfg, "ElectSpacing_voltage", "electrical.spacing_voltage" );
364
365 ret &= fromLegacyString( aCfg, "RegulR1", "regulators.r1" );
366 ret &= fromLegacyString( aCfg, "RegulR2", "regulators.r2" );
367 ret &= fromLegacyString( aCfg, "RegulVREF", "regulators.vref" );
368 ret &= fromLegacyString( aCfg, "RegulVOUT", "regulators.vout" );
369 ret &= fromLegacyString( aCfg, "DataFilename", "regulators.data_file" );
370 ret &= fromLegacyString( aCfg, "RegulName", "regulators.selected_regulator" );
371 ret &= fromLegacy<int>( aCfg, "RegulType", "regulators.type" );
372 ret &= fromLegacy<int>( aCfg, "RegulLastParam", "regulators.last_param" );
373
374 ret &= fromLegacyString( aCfg, "TW_Track_Current", "track_width.current" );
375 ret &= fromLegacyString( aCfg, "TW_Delta_TC", "track_width.delta_tc" );
376 ret &= fromLegacyString( aCfg, "TW_Track_Len", "track_width.track_len" );
377 ret &= fromLegacy<int>( aCfg, "TW_Track_Len_Unit", "track_width.track_len_units" );
378 ret &= fromLegacyString( aCfg, "TW_Resistivity", "track_width.resistivity" );
379 ret &= fromLegacyString( aCfg, "TW_ExtTrack_Width", "track_width.ext_track_width" );
380 ret &= fromLegacy<int>( aCfg, "TW_ExtTrack_Width_Unit", "track_width.ext_track_width_units" );
381 ret &= fromLegacyString( aCfg, "TW_ExtTrack_Thickness", "track_width.ext_track_thickness" );
382 ret &= fromLegacy<int>( aCfg, "TW_ExtTrack_Thickness_Unit",
383 "track_width.ext_track_thickness_units" );
384 ret &= fromLegacyString( aCfg, "TW_IntTrack_Width", "track_width.int_track_width" );
385 ret &= fromLegacy<int>( aCfg, "TW_IntTrack_Width_Unit", "track_width.int_track_width_units" );
386 ret &= fromLegacyString( aCfg, "TW_IntTrack_Thickness", "track_width.int_track_thickness" );
387 ret &= fromLegacy<int>( aCfg, "TW_IntTrack_Thickness_Unit",
388 "track_width.int_track_thickness_units" );
389
390 ret &= fromLegacy<int>( aCfg, "Transline_selection", "trans_line.selection" );
391
392 {
393 nlohmann::json::json_pointer ptr =
395
396 wxString key;
397 double value = 0;
398 int units = 0;
399
400 const std::array<std::string, 9> transline_names = { "MicroStrip", "CoPlanar", "GrCoPlanar",
401 "RectWaveGuide", "Coax", "Coupled_MicroStrip", "Coupled_Stripline", "StripLine",
402 "TwistedPair" };
403
404 for( const auto& name : transline_names )
405 {
406 long index = 0;
407 aCfg->SetPath( name );
408 ptr.push_back( name );
409
410 while( aCfg->GetNextEntry( key, index ) )
411 {
412 // Keys look like "translineprmN" and "translineprmNunit"
413 wxString dest = key;
414 dest.Replace( "translineprm", wxEmptyString );
415
416 if( dest.EndsWith( "unit" ) )
417 {
418 dest.Replace( "unit", wxEmptyString );
419 aCfg->Read( key, &units );
420 ptr.push_back( "units" );
421
422 ( *m_internals )[ptr].push_back( { { dest.ToStdString(), units } } );
423
424 ptr.pop_back();
425 }
426 else
427 {
428 aCfg->Read( key, &value );
429 ptr.push_back( "values" );
430
431 ( *m_internals )[ptr].push_back( { { dest.ToStdString(), value } } );
432
433 ptr.pop_back();
434 }
435 }
436
437 ptr.pop_back();
438 aCfg->SetPath( ".." );
439 }
440 }
441
442 ret &= fromLegacyString( aCfg, "VS_Hole_Dia", "via_size.hole_diameter" );
443 ret &= fromLegacy<int>( aCfg, "VS_Hole_Dia_Unit", "via_size.hole_diameter_units" );
444 ret &= fromLegacyString( aCfg, "VS_Plating_Thickness", "via_size.thickness" );
445 ret &= fromLegacy<int>( aCfg, "VS_Plating_Thickness_Unit", "via_size.thickness_units" );
446 ret &= fromLegacyString( aCfg, "VS_Via_Length", "via_size.length" );
447 ret &= fromLegacy<int>( aCfg, "VS_Via_Length_Unit", "via_size.length_units" );
448 ret &= fromLegacyString( aCfg, "VS_Pad_Dia", "via_size.pad_diameter" );
449 ret &= fromLegacy<int>( aCfg, "VS_Pad_Dia_Unit", "via_size.pad_diameter_units" );
450 ret &= fromLegacyString( aCfg, "VS_Clearance_Dia", "via_size.clearance_diameter" );
451 ret &= fromLegacy<int>( aCfg, "VS_Clearance_Dia_Unit",
452 "via_size.clearance_diameter_units" );
453 ret &= fromLegacyString( aCfg, "VS_Characteristic_Impedance",
454 "via_size.characteristic_impedance" );
455 ret &= fromLegacy<int>( aCfg, "VS_Characteristic_Impedance_Unit",
456 "via_size.characteristic_impedance_units" );
457 ret &= fromLegacyString( aCfg, "VS_Current", "via_size.applied_current" );
458 ret &= fromLegacyString( aCfg, "VS_Resistivity", "via_size.plating_resistivity" );
459 ret &= fromLegacyString( aCfg, "VS_Permittivity", "via_size.permittivity" );
460 ret &= fromLegacyString( aCfg, "VS_Temperature_Differential", "via_size.temp_rise" );
461 ret &= fromLegacyString( aCfg, "VS_Pulse_Rise_Time", "via_size.pulse_rise_time" );
462
463 return ret;
464}
int index
const char * name
APP_SETTINGS_BASE(const std::string &aFilename, int aSchemaVersion)
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.
bool fromLegacyString(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig string value to a given JSON pointer value.
bool fromLegacy(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig value to a given JSON pointer value.
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
Represents a map of <std::string, Value>.
Definition parameters.h:736
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
const int pcbCalculatorSchemaVersion
! Update the schema version whenever a migration is required
#define DEFAULT_REGULATOR_RESTOL
#define DEFAULT_REGULATOR_IADJ_MAX
#define DEFAULT_REGULATOR_IADJ_TYP
#define DEFAULT_REGULATOR_R2
#define DEFAULT_REGULATOR_R1
#define DEFAULT_REGULATOR_VREF_TYP
#define DEFAULT_REGULATOR_VREF_MIN
#define DEFAULT_REGULATOR_VREF_MAX
#define DEFAULT_REGULATOR_VOUT_TYP
std::string path