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