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-2014 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_i.h>
28 #include <bitmaps.h>
29 
30 // Bitmaps:
31 #include "bitmaps/c_microstrip.cpp"
32 #include "bitmaps/microstrip.cpp"
33 #include "bitmaps/twistedpair.cpp"
34 #include "bitmaps/coax.cpp"
35 #include "bitmaps/cpw.cpp"
36 #include "bitmaps/cpw_back.cpp"
37 #include "bitmaps/stripline.cpp"
39 
40 // transline specific functions:
41 #include "transline/transline.h"
42 #include "transline/microstrip.h"
43 #include "transline/coplanar.h"
45 #include "transline/coax.h"
46 #include "transline/c_microstrip.h"
47 #include "transline/stripline.h"
48 #include "transline/twistedpair.h"
49 
51 #include "widgets/unit_selector.h"
52 #include "transline_ident.h"
53 
54 
55 /*
56  * TRANSLINE_PRM
57  * A class to handle one parameter of transline
58  */
60  const char* aKeywordCfg,
61  const wxString& aDlgLabel,
62  const wxString& aToolTip,
63  double aValue,
64  bool aConvUnit )
65 {
66  m_Type = aType;
67  m_Id = aId;
68  m_DlgLabel = aDlgLabel;
69  m_KeyWord = aKeywordCfg;
70  m_ToolTip = aToolTip;
71  m_Value = aValue;
72  m_ConvUnit = aConvUnit;
73  m_ValueCtrl = NULL;
74  m_UnitCtrl = NULL;
75  m_UnitSelection = 0;
77  }
78 
79 
81 {
82  if( m_UnitCtrl && m_ConvUnit )
83  return 1.0 / ( (UNIT_SELECTOR*) m_UnitCtrl )->GetUnitScale();
84  else
85  return 1.0;
86 }
87 
88 
90 {
91  if( m_UnitCtrl )
92  return ( (UNIT_SELECTOR*) m_UnitCtrl )->GetUnitScale();
93  else
94  return 1.0;
95 }
96 
97 
98 /*
99  * TRANSLINE_IDENT
100  * A class to handle a list of parameters of a given transline
101  * Important note:
102  * the first string of TRANSLINE_PRM (m_KeyWord) is a keyword in config file.
103  * it can contain only ASCII7 chars
104  * the second string of TRANSLINE_PRM (m_DlgLabel) is a string translated for dialog,
105  * so mark it for translation (m_KeyWord and m_DlgLabel are usually the same in English)
106  * and of course do not mark translatable m_DlgLabel that obviously cannot be translated,
107  * like "H" or "H_t"
108  */
109 
111 {
112  m_Type = aType; // The type of transline handled
113  m_Icon = NULL; // An xpm icon to display in dialogs
114  m_TLine = NULL; // The TRANSLINE itself
115  m_HasPrmSelection = false; // true if selection of parameters must be enabled in dialog menu
116 
117  // Add common prms:
118  // Default values are for FR4
120  "Er", wxT( "εr" ),
121  _( "Substrate relative permittivity (dielectric constant)" ),
122  4.6, false ) );
124  "TanD", wxT( "tan δ" ),
125  _( "Dielectric loss (dissipation factor)" ),
126  2e-2, false ) );
127 
128  // Default value is for copper
130  "Rho", wxT( "ρ" ),
131  _( "Electrical resistivity or specific electrical resistance of conductor (ohm*meter)" ),
132  1.72e-8, false ) );
133 
134  // Default value is in GHz
136  "Frequency", _( "Frequency" ),
137  _( "Frequency of the input signal" ), 1.0, true ) );
138 
139 
140  switch( m_Type )
141  {
142  case MICROSTRIP_TYPE: // microstrip
143  m_TLine = new MICROSTRIP();
144  m_Icon = new wxBitmap( KiBitmap( microstrip_xpm ) );
145 
146  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
147  m_Messages.Add( _( "Conductor losses:" ) );
148  m_Messages.Add( _( "Dielectric losses:" ) );
149  m_Messages.Add( _( "Skin depth:" ) );
150 
152  "H", "H", _( "Height of substrate" ), 0.2, true ) );
154  "H_t", "H(top)", _( "Height of box top" ), 1e20, true ) );
156  "T", "T",
157  _( "Strip thickness" ), 0.035, true ) );
159  "Rough", _( "Roughness" ),
160  _( "Conductor roughness" ), 0.0, true ) );
162  "mu Rel S", wxString::Format( wxT( "μ(%s)" ), _( "substrate" ) ),
163  _( "Relative permeability (mu) of substrate" ), 1, false ) );
165  "mu Rel C", wxString::Format( wxT( "μ(%s)" ), _( "conductor" ) ),
166  _( "Relative permeability (mu) of conductor" ), 1,
167  false ) );
168 
170  "W", "W", _( "Line width" ), 0.2, true ) );
172  "L", "L", _( "Line length" ), 50.0, true ) );
173 
175  "Z0", "Z0", _( "Characteristic impedance" ), 50.0, true ) );
178  "Ang_l", "Ang_l", _( "Electrical length" ), 0.0, true ) );
179  break;
180 
181  case CPW_TYPE: // coplanar waveguide
182  m_TLine = new COPLANAR();
183  m_Icon = new wxBitmap( KiBitmap( cpw_xpm ) );
184  m_HasPrmSelection = true;
185 
186  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
187  m_Messages.Add( _( "Conductor losses:" ) );
188  m_Messages.Add( _( "Dielectric losses:" ) );
189  m_Messages.Add( _( "Skin depth:" ) );
190 
192  "H", "H", _( "Height of substrate" ), 0.2, true ) );
194  "T", "T", _( "Strip thickness" ), 0.035, true ) );
196  "mu Rel C", wxString::Format( wxT( "μ(%s)" ), _( "conductor" ) ),
197  _( "Relative permeability (mu) of conductor" ), 1,
198  false ) );
199 
201  "W", "W", _( "Line width" ), 0.2, true ) );
203  "S", "S", _( "Gap width" ), 0.2, true ) );
205  "L", "L", _( "Line length" ), 50.0, true ) );
206 
208  "Z0", "Z0", _( "Characteristic impedance" ), 50.0, true ) );
211  "Ang_l", "Ang_l", _( "Electrical length" ), 0.0, true ) );
212  break;
213 
214  case GROUNDED_CPW_TYPE: // grounded coplanar waveguide
215  m_TLine = new GROUNDEDCOPLANAR();
216  m_Icon = new wxBitmap( KiBitmap( cpw_back_xpm ) );
217  m_HasPrmSelection = true;
218 
219  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
220  m_Messages.Add( _( "Conductor losses:" ) );
221  m_Messages.Add( _( "Dielectric losses:" ) );
222  m_Messages.Add( _( "Skin depth:" ) );
223 
225  "H", "H", _( "Height of substrate" ), 0.2, true ) );
227  "T", "T", _( "Strip thickness" ), 0.035, true ) );
229  "mu Rel C", wxString::Format( wxT( "μ(%s)" ), _( "conductor" ) ),
230  _( "Relative permeability (mu) of conductor" ), 1,
231  false ) );
232 
234  "W", "W", _( "Line width" ), 0.2, true ) );
236  "S", "S", _( "Gap width" ), 0.2, true ) );
238  "L", "L", _( "Line length" ), 50.0, true ) );
239 
241  "Z0", "Z0", _( "Characteristic impedance" ), 50.0, true ) );
244  "Ang_l", "Ang_l", _( "Electrical length" ), 0, true ) );
245  break;
246 
247 
248  case RECTWAVEGUIDE_TYPE: // rectangular waveguide
249  m_TLine = new RECTWAVEGUIDE();
250  m_Icon = new wxBitmap( KiBitmap( rectwaveguide_xpm ) );
251  m_HasPrmSelection = true;
252 
253  m_Messages.Add( _( "ZF(H10) = Ey / Hx:" ) );
254  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
255  m_Messages.Add( _( "Conductor losses:" ) );
256  m_Messages.Add( _( "Dielectric losses:" ) );
257  m_Messages.Add( _( "TE-modes:" ) );
258  m_Messages.Add( _( "TM-modes:" ) );
259 
261  "mu Rel I", wxString::Format( wxT( "μ(%s)" ), _( "insulator" ) ),
262  _( "Relative permeability (mu) of insulator" ), 1, false ) );
264  "mu Rel C", wxString::Format( wxT( "μ(%s)" ), _( "conductor" ) ),
265  _( "Relative permeability (mu) of conductor" ), 1,
266  false ) );
267 
269  "a", "a", _( "Width of waveguide" ), 10.0, true ) );
271  "b", "b", _( "Height of waveguide" ), 5.0, true ) );
273  "L", "L", _( "Waveguide length" ), 50.0, true ) );
274 
276  "Z0", "Z0", _( "Characteristic impedance" ), 50.0, true ) );
279  "Ang_l", "Ang_l", _( "Electrical length" ), 0, true ) );
280  break;
281 
282  case COAX_TYPE: // coaxial cable
283  m_TLine = new COAX();
284  m_Icon = new wxBitmap( KiBitmap( coax_xpm ) );
285  m_HasPrmSelection = true;
286 
287  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
288  m_Messages.Add( _( "Conductor losses:" ) );
289  m_Messages.Add( _( "Dielectric losses:" ) );
290  m_Messages.Add( _( "TE-modes:" ) );
291  m_Messages.Add( _( "TM-modes:" ) );
292 
294  "mu Rel I", wxString::Format( wxT( "μ(%s)" ), _( "insulator" ) ),
295  _( "Relative permeability (mu) of insulator" ), 1, false ) );
297  "mu Rel C", wxString::Format( wxT( "μ(%s)" ), _( "conductor" ) ),
298  _( "Relative permeability (mu) of conductor" ), 1,
299  false ) );
300 
302  "Din", _( "Din" ),
303  _( "Inner diameter (conductor)" ), 1.0, true ) );
305  "Dout", _( "Dout" ),
306  _( "Outer diameter (insulator)" ), 8.0, true ) );
308  "L", "L", _( "Line length" ), 50.0, true ) );
309 
311  "Z0", "Z0", _( "Characteristic impedance" ), 50.0, true ) );
314  "Ang_l", "Ang_l", _( "Electrical length" ), 0.0, true ) );
315  break;
316 
317  case C_MICROSTRIP_TYPE: // coupled microstrip
318  m_TLine = new C_MICROSTRIP();
319  m_Icon = new wxBitmap( KiBitmap( c_microstrip_xpm ) );
320  m_HasPrmSelection = true;
321 
322  m_Messages.Add( wxString::Format( _( "Effective %s (even):" ), wxT( "εr" ) ) );
323  m_Messages.Add( wxString::Format( _( "Effective %s (odd):" ), wxT( "εr" ) ) );
324  m_Messages.Add( _( "Conductor losses (even):" ) );
325  m_Messages.Add( _( "Conductor losses (odd):" ) );
326  m_Messages.Add( _( "Dielectric losses (even):" ) );
327  m_Messages.Add( _( "Dielectric losses (odd):" ) );
328  m_Messages.Add( _( "Skin depth:" ) );
329 
331  "H", "H", _( "Height of substrate" ), 0.2, true ) );
333  "H_t", "H_t", _( "Height of box top" ), 1e20, true ) );
335  "T", "T", _( "Strip thickness" ), 0.035, true ) );
337  "Rough", _( "Roughness" ),
338  _( "Conductor roughness" ), 0.0, true ) );
340  "mu rel C", wxString::Format( wxT( "μ(%s)" ), _( "conductor" ) ),
341  _( "Relative permeability (mu) of conductor" ), 1,
342  false ) );
343 
345  "W", "W", _( "Line width" ), 0.2, true ) );
347  "S", "S", _( "Gap width" ), 0.2, true ) );
349  "L", "L", _( "Line length" ), 50.0, true ) );
350 
352  "Zeven", _( "Zeven" ),
353  _( "Even mode impedance (lines driven by common voltages)" ), 50.0, true ) );
355  "Zodd", _( "Zodd" ),
356  _( "Odd mode impedance (lines driven by opposite (differential) voltages)" ), 50.0, true ) );
358  "Ang_l", "Ang_l",
359  _( "Electrical length" ), 0.0, true ) );
360  break;
361 
362  case STRIPLINE_TYPE: // stripline
363  m_TLine = new STRIPLINE();
364  m_Icon = new wxBitmap( KiBitmap( stripline_xpm ) );
365 
366  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
367  m_Messages.Add( _( "Conductor losses:" ) );
368  m_Messages.Add( _( "Dielectric losses:" ) );
369  m_Messages.Add( _( "Skin depth:" ) );
370 
372  "H", "H", _( "Height of substrate" ), 0.2, true ) );
374  "a", "a", _( "Distance between strip and top metal" ), 0.2,
375  true ) );
377  "T", "T", _( "Strip thickness" ), 0.035, true ) );
379  "mu Rel C", wxString::Format( wxT( "μ(%s)" ), _( "conductor" ) ),
380  _( "Relative permeability (mu) of conductor" ), 1, false ) );
381 
383  "W", "W", _( "Line width" ), 0.2, true ) );
385  "L", "L", _( "Line length" ), 50.0, true ) );
386 
388  "Z0", "Z0", _( "Characteristic impedance" ), 50, true ) );
391  "Ang_l", "Ang_l", _( "Electrical length" ), 0, true ) );
392  break;
393 
394  case TWISTEDPAIR_TYPE: // twisted pair
395  m_TLine = new TWISTEDPAIR();
396  m_Icon = new wxBitmap( KiBitmap( twistedpair_xpm ) );
397  m_HasPrmSelection = true;
398 
399  m_Messages.Add( wxString::Format( _( "Effective %s:" ), wxT( "εr" ) ) );
400  m_Messages.Add( _( "Conductor losses:" ) );
401  m_Messages.Add( _( "Dielectric losses:" ) );
402  m_Messages.Add( _( "Skin depth:" ) );
403 
405  "Twists", _( "Twists" ),
406  _( "Number of twists per length" ), 0.0, false ) );
408  "mu Rel C", wxString::Format( wxT( "μ(%s)" ), _( "conductor" ) ),
409  _( "Relative permeability (mu) of conductor" ), 1,
410  false ) );
412  "ErEnv", wxString::Format( wxT( "εr(%s)" ), _( "environment" ) ),
413  _( "Relative permittivity of environment" ), 1,
414  false ) );
416  "Din", _( "Din" ),
417  _( "Inner diameter (conductor)" ), 1.0, true ) );
419  "Dout", _( "Dout" ),
420  _( "Outer diameter (insulator)" ), 8.0, true ) );
422  "L", "L", _( "Cable length" ), 50.0, true ) );
423 
425  "Z0", "Z0", _( "Characteristic impedance" ), 50.0, true ) );
428  "Ang_l", "Ang_l", _( "Electrical length" ), 0.0, true ) );
429  break;
430 
431  case END_OF_LIST_TYPE: // Not really used
432  break;
433  }
434 }
435 
437 {
438  delete m_TLine;
439  delete m_Icon;
440 
441  for( auto& ii : m_prms_List )
442  delete ii;
443 
444  m_prms_List.clear();
445 }
446 
447 
449 {
450  auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
451  std::string name( m_TLine->m_Name );
452 
453  if( cfg->m_TransLine.param_values.count( name ) )
454  {
455  wxASSERT( cfg->m_TransLine.param_units.count( name ) );
456 
457  for( auto& p : m_prms_List )
458  {
459  try
460  {
461  p->m_Value = cfg->m_TransLine.param_values.at( name ).at( p->m_KeyWord );
462  p->m_UnitSelection = cfg->m_TransLine.param_units.at( name ).at( p->m_KeyWord );
463  }
464  catch( ... )
465  {}
466  }
467  }
468 }
469 
470 
472 {
473  auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
474  std::string name( m_TLine->m_Name );
475 
476  for( auto& param : m_prms_List )
477  {
478  if( !std::isfinite( param->m_Value ) )
479  param->m_Value = 0;
480 
481  cfg->m_TransLine.param_values[ name ][ param->m_KeyWord ] = param->m_Value;
482  cfg->m_TransLine.param_units[ name ][ param->m_KeyWord ] = param->m_UnitSelection;
483  }
484 }
485 
wxBitmap * m_Icon
double FromUserUnit()
double m_NormalizedValue
wxString m_DlgLabel
void AddPrm(TRANSLINE_PRM *aParam)
wxArrayString m_Messages
wxString m_ToolTip
PRM_TYPE
enum TRANSLINE_TYPE_ID m_Type
const BITMAP_OPAQUE rectwaveguide_xpm[1]
#define NULL
std::vector< TRANSLINE_PRM * > m_prms_List
const BITMAP_OPAQUE cpw_xpm[1]
Definition: cpw.cpp:804
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
PRMS_ID
Definition: transline.h:37
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
const BITMAP_OPAQUE c_microstrip_xpm[1]
const BITMAP_OPAQUE stripline_xpm[1]
TRANSLINE_TYPE_ID
const char * m_Name
Definition: transline.h:85
const BITMAP_OPAQUE cpw_back_xpm[1]
Definition: cpw_back.cpp:817
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
const BITMAP_OPAQUE twistedpair_xpm[1]
const BITMAP_OPAQUE coax_xpm[1]
const char * name
Definition: DXF_plotter.cpp:59
#define _(s)
Definition: 3d_actions.cpp:33
TRANSLINE * m_TLine
const BITMAP_OPAQUE microstrip_xpm[1]
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)
TRANSLINE_PRM ctor.