KiCad PCB EDA Suite
transline_dlg_funct.cpp File Reference
#include <wx/filename.h>
#include <wx/settings.h>
#include <wx/wx.h>
#include <bitmaps/bitmap_types.h>
#include "common_data.h"
#include "pcb_calculator_frame.h"
#include "bitmaps/microstrip_zodd_zeven.cpp"

Go to the source code of this file.

Classes

struct  DLG_PRM_DATA
 

Macros

#define substrateprms_cnt   (sizeof(substrateprms)/sizeof(substrateprms[0]))
 
#define physprms_cnt   (sizeof(physprms)/sizeof(physprms[0]))
 
#define elecprms_cnt   (sizeof(elecprms)/sizeof(elecprms[0]))
 
#define frequencyprms_cnt   (sizeof(frequencyprms)/sizeof(frequencyprms[0]))
 

Functions

double DoubleFromString (const wxString &TextValue)
 
static bool findMatch (wxArrayString &aList, const wxString &aValue, int &aIdx)
 

Macro Definition Documentation

◆ elecprms_cnt

#define elecprms_cnt   (sizeof(elecprms)/sizeof(elecprms[0]))

◆ frequencyprms_cnt

#define frequencyprms_cnt   (sizeof(frequencyprms)/sizeof(frequencyprms[0]))

◆ physprms_cnt

#define physprms_cnt   (sizeof(physprms)/sizeof(physprms[0]))

◆ substrateprms_cnt

#define substrateprms_cnt   (sizeof(substrateprms)/sizeof(substrateprms[0]))

Function Documentation

◆ DoubleFromString()

double DoubleFromString ( const wxString &  TextValue)

Definition at line 36 of file params_read_write.cpp.

37 {
38  double value = 0;
39 
40  /* Acquire the 'right' decimal point separator */
41  const struct lconv* lc = localeconv();
42  wxChar decimal_point = lc->decimal_point[0];
43  wxString buf( TextValue.Strip( wxString::both ) );
44 
45  /* Convert the period in decimal point */
46  buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
47  // An ugly fix needed by WxWidgets 2.9.1 that sometimes
48  // back to a point as separator, although the separator is the comma
49  buf.Replace( wxT( "," ), wxString( decimal_point, 1 ) );
50 
51  /* Find the end of the numeric part
52  *(when units are append to the number, remove them)
53  */
54  unsigned brk_point = 0;
55  while( brk_point < buf.Len() )
56  {
57  wxChar ch = buf[brk_point];
58  if( !( ( ch >= '0' && ch <= '9' ) || ( ch == decimal_point ) || ( ch == '-' )
59  || ( ch == '+' ) || ( ch == 'e' ) || ( ch == 'E' ) ) )
60  {
61  break;
62  }
63  ++brk_point;
64  }
65 
66  // Check for strings that cannot qualify as a number
67  if( brk_point == 0 )
68  {
69  return std::nan( "" );
70  }
71 
72  /* Extract the numeric part */
73  if( !buf.Left( brk_point ).ToDouble( &value ) )
74  {
75  return std::nan( "" );
76  }
77  return value;
78 }

Referenced by PCB_CALCULATOR_FRAME::TransfDlgDataToTranslineParams().

◆ findMatch()

static bool findMatch ( wxArrayString &  aList,
const wxString &  aValue,
int &  aIdx 
)
static

Definition at line 39 of file transline_dlg_funct.cpp.

40 {
41  bool success = false;
42  // Find the previous choice index:
43  aIdx = 0;
44 
45  // Some countries use comma instead of point as separator.
46  // The value can be enter with pint or comma
47  // use point for string comparisons:
48  wxString cvalue = aValue;
49  cvalue.Replace( ',', '.' );
50 
51  // First compare strings:
52  for( wxString& text: aList )
53  {
54  if( text.IsEmpty() ) // No match found: select the empty line choice
55  break;
56 
57  wxString val_str = text.BeforeFirst( ' ' );
58  val_str.Replace( ',', '.' );
59 
60  // compare string values
61  if( val_str == cvalue )
62  {
63  success = true;
64  break;
65  }
66 
67  aIdx++;
68  }
69 
70  // Due to multiple ways to write a double, if string values
71  // do not match, compare double values
72  if( !success )
73  {
74  struct lconv* lc = localeconv();
75  char localeDecimalSeparator = *lc->decimal_point;
76 
77  if( localeDecimalSeparator == ',' )
78  cvalue.Replace( '.', ',' );
79 
80  double curr_value;
81  cvalue.ToDouble( &curr_value );
82 
83  aIdx = 0;
84 
85  for( wxString& text: aList )
86  {
87  if( text.IsEmpty() ) // No match found: select the empty line choice
88  break;
89 
90  double val;
91  wxString val_str = text.BeforeFirst( ' ' );
92 
93  if( localeDecimalSeparator == ',' )
94  val_str.Replace( '.', ',' );
95 
96  val_str.ToDouble( &val );;
97 
98  if( curr_value == val )
99  {
100  success = true;
101  break;
102  }
103 
104  aIdx++;
105  }
106  }
107 
108  return success;
109 }

References text.

Referenced by PCB_CALCULATOR_FRAME::OnTranslineEpsilonR_Button(), PCB_CALCULATOR_FRAME::OnTranslineRho_Button(), and PCB_CALCULATOR_FRAME::OnTranslineTanD_Button().