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) 2020 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 ),
38  m_Attenuators(),
39  m_BoardClassUnits( 0 ),
40  m_ColorCodeTolerance( 0 ),
41  m_Electrical(),
42  m_LastPage( 0 ),
43  m_Regulators(),
44  m_TrackWidth(),
45  m_TransLine(),
46  m_ViaSize()
47 {
48  // Build settings:
49  m_params.emplace_back( new PARAM<int>( "board_class_units", &m_BoardClassUnits, 0 ) );
50 
51  m_params.emplace_back( new PARAM<int>( "color_code_tolerance", &m_ColorCodeTolerance, 0 ) );
52 
53  m_params.emplace_back( new PARAM<int>( "last_page", &m_LastPage, 0 ) );
54 
55  m_params.emplace_back( new PARAM<int>( "translines.type", &m_TransLine.type, 0 ) );
56 
57  m_params.emplace_back( new PARAM<int>( "attenuators.type", &m_Attenuators.type, 0 ) );
58 
59  const std::array<std::string, 4> att_names = { "att_pi", "att_tee",
60  "att_bridge", "att_splitter" };
61 
62  for( const auto& att_name : att_names )
63  {
64  std::string path = "attenuators." + att_name;
65  m_Attenuators.attenuators[ att_name ] = ATTENUATOR();
66  ATTENUATOR* att = &m_Attenuators.attenuators[ att_name ];
67 
68  m_params.emplace_back( new PARAM<double>( path + ".attenuation", &att->attenuation, 6.0 ) );
69  m_params.emplace_back( new PARAM<double>( path + ".zin", &att->zin, 50.0 ) );
70  m_params.emplace_back( new PARAM<double>( path + ".zout", &att->zout, 50.0 ) );
71  }
72 
73  m_params.emplace_back( new PARAM<int>( "electrical.spacing_units",
75 
76  m_params.emplace_back( new PARAM<wxString>( "electrical.spacing_voltage",
77  &m_Electrical.spacing_voltage, "500" ) );
78 
79  m_params.emplace_back( new PARAM<wxString>( "regulators.r1", &m_Regulators.r1, "10" ) );
80 
81  m_params.emplace_back( new PARAM<wxString>( "regulators.r2", &m_Regulators.r2, "10" ) );
82 
83  m_params.emplace_back( new PARAM<wxString>( "regulators.vref", &m_Regulators.vref, "3" ) );
84 
85  m_params.emplace_back( new PARAM<wxString>( "regulators.vout", &m_Regulators.vout, "12" ) );
86 
87  m_params.emplace_back( new PARAM<wxString>( "regulators.data_file",
88  &m_Regulators.data_file, "" ) );
89 
90  m_params.emplace_back( new PARAM<wxString>( "regulators.selected_regulator",
92 
93  m_params.emplace_back( new PARAM<int>( "regulators.type", &m_Regulators.type, 0 ) );
94 
95  m_params.emplace_back( new PARAM<int>( "regulators.last_param", &m_Regulators.last_param, 0 ) );
96 
97  m_params.emplace_back( new PARAM<wxString>( "track_width.current",
98  &m_TrackWidth.current, "1.0" ) );
99 
100  m_params.emplace_back( new PARAM<wxString>( "track_width.delta_tc",
101  &m_TrackWidth.delta_tc, "10.0" ) );
102 
103  m_params.emplace_back( new PARAM<wxString>( "track_width.track_len",
104  &m_TrackWidth.track_len, "20" ) );
105 
106  m_params.emplace_back( new PARAM<int>( "track_width.track_len_units",
108 
109  m_params.emplace_back( new PARAM<wxString>( "track_width.resistivity",
110  &m_TrackWidth.resistivity, "1.72e-8" ) );
111 
112  m_params.emplace_back( new PARAM<wxString>( "track_width.ext_track_width",
113  &m_TrackWidth.ext_track_width, "0.2" ) );
114 
115  m_params.emplace_back( new PARAM<int>( "track_width.ext_track_width_units",
117 
118  m_params.emplace_back( new PARAM<wxString>( "track_width.ext_track_thickness",
119  &m_TrackWidth.ext_track_thickness, "0.035" ) );
120 
121  m_params.emplace_back( new PARAM<int>( "track_width.ext_track_thickness_units",
123 
124  m_params.emplace_back( new PARAM<wxString>( "track_width.int_track_width",
125  &m_TrackWidth.int_track_width, "0.2" ) );
126 
127  m_params.emplace_back( new PARAM<int>( "track_width.int_track_width_units",
129 
130  m_params.emplace_back( new PARAM<wxString>( "track_width.int_track_thickness",
131  &m_TrackWidth.int_track_thickness, "0.035" ) );
132 
133  m_params.emplace_back( new PARAM<int>( "track_width.int_track_thickness_units",
135 
136  {
137  const std::array<std::string, 8> transline_names = { "MicroStrip", "CoPlanar", "GrCoPlanar",
138  "RectWaveGuide", "Coax", "Coupled_MicroStrip", "StripLine", "TwistedPair" };
139 
140  for( const auto& name : transline_names )
141  {
144 
145  std::string path = "trans_line." + name + ".";
146 
147  m_params.emplace_back( new PARAM_MAP<double>( path + "values",
148  &m_TransLine.param_values.at( name ), {} ) );
149 
150  m_params.emplace_back( new PARAM_MAP<int>( path + "units",
151  &m_TransLine.param_units.at( name ), {} ) );
152  }
153  }
154 
155  m_params.emplace_back( new PARAM<wxString>( "via_size.hole_diameter",
156  &m_ViaSize.hole_diameter, "0.4" ) );
157 
158  m_params.emplace_back( new PARAM<int>( "via_size.hole_diameter_units",
160 
161  m_params.emplace_back( new PARAM<wxString>( "via_size.thickness",
162  &m_ViaSize.thickness, "0.035" ) );
163 
164  m_params.emplace_back( new PARAM<int>( "via_size.thickness_units",
165  &m_ViaSize.thickness_units, 0 ) );
166 
167  m_params.emplace_back( new PARAM<wxString>( "via_size.length",
168  &m_ViaSize.length, "1.6" ) );
169 
170  m_params.emplace_back( new PARAM<int>( "via_size.length_units", &m_ViaSize.length_units, 0 ) );
171 
172  m_params.emplace_back( new PARAM<wxString>( "via_size.pad_diameter",
173  &m_ViaSize.pad_diameter, "0.6" ) );
174 
175  m_params.emplace_back( new PARAM<int>( "via_size.pad_diameter_units",
177 
178  m_params.emplace_back( new PARAM<wxString>( "via_size.clearance_diameter",
179  &m_ViaSize.clearance_diameter, "1.0" ) );
180 
181  m_params.emplace_back( new PARAM<int>( "via_size.clearance_diameter_units",
183 
184  m_params.emplace_back( new PARAM<wxString>( "via_size.characteristic_impedance",
186 
187  m_params.emplace_back( new PARAM<int>( "via_size.characteristic_impedance_units",
189 
190  m_params.emplace_back( new PARAM<wxString>( "via_size.applied_current",
191  &m_ViaSize.applied_current, "1" ) );
192 
193  m_params.emplace_back( new PARAM<wxString>( "via_size.plating_resistivity",
194  &m_ViaSize.plating_resistivity, "1.72e-8" ) );
195 
196  m_params.emplace_back( new PARAM<wxString>( "via_size.permittivity",
197  &m_ViaSize.permittivity, "4.5" ) );
198 
199  m_params.emplace_back( new PARAM<wxString>( "via_size.temp_rise",
200  &m_ViaSize.temp_rise, "10" ) );
201 
202  m_params.emplace_back( new PARAM<wxString>( "via_size.pulse_rise_time",
203  &m_ViaSize.pulse_rise_time, "1" ) );
204 }
205 
206 
208 {
209  bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
210 
211  ret &= fromLegacy<int>( aCfg, "BrdClass_selection", "board_class_units" );
212  ret &= fromLegacy<int>( aCfg, "CC_selection", "color_code_tolerance" );
213  ret &= fromLegacy<int>( aCfg, "Page_selection", "last_page" );
214 
215  ret &= fromLegacy<int>( aCfg, "Att_selection", "attenuators.type" );
216 
217  {
218  nlohmann::json::json_pointer ptr =
220 
221  const std::array<std::string, 4> att_names = { "att_pi", "att_tee",
222  "att_bridge", "att_splitter" };
223  double val = 0;
224 
225  for( const auto& att : att_names )
226  {
227  aCfg->SetPath( "Attenuators/" + att );
228  ptr.push_back( att );
229 
230  if( aCfg->Read( "Attenuation", &val ) )
231  ( *m_internals )[ptr]["attenuation"] = val;
232 
233  if( aCfg->Read( "Zin", &val ) )
234  ( *m_internals )[ptr]["zin"] = val;
235 
236  if( aCfg->Read( "Zout", &val ) )
237  ( *m_internals )[ptr]["zout"] = val;
238 
239  ptr.pop_back();
240  aCfg->SetPath( "../.." );
241  }
242  }
243 
244  ret &= fromLegacy<int>( aCfg, "ElectSpacing_selection", "electrical.spacing_units" );
245  ret &= fromLegacyString( aCfg, "ElectSpacing_voltage", "electrical.spacing_voltage" );
246 
247  ret &= fromLegacyString( aCfg, "RegulR1", "regulators.r1" );
248  ret &= fromLegacyString( aCfg, "RegulR2", "regulators.r2" );
249  ret &= fromLegacyString( aCfg, "RegulVREF", "regulators.vref" );
250  ret &= fromLegacyString( aCfg, "RegulVOUT", "regulators.vout" );
251  ret &= fromLegacyString( aCfg, "DataFilename", "regulators.data_file" );
252  ret &= fromLegacyString( aCfg, "RegulName", "regulators.selected_regulator" );
253  ret &= fromLegacy<int>( aCfg, "RegulType", "regulators.type" );
254  ret &= fromLegacy<int>( aCfg, "RegulLastParam", "regulators.last_param" );
255 
256  ret &= fromLegacyString( aCfg, "TW_Track_Current", "track_width.current" );
257  ret &= fromLegacyString( aCfg, "TW_Delta_TC", "track_width.delta_tc" );
258  ret &= fromLegacyString( aCfg, "TW_Track_Len", "track_width.track_len" );
259  ret &= fromLegacy<int>( aCfg, "TW_Track_Len_Unit", "track_width.track_len_units" );
260  ret &= fromLegacyString( aCfg, "TW_Resistivity", "track_width.resistivity" );
261  ret &= fromLegacyString( aCfg, "TW_ExtTrack_Width", "track_width.ext_track_width" );
262  ret &= fromLegacy<int>( aCfg, "TW_ExtTrack_Width_Unit", "track_width.ext_track_width_units" );
263  ret &= fromLegacyString( aCfg, "TW_ExtTrack_Thickness", "track_width.ext_track_thickness" );
264  ret &= fromLegacy<int>( aCfg, "TW_ExtTrack_Thickness_Unit",
265  "track_width.ext_track_thickness_units" );
266  ret &= fromLegacyString( aCfg, "TW_IntTrack_Width", "track_width.int_track_width" );
267  ret &= fromLegacy<int>( aCfg, "TW_IntTrack_Width_Unit", "track_width.int_track_width_units" );
268  ret &= fromLegacyString( aCfg, "TW_IntTrack_Thickness", "track_width.int_track_thickness" );
269  ret &= fromLegacy<int>( aCfg, "TW_IntTrack_Thickness_Unit",
270  "track_width.int_track_thickness_units" );
271 
272  ret &= fromLegacy<int>( aCfg, "Transline_selection", "trans_line.selection" );
273 
274  {
275  nlohmann::json::json_pointer ptr =
277 
278  wxString key;
279  double value = 0;
280  int units = 0;
281 
282  const std::array<std::string, 8> transline_names = { "MicroStrip", "CoPlanar", "GrCoPlanar",
283  "RectWaveGuide", "Coax", "Coupled_MicroStrip", "StripLine", "TwistedPair" };
284 
285  for( const auto& name : transline_names )
286  {
287  long index = 0;
288  aCfg->SetPath( name );
289  ptr.push_back( name );
290 
291  while( aCfg->GetNextEntry( key, index ) )
292  {
293  // Keys look like "translineprmN" and "translineprmNunit"
294  wxString dest = key;
295  dest.Replace( "translineprm", wxEmptyString );
296 
297  if( dest.EndsWith( "unit" ) )
298  {
299  dest.Replace( "unit", wxEmptyString );
300  aCfg->Read( key, &units );
301  ptr.push_back( "units" );
302 
303  ( *m_internals )[ptr].push_back( { { dest.ToStdString(), units } } );
304 
305  ptr.pop_back();
306  }
307  else
308  {
309  aCfg->Read( key, &value );
310  ptr.push_back( "values" );
311 
312  ( *m_internals )[ptr].push_back( { { dest.ToStdString(), value } } );
313 
314  ptr.pop_back();
315  }
316  }
317 
318  ptr.pop_back();
319  aCfg->SetPath( ".." );
320  }
321  }
322 
323  ret &= fromLegacyString( aCfg, "VS_Hole_Dia", "via_size.hole_diameter" );
324  ret &= fromLegacy<int>( aCfg, "VS_Hole_Dia_Unit", "via_size.hole_diameter_units" );
325  ret &= fromLegacyString( aCfg, "VS_Plating_Thickness", "via_size.thickness" );
326  ret &= fromLegacy<int>( aCfg, "VS_Plating_Thickness_Unit", "via_size.thickness_units" );
327  ret &= fromLegacyString( aCfg, "VS_Via_Length", "via_size.length" );
328  ret &= fromLegacy<int>( aCfg, "VS_Via_Length_Unit", "via_size.length_units" );
329  ret &= fromLegacyString( aCfg, "VS_Pad_Dia", "via_size.pad_diameter" );
330  ret &= fromLegacy<int>( aCfg, "VS_Pad_Dia_Unit", "via_size.pad_diameter_units" );
331  ret &= fromLegacyString( aCfg, "VS_Clearance_Dia", "via_size.clearance_diameter" );
332  ret &= fromLegacy<int>( aCfg, "VS_Clearance_Dia_Unit",
333  "via_size.clearance_diameter_units" );
334  ret &= fromLegacyString( aCfg, "VS_Characteristic_Impedance",
335  "via_size.characteristic_impedance" );
336  ret &= fromLegacy<int>( aCfg, "VS_Characteristic_Impedance_Unit",
337  "via_size.characteristic_impedance_units" );
338  ret &= fromLegacyString( aCfg, "VS_Current", "via_size.applied_current" );
339  ret &= fromLegacyString( aCfg, "VS_Resistivity", "via_size.plating_resistivity" );
340  ret &= fromLegacyString( aCfg, "VS_Permittivity", "via_size.permittivity" );
341  ret &= fromLegacyString( aCfg, "VS_Temperature_Differential", "via_size.temp_rise" );
342  ret &= fromLegacyString( aCfg, "VS_Pulse_Rise_Time", "via_size.pulse_rise_time" );
343 
344  return ret;
345 }
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
std::map< std::string, TL_PARAM_MAP > param_values
Transline parameters, per transline type.
Represents a map of <std::string, Value>.
Definition: parameters.h:511
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
std::map< std::string, double > TL_PARAM_MAP
Map of TRANSLINE_PRM id to value.
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.
std::map< std::string, TL_PARAM_UNITS_MAP > param_units
Transline parameter units selections, per transline type.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
std::unique_ptr< JSON_SETTINGS_INTERNALS > m_internals
const int pcbCalculatorSchemaVersion
! Update the schema version whenever a migration is required
std::unordered_map< std::string, ATTENUATOR > attenuators
std::map< std::string, int > TL_PARAM_UNITS_MAP
Map of TRANSLINE_PRM id to units selection.
bool fromLegacyString(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig string value to a given JSON pointer value.
const char * name
Definition: DXF_plotter.cpp:56