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 (C) 2023 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
37 APP_SETTINGS_BASE( "pcb_calculator", pcbCalculatorSchemaVersion ), m_Attenuators(),
38 m_BoardClassUnits( 0 ), m_ColorCodeTolerance( 0 ), m_Electrical(), m_LastPage( 0 ),
39 m_Regulators(), m_cableSize(), m_wavelength(), m_TrackWidth(), m_TransLine(), m_ViaSize()
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, 0 ) );
47
48 m_params.emplace_back( new PARAM<int>( "translines.type", &m_TransLine.type, 0 ) );
49
50 m_params.emplace_back( new PARAM<int>( "attenuators.type", &m_Attenuators.type, 0 ) );
51
52 const std::array<std::string, 4> att_names = { "att_pi", "att_tee",
53 "att_bridge", "att_splitter" };
54
55 for( const auto& att_name : att_names )
56 {
57 std::string path = "attenuators." + att_name;
58 m_Attenuators.attenuators[ att_name ] = ATTENUATOR();
59 ATTENUATOR* att = &m_Attenuators.attenuators[ att_name ];
60
61 m_params.emplace_back( new PARAM<double>( path + ".attenuation", &att->attenuation, 6.0 ) );
62 m_params.emplace_back( new PARAM<double>( path + ".zin", &att->zin, 50.0 ) );
63 m_params.emplace_back( new PARAM<double>( path + ".zout", &att->zout, 50.0 ) );
64 }
65
66 // Electrical spacing params
67 m_params.emplace_back( new PARAM<int>( "electrical.spacing_units",
69
70 m_params.emplace_back( new PARAM<wxString>( "electrical.spacing_voltage",
71 &m_Electrical.spacing_voltage, "500" ) );
72
73 m_params.emplace_back( new PARAM<double>( "electrical.iec60664_ratedVoltage",
75
76 m_params.emplace_back( new PARAM<int>( "electrical.iec60664_OVC",
78
79 m_params.emplace_back( new PARAM<double>( "electrical.iec60664_RMSvoltage",
81
82 m_params.emplace_back( new PARAM<double>( "electrical.iec60664_transientOV",
84
85 m_params.emplace_back( new PARAM<double>( "electrical.iec60664_peakOV",
87
88 m_params.emplace_back( new PARAM<int>( "electrical.iec60664_insulationType",
90
91 m_params.emplace_back( new PARAM<int>( "electrical.iec60664_pollutionDegree",
93
94 m_params.emplace_back( new PARAM<int>( "electrical.iec60664_materialGroup",
96
97 m_params.emplace_back( new PARAM<int>( "electrical.iec60664_pcbMaterial",
99
100 m_params.emplace_back( new PARAM<double>( "electrical.iec60664_altitude",
102
103 // Regulators params
104 m_params.emplace_back( new PARAM<wxString>( "regulators.resTol", &m_Regulators.resTol,
106
107 m_params.emplace_back(
108 new PARAM<wxString>( "regulators.r1", &m_Regulators.r1, DEFAULT_REGULATOR_R1 ) );
109
110 m_params.emplace_back(
111 new PARAM<wxString>( "regulators.r2", &m_Regulators.r2, DEFAULT_REGULATOR_R2 ) );
112
113 m_params.emplace_back( new PARAM<wxString>( "regulators.vrefMin", &m_Regulators.vrefMin,
115 m_params.emplace_back( new PARAM<wxString>( "regulators.vrefTyp", &m_Regulators.vrefTyp,
117 m_params.emplace_back( new PARAM<wxString>( "regulators.vrefMax", &m_Regulators.vrefMax,
119
120 m_params.emplace_back( new PARAM<wxString>( "regulators.voutTyp", &m_Regulators.voutTyp,
122
123 m_params.emplace_back( new PARAM<wxString>( "regulators.iadjTyp", &m_Regulators.iadjTyp,
125 m_params.emplace_back( new PARAM<wxString>( "regulators.iadjMax", &m_Regulators.iadjMax,
127
128 m_params.emplace_back( new PARAM<wxString>( "regulators.data_file",
129 &m_Regulators.data_file, "" ) );
130
131 m_params.emplace_back( new PARAM<wxString>( "regulators.selected_regulator",
133
134 m_params.emplace_back( new PARAM<int>( "regulators.type", &m_Regulators.type, 1 ) );
135
136 m_params.emplace_back( new PARAM<int>( "regulators.last_param", &m_Regulators.last_param, 0 ) );
137
138 // cable_size params
139 m_params.emplace_back( new PARAM<wxString>( "cable_size.conductorMaterialResitivity",
141
142 m_params.emplace_back( new PARAM<wxString>( "cable_size.conductorTemperature",
144
145 m_params.emplace_back( new PARAM<wxString>( "cable_size.conductorThermalCoef",
147
148 m_params.emplace_back( new PARAM<int>( "cable_size.currentDensityChoice",
150
151 m_params.emplace_back(
152 new PARAM<int>( "cable_size.diameterUnit", &m_cableSize.diameterUnit, 0 ) );
153
154 m_params.emplace_back( new PARAM<int>( "cable_size.linResUnit", &m_cableSize.linResUnit, 0 ) );
155
156 m_params.emplace_back(
157 new PARAM<int>( "cable_size.frequencyUnit", &m_cableSize.frequencyUnit, 0 ) );
158
159 m_params.emplace_back( new PARAM<int>( "cable_size.lengthUnit", &m_cableSize.lengthUnit, 0 ) );
160
161 // wavelength params
162 m_params.emplace_back(
163 new PARAM<double>( "wavelength.frequency", &m_wavelength.frequency, 1e9 ) );
164
165 m_params.emplace_back(
166 new PARAM<double>( "wavelength.permeability", &m_wavelength.permeability, 1 ) );
167
168 m_params.emplace_back(
169 new PARAM<double>( "wavelength.permittivity", &m_wavelength.permittivity, 4.5 ) );
170
171 m_params.emplace_back(
172 new PARAM<int>( "wavelength.frequencyUnit", &m_wavelength.frequencyUnit, 0 ) );
173
174 m_params.emplace_back( new PARAM<int>( "wavelength.periodUnit", &m_wavelength.periodUnit, 0 ) );
175
176 m_params.emplace_back( new PARAM<int>( "wavelength.wavelengthVacuumUnit",
178
179 m_params.emplace_back( new PARAM<int>( "wavelength.wavelengthMediumUnit",
181
182 m_params.emplace_back( new PARAM<int>( "wavelength.speedUnit", &m_wavelength.speedUnit, 0 ) );
183
184 m_params.emplace_back( new PARAM<wxString>( "track_width.current",
185 &m_TrackWidth.current, "1.0" ) );
186
187 m_params.emplace_back( new PARAM<wxString>( "track_width.delta_tc",
188 &m_TrackWidth.delta_tc, "10.0" ) );
189
190 m_params.emplace_back( new PARAM<wxString>( "track_width.track_len",
191 &m_TrackWidth.track_len, "20" ) );
192
193 m_params.emplace_back( new PARAM<int>( "track_width.track_len_units",
195
196 m_params.emplace_back( new PARAM<wxString>( "track_width.resistivity",
197 &m_TrackWidth.resistivity, "1.72e-8" ) );
198
199 m_params.emplace_back( new PARAM<wxString>( "track_width.ext_track_width",
200 &m_TrackWidth.ext_track_width, "0.2" ) );
201
202 m_params.emplace_back( new PARAM<int>( "track_width.ext_track_width_units",
204
205 m_params.emplace_back( new PARAM<wxString>( "track_width.ext_track_thickness",
207
208 m_params.emplace_back( new PARAM<int>( "track_width.ext_track_thickness_units",
210
211 m_params.emplace_back( new PARAM<wxString>( "track_width.int_track_width",
212 &m_TrackWidth.int_track_width, "0.2" ) );
213
214 m_params.emplace_back( new PARAM<int>( "track_width.int_track_width_units",
216
217 m_params.emplace_back( new PARAM<wxString>( "track_width.int_track_thickness",
219
220 m_params.emplace_back( new PARAM<int>( "track_width.int_track_thickness_units",
222
223 {
224 const std::array<std::string, 8> transline_names = { "MicroStrip", "CoPlanar", "GrCoPlanar",
225 "RectWaveGuide", "Coax", "Coupled_MicroStrip", "StripLine", "TwistedPair" };
226
227 for( const auto& name : transline_names )
228 {
231
232 std::string path = "trans_line." + name + ".";
233
234 m_params.emplace_back( new PARAM_MAP<double>( path + "values",
235 &m_TransLine.param_values.at( name ), {} ) );
236
237 m_params.emplace_back( new PARAM_MAP<int>( path + "units",
238 &m_TransLine.param_units.at( name ), {} ) );
239 }
240 }
241
242 m_params.emplace_back( new PARAM<wxString>( "via_size.hole_diameter",
243 &m_ViaSize.hole_diameter, "0.4" ) );
244
245 m_params.emplace_back( new PARAM<int>( "via_size.hole_diameter_units",
247
248 m_params.emplace_back( new PARAM<wxString>( "via_size.thickness",
249 &m_ViaSize.thickness, "0.035" ) );
250
251 m_params.emplace_back( new PARAM<int>( "via_size.thickness_units",
253
254 m_params.emplace_back( new PARAM<wxString>( "via_size.length",
255 &m_ViaSize.length, "1.6" ) );
256
257 m_params.emplace_back( new PARAM<int>( "via_size.length_units", &m_ViaSize.length_units, 0 ) );
258
259 m_params.emplace_back( new PARAM<wxString>( "via_size.pad_diameter",
260 &m_ViaSize.pad_diameter, "0.6" ) );
261
262 m_params.emplace_back( new PARAM<int>( "via_size.pad_diameter_units",
264
265 m_params.emplace_back( new PARAM<wxString>( "via_size.clearance_diameter",
266 &m_ViaSize.clearance_diameter, "1.0" ) );
267
268 m_params.emplace_back( new PARAM<int>( "via_size.clearance_diameter_units",
270
271 m_params.emplace_back( new PARAM<wxString>( "via_size.characteristic_impedance",
273
274 m_params.emplace_back( new PARAM<int>( "via_size.characteristic_impedance_units",
276
277 m_params.emplace_back( new PARAM<wxString>( "via_size.applied_current",
278 &m_ViaSize.applied_current, "1" ) );
279
280 m_params.emplace_back( new PARAM<wxString>( "via_size.plating_resistivity",
281 &m_ViaSize.plating_resistivity, "1.72e-8" ) );
282
283 m_params.emplace_back( new PARAM<wxString>( "via_size.permittivity",
284 &m_ViaSize.permittivity, "4.5" ) );
285
286 m_params.emplace_back( new PARAM<wxString>( "via_size.temp_rise",
287 &m_ViaSize.temp_rise, "10" ) );
288
289 m_params.emplace_back( new PARAM<wxString>( "via_size.pulse_rise_time",
290 &m_ViaSize.pulse_rise_time, "1" ) );
291
292 m_params.emplace_back( new PARAM<wxString>( "corrosion_table.threshold_voltage",
294
295 m_params.emplace_back( new PARAM<bool>( "corrosion_table.show_symbols",
297}
298
299
301{
302 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
303
304 ret &= fromLegacy<int>( aCfg, "BrdClass_selection", "board_class_units" );
305 ret &= fromLegacy<int>( aCfg, "CC_selection", "color_code_tolerance" );
306 ret &= fromLegacy<int>( aCfg, "Page_selection", "last_page" );
307
308 ret &= fromLegacy<int>( aCfg, "Att_selection", "attenuators.type" );
309
310 {
311 nlohmann::json::json_pointer ptr =
313
314 const std::array<std::string, 4> att_names = { "att_pi", "att_tee",
315 "att_bridge", "att_splitter" };
316 double val = 0;
317
318 for( const auto& att : att_names )
319 {
320 aCfg->SetPath( "Attenuators/" + att );
321 ptr.push_back( att );
322
323 if( aCfg->Read( "Attenuation", &val ) )
324 ( *m_internals )[ptr]["attenuation"] = val;
325
326 if( aCfg->Read( "Zin", &val ) )
327 ( *m_internals )[ptr]["zin"] = val;
328
329 if( aCfg->Read( "Zout", &val ) )
330 ( *m_internals )[ptr]["zout"] = val;
331
332 ptr.pop_back();
333 aCfg->SetPath( "../.." );
334 }
335 }
336
337 ret &= fromLegacy<int>( aCfg, "ElectSpacing_selection", "electrical.spacing_units" );
338 ret &= fromLegacyString( aCfg, "ElectSpacing_voltage", "electrical.spacing_voltage" );
339
340 ret &= fromLegacyString( aCfg, "RegulR1", "regulators.r1" );
341 ret &= fromLegacyString( aCfg, "RegulR2", "regulators.r2" );
342 ret &= fromLegacyString( aCfg, "RegulVREF", "regulators.vref" );
343 ret &= fromLegacyString( aCfg, "RegulVOUT", "regulators.vout" );
344 ret &= fromLegacyString( aCfg, "DataFilename", "regulators.data_file" );
345 ret &= fromLegacyString( aCfg, "RegulName", "regulators.selected_regulator" );
346 ret &= fromLegacy<int>( aCfg, "RegulType", "regulators.type" );
347 ret &= fromLegacy<int>( aCfg, "RegulLastParam", "regulators.last_param" );
348
349 ret &= fromLegacyString( aCfg, "TW_Track_Current", "track_width.current" );
350 ret &= fromLegacyString( aCfg, "TW_Delta_TC", "track_width.delta_tc" );
351 ret &= fromLegacyString( aCfg, "TW_Track_Len", "track_width.track_len" );
352 ret &= fromLegacy<int>( aCfg, "TW_Track_Len_Unit", "track_width.track_len_units" );
353 ret &= fromLegacyString( aCfg, "TW_Resistivity", "track_width.resistivity" );
354 ret &= fromLegacyString( aCfg, "TW_ExtTrack_Width", "track_width.ext_track_width" );
355 ret &= fromLegacy<int>( aCfg, "TW_ExtTrack_Width_Unit", "track_width.ext_track_width_units" );
356 ret &= fromLegacyString( aCfg, "TW_ExtTrack_Thickness", "track_width.ext_track_thickness" );
357 ret &= fromLegacy<int>( aCfg, "TW_ExtTrack_Thickness_Unit",
358 "track_width.ext_track_thickness_units" );
359 ret &= fromLegacyString( aCfg, "TW_IntTrack_Width", "track_width.int_track_width" );
360 ret &= fromLegacy<int>( aCfg, "TW_IntTrack_Width_Unit", "track_width.int_track_width_units" );
361 ret &= fromLegacyString( aCfg, "TW_IntTrack_Thickness", "track_width.int_track_thickness" );
362 ret &= fromLegacy<int>( aCfg, "TW_IntTrack_Thickness_Unit",
363 "track_width.int_track_thickness_units" );
364
365 ret &= fromLegacy<int>( aCfg, "Transline_selection", "trans_line.selection" );
366
367 {
368 nlohmann::json::json_pointer ptr =
370
371 wxString key;
372 double value = 0;
373 int units = 0;
374
375 const std::array<std::string, 8> transline_names = { "MicroStrip", "CoPlanar", "GrCoPlanar",
376 "RectWaveGuide", "Coax", "Coupled_MicroStrip", "StripLine", "TwistedPair" };
377
378 for( const auto& name : transline_names )
379 {
380 long index = 0;
381 aCfg->SetPath( name );
382 ptr.push_back( name );
383
384 while( aCfg->GetNextEntry( key, index ) )
385 {
386 // Keys look like "translineprmN" and "translineprmNunit"
387 wxString dest = key;
388 dest.Replace( "translineprm", wxEmptyString );
389
390 if( dest.EndsWith( "unit" ) )
391 {
392 dest.Replace( "unit", wxEmptyString );
393 aCfg->Read( key, &units );
394 ptr.push_back( "units" );
395
396 ( *m_internals )[ptr].push_back( { { dest.ToStdString(), units } } );
397
398 ptr.pop_back();
399 }
400 else
401 {
402 aCfg->Read( key, &value );
403 ptr.push_back( "values" );
404
405 ( *m_internals )[ptr].push_back( { { dest.ToStdString(), value } } );
406
407 ptr.pop_back();
408 }
409 }
410
411 ptr.pop_back();
412 aCfg->SetPath( ".." );
413 }
414 }
415
416 ret &= fromLegacyString( aCfg, "VS_Hole_Dia", "via_size.hole_diameter" );
417 ret &= fromLegacy<int>( aCfg, "VS_Hole_Dia_Unit", "via_size.hole_diameter_units" );
418 ret &= fromLegacyString( aCfg, "VS_Plating_Thickness", "via_size.thickness" );
419 ret &= fromLegacy<int>( aCfg, "VS_Plating_Thickness_Unit", "via_size.thickness_units" );
420 ret &= fromLegacyString( aCfg, "VS_Via_Length", "via_size.length" );
421 ret &= fromLegacy<int>( aCfg, "VS_Via_Length_Unit", "via_size.length_units" );
422 ret &= fromLegacyString( aCfg, "VS_Pad_Dia", "via_size.pad_diameter" );
423 ret &= fromLegacy<int>( aCfg, "VS_Pad_Dia_Unit", "via_size.pad_diameter_units" );
424 ret &= fromLegacyString( aCfg, "VS_Clearance_Dia", "via_size.clearance_diameter" );
425 ret &= fromLegacy<int>( aCfg, "VS_Clearance_Dia_Unit",
426 "via_size.clearance_diameter_units" );
427 ret &= fromLegacyString( aCfg, "VS_Characteristic_Impedance",
428 "via_size.characteristic_impedance" );
429 ret &= fromLegacy<int>( aCfg, "VS_Characteristic_Impedance_Unit",
430 "via_size.characteristic_impedance_units" );
431 ret &= fromLegacyString( aCfg, "VS_Current", "via_size.applied_current" );
432 ret &= fromLegacyString( aCfg, "VS_Resistivity", "via_size.plating_resistivity" );
433 ret &= fromLegacyString( aCfg, "VS_Permittivity", "via_size.permittivity" );
434 ret &= fromLegacyString( aCfg, "VS_Temperature_Differential", "via_size.temp_rise" );
435 ret &= fromLegacyString( aCfg, "VS_Pulse_Rise_Time", "via_size.pulse_rise_time" );
436
437 return ret;
438}
const char * name
Definition: DXF_plotter.cpp:57
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
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.
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
Represents a map of <std::string, Value>.
Definition: parameters.h:724
std::map< std::string, double > TL_PARAM_MAP
Map of TRANSLINE_PRM id to value.
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
std::map< std::string, int > TL_PARAM_UNITS_MAP
Map of TRANSLINE_PRM id to units selection.
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::unordered_map< std::string, ATTENUATOR > attenuators
std::map< std::string, TL_PARAM_MAP > param_values
Transline parameters, per transline type.
std::map< std::string, TL_PARAM_UNITS_MAP > param_units
Transline parameter units selections, per transline type.