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>
27 #include <settings/parameters.h>
28 #include <wx/config.h>
29 
30 
33 
34 
37 {
38  // Make Coverity happy:
41  m_LastPage = 0;
42 
43  // Build settings:
44  m_params.emplace_back( new PARAM<int>( "board_class_units", &m_BoardClassUnits, 0 ) );
45 
46  m_params.emplace_back( new PARAM<int>( "color_code_tolerance", &m_ColorCodeTolerance, 0 ) );
47 
48  m_params.emplace_back( new PARAM<int>( "last_page", &m_LastPage, 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  m_params.emplace_back( new PARAM<int>( "regulators.type", &m_Regulators.type, 0 ) );
87 
88  m_params.emplace_back( new PARAM<int>( "regulators.last_param", &m_Regulators.last_param, 0 ) );
89 
90  m_params.emplace_back( new PARAM<wxString>( "track_width.current",
91  &m_TrackWidth.current, "1.0" ) );
92 
93  m_params.emplace_back( new PARAM<wxString>( "track_width.delta_tc",
94  &m_TrackWidth.delta_tc, "10.0" ) );
95 
96  m_params.emplace_back( new PARAM<wxString>( "track_width.track_len",
97  &m_TrackWidth.track_len, "20" ) );
98 
99  m_params.emplace_back( new PARAM<int>( "track_width.track_len_units",
101 
102  m_params.emplace_back( new PARAM<wxString>( "track_width.resistivity",
103  &m_TrackWidth.resistivity, "1.72e-8" ) );
104 
105  m_params.emplace_back( new PARAM<wxString>( "track_width.ext_track_width",
106  &m_TrackWidth.ext_track_width, "0.2" ) );
107 
108  m_params.emplace_back( new PARAM<int>( "track_width.ext_track_width_units",
110 
111  m_params.emplace_back( new PARAM<wxString>( "track_width.ext_track_thickness",
112  &m_TrackWidth.ext_track_thickness, "0.035" ) );
113 
114  m_params.emplace_back( new PARAM<int>( "track_width.ext_track_thickness_units",
116 
117  m_params.emplace_back( new PARAM<wxString>( "track_width.int_track_width",
118  &m_TrackWidth.int_track_width, "0.2" ) );
119 
120  m_params.emplace_back( new PARAM<int>( "track_width.int_track_width_units",
122 
123  m_params.emplace_back( new PARAM<wxString>( "track_width.int_track_thickness",
124  &m_TrackWidth.int_track_thickness, "0.035" ) );
125 
126  m_params.emplace_back( new PARAM<int>( "track_width.int_track_thickness_units",
128 
129  {
130  const std::array<std::string, 8> transline_names = { "MicroStrip", "CoPlanar", "GrCoPlanar",
131  "RectWaveGuide", "Coax", "Coupled_MicroStrip", "StripLine", "TwistedPair" };
132 
133  for( const auto& name : transline_names )
134  {
137 
138  std::string path = "trans_line." + name + ".";
139 
140  m_params.emplace_back( new PARAM_MAP<double>( path + "values",
141  &m_TransLine.param_values.at( name ), {} ) );
142 
143  m_params.emplace_back( new PARAM_MAP<int>( path + "units",
144  &m_TransLine.param_units.at( name ), {} ) );
145  }
146  }
147 
148  m_params.emplace_back( new PARAM<wxString>( "via_size.hole_diameter",
149  &m_ViaSize.hole_diameter, "0.4" ) );
150 
151  m_params.emplace_back( new PARAM<int>( "via_size.hole_diameter_units",
153 
154  m_params.emplace_back( new PARAM<wxString>( "via_size.thickness",
155  &m_ViaSize.thickness, "0.035" ) );
156 
157  m_params.emplace_back( new PARAM<int>( "via_size.thickness_units",
158  &m_ViaSize.thickness_units, 0 ) );
159 
160  m_params.emplace_back( new PARAM<wxString>( "via_size.length",
161  &m_ViaSize.length, "1.6" ) );
162 
163  m_params.emplace_back( new PARAM<int>( "via_size.length_units", &m_ViaSize.length_units, 0 ) );
164 
165  m_params.emplace_back( new PARAM<wxString>( "via_size.pad_diameter",
166  &m_ViaSize.pad_diameter, "0.6" ) );
167 
168  m_params.emplace_back( new PARAM<int>( "via_size.pad_diameter_units",
170 
171  m_params.emplace_back( new PARAM<wxString>( "via_size.clearance_diameter",
172  &m_ViaSize.clearance_diameter, "1.0" ) );
173 
174  m_params.emplace_back( new PARAM<int>( "via_size.clearance_diameter_units",
176 
177  m_params.emplace_back( new PARAM<wxString>( "via_size.characteristic_impedance",
179 
180  m_params.emplace_back( new PARAM<int>( "via_size.characteristic_impedance_units",
182 
183  m_params.emplace_back( new PARAM<wxString>( "via_size.applied_current",
184  &m_ViaSize.applied_current, "1" ) );
185 
186  m_params.emplace_back( new PARAM<wxString>( "via_size.plating_resistivity",
187  &m_ViaSize.plating_resistivity, "1.72e-8" ) );
188 
189  m_params.emplace_back( new PARAM<wxString>( "via_size.permittivity",
190  &m_ViaSize.permittivity, "4.5" ) );
191 
192  m_params.emplace_back( new PARAM<wxString>( "via_size.temp_rise",
193  &m_ViaSize.temp_rise, "10" ) );
194 
195  m_params.emplace_back( new PARAM<wxString>( "via_size.pulse_rise_time",
196  &m_ViaSize.pulse_rise_time, "1" ) );
197 }
198 
199 
201 {
202  bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
203 
204  ret &= fromLegacy<int>( aCfg, "BrdClass_selection", "board_class_units" );
205  ret &= fromLegacy<int>( aCfg, "CC_selection", "color_code_tolerance" );
206  ret &= fromLegacy<int>( aCfg, "Page_selection", "last_page" );
207 
208  ret &= fromLegacy<int>( aCfg, "Att_selection", "attenuators.type" );
209 
210  {
211  nlohmann::json::json_pointer ptr = PointerFromString( "attenuators" );
212  const std::array<std::string, 4> att_names = { "att_pi", "att_tee",
213  "att_bridge", "att_splitter" };
214  double val = 0;
215 
216  for( const auto& att : att_names )
217  {
218  aCfg->SetPath( "Attenuators/" + att );
219  ptr.push_back( att );
220 
221  if( aCfg->Read( "Attenuation", &val ) )
222  ( *this )[ptr]["attenuation"] = val;
223 
224  if( aCfg->Read( "Zin", &val ) )
225  ( *this )[ptr]["zin"] = val;
226 
227  if( aCfg->Read( "Zout", &val ) )
228  ( *this )[ptr]["zout"] = val;
229 
230  ptr.pop_back();
231  aCfg->SetPath( "../.." );
232  }
233  }
234 
235  ret &= fromLegacy<int>( aCfg, "ElectSpacing_selection", "electrical.spacing_units" );
236  ret &= fromLegacyString( aCfg, "ElectSpacing_voltage", "electrical.spacing_voltage" );
237 
238  ret &= fromLegacyString( aCfg, "RegulR1", "regulators.r1" );
239  ret &= fromLegacyString( aCfg, "RegulR2", "regulators.r2" );
240  ret &= fromLegacyString( aCfg, "RegulVREF", "regulators.vref" );
241  ret &= fromLegacyString( aCfg, "RegulVOUT", "regulators.vout" );
242  ret &= fromLegacyString( aCfg, "DataFilename", "regulators.data_file" );
243  ret &= fromLegacyString( aCfg, "RegulName", "regulators.selected_regulator" );
244  ret &= fromLegacy<int>( aCfg, "RegulType", "regulators.type" );
245  ret &= fromLegacy<int>( aCfg, "RegulLastParam", "regulators.last_param" );
246 
247  ret &= fromLegacyString( aCfg, "TW_Track_Current", "track_width.current" );
248  ret &= fromLegacyString( aCfg, "TW_Delta_TC", "track_width.delta_tc" );
249  ret &= fromLegacyString( aCfg, "TW_Track_Len", "track_width.track_len" );
250  ret &= fromLegacy<int>( aCfg, "TW_Track_Len_Unit", "track_width.track_len_units" );
251  ret &= fromLegacyString( aCfg, "TW_Resistivity", "track_width.resistivity" );
252  ret &= fromLegacyString( aCfg, "TW_ExtTrack_Width", "track_width.ext_track_width" );
253  ret &= fromLegacy<int>( aCfg, "TW_ExtTrack_Width_Unit", "track_width.ext_track_width_units" );
254  ret &= fromLegacyString( aCfg, "TW_ExtTrack_Thickness", "track_width.ext_track_thickness" );
255  ret &= fromLegacy<int>( aCfg, "TW_ExtTrack_Thickness_Unit",
256  "track_width.ext_track_thickness_units" );
257  ret &= fromLegacyString( aCfg, "TW_IntTrack_Width", "track_width.int_track_width" );
258  ret &= fromLegacy<int>( aCfg, "TW_IntTrack_Width_Unit", "track_width.int_track_width_units" );
259  ret &= fromLegacyString( aCfg, "TW_IntTrack_Thickness", "track_width.int_track_thickness" );
260  ret &= fromLegacy<int>( aCfg, "TW_IntTrack_Thickness_Unit",
261  "track_width.int_track_thickness_units" );
262 
263  ret &= fromLegacy<int>( aCfg, "Transline_selection", "trans_line.selection" );
264 
265  {
266  nlohmann::json::json_pointer ptr = PointerFromString( "trans_line" );
267  wxString key;
268  double value = 0;
269  int units = 0;
270 
271  const std::array<std::string, 8> transline_names = { "MicroStrip", "CoPlanar", "GrCoPlanar",
272  "RectWaveGuide", "Coax", "Coupled_MicroStrip", "StripLine", "TwistedPair" };
273 
274  for( const auto& name : transline_names )
275  {
276  long index = 0;
277  aCfg->SetPath( name );
278  ptr.push_back( name );
279 
280  while( aCfg->GetNextEntry( key, index ) )
281  {
282  // Keys look like "translineprmN" and "translineprmNunit"
283  wxString dest = key;
284  dest.Replace( "translineprm", wxEmptyString );
285 
286  if( dest.EndsWith( "unit" ) )
287  {
288  dest.Replace( "unit", wxEmptyString );
289  aCfg->Read( key, &units );
290  ptr.push_back( "units" );
291 
292  ( *this )[ptr].push_back( { { dest.ToStdString(), units } } );
293 
294  ptr.pop_back();
295  }
296  else
297  {
298  aCfg->Read( key, &value );
299  ptr.push_back( "values" );
300 
301  ( *this )[ptr].push_back( { { dest.ToStdString(), value } } );
302 
303  ptr.pop_back();
304  }
305  }
306 
307  ptr.pop_back();
308  aCfg->SetPath( ".." );
309  }
310  }
311 
312  ret &= fromLegacyString( aCfg, "VS_Hole_Dia", "via_size.hole_diameter" );
313  ret &= fromLegacy<int>( aCfg, "VS_Hole_Dia_Unit", "via_size.hole_diameter_units" );
314  ret &= fromLegacyString( aCfg, "VS_Plating_Thickness", "via_size.thickness" );
315  ret &= fromLegacy<int>( aCfg, "VS_Plating_Thickness_Unit", "via_size.thickness_units" );
316  ret &= fromLegacyString( aCfg, "VS_Via_Length", "via_size.length" );
317  ret &= fromLegacy<int>( aCfg, "VS_Via_Length_Unit", "via_size.length_units" );
318  ret &= fromLegacyString( aCfg, "VS_Pad_Dia", "via_size.pad_diameter" );
319  ret &= fromLegacy<int>( aCfg, "VS_Pad_Dia_Unit", "via_size.pad_diameter_units" );
320  ret &= fromLegacyString( aCfg, "VS_Clearance_Dia", "via_size.clearance_diameter" );
321  ret &= fromLegacy<int>( aCfg, "VS_Clearance_Dia_Unit",
322  "via_size.clearance_diameter_units" );
323  ret &= fromLegacyString( aCfg, "VS_Characteristic_Impedance",
324  "via_size.characteristic_impedance" );
325  ret &= fromLegacy<int>( aCfg, "VS_Characteristic_Impedance_Unit",
326  "via_size.characteristic_impedance_units" );
327  ret &= fromLegacyString( aCfg, "VS_Current", "via_size.applied_current" );
328  ret &= fromLegacyString( aCfg, "VS_Resistivity", "via_size.plating_resistivity" );
329  ret &= fromLegacyString( aCfg, "VS_Permittivity", "via_size.permittivity" );
330  ret &= fromLegacyString( aCfg, "VS_Temperature_Differential", "via_size.temp_rise" );
331  ret &= fromLegacyString( aCfg, "VS_Pulse_Rise_Time", "via_size.pulse_rise_time" );
332 
333  return ret;
334 }
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:574
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.
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:91
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:60
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.