KiCad PCB EDA Suite
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) 2022 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 m_params.emplace_back( new PARAM<int>( "electrical.spacing_units",
68
69 m_params.emplace_back( new PARAM<wxString>( "electrical.spacing_voltage",
70 &m_Electrical.spacing_voltage, "500" ) );
71
72 m_params.emplace_back( new PARAM<wxString>( "regulators.r1", &m_Regulators.r1, "10" ) );
73
74 m_params.emplace_back( new PARAM<wxString>( "regulators.r2", &m_Regulators.r2, "10" ) );
75
76 m_params.emplace_back( new PARAM<wxString>( "regulators.vref", &m_Regulators.vref, "3" ) );
77
78 m_params.emplace_back( new PARAM<wxString>( "regulators.vout", &m_Regulators.vout, "12" ) );
79
80 m_params.emplace_back( new PARAM<wxString>( "regulators.data_file",
81 &m_Regulators.data_file, "" ) );
82
83 m_params.emplace_back( new PARAM<wxString>( "regulators.selected_regulator",
85
86
87 m_params.emplace_back( new PARAM<wxString>( "cable_size.conductorMaterialResitivity",
89
90 m_params.emplace_back( new PARAM<wxString>( "cable_size.conductorTemperature",
92
93 m_params.emplace_back( new PARAM<wxString>( "cable_size.conductorThermalCoef",
95
96 m_params.emplace_back( new PARAM<int>( "regulators.type", &m_Regulators.type, 0 ) );
97
98 m_params.emplace_back( new PARAM<int>( "regulators.last_param", &m_Regulators.last_param, 0 ) );
99
100 m_params.emplace_back(
101 new PARAM<int>( "cable_size.diameterUnit", &m_cableSize.diameterUnit, 0 ) );
102
103 m_params.emplace_back( new PARAM<int>( "cable_size.linResUnit", &m_cableSize.linResUnit, 0 ) );
104
105 m_params.emplace_back(
106 new PARAM<int>( "cable_size.frequencyUnit", &m_cableSize.frequencyUnit, 0 ) );
107
108 m_params.emplace_back( new PARAM<int>( "cable_size.lengthUnit", &m_cableSize.lengthUnit, 0 ) );
109
110 m_params.emplace_back(
111 new PARAM<double>( "wavelength.frequency", &m_wavelength.frequency, 1e9 ) );
112
113 m_params.emplace_back(
114 new PARAM<double>( "wavelength.permeability", &m_wavelength.permeability, 1 ) );
115
116 m_params.emplace_back(
117 new PARAM<double>( "wavelength.permittivity", &m_wavelength.permittivity, 4.6 ) );
118
119 m_params.emplace_back(
120 new PARAM<int>( "wavelength.frequencyUnit", &m_wavelength.frequencyUnit, 0 ) );
121
122 m_params.emplace_back( new PARAM<int>( "wavelength.periodUnit", &m_wavelength.periodUnit, 0 ) );
123
124 m_params.emplace_back( new PARAM<int>( "wavelength.wavelengthVacuumUnit",
126
127 m_params.emplace_back( new PARAM<int>( "wavelength.wavelengthMediumUnit",
129
130 m_params.emplace_back( new PARAM<int>( "wavelength.speedUnit", &m_wavelength.speedUnit, 0 ) );
131
132 m_params.emplace_back( new PARAM<wxString>( "track_width.current",
133 &m_TrackWidth.current, "1.0" ) );
134
135 m_params.emplace_back( new PARAM<wxString>( "track_width.delta_tc",
136 &m_TrackWidth.delta_tc, "10.0" ) );
137
138 m_params.emplace_back( new PARAM<wxString>( "track_width.track_len",
139 &m_TrackWidth.track_len, "20" ) );
140
141 m_params.emplace_back( new PARAM<int>( "track_width.track_len_units",
143
144 m_params.emplace_back( new PARAM<wxString>( "track_width.resistivity",
145 &m_TrackWidth.resistivity, "1.72e-8" ) );
146
147 m_params.emplace_back( new PARAM<wxString>( "track_width.ext_track_width",
148 &m_TrackWidth.ext_track_width, "0.2" ) );
149
150 m_params.emplace_back( new PARAM<int>( "track_width.ext_track_width_units",
152
153 m_params.emplace_back( new PARAM<wxString>( "track_width.ext_track_thickness",
154 &m_TrackWidth.ext_track_thickness, "0.035" ) );
155
156 m_params.emplace_back( new PARAM<int>( "track_width.ext_track_thickness_units",
158
159 m_params.emplace_back( new PARAM<wxString>( "track_width.int_track_width",
160 &m_TrackWidth.int_track_width, "0.2" ) );
161
162 m_params.emplace_back( new PARAM<int>( "track_width.int_track_width_units",
164
165 m_params.emplace_back( new PARAM<wxString>( "track_width.int_track_thickness",
166 &m_TrackWidth.int_track_thickness, "0.035" ) );
167
168 m_params.emplace_back( new PARAM<int>( "track_width.int_track_thickness_units",
170
171 {
172 const std::array<std::string, 8> transline_names = { "MicroStrip", "CoPlanar", "GrCoPlanar",
173 "RectWaveGuide", "Coax", "Coupled_MicroStrip", "StripLine", "TwistedPair" };
174
175 for( const auto& name : transline_names )
176 {
179
180 std::string path = "trans_line." + name + ".";
181
182 m_params.emplace_back( new PARAM_MAP<double>( path + "values",
183 &m_TransLine.param_values.at( name ), {} ) );
184
185 m_params.emplace_back( new PARAM_MAP<int>( path + "units",
186 &m_TransLine.param_units.at( name ), {} ) );
187 }
188 }
189
190 m_params.emplace_back( new PARAM<wxString>( "via_size.hole_diameter",
191 &m_ViaSize.hole_diameter, "0.4" ) );
192
193 m_params.emplace_back( new PARAM<int>( "via_size.hole_diameter_units",
195
196 m_params.emplace_back( new PARAM<wxString>( "via_size.thickness",
197 &m_ViaSize.thickness, "0.035" ) );
198
199 m_params.emplace_back( new PARAM<int>( "via_size.thickness_units",
201
202 m_params.emplace_back( new PARAM<wxString>( "via_size.length",
203 &m_ViaSize.length, "1.6" ) );
204
205 m_params.emplace_back( new PARAM<int>( "via_size.length_units", &m_ViaSize.length_units, 0 ) );
206
207 m_params.emplace_back( new PARAM<wxString>( "via_size.pad_diameter",
208 &m_ViaSize.pad_diameter, "0.6" ) );
209
210 m_params.emplace_back( new PARAM<int>( "via_size.pad_diameter_units",
212
213 m_params.emplace_back( new PARAM<wxString>( "via_size.clearance_diameter",
214 &m_ViaSize.clearance_diameter, "1.0" ) );
215
216 m_params.emplace_back( new PARAM<int>( "via_size.clearance_diameter_units",
218
219 m_params.emplace_back( new PARAM<wxString>( "via_size.characteristic_impedance",
221
222 m_params.emplace_back( new PARAM<int>( "via_size.characteristic_impedance_units",
224
225 m_params.emplace_back( new PARAM<wxString>( "via_size.applied_current",
226 &m_ViaSize.applied_current, "1" ) );
227
228 m_params.emplace_back( new PARAM<wxString>( "via_size.plating_resistivity",
229 &m_ViaSize.plating_resistivity, "1.72e-8" ) );
230
231 m_params.emplace_back( new PARAM<wxString>( "via_size.permittivity",
232 &m_ViaSize.permittivity, "4.5" ) );
233
234 m_params.emplace_back( new PARAM<wxString>( "via_size.temp_rise",
235 &m_ViaSize.temp_rise, "10" ) );
236
237 m_params.emplace_back( new PARAM<wxString>( "via_size.pulse_rise_time",
238 &m_ViaSize.pulse_rise_time, "1" ) );
239
240 m_params.emplace_back( new PARAM<wxString>( "corrosion_table.threshold_voltage",
242
243}
244
245
247{
248 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
249
250 ret &= fromLegacy<int>( aCfg, "BrdClass_selection", "board_class_units" );
251 ret &= fromLegacy<int>( aCfg, "CC_selection", "color_code_tolerance" );
252 ret &= fromLegacy<int>( aCfg, "Page_selection", "last_page" );
253
254 ret &= fromLegacy<int>( aCfg, "Att_selection", "attenuators.type" );
255
256 {
257 nlohmann::json::json_pointer ptr =
259
260 const std::array<std::string, 4> att_names = { "att_pi", "att_tee",
261 "att_bridge", "att_splitter" };
262 double val = 0;
263
264 for( const auto& att : att_names )
265 {
266 aCfg->SetPath( "Attenuators/" + att );
267 ptr.push_back( att );
268
269 if( aCfg->Read( "Attenuation", &val ) )
270 ( *m_internals )[ptr]["attenuation"] = val;
271
272 if( aCfg->Read( "Zin", &val ) )
273 ( *m_internals )[ptr]["zin"] = val;
274
275 if( aCfg->Read( "Zout", &val ) )
276 ( *m_internals )[ptr]["zout"] = val;
277
278 ptr.pop_back();
279 aCfg->SetPath( "../.." );
280 }
281 }
282
283 ret &= fromLegacy<int>( aCfg, "ElectSpacing_selection", "electrical.spacing_units" );
284 ret &= fromLegacyString( aCfg, "ElectSpacing_voltage", "electrical.spacing_voltage" );
285
286 ret &= fromLegacyString( aCfg, "RegulR1", "regulators.r1" );
287 ret &= fromLegacyString( aCfg, "RegulR2", "regulators.r2" );
288 ret &= fromLegacyString( aCfg, "RegulVREF", "regulators.vref" );
289 ret &= fromLegacyString( aCfg, "RegulVOUT", "regulators.vout" );
290 ret &= fromLegacyString( aCfg, "DataFilename", "regulators.data_file" );
291 ret &= fromLegacyString( aCfg, "RegulName", "regulators.selected_regulator" );
292 ret &= fromLegacy<int>( aCfg, "RegulType", "regulators.type" );
293 ret &= fromLegacy<int>( aCfg, "RegulLastParam", "regulators.last_param" );
294
295 ret &= fromLegacyString( aCfg, "TW_Track_Current", "track_width.current" );
296 ret &= fromLegacyString( aCfg, "TW_Delta_TC", "track_width.delta_tc" );
297 ret &= fromLegacyString( aCfg, "TW_Track_Len", "track_width.track_len" );
298 ret &= fromLegacy<int>( aCfg, "TW_Track_Len_Unit", "track_width.track_len_units" );
299 ret &= fromLegacyString( aCfg, "TW_Resistivity", "track_width.resistivity" );
300 ret &= fromLegacyString( aCfg, "TW_ExtTrack_Width", "track_width.ext_track_width" );
301 ret &= fromLegacy<int>( aCfg, "TW_ExtTrack_Width_Unit", "track_width.ext_track_width_units" );
302 ret &= fromLegacyString( aCfg, "TW_ExtTrack_Thickness", "track_width.ext_track_thickness" );
303 ret &= fromLegacy<int>( aCfg, "TW_ExtTrack_Thickness_Unit",
304 "track_width.ext_track_thickness_units" );
305 ret &= fromLegacyString( aCfg, "TW_IntTrack_Width", "track_width.int_track_width" );
306 ret &= fromLegacy<int>( aCfg, "TW_IntTrack_Width_Unit", "track_width.int_track_width_units" );
307 ret &= fromLegacyString( aCfg, "TW_IntTrack_Thickness", "track_width.int_track_thickness" );
308 ret &= fromLegacy<int>( aCfg, "TW_IntTrack_Thickness_Unit",
309 "track_width.int_track_thickness_units" );
310
311 ret &= fromLegacy<int>( aCfg, "Transline_selection", "trans_line.selection" );
312
313 {
314 nlohmann::json::json_pointer ptr =
316
317 wxString key;
318 double value = 0;
319 int units = 0;
320
321 const std::array<std::string, 8> transline_names = { "MicroStrip", "CoPlanar", "GrCoPlanar",
322 "RectWaveGuide", "Coax", "Coupled_MicroStrip", "StripLine", "TwistedPair" };
323
324 for( const auto& name : transline_names )
325 {
326 long index = 0;
327 aCfg->SetPath( name );
328 ptr.push_back( name );
329
330 while( aCfg->GetNextEntry( key, index ) )
331 {
332 // Keys look like "translineprmN" and "translineprmNunit"
333 wxString dest = key;
334 dest.Replace( "translineprm", wxEmptyString );
335
336 if( dest.EndsWith( "unit" ) )
337 {
338 dest.Replace( "unit", wxEmptyString );
339 aCfg->Read( key, &units );
340 ptr.push_back( "units" );
341
342 ( *m_internals )[ptr].push_back( { { dest.ToStdString(), units } } );
343
344 ptr.pop_back();
345 }
346 else
347 {
348 aCfg->Read( key, &value );
349 ptr.push_back( "values" );
350
351 ( *m_internals )[ptr].push_back( { { dest.ToStdString(), value } } );
352
353 ptr.pop_back();
354 }
355 }
356
357 ptr.pop_back();
358 aCfg->SetPath( ".." );
359 }
360 }
361
362 ret &= fromLegacyString( aCfg, "VS_Hole_Dia", "via_size.hole_diameter" );
363 ret &= fromLegacy<int>( aCfg, "VS_Hole_Dia_Unit", "via_size.hole_diameter_units" );
364 ret &= fromLegacyString( aCfg, "VS_Plating_Thickness", "via_size.thickness" );
365 ret &= fromLegacy<int>( aCfg, "VS_Plating_Thickness_Unit", "via_size.thickness_units" );
366 ret &= fromLegacyString( aCfg, "VS_Via_Length", "via_size.length" );
367 ret &= fromLegacy<int>( aCfg, "VS_Via_Length_Unit", "via_size.length_units" );
368 ret &= fromLegacyString( aCfg, "VS_Pad_Dia", "via_size.pad_diameter" );
369 ret &= fromLegacy<int>( aCfg, "VS_Pad_Dia_Unit", "via_size.pad_diameter_units" );
370 ret &= fromLegacyString( aCfg, "VS_Clearance_Dia", "via_size.clearance_diameter" );
371 ret &= fromLegacy<int>( aCfg, "VS_Clearance_Dia_Unit",
372 "via_size.clearance_diameter_units" );
373 ret &= fromLegacyString( aCfg, "VS_Characteristic_Impedance",
374 "via_size.characteristic_impedance" );
375 ret &= fromLegacy<int>( aCfg, "VS_Characteristic_Impedance_Unit",
376 "via_size.characteristic_impedance_units" );
377 ret &= fromLegacyString( aCfg, "VS_Current", "via_size.applied_current" );
378 ret &= fromLegacyString( aCfg, "VS_Resistivity", "via_size.plating_resistivity" );
379 ret &= fromLegacyString( aCfg, "VS_Permittivity", "via_size.permittivity" );
380 ret &= fromLegacyString( aCfg, "VS_Temperature_Differential", "via_size.temp_rise" );
381 ret &= fromLegacyString( aCfg, "VS_Pulse_Rise_Time", "via_size.pulse_rise_time" );
382
383 return ret;
384}
const char * name
Definition: DXF_plotter.cpp:56
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:110
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:548
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
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.