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