From 56525296ba52b53158ee4323d2419011d0806290 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 4 Nov 2019 12:59:22 +0100 Subject: [PATCH] Pcb_calculator: TransLine default parameters pre-selection: fix a minor issue in countries using comma sepator in doubles. --- pcb_calculator/transline_dlg_funct.cpp | 31 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/pcb_calculator/transline_dlg_funct.cpp b/pcb_calculator/transline_dlg_funct.cpp index df30fac8d4..fcdcb52f68 100644 --- a/pcb_calculator/transline_dlg_funct.cpp +++ b/pcb_calculator/transline_dlg_funct.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2011 jean-pierre.charras - * Copyright (C) 1992-2011 Kicad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2019 Kicad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -30,10 +30,9 @@ extern double DoubleFromString( const wxString& TextValue ); -// these values come from QucsStudio ( by Michael Margraf ) +// Display a selection of usual Er, TanD, Rho values +// List format is -// Display a selection of usual Er, TanD, Rho values -// format is // A helper function to find the choice in a list of values // return true if a index in aList that matches aValue is found. @@ -42,14 +41,10 @@ static bool findMatch(wxArrayString& aList, wxString& aValue, int& aIdx ) bool success = false; // Find the previous choice index: aIdx = 0; - double curr_value; - - // Calculate the current value (can be in "C" or current locale): - if( !aValue.ToDouble( &curr_value ) ) - aValue.ToCDouble( &curr_value ); // Some countries use comma instead of point as separator. - // use point for comparisons: + // The value can be enter with pint or comma + // use point for string comparisons: wxString cvalue = aValue; cvalue.Replace( ',', '.' ); @@ -76,6 +71,15 @@ static bool findMatch(wxArrayString& aList, wxString& aValue, int& aIdx ) // do not match, compare double values if( !success ) { + struct lconv* lc = localeconv(); + char localeDecimalSeparator = *lc->decimal_point; + + if( localeDecimalSeparator == ',' ) + cvalue.Replace( '.', ',' ); + + double curr_value; + cvalue.ToDouble( &curr_value ); + aIdx = 0; for( wxString& text: aList ) @@ -84,7 +88,12 @@ static bool findMatch(wxArrayString& aList, wxString& aValue, int& aIdx ) break; double val; - text.BeforeFirst( ' ' ).ToDouble( &val );; + wxString val_str = text.BeforeFirst( ' ' ); + + if( localeDecimalSeparator == ',' ) + val_str.Replace( '.', ',' ); + + val_str.ToDouble( &val );; if( curr_value == val ) {