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 
28 // Bitmaps:
29 #include <c_microstrip.xpm>
30 #include <microstrip.xpm>
31 #include <twistedpair.xpm>
32 #include <coax.xpm>
33 #include <cpw.xpm>
34 #include <cpw_back.xpm>
35 #include <stripline.xpm>
36 #include <rectwaveguide.xpm>
37 
38 // transline specific functions:
39 #include <transline.h>
40 #include <microstrip.h>
41 #include <coplanar.h>
42 #include <rectwaveguide.h>
43 #include <coax.h>
44 #include <c_microstrip.h>
45 #include <stripline.h>
46 #include <twistedpair.h>
47 
48 #include <kiface_i.h>
50 #include <UnitSelector.h>
51 #include <transline_ident.h>
52 
53 
54 /*
55  * TRANSLINE_PRM
56  * A class to handle one parameter of transline
57  */
59  const wxString& aLabel,
60  const wxString& aToolTip,
61  double aValue,
62  bool aConvUnit )
63 {
64  m_Type = aType;
65  m_Id = aId;
66  m_Label = aLabel;
67  m_ToolTip = aToolTip;
68  m_Value = aValue;
69  m_ConvUnit = aConvUnit;
70  m_ValueCtrl = NULL;
71  m_UnitCtrl = NULL;
72  m_UnitSelection = 0;
74  }
75 
76 
78 {
79  if( m_UnitCtrl && m_ConvUnit )
80  return 1.0 / ( (UNIT_SELECTOR*) m_UnitCtrl )->GetUnitScale();
81  else
82  return 1.0;
83 }
84 
85 
87 {
88  if( m_UnitCtrl )
89  return ( (UNIT_SELECTOR*) m_UnitCtrl )->GetUnitScale();
90  else
91  return 1.0;
92 }
93 
94 
95 /*
96  * TRANSLINE_IDENT
97  * A class to handle a list of parameters of a given transline
98  */
99 
101 {
102  m_Type = aType; // The type of transline handled
103  m_Icon = NULL; // An xpm icon to display in dialogs
104  m_TLine = NULL; // The TRANSLINE itself
105  m_HasPrmSelection = false; // true if selection of parameters must be enabled in dialog menu
106 
107  // Add common prms:
108  // Default values are for FR4
110  _( "Er" ), _( "Epsilon R: substrate relative dielectric constant" ),
111  4.6, false ) );
113  _( "TanD" ), _( "Tangent delta: dielectric loss factor." ), 2e-2,
114  false ) );
115 
116  // Default value is for copper
118  _( "Rho" ),
119  _( "Electrical resistivity or specific electrical resistance of conductor (Ohm*meter)" ),
120  1.72e-8, false ) );
121 
122  // Default value is in GHz
124  _( "Frequency" ), _( "Frequency of the input signal" ), 1.0, true ) );
125 
126 
127  switch( m_Type )
128  {
129  case MICROSTRIP_TYPE: // microstrip
130  m_TLine = new MICROSTRIP();
131  m_Icon = new wxBitmap( microstrip_xpm );
132 
133  m_Messages.Add( _( "ErEff:" ) );
134  m_Messages.Add( _( "Conductor Losses:" ) );
135  m_Messages.Add( _( "Dielectric Losses:" ) );
136  m_Messages.Add( _( "Skin Depth:" ) );
137 
139  "H", _( "Height of Substrate" ), 0.2, true ) );
141  "H_t", _( "Height of Box Top" ), 1e20, true ) );
143  "T", _( "Strip Thickness" ), 0.035, true ) );
145  _( "Rough" ), _( "Conductor Roughness" ), 0.0, true ) );
147  _( "mu Rel S" ),
148  _( "Relative Permeability (mu) of Substrate" ), 1, false ) );
150  _( "mu Rel C" ), _( "Relative Permeability (mu) of Conductor" ), 1,
151  false ) );
152 
154  "W", _( "Line Width" ), 0.2, true ) );
156  "L", _( "Line Length" ), 50.0, true ) );
157 
159  "Z0", _( "Characteristic Impedance" ), 50.0, true ) );
162  "Ang_l", _( "Electrical Length" ), 0.0, true ) );
163  break;
164 
165  case CPW_TYPE: // coplanar waveguide
166  m_TLine = new COPLANAR();
167  m_Icon = new wxBitmap( cpw_xpm );
168  m_HasPrmSelection = true;
169 
170  m_Messages.Add( _( "ErEff:" ) );
171  m_Messages.Add( _( "Conductor Losses:" ) );
172  m_Messages.Add( _( "Dielectric Losses:" ) );
173  m_Messages.Add( _( "Skin Depth:" ) );
174 
176  "H", _( "Height of Substrate" ), 0.2, true ) );
178  "T", _( "Strip Thickness" ), 0.035, true ) );
180  _( "mu Rel C" ), _( "Relative Permeability (mu) of Conductor" ), 1,
181  false ) );
182 
184  "W", _( "Line Width" ), 0.2, true ) );
186  "S", _( "Gap Width" ), 0.2, true ) );
188  "L", _( "Line Length" ), 50.0, true ) );
189 
191  "Z0", _( "Characteristic Impedance" ), 50.0, true ) );
194  "Ang_l", _( "Electrical Length" ), 0.0, true ) );
195  break;
196 
197  case GROUNDED_CPW_TYPE: // grounded coplanar waveguide
198  m_TLine = new GROUNDEDCOPLANAR();
199  m_Icon = new wxBitmap( cpw_back_xpm );
200  m_HasPrmSelection = true;
201 
202  m_Messages.Add( _( "ErEff:" ) );
203  m_Messages.Add( _( "Conductor Losses:" ) );
204  m_Messages.Add( _( "Dielectric Losses:" ) );
205  m_Messages.Add( _( "Skin Depth:" ) );
206 
208  "H", _( "Height of Substrate" ), 0.2, true ) );
210  "T", _( "Strip Thickness" ), 0.035, true ) );
212  "mu Rel C", _( "Relative Permeability (mu) of Conductor" ), 1,
213  false ) );
214 
216  "W", _( "Line Width" ), 0.2, true ) );
218  "S", _( "Gap Width" ), 0.2, true ) );
220  "L", _( "Line Length" ), 50.0, true ) );
221 
223  "Z0", _( "Characteristic Impedance" ), 50.0, true ) );
226  "Ang_l", _( "Electrical Length" ), 0, true ) );
227  break;
228 
229 
230  case RECTWAVEGUIDE_TYPE: // rectangular waveguide
231  m_TLine = new RECTWAVEGUIDE();
232  m_Icon = new wxBitmap( rectwaveguide_xpm );
233  m_HasPrmSelection = true;
234 
235  m_Messages.Add( _( "ZF(H10) = Ey / Hx:" ) );
236  m_Messages.Add( _( "ErEff:" ) );
237  m_Messages.Add( _( "Conductor Losses:" ) );
238  m_Messages.Add( _( "Dielectric Losses:" ) );
239  m_Messages.Add( _( "TE-Modes:" ) );
240  m_Messages.Add( _( "TM-Modes:" ) );
241 
243  _( "mu Rel I" ), _( "Relative Permeability (mu) of Insulator" ), 1, false ) );
245  _( "mu Rel C" ), _( "Relative Permeability (mu) of Conductor" ), 1,
246  false ) );
247 
249  "a", _( "Width of Waveguide" ), 10.0, true ) );
251  "b", _( "Height of Waveguide" ), 5.0, true ) );
253  "L", _( "Waveguide Length" ), 50.0, true ) );
254 
256  "Z0", _( "Characteristic Impedance" ), 50.0, true ) );
259  "Ang_l", _( "Electrical Length" ), 0, true ) );
260  break;
261 
262  case COAX_TYPE: // coaxial cable
263  m_TLine = new COAX();
264  m_Icon = new wxBitmap( coax_xpm );
265  m_HasPrmSelection = true;
266 
267  m_Messages.Add( _( "ErEff:" ) );
268  m_Messages.Add( _( "Conductor Losses:" ) );
269  m_Messages.Add( _( "Dielectric Losses:" ) );
270  m_Messages.Add( _( "TE-Modes:" ) );
271  m_Messages.Add( _( "TM-Modes:" ) );
272 
274  _( "mu Rel I" ), _( "Relative Permeability (mu) of Insulator" ), 1, false ) );
276  _( "mu Rel C" ), _( "Relative Permeability (mu) of Conductor" ), 1,
277  false ) );
278 
280  _( "Din" ), _( "Inner Diameter (conductor)" ), 1.0, true ) );
282  _( "Dout" ), _( "Outer Diameter (insulator)" ), 8.0, true ) );
284  "L", _( "Line Length" ), 50.0, true ) );
285 
287  "Z0", _( "Characteristic Impedance" ), 50.0, true ) );
290  "Ang_l", _( "Electrical Length" ), 0.0, true ) );
291  break;
292 
293  case C_MICROSTRIP_TYPE: // coupled microstrip
294  m_TLine = new C_MICROSTRIP();
295  m_Icon = new wxBitmap( c_microstrip_xpm );
296  m_HasPrmSelection = true;
297 
298  m_Messages.Add( _( "ErEff Even:" ) );
299  m_Messages.Add( _( "ErEff Odd:" ) );
300  m_Messages.Add( _( "Conductor Losses Even:" ) );
301  m_Messages.Add( _( "Conductor Losses Odd:" ) );
302  m_Messages.Add( _( "Dielectric Losses Even:" ) );
303  m_Messages.Add( _( "Dielectric Losses Odd:" ) );
304  m_Messages.Add( _( "Skin Depth:" ) );
305 
307  "H", _( "Height of Substrate" ), 0.2, true ) );
309  "H_t", _( "Height of Box Top" ), 1e20, true ) );
311  "T", _( "Strip Thickness" ), 0.035, true ) );
313  _( "Rough" ), _( "Conductor Roughness" ), 0.0, true ) );
315  _( "mu Rel C" ), _( "Relative Permeability (mu) of Conductor" ), 1,
316  false ) );
317 
319  "W", _( "Line Width" ), 0.2, true ) );
321  "S", _( "Gap Width" ), 0.2, true ) );
323  "L", _( "Line Length" ), 50.0, true ) );
324 
326  _( "Zeven" ), _( "Even mode impedance (lines driven by common voltages)" ), 50.0, true ) );
328  _( "Zodd" ), _( "Odd mode impedance (lines driven by opposite (differential) voltages)" ), 50.0, true ) );
330  "Ang_l", _( "Electrical Length" ), 0.0, true ) );
331  break;
332 
333  case STRIPLINE_TYPE: // stripline
334  m_TLine = new STRIPLINE();
335  m_Icon = new wxBitmap( stripline_xpm );
336 
337  m_Messages.Add( _( "ErEff:" ) );
338  m_Messages.Add( _( "Conductor Losses:" ) );
339  m_Messages.Add( _( "Dielectric Losses:" ) );
340  m_Messages.Add( _( "Skin Depth:" ) );
341 
343  "H", _( "Height of Substrate" ), 0.2, true ) );
345  "a", _( "distance between strip and top metal" ), 0.2,
346  true ) );
348  "T", _( "Strip Thickness" ), 0.035, true ) );
350  _( "mu Rel C" ), _( "Relative Permeability (mu) of Conductor" ), 1,
351  false ) );
352 
354  "W", _( "Line Width" ), 0.2, true ) );
356  "L", _( "Line Length" ), 50.0, true ) );
357 
359  "Z0", _( "Characteristic Impedance" ), 50, true ) );
362  "Ang_l", _( "Electrical Length" ), 0, true ) );
363  break;
364 
365  case TWISTEDPAIR_TYPE: // twisted pair
366  m_TLine = new TWISTEDPAIR();
367  m_Icon = new wxBitmap( twistedpair_xpm );
368  m_HasPrmSelection = true;
369 
370  m_Messages.Add( _( "ErEff:" ) );
371  m_Messages.Add( _( "Conductor Losses:" ) );
372  m_Messages.Add( _( "Dielectric Losses:" ) );
373  m_Messages.Add( _( "Skin Depth:" ) );
374 
376  _( "Twists" ), _( "Number of Twists per Length" ), 0.0, false ) );
378  _( "mu Rel C" ), _( "Relative Permeability (mu) of Conductor" ), 1,
379  false ) );
381  _( "ErEnv" ), _( "Relative Permittivity of Environment" ), 1,
382  false ) );
384  _( "Din" ), _( "Inner Diameter (conductor)" ), 1.0, true ) );
386  _( "Dout" ), _( "Outer Diameter (insulator)" ), 8.0, true ) );
388  "L", _( "Cable Length" ), 50.0, true ) );
389 
391  "Z0", _( "Characteristic Impedance" ), 50.0, true ) );
394  "Ang_l", _( "Electrical Length" ), 0.0, true ) );
395  break;
396 
397  case END_OF_LIST_TYPE: // Not really used
398  break;
399  }
400 }
401 
403 {
404  delete m_TLine;
405  delete m_Icon;
406 
407  for( auto& ii : m_prms_List )
408  delete ii;
409 
410  m_prms_List.clear();
411 }
412 
413 
415 {
416  auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
417  std::string name( m_TLine->m_Name );
418 
419  if( cfg->m_TransLine.param_values.count( name ) )
420  {
421  wxASSERT( cfg->m_TransLine.param_units.count( name ) );
422 
423  for( auto& param : m_prms_List )
424  {
425  std::string id = param->m_Label.ToStdString();
426 
427  try
428  {
429  param->m_Value = cfg->m_TransLine.param_values.at( name ).at( id );
430  param->m_UnitSelection = cfg->m_TransLine.param_units.at( name ).at( id );
431  }
432  catch( ... )
433  {}
434  }
435  }
436 }
437 
438 
440 {
441  auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
442  std::string name( m_TLine->m_Name );
443 
444  for( auto& param : m_prms_List )
445  {
446  std::string id = param->m_Label.ToStdString();
447 
448  if( !std::isfinite( param->m_Value ) )
449  {
450  param->m_Value = 0;
451  }
452 
453  cfg->m_TransLine.param_values[ name ][ id ] = param->m_Value;
454  cfg->m_TransLine.param_units[ name ][ id ] = param->m_UnitSelection;
455  }
456 }
457 
wxBitmap * m_Icon
double FromUserUnit()
double m_NormalizedValue
TRANSLINE_PRM(PRM_TYPE aType, PRMS_ID aId, const wxString &aLabel=wxEmptyString, const wxString &aToolTip=wxEmptyString, double aValue=0.0, bool aConvUnit=false)
void AddPrm(TRANSLINE_PRM *aParam)
wxArrayString m_Messages
wxString m_ToolTip
PRM_TYPE
wxString m_Label
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
Definition: coax.h:30
const char * name
Definition: DXF_plotter.cpp:60
#define _(s)
Definition: 3d_actions.cpp:33
TRANSLINE * m_TLine
TRANSLINE_IDENT(enum TRANSLINE_TYPE_ID aType)
a wxChoiceBox to select units in Pcb_Calculator