KiCad PCB EDA Suite
pcb_calculator_utils.cpp File Reference
#include <pcb_calculator_utils.h>
#include <locale.h>

Go to the source code of this file.

Functions

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

Function Documentation

◆ findMatch()

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

Definition at line 23 of file pcb_calculator_utils.cpp.

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

References text.

Referenced by PANEL_WAVELENGTH::OnButtonPermittivity(), PANEL_TRANSLINE::OnTranslineEpsilonR_Button(), PANEL_TRANSLINE::OnTranslineRho_Button(), and PANEL_TRANSLINE::OnTranslineTanD_Button().