KiCad PCB EDA Suite
panel_via_size.cpp File Reference
#include <cmath>
#include <wx/choicdlg.h>
#include <bitmaps.h>
#include <calculator_panels/panel_via_size.h>
#include <common_data.h>
#include <pcb_calculator_settings.h>
#include <units_scales.h>

Go to the source code of this file.

Macros

#define DEFAULT_UNIT_SEL_MM   0
 
#define DEFAULT_UNIT_SEL_OHM   0
 

Functions

double DoubleFromString (const wxString &TextValue)
 

Macro Definition Documentation

◆ DEFAULT_UNIT_SEL_MM

#define DEFAULT_UNIT_SEL_MM   0

◆ DEFAULT_UNIT_SEL_OHM

#define DEFAULT_UNIT_SEL_OHM   0

Function Documentation

◆ DoubleFromString()

double DoubleFromString ( const wxString &  TextValue)

Definition at line 37 of file params_read_write.cpp.

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

Referenced by PANEL_VIA_SIZE::onUpdateViaCalcErrorText(), and PANEL_VIA_SIZE::OnViaCalculate().