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 
29 // Bitmaps:
30 #include "bitmaps/c_microstrip.xpm"
31 #include "bitmaps/microstrip.xpm"
32 #include "bitmaps/twistedpair.xpm"
33 #include "bitmaps/coax.xpm"
34 #include "bitmaps/cpw.xpm"
35 #include "bitmaps/cpw_back.xpm"
36 #include "bitmaps/stripline.xpm"
37 #include "bitmaps/rectwaveguide.xpm"
38 
39 // transline specific functions:
40 #include "transline/transline.h"
41 #include "transline/microstrip.h"
42 #include "transline/coplanar.h"
44 #include "transline/coax.h"
45 #include "transline/c_microstrip.h"
46 #include "transline/stripline.h"
47 #include "transline/twistedpair.h"
48 
50 #include "widgets/unit_selector.h"
51 #include "transline_ident.h"
52 
53 
54 /*
55  * TRANSLINE_PRM
56  * A class to handle one parameter of transline
57  */
59  const char* aKeywordCfg,
60  const wxString& aDlgLabel,
61  const wxString& aToolTip,
62  double aValue,
63  bool aConvUnit )
64 {
65  m_Type = aType;
66  m_Id = aId;
67  m_DlgLabel = aDlgLabel;
68  m_KeyWord = aKeywordCfg;
69  m_ToolTip = aToolTip;
70  m_Value = aValue;
71  m_ConvUnit = aConvUnit;
72  m_ValueCtrl = NULL;
73  m_UnitCtrl = NULL;
74  m_UnitSelection = 0;
76  }
77 
78 
80 {
81  if( m_UnitCtrl && m_ConvUnit )
82  return 1.0 / ( (UNIT_SELECTOR*) m_UnitCtrl )->GetUnitScale();
83  else
84  return 1.0;
85 }
86 
87 
89 {
90  if( m_UnitCtrl )
91  return ( (UNIT_SELECTOR*) m_UnitCtrl )->GetUnitScale();
92  else
93  return 1.0;
94 }
95 
96 
97 /*
98  * TRANSLINE_IDENT
99  * A class to handle a list of parameters of a given transline
100  * Important note:
101  * the first string of TRANSLINE_PRM (m_KeyWord) is a keyword in config file.
102  * it can contain only ASCII7 chars
103  * the second string of TRANSLINE_PRM (m_DlgLabel) is a string translated for dialog,
104  * so mark it for translation (m_KeyWord and m_DlgLabel are usually the same in English)
105  * and of course do not mark translatable m_DlgLabel that obviously cannot be translated,
106  * like "H" or "H_t"
107  */
108 
110 {
111  m_Type = aType; // The type of transline handled
112  m_Icon = NULL; // An xpm icon to display in dialogs
113  m_TLine = NULL; // The TRANSLINE itself
114  m_HasPrmSelection = false; // true if selection of parameters must be enabled in dialog menu
115 
116  // Add common prms:
117  // Default values are for FR4
119  "Er", _( "Er" ),
120  _( "Epsilon R: substrate relative dielectric constant" ),
121  4.6, false ) );
123  "TanD", _( "TanD" ),
124  _( "Tangent delta: dielectric loss factor." ), 2e-2,
125  false ) );
126 
127  // Default value is for copper
129  "Rho", _( "Rho" ),
130  _( "Electrical resistivity or specific electrical resistance of conductor (Ohm*meter)" ),
131  1.72e-8, false ) );
132 
133  // Default value is in GHz
135  "Frequency", _( "Frequency" ),
136  _( "Frequency of the input signal" ), 1.0, true ) );
137 
138 
139  switch( m_Type )
140  {
141  case MICROSTRIP_TYPE: // microstrip
142  m_TLine = new MICROSTRIP();
143  m_Icon = new wxBitmap( microstrip_xpm );
144 
145  m_Messages.Add( _( "ErEff:" ) );
146  m_Messages.Add( _( "Conductor Losses:" ) );
147  m_Messages.Add( _( "Dielectric Losses:" ) );
148  m_Messages.Add( _( "Skin Depth:" ) );
149 
151  "H", "H", _( "Height of Substrate" ), 0.2, true ) );
153  "H_t", "H_t", _( "Height of Box Top" ), 1e20, true ) );
155  "T", "T",
156  _( "Strip Thickness" ), 0.035, true ) );
158  "Rough", _( "Rough" ),
159  _( "Conductor Roughness" ), 0.0, true ) );
161  "mu Rel S",_( "mu Rel S" ),
162  _( "Relative Permeability (mu) of Substrate" ), 1, false ) );
164  "mu Rel C", _( "mu Rel C" ),
165  _( "Relative Permeability (mu) of Conductor" ), 1,
166  false ) );
167 
169  "W", "W", _( "Line Width" ), 0.2, true ) );
171  "L", "L", _( "Line Length" ), 50.0, true ) );
172 
174  "Z0", "Z0", _( "Characteristic Impedance" ), 50.0, true ) );
177  "Ang_l", "Ang_l", _( "Electrical Length" ), 0.0, true ) );
178  break;
179 
180  case CPW_TYPE: // coplanar waveguide
181  m_TLine = new COPLANAR();
182  m_Icon = new wxBitmap( cpw_xpm );
183  m_HasPrmSelection = true;
184 
185  m_Messages.Add( _( "ErEff:" ) );
186  m_Messages.Add( _( "Conductor Losses:" ) );
187  m_Messages.Add( _( "Dielectric Losses:" ) );
188  m_Messages.Add( _( "Skin Depth:" ) );
189 
191  "H", "H", _( "Height of Substrate" ), 0.2, true ) );
193  "T", "T", _( "Strip Thickness" ), 0.035, true ) );
195  "mu Rel C", _( "mu Rel C" ),
196  _( "Relative Permeability (mu) of Conductor" ), 1,
197  false ) );
198 
200  "W", "W", _( "Line Width" ), 0.2, true ) );
202  "S", "S", _( "Gap Width" ), 0.2, true ) );
204  "L", "L", _( "Line Length" ), 50.0, true ) );
205 
207  "Z0", "Z0", _( "Characteristic Impedance" ), 50.0, true ) );
210  "Ang_l", "Ang_l", _( "Electrical Length" ), 0.0, true ) );
211  break;
212 
213  case GROUNDED_CPW_TYPE: // grounded coplanar waveguide
214  m_TLine = new GROUNDEDCOPLANAR();
215  m_Icon = new wxBitmap( cpw_back_xpm );
216  m_HasPrmSelection = true;
217 
218  m_Messages.Add( _( "ErEff:" ) );
219  m_Messages.Add( _( "Conductor Losses:" ) );
220  m_Messages.Add( _( "Dielectric Losses:" ) );
221  m_Messages.Add( _( "Skin Depth:" ) );
222 
224  "H", "H", _( "Height of Substrate" ), 0.2, true ) );
226  "T", "T", _( "Strip Thickness" ), 0.035, true ) );
228  "mu Rel C", "mu Rel C",
229  _( "Relative Permeability (mu) of Conductor" ), 1,
230  false ) );
231 
233  "W", "W", _( "Line Width" ), 0.2, true ) );
235  "S", "S", _( "Gap Width" ), 0.2, true ) );
237  "L", "L", _( "Line Length" ), 50.0, true ) );
238 
240  "Z0", "Z0", _( "Characteristic Impedance" ), 50.0, true ) );
243  "Ang_l", "Ang_l", _( "Electrical Length" ), 0, true ) );
244  break;
245 
246 
247  case RECTWAVEGUIDE_TYPE: // rectangular waveguide
248  m_TLine = new RECTWAVEGUIDE();
249  m_Icon = new wxBitmap( rectwaveguide_xpm );
250  m_HasPrmSelection = true;
251 
252  m_Messages.Add( _( "ZF(H10) = Ey / Hx:" ) );
253  m_Messages.Add( _( "ErEff:" ) );
254  m_Messages.Add( _( "Conductor Losses:" ) );
255  m_Messages.Add( _( "Dielectric Losses:" ) );
256  m_Messages.Add( _( "TE-Modes:" ) );
257  m_Messages.Add( _( "TM-Modes:" ) );
258 
260  "mu Rel I",_( "mu Rel I" ),
261  _( "Relative Permeability (mu) of Insulator" ), 1, false ) );
263  "mu Rel C",_( "mu Rel C" ),
264  _( "Relative Permeability (mu) of Conductor" ), 1,
265  false ) );
266 
268  "a", "a", _( "Width of Waveguide" ), 10.0, true ) );
270  "b", "b", _( "Height of Waveguide" ), 5.0, true ) );
272  "L", "L", _( "Waveguide Length" ), 50.0, true ) );
273 
275  "Z0", "Z0", _( "Characteristic Impedance" ), 50.0, true ) );
278  "Ang_l", "Ang_l", _( "Electrical Length" ), 0, true ) );
279  break;
280 
281  case COAX_TYPE: // coaxial cable
282  m_TLine = new COAX();
283  m_Icon = new wxBitmap( coax_xpm );
284  m_HasPrmSelection = true;
285 
286  m_Messages.Add( _( "ErEff:" ) );
287  m_Messages.Add( _( "Conductor Losses:" ) );
288  m_Messages.Add( _( "Dielectric Losses:" ) );
289  m_Messages.Add( _( "TE-Modes:" ) );
290  m_Messages.Add( _( "TM-Modes:" ) );
291 
293  "mu Rel I", _( "mu Rel I" ),
294  _( "Relative Permeability (mu) of Insulator" ), 1, false ) );
296  "mu Rel C", _( "mu Rel C" ),
297  _( "Relative Permeability (mu) of Conductor" ), 1,
298  false ) );
299 
301  "Din", _( "Din" ),
302  _( "Inner Diameter (conductor)" ), 1.0, true ) );
304  "Dout", _( "Dout" ),
305  _( "Outer Diameter (insulator)" ), 8.0, true ) );
307  "L", "L",
308  _( "Line Length" ), 50.0, true ) );
309 
311  "Z0", "Z0",
312  _( "Characteristic Impedance" ), 50.0, true ) );
315  "Ang_l", "Ang_l",
316  _( "Electrical Length" ), 0.0, true ) );
317  break;
318 
319  case C_MICROSTRIP_TYPE: // coupled microstrip
320  m_TLine = new C_MICROSTRIP();
321  m_Icon = new wxBitmap( c_microstrip_xpm );
322  m_HasPrmSelection = true;
323 
324  m_Messages.Add( _( "ErEff Even:" ) );
325  m_Messages.Add( _( "ErEff Odd:" ) );
326  m_Messages.Add( _( "Conductor Losses Even:" ) );
327  m_Messages.Add( _( "Conductor Losses Odd:" ) );
328  m_Messages.Add( _( "Dielectric Losses Even:" ) );
329  m_Messages.Add( _( "Dielectric Losses Odd:" ) );
330  m_Messages.Add( _( "Skin Depth:" ) );
331 
333  "H", "H",
334  _( "Height of Substrate" ), 0.2, true ) );
336  "H_t", "H_t",
337  _( "Height of Box Top" ), 1e20, true ) );
339  "T", "T",
340  _( "Strip Thickness" ), 0.035, true ) );
342  "Rough", _( "Rough" ),
343  _( "Conductor Roughness" ), 0.0, true ) );
345  "mu Rel C", _( "mu Rel C" ),
346  _( "Relative Permeability (mu) of Conductor" ), 1,
347  false ) );
348 
350  "W", "W",
351  _( "Line Width" ), 0.2, true ) );
353  "S", "S",
354  _( "Gap Width" ), 0.2, true ) );
356  "L", "L",
357  _( "Line Length" ), 50.0, true ) );
358 
360  "Zeven", _( "Zeven" ),
361  _( "Even mode impedance (lines driven by common voltages)" ), 50.0, true ) );
363  "Zodd", _( "Zodd" ),
364  _( "Odd mode impedance (lines driven by opposite (differential) voltages)" ), 50.0, true ) );
366  "Ang_l", "Ang_l",
367  _( "Electrical Length" ), 0.0, true ) );
368  break;
369 
370  case STRIPLINE_TYPE: // stripline
371  m_TLine = new STRIPLINE();
372  m_Icon = new wxBitmap( stripline_xpm );
373 
374  m_Messages.Add( _( "ErEff:" ) );
375  m_Messages.Add( _( "Conductor Losses:" ) );
376  m_Messages.Add( _( "Dielectric Losses:" ) );
377  m_Messages.Add( _( "Skin Depth:" ) );
378 
380  "H", "H",
381  _( "Height of Substrate" ), 0.2, true ) );
383  "a", "a",
384  _( "distance between strip and top metal" ), 0.2,
385  true ) );
387  "T", "T",
388  _( "Strip Thickness" ), 0.035, true ) );
390  "mu Rel C", _( "mu Rel C" ),
391  _( "Relative Permeability (mu) of Conductor" ), 1,
392  false ) );
393 
395  "W", "W",
396  _( "Line Width" ), 0.2, true ) );
398  "L", "L",
399  _( "Line Length" ), 50.0, true ) );
400 
402  "Z0", "Z0",
403  _( "Characteristic Impedance" ), 50, true ) );
406  "Ang_l", "Ang_l",
407  _( "Electrical Length" ), 0, true ) );
408  break;
409 
410  case TWISTEDPAIR_TYPE: // twisted pair
411  m_TLine = new TWISTEDPAIR();
412  m_Icon = new wxBitmap( twistedpair_xpm );
413  m_HasPrmSelection = true;
414 
415  m_Messages.Add( _( "ErEff:" ) );
416  m_Messages.Add( _( "Conductor Losses:" ) );
417  m_Messages.Add( _( "Dielectric Losses:" ) );
418  m_Messages.Add( _( "Skin Depth:" ) );
419 
421  "Twists", _( "Twists" ),
422  _( "Number of Twists per Length" ), 0.0, false ) );
424  "mu Rel C", _( "mu Rel C" ),
425  _( "Relative Permeability (mu) of Conductor" ), 1,
426  false ) );
428  "ErEnv", _( "ErEnv" ),
429  _( "Relative Permittivity of Environment" ), 1,
430  false ) );
432  "Din", _( "Din" ),
433  _( "Inner Diameter (conductor)" ), 1.0, true ) );
435  "Dout", _( "Dout" ),
436  _( "Outer Diameter (insulator)" ), 8.0, true ) );
438  "L", "L",
439  _( "Cable Length" ), 50.0, true ) );
440 
442  "Z0", "Z0",
443  _( "Characteristic Impedance" ), 50.0, true ) );
446  "Ang_l", "Ang_l",
447  _( "Electrical Length" ), 0.0, true ) );
448  break;
449 
450  case END_OF_LIST_TYPE: // Not really used
451  break;
452  }
453 }
454 
456 {
457  delete m_TLine;
458  delete m_Icon;
459 
460  for( auto& ii : m_prms_List )
461  delete ii;
462 
463  m_prms_List.clear();
464 }
465 
466 
468 {
469  auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
470  std::string name( m_TLine->m_Name );
471 
472  if( cfg->m_TransLine.param_values.count( name ) )
473  {
474  wxASSERT( cfg->m_TransLine.param_units.count( name ) );
475 
476  for( auto& param : m_prms_List )
477  {
478  try
479  {
480  param->m_Value =
481  cfg->m_TransLine.param_values.at( name ).at( param->m_KeyWord );
482  param->m_UnitSelection =
483  cfg->m_TransLine.param_units.at( name ).at( param->m_KeyWord );
484  }
485  catch( ... )
486  {}
487  }
488  }
489 }
490 
491 
493 {
494  auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
495  std::string name( m_TLine->m_Name );
496 
497  for( auto& param : m_prms_List )
498  {
499  if( !std::isfinite( param->m_Value ) )
500  {
501  param->m_Value = 0;
502  }
503 
504  cfg->m_TransLine.param_values[ name ][ param->m_KeyWord ] = param->m_Value;
505  cfg->m_TransLine.param_units[ name ][ param->m_KeyWord ] = param->m_UnitSelection;
506  }
507 }
508 
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
#define NULL
std::vector< TRANSLINE_PRM * > m_prms_List
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
PRMS_ID
Definition: transline.h:37
TRANSLINE_TYPE_ID
const char * m_Name
Definition: transline.h:85
std::string m_KeyWord
Definition: coax.h:30
const char * name
Definition: DXF_plotter.cpp:59
#define _(s)
Definition: 3d_actions.cpp:33
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)
TRANSLINE_PRM ctor.