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.r1", &m_Regulators.r1, "10" ) );
105
106 m_params.emplace_back( new PARAM<wxString>( "regulators.r2", &m_Regulators.r2, "10" ) );
107
108 m_params.emplace_back( new PARAM<wxString>( "regulators.vref", &m_Regulators.vref, "3" ) );
109
110 m_params.emplace_back( new PARAM<wxString>( "regulators.vout", &m_Regulators.vout, "12" ) );
111
112 m_params.emplace_back( new PARAM<wxString>( "regulators.data_file",
113 &m_Regulators.data_file, "" ) );
114
115 m_params.emplace_back( new PARAM<wxString>( "regulators.selected_regulator",
117
118 m_params.emplace_back( new PARAM<int>( "regulators.type", &m_Regulators.type, 0 ) );
119
120 m_params.emplace_back( new PARAM<int>( "regulators.last_param", &m_Regulators.last_param, 0 ) );
121
122 // cable_size params
123 m_params.emplace_back( new PARAM<wxString>( "cable_size.conductorMaterialResitivity",
125
126 m_params.emplace_back( new PARAM<wxString>( "cable_size.conductorTemperature",
128
129 m_params.emplace_back( new PARAM<wxString>( "cable_size.conductorThermalCoef",
131
132 m_params.emplace_back( new PARAM<int>( "cable_size.currentDensityChoice",
134
135 m_params.emplace_back(
136 new PARAM<int>( "cable_size.diameterUnit", &m_cableSize.diameterUnit, 0 ) );
137
138 m_params.emplace_back( new PARAM<int>( "cable_size.linResUnit", &m_cableSize.linResUnit, 0 ) );
139
140 m_params.emplace_back(
141 new PARAM<int>( "cable_size.frequencyUnit", &m_cableSize.frequencyUnit, 0 ) );
142
143 m_params.emplace_back( new PARAM<int>( "cable_size.lengthUnit", &m_cableSize.lengthUnit, 0 ) );
144
145 // wavelength params
146 m_params.emplace_back(
147 new PARAM<double>( "wavelength.frequency", &m_wavelength.frequency, 1e9 ) );
148
149 m_params.emplace_back(
150 new PARAM<double>( "wavelength.permeability", &m_wavelength.permeability, 1 ) );
151
152 m_params.emplace_back(
153 new PARAM<double>( "wavelength.permittivity", &m_wavelength.permittivity, 4.5 ) );
154
155 m_params.emplace_back(
156 new PARAM<int>( "wavelength.frequencyUnit", &m_wavelength.frequencyUnit, 0 ) );
157
158 m_params.emplace_back( new PARAM<int>( "wavelength.periodUnit", &m_wavelength.periodUnit, 0 ) );
159
160 m_params.emplace_back( new PARAM<int>( "wavelength.wavelengthVacuumUnit",
162
163 m_params.emplace_back( new PARAM<int>( "wavelength.wavelengthMediumUnit",
165
166 m_params.emplace_back( new PARAM<int>( "wavelength.speedUnit", &m_wavelength.speedUnit, 0 ) );
167
168 m_params.emplace_back( new PARAM<wxString>( "track_width.current",
169 &m_TrackWidth.current, "1.0" ) );
170
171 m_params.emplace_back( new PARAM<wxString>( "track_width.delta_tc",
172 &m_TrackWidth.delta_tc, "10.0" ) );
173
174 m_params.emplace_back( new PARAM<wxString>( "track_width.track_len",
175 &m_TrackWidth.track_len, "20" ) );
176
177 m_params.emplace_back( new PARAM<int>( "track_width.track_len_units",
179
180 m_params.emplace_back( new PARAM<wxString>( "track_width.resistivity",
181 &m_TrackWidth.resistivity, "1.72e-8" ) );
182
183 m_params.emplace_back( new PARAM<wxString>( "track_width.ext_track_width",
184 &m_TrackWidth.ext_track_width, "0.2" ) );
185
186 m_params.emplace_back( new PARAM<int>( "track_width.ext_track_width_units",
188
189 m_params.emplace_back( new PARAM<wxString>( "track_width.ext_track_thickness",
190 &m_TrackWidth.ext_track_thickness, "0.035" ) );
191
192 m_params.emplace_back( new PARAM<int>( "track_width.ext_track_thickness_units",
194
195 m_params.emplace_back( new PARAM<wxString>( "track_width.int_track_width",
196 &m_TrackWidth.int_track_width, "0.2" ) );
197
198 m_params.emplace_back( new PARAM<int>( "track_width.int_track_width_units",
200
201 m_params.emplace_back( new PARAM<wxString>( "track_width.int_track_thickness",
202 &m_TrackWidth.int_track_thickness, "0.035" ) );
203
204 m_params.emplace_back( new PARAM<int>( "track_width.int_track_thickness_units",
206
207 {
208 const std::array<std::string, 8> transline_names = { "MicroStrip", "CoPlanar", "GrCoPlanar",
209 "RectWaveGuide", "Coax", "Coupled_MicroStrip", "StripLine", "TwistedPair" };
210
211 for( const auto& name : transline_names )
212 {
215
216 std::string path = "trans_line." + name + ".";
217
218 m_params.emplace_back( new PARAM_MAP<double>( path + "values",
219 &m_TransLine.param_values.at( name ), {} ) );
220
221 m_params.emplace_back( new PARAM_MAP<int>( path + "units",
222 &m_TransLine.param_units.at( name ), {} ) );
223 }
224 }
225
226 m_params.emplace_back( new PARAM<wxString>( "via_size.hole_diameter",
227 &m_ViaSize.hole_diameter, "0.4" ) );
228
229 m_params.emplace_back( new PARAM<int>( "via_size.hole_diameter_units",
231
232 m_params.emplace_back( new PARAM<wxString>( "via_size.thickness",
233 &m_ViaSize.thickness, "0.035" ) );
234
235 m_params.emplace_back( new PARAM<int>( "via_size.thickness_units",
237
238 m_params.emplace_back( new PARAM<wxString>( "via_size.length",
239 &m_ViaSize.length, "1.6" ) );
240
241 m_params.emplace_back( new PARAM<int>( "via_size.length_units", &m_ViaSize.length_units, 0 ) );
242
243 m_params.emplace_back( new PARAM<wxString>( "via_size.pad_diameter",
244 &m_ViaSize.pad_diameter, "0.6" ) );
245
246 m_params.emplace_back( new PARAM<int>( "via_size.pad_diameter_units",
248
249 m_params.emplace_back( new PARAM<wxString>( "via_size.clearance_diameter",
250 &m_ViaSize.clearance_diameter, "1.0" ) );
251
252 m_params.emplace_back( new PARAM<int>( "via_size.clearance_diameter_units",
254
255 m_params.emplace_back( new PARAM<wxString>( "via_size.characteristic_impedance",
257
258 m_params.emplace_back( new PARAM<int>( "via_size.characteristic_impedance_units",
260
261 m_params.emplace_back( new PARAM<wxString>( "via_size.applied_current",
262 &m_ViaSize.applied_current, "1" ) );
263
264 m_params.emplace_back( new PARAM<wxString>( "via_size.plating_resistivity",
265 &m_ViaSize.plating_resistivity, "1.72e-8" ) );
266
267 m_params.emplace_back( new PARAM<wxString>( "via_size.permittivity",
268 &m_ViaSize.permittivity, "4.5" ) );
269
270 m_params.emplace_back( new PARAM<wxString>( "via_size.temp_rise",
271 &m_ViaSize.temp_rise, "10" ) );
272
273 m_params.emplace_back( new PARAM<wxString>( "via_size.pulse_rise_time",
274 &m_ViaSize.pulse_rise_time, "1" ) );
275
276 m_params.emplace_back( new PARAM<wxString>( "corrosion_table.threshold_voltage",
278
279}
280
281
283{
284 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
285
286 ret &= fromLegacy<int>( aCfg, "BrdClass_selection", "board_class_units" );
287 ret &= fromLegacy<int>( aCfg, "CC_selection", "color_code_tolerance" );
288 ret &= fromLegacy<int>( aCfg, "Page_selection", "last_page" );
289
290 ret &= fromLegacy<int>( aCfg, "Att_selection", "attenuators.type" );
291
292 {
293 nlohmann::json::json_pointer ptr =
295
296 const std::array<std::string, 4> att_names = { "att_pi", "att_tee",
297 "att_bridge", "att_splitter" };
298 double val = 0;
299
300 for( const auto& att : att_names )
301 {
302 aCfg->SetPath( "Attenuators/" + att );
303 ptr.push_back( att );
304
305 if( aCfg->Read( "Attenuation", &val ) )
306 ( *m_internals )[ptr]["attenuation"] = val;
307
308 if( aCfg->Read( "Zin", &val ) )
309 ( *m_internals )[ptr]["zin"] = val;
310
311 if( aCfg->Read( "Zout", &val ) )
312 ( *m_internals )[ptr]["zout"] = val;
313
314 ptr.pop_back();
315 aCfg->SetPath( "../.." );
316 }
317 }
318
319 ret &= fromLegacy<int>( aCfg, "ElectSpacing_selection", "electrical.spacing_units" );
320 ret &= fromLegacyString( aCfg, "ElectSpacing_voltage", "electrical.spacing_voltage" );
321
322 ret &= fromLegacyString( aCfg, "RegulR1", "regulators.r1" );
323 ret &= fromLegacyString( aCfg, "RegulR2", "regulators.r2" );
324 ret &= fromLegacyString( aCfg, "RegulVREF", "regulators.vref" );
325 ret &= fromLegacyString( aCfg, "RegulVOUT", "regulators.vout" );
326 ret &= fromLegacyString( aCfg, "DataFilename", "regulators.data_file" );
327 ret &= fromLegacyString( aCfg, "RegulName", "regulators.selected_regulator" );
328 ret &= fromLegacy<int>( aCfg, "RegulType", "regulators.type" );
329 ret &= fromLegacy<int>( aCfg, "RegulLastParam", "regulators.last_param" );
330
331 ret &= fromLegacyString( aCfg, "TW_Track_Current", "track_width.current" );
332 ret &= fromLegacyString( aCfg, "TW_Delta_TC", "track_width.delta_tc" );
333 ret &= fromLegacyString( aCfg, "TW_Track_Len", "track_width.track_len" );
334 ret &= fromLegacy<int>( aCfg, "TW_Track_Len_Unit", "track_width.track_len_units" );
335 ret &= fromLegacyString( aCfg, "TW_Resistivity", "track_width.resistivity" );
336 ret &= fromLegacyString( aCfg, "TW_ExtTrack_Width", "track_width.ext_track_width" );
337 ret &= fromLegacy<int>( aCfg, "TW_ExtTrack_Width_Unit", "track_width.ext_track_width_units" );
338 ret &= fromLegacyString( aCfg, "TW_ExtTrack_Thickness", "track_width.ext_track_thickness" );
339 ret &= fromLegacy<int>( aCfg, "TW_ExtTrack_Thickness_Unit",
340 "track_width.ext_track_thickness_units" );
341 ret &= fromLegacyString( aCfg, "TW_IntTrack_Width", "track_width.int_track_width" );
342 ret &= fromLegacy<int>( aCfg, "TW_IntTrack_Width_Unit", "track_width.int_track_width_units" );
343 ret &= fromLegacyString( aCfg, "TW_IntTrack_Thickness", "track_width.int_track_thickness" );
344 ret &= fromLegacy<int>( aCfg, "TW_IntTrack_Thickness_Unit",
345 "track_width.int_track_thickness_units" );
346
347 ret &= fromLegacy<int>( aCfg, "Transline_selection", "trans_line.selection" );
348
349 {
350 nlohmann::json::json_pointer ptr =
352
353 wxString key;
354 double value = 0;
355 int units = 0;
356
357 const std::array<std::string, 8> transline_names = { "MicroStrip", "CoPlanar", "GrCoPlanar",
358 "RectWaveGuide", "Coax", "Coupled_MicroStrip", "StripLine", "TwistedPair" };
359
360 for( const auto& name : transline_names )
361 {
362 long index = 0;
363 aCfg->SetPath( name );
364 ptr.push_back( name );
365
366 while( aCfg->GetNextEntry( key, index ) )
367 {
368 // Keys look like "translineprmN" and "translineprmNunit"
369 wxString dest = key;
370 dest.Replace( "translineprm", wxEmptyString );
371
372 if( dest.EndsWith( "unit" ) )
373 {
374 dest.Replace( "unit", wxEmptyString );
375 aCfg->Read( key, &units );
376 ptr.push_back( "units" );
377
378 ( *m_internals )[ptr].push_back( { { dest.ToStdString(), units } } );
379
380 ptr.pop_back();
381 }
382 else
383 {
384 aCfg->Read( key, &value );
385 ptr.push_back( "values" );
386
387 ( *m_internals )[ptr].push_back( { { dest.ToStdString(), value } } );
388
389 ptr.pop_back();
390 }
391 }
392
393 ptr.pop_back();
394 aCfg->SetPath( ".." );
395 }
396 }
397
398 ret &= fromLegacyString( aCfg, "VS_Hole_Dia", "via_size.hole_diameter" );
399 ret &= fromLegacy<int>( aCfg, "VS_Hole_Dia_Unit", "via_size.hole_diameter_units" );
400 ret &= fromLegacyString( aCfg, "VS_Plating_Thickness", "via_size.thickness" );
401 ret &= fromLegacy<int>( aCfg, "VS_Plating_Thickness_Unit", "via_size.thickness_units" );
402 ret &= fromLegacyString( aCfg, "VS_Via_Length", "via_size.length" );
403 ret &= fromLegacy<int>( aCfg, "VS_Via_Length_Unit", "via_size.length_units" );
404 ret &= fromLegacyString( aCfg, "VS_Pad_Dia", "via_size.pad_diameter" );
405 ret &= fromLegacy<int>( aCfg, "VS_Pad_Dia_Unit", "via_size.pad_diameter_units" );
406 ret &= fromLegacyString( aCfg, "VS_Clearance_Dia", "via_size.clearance_diameter" );
407 ret &= fromLegacy<int>( aCfg, "VS_Clearance_Dia_Unit",
408 "via_size.clearance_diameter_units" );
409 ret &= fromLegacyString( aCfg, "VS_Characteristic_Impedance",
410 "via_size.characteristic_impedance" );
411 ret &= fromLegacy<int>( aCfg, "VS_Characteristic_Impedance_Unit",
412 "via_size.characteristic_impedance_units" );
413 ret &= fromLegacyString( aCfg, "VS_Current", "via_size.applied_current" );
414 ret &= fromLegacyString( aCfg, "VS_Resistivity", "via_size.plating_resistivity" );
415 ret &= fromLegacyString( aCfg, "VS_Permittivity", "via_size.permittivity" );
416 ret &= fromLegacyString( aCfg, "VS_Temperature_Differential", "via_size.temp_rise" );
417 ret &= fromLegacyString( aCfg, "VS_Pulse_Rise_Time", "via_size.pulse_rise_time" );
418
419 return ret;
420}
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: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.