KiCad PCB EDA Suite
transline_ident.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) 2011-2014 Jean-Pierre Charras
5  * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
24 #include <wx/intl.h>
25 #include <wx/arrstr.h>
26 
27 #include <kiface_base.h>
28 #include <bitmaps.h>
29 
30 // transline specific functions:
31 #include "transline/transline.h"
32 #include "transline/microstrip.h"
33 #include "transline/coplanar.h"
35 #include "transline/coax.h"
36 #include "transline/c_microstrip.h"
37 #include "transline/stripline.h"
38 #include "transline/twistedpair.h"
39 
41 #include "widgets/unit_selector.h"
42 #include "transline_ident.h"
43 
44 
45 TRANSLINE_PRM::TRANSLINE_PRM( PRM_TYPE aType, PRMS_ID aId, const char* aKeywordCfg,
46  const wxString& aDlgLabel, const wxString& aToolTip,
47  double aValue, bool aConvUnit )
48 {
49  m_Type = aType;
50  m_Id = aId;
51  m_DlgLabel = aDlgLabel;
52  m_KeyWord = aKeywordCfg;
53  m_ToolTip = aToolTip;
54  m_Value = aValue;
55  m_ConvUnit = aConvUnit;
56  m_ValueCtrl = nullptr;
57  m_UnitCtrl = nullptr;
58  m_UnitSelection = 0;
60  }
61 
62 
64 {
65  if( m_UnitCtrl && m_ConvUnit )
66  return 1.0 / ( (UNIT_SELECTOR*) m_UnitCtrl )->GetUnitScale();
67  else
68  return 1.0;
69 }
70 
71 
73 {
74  if( m_UnitCtrl )
75  return ( (UNIT_SELECTOR*) m_UnitCtrl )->GetUnitScale();
76  else
77  return 1.0;
78 }
79 
80 
82 {
83  m_Type = aType; // The type of transline handled
84  m_Icon = nullptr; // An xpm icon to display in dialogs
85  m_TLine = nullptr; // The TRANSLINE itself
86  m_HasPrmSelection = false; // true if selection of parameters must be enabled in dialog menu
87 
88  // Add common prms:
89  // Default values are for FR4
91  "Er", wxT( "εr" ),
92  _( "Substrate relative permittivity (dielectric constant)" ),
93  4.6, false ) );
95  "TanD", wxT( "tan δ" ),
96  _( "Dielectric loss (dissipation factor)" ),
97  2e-2, false ) );
98 
99  // Default value is for copper
101  "Rho", wxT( "ρ" ),
102  _( "Electrical resistivity or specific electrical resistance of "
103  "conductor (ohm*meter)" ),
104  1.72e-8, false ) );
105 
106  // Default value is in GHz
108  "Frequency", _( "Frequency" ),
109  _( "Frequency of the input signal" ), 1.0, true ) );
110 
111 
112  switch( m_Type )
113  {
114  case MICROSTRIP_TYPE: // microstrip
115  m_TLine = new MICROSTRIP();
117 
118  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
119  m_Messages.Add( _( "Conductor losses:" ) );
120  m_Messages.Add( _( "Dielectric losses:" ) );
121  m_Messages.Add( _( "Skin depth:" ) );
122 
124  "H", "H", _( "Height of substrate" ), 0.2, true ) );
126  "H_t", "H(top)", _( "Height of box top" ), 1e20, true ) );
128  "T", "T",
129  _( "Strip thickness" ), 0.035, true ) );
131  "Rough", _( "Roughness" ),
132  _( "Conductor roughness" ), 0.0, true ) );
134  "mu Rel S", wxString::Format( wxT( "μ(%s)" ),
135  _( "substrate" ) ),
136  _( "Relative permeability (mu) of substrate" ), 1, false ) );
138  "mu Rel C", wxString::Format( wxT( "μ(%s)" ),
139  _( "conductor" ) ),
140  _( "Relative permeability (mu) of conductor" ), 1,
141  false ) );
142 
144  "W", "W", _( "Line width" ), 0.2, true ) );
146  "L", "L", _( "Line length" ), 50.0, true ) );
147 
149  "Z0", "Z0", _( "Characteristic impedance" ), 50.0, true ) );
152  "Ang_l", "Ang_l", _( "Electrical length" ), 0.0, true ) );
153  break;
154 
155  case CPW_TYPE: // coplanar waveguide
156  m_TLine = new COPLANAR();
158  m_HasPrmSelection = true;
159 
160  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
161  m_Messages.Add( _( "Conductor losses:" ) );
162  m_Messages.Add( _( "Dielectric losses:" ) );
163  m_Messages.Add( _( "Skin depth:" ) );
164 
166  "H", "H", _( "Height of substrate" ), 0.2, true ) );
168  "T", "T", _( "Strip thickness" ), 0.035, true ) );
170  "mu Rel C", wxString::Format( wxT( "μ(%s)" ),
171  _( "conductor" ) ),
172  _( "Relative permeability (mu) of conductor" ), 1,
173  false ) );
174 
176  "W", "W", _( "Line width" ), 0.2, true ) );
178  "S", "S", _( "Gap width" ), 0.2, true ) );
180  "L", "L", _( "Line length" ), 50.0, true ) );
181 
183  "Z0", "Z0", _( "Characteristic impedance" ), 50.0, true ) );
186  "Ang_l", "Ang_l", _( "Electrical length" ), 0.0, true ) );
187  break;
188 
189  case GROUNDED_CPW_TYPE: // grounded coplanar waveguide
190  m_TLine = new GROUNDEDCOPLANAR();
192  m_HasPrmSelection = true;
193 
194  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
195  m_Messages.Add( _( "Conductor losses:" ) );
196  m_Messages.Add( _( "Dielectric losses:" ) );
197  m_Messages.Add( _( "Skin depth:" ) );
198 
200  "H", "H", _( "Height of substrate" ), 0.2, true ) );
202  "T", "T", _( "Strip thickness" ), 0.035, true ) );
204  "mu Rel C", wxString::Format( wxT( "μ(%s)" ),
205  _( "conductor" ) ),
206  _( "Relative permeability (mu) of conductor" ), 1,
207  false ) );
208 
210  "W", "W", _( "Line width" ), 0.2, true ) );
212  "S", "S", _( "Gap width" ), 0.2, true ) );
214  "L", "L", _( "Line length" ), 50.0, true ) );
215 
217  "Z0", "Z0", _( "Characteristic impedance" ), 50.0, true ) );
220  "Ang_l", "Ang_l", _( "Electrical length" ), 0, true ) );
221  break;
222 
223 
224  case RECTWAVEGUIDE_TYPE: // rectangular waveguide
225  m_TLine = new RECTWAVEGUIDE();
227  m_HasPrmSelection = true;
228 
229  m_Messages.Add( _( "ZF(H10) = Ey / Hx:" ) );
230  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
231  m_Messages.Add( _( "Conductor losses:" ) );
232  m_Messages.Add( _( "Dielectric losses:" ) );
233  m_Messages.Add( _( "TE-modes:" ) );
234  m_Messages.Add( _( "TM-modes:" ) );
235 
237  "mu Rel I", wxString::Format( wxT( "μ(%s)" ),
238  _( "insulator" ) ),
239  _( "Relative permeability (mu) of insulator" ), 1, false ) );
241  "mu Rel C", wxString::Format( wxT( "μ(%s)" ),
242  _( "conductor" ) ),
243  _( "Relative permeability (mu) of conductor" ), 1,
244  false ) );
245 
247  "a", "a", _( "Width of waveguide" ), 10.0, true ) );
249  "b", "b", _( "Height of waveguide" ), 5.0, true ) );
251  "L", "L", _( "Waveguide length" ), 50.0, true ) );
252 
254  "Z0", "Z0", _( "Characteristic impedance" ), 50.0, true ) );
257  "Ang_l", "Ang_l", _( "Electrical length" ), 0, true ) );
258  break;
259 
260  case COAX_TYPE: // coaxial cable
261  m_TLine = new COAX();
263  m_HasPrmSelection = true;
264 
265  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
266  m_Messages.Add( _( "Conductor losses:" ) );
267  m_Messages.Add( _( "Dielectric losses:" ) );
268  m_Messages.Add( _( "TE-modes:" ) );
269  m_Messages.Add( _( "TM-modes:" ) );
270 
272  "mu Rel I", wxString::Format( wxT( "μ(%s)" ),
273  _( "insulator" ) ),
274  _( "Relative permeability (mu) of insulator" ), 1, false ) );
276  "mu Rel C", wxString::Format( wxT( "μ(%s)" ),
277  _( "conductor" ) ),
278  _( "Relative permeability (mu) of conductor" ), 1,
279  false ) );
280 
282  "Din", _( "Din" ),
283  _( "Inner diameter (conductor)" ), 1.0, true ) );
285  "Dout", _( "Dout" ),
286  _( "Outer diameter (insulator)" ), 8.0, true ) );
288  "L", "L", _( "Line length" ), 50.0, true ) );
289 
291  "Z0", "Z0", _( "Characteristic impedance" ), 50.0, true ) );
294  "Ang_l", "Ang_l", _( "Electrical length" ), 0.0, true ) );
295  break;
296 
297  case C_MICROSTRIP_TYPE: // coupled microstrip
298  m_TLine = new C_MICROSTRIP();
300  m_HasPrmSelection = true;
301 
302  m_Messages.Add( wxString::Format( _( "Effective %s (even):" ), wxT( "εr" ) ) );
303  m_Messages.Add( wxString::Format( _( "Effective %s (odd):" ), wxT( "εr" ) ) );
304  m_Messages.Add( _( "Conductor losses (even):" ) );
305  m_Messages.Add( _( "Conductor losses (odd):" ) );
306  m_Messages.Add( _( "Dielectric losses (even):" ) );
307  m_Messages.Add( _( "Dielectric losses (odd):" ) );
308  m_Messages.Add( _( "Skin depth:" ) );
309  m_Messages.Add( _( "Differential Impedance (Zd):" ) );
310 
312  "H", "H", _( "Height of substrate" ), 0.2, true ) );
314  "H_t", "H_t", _( "Height of box top" ), 1e20, true ) );
316  "T", "T", _( "Strip thickness" ), 0.035, true ) );
318  "Rough", _( "Roughness" ),
319  _( "Conductor roughness" ), 0.0, true ) );
321  "mu rel C", wxString::Format( wxT( "μ(%s)" ),
322  _( "conductor" ) ),
323  _( "Relative permeability (mu) of conductor" ), 1,
324  false ) );
325 
327  "W", "W", _( "Line width" ), 0.2, true ) );
329  "S", "S", _( "Gap width" ), 0.2, true ) );
331  "L", "L", _( "Line length" ), 50.0, true ) );
332 
334  "Zeven", _( "Zeven" ),
335  _( "Even mode impedance (lines driven by common voltages)" ),
336  50.0, true ) );
338  "Zodd", _( "Zodd" ),
339  _( "Odd mode impedance (lines driven by opposite "
340  "(differential) voltages)" ), 50.0, true ) );
342  "Ang_l", "Ang_l",
343  _( "Electrical length" ), 0.0, true ) );
344  break;
345 
346  case STRIPLINE_TYPE: // stripline
347  m_TLine = new STRIPLINE();
349 
350  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
351  m_Messages.Add( _( "Conductor losses:" ) );
352  m_Messages.Add( _( "Dielectric losses:" ) );
353  m_Messages.Add( _( "Skin depth:" ) );
354 
356  "H", "H", _( "Height of substrate" ), 0.2, true ) );
358  "a", "a", _( "Distance between strip and top metal" ), 0.2,
359  true ) );
361  "T", "T", _( "Strip thickness" ), 0.035, true ) );
363  "mu Rel C", wxString::Format( wxT( "μ(%s)" ),
364  _( "conductor" ) ),
365  _( "Relative permeability (mu) of conductor" ), 1, false ) );
366 
368  "W", "W", _( "Line width" ), 0.2, true ) );
370  "L", "L", _( "Line length" ), 50.0, true ) );
371 
373  "Z0", "Z0", _( "Characteristic impedance" ), 50, true ) );
376  "Ang_l", "Ang_l", _( "Electrical length" ), 0, true ) );
377  break;
378 
379  case TWISTEDPAIR_TYPE: // twisted pair
380  m_TLine = new TWISTEDPAIR();
382  m_HasPrmSelection = true;
383 
384  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
385  m_Messages.Add( _( "Conductor losses:" ) );
386  m_Messages.Add( _( "Dielectric losses:" ) );
387  m_Messages.Add( _( "Skin depth:" ) );
388 
390  "Twists", _( "Twists" ),
391  _( "Number of twists per length" ), 0.0, false ) );
393  "mu Rel C", wxString::Format( wxT( "μ(%s)" ),
394  _( "conductor" ) ),
395  _( "Relative permeability (mu) of conductor" ), 1,
396  false ) );
398  "ErEnv", wxString::Format( wxT( "εr(%s)" ),
399  _( "environment" ) ),
400  _( "Relative permittivity of environment" ), 1,
401  false ) );
403  "Din", _( "Din" ),
404  _( "Inner diameter (conductor)" ), 1.0, true ) );
406  "Dout", _( "Dout" ),
407  _( "Outer diameter (insulator)" ), 8.0, true ) );
409  "L", "L", _( "Cable length" ), 50.0, true ) );
410 
412  "Z0", "Z0", _( "Characteristic impedance" ), 50.0, true ) );
415  "Ang_l", "Ang_l", _( "Electrical length" ), 0.0, true ) );
416  break;
417 
418  case END_OF_LIST_TYPE: // Not really used
419  break;
420  }
421 }
422 
424 {
425  delete m_TLine;
426  delete m_Icon;
427 
428  for( auto& ii : m_prms_List )
429  delete ii;
430 
431  m_prms_List.clear();
432 }
433 
434 
436 {
437  auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
438  std::string name( m_TLine->m_Name );
439 
440  if( cfg->m_TransLine.param_values.count( name ) )
441  {
442  wxASSERT( cfg->m_TransLine.param_units.count( name ) );
443 
444  for( auto& p : m_prms_List )
445  {
446  try
447  {
448  p->m_Value = cfg->m_TransLine.param_values.at( name ).at( p->m_KeyWord );
449  p->m_UnitSelection = cfg->m_TransLine.param_units.at( name ).at( p->m_KeyWord );
450  }
451  catch( ... )
452  {}
453  }
454  }
455 }
456 
457 
459 {
460  auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
461  std::string name( m_TLine->m_Name );
462 
463  for( auto& param : m_prms_List )
464  {
465  if( !std::isfinite( param->m_Value ) )
466  param->m_Value = 0;
467 
468  cfg->m_TransLine.param_values[ name ][ param->m_KeyWord ] = param->m_Value;
469  cfg->m_TransLine.param_units[ name ][ param->m_KeyWord ] = param->m_UnitSelection;
470  }
471 }
472 
double FromUserUnit()
double m_NormalizedValue
wxString m_DlgLabel
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
void AddPrm(TRANSLINE_PRM *aParam)
A class to handle one parameter of transline.
wxArrayString m_Messages
wxString m_ToolTip
PRM_TYPE
enum TRANSLINE_TYPE_ID m_Type
std::vector< TRANSLINE_PRM * > m_prms_List
PRMS_ID
Definition: transline.h:36
#define _(s)
TRANSLINE_TYPE_ID
const char * m_Name
Definition: transline.h:84
std::string m_KeyWord
Definition: coax.h:30
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxBitmap * KiBitmapNew(BITMAPS aBitmap)
Allocate a wxBitmap on heap from a memory record, held in a BITMAPS.
Definition: bitmap.cpp:199
const char * name
Definition: DXF_plotter.cpp:56
TRANSLINE * m_TLine
TRANSLINE_IDENT(enum TRANSLINE_TYPE_ID aType)
TRANSLINE_PRM(PRM_TYPE aType, PRMS_ID aId, const char *aKeywordCfg="", const wxString &aDlgLabel=wxEmptyString, const wxString &aToolTip=wxEmptyString, double aValue=0.0, bool aConvUnit=false)