33#include <wx/textentry.h>
34#include <wx/numformatter.h>
43 aString.Left( 1 ).ToLong( &val );
45 Range = aString.Right( aString.Length() - 1 );
57 if(
Range.GetChar( 0 ) ==
'~' )
71 if( aString.IsEmpty() )
74 char units[8] = { 0, };
77 sscanf( (
const char*) aString.c_str(),
"%lf%7s", &
m_base, units );
87 for(
char* bufPtr = units; *bufPtr; ++bufPtr )
88 *bufPtr = tolower( *bufPtr );
90 if( strcmp( units,
"meg" ) == 0 )
116 while( std::fabs(
m_base ) >= 1000.0 )
152 return wxEmptyString;
172 return wxEmptyString;
215 wxString
res( wxString::Format(
"%.3f",
ToDouble() ) );
224 wxString range( aFormat.
Range );
226 if( range.StartsWith( wxS(
"~" ) ) )
241 while( std::fabs( mantissa ) >= 10.0 )
247 while( mantissa != 0.0 && std::fabs( mantissa ) < 1.0 )
256 wxString
res = wxString::FromCDouble( mantissa, std::max( 0, aFormat.
Precision -
scale - 1 ) );
260 res = wxString::FromCDouble( mantissa );
268 wxString
res = wxString::FromCDouble(
m_base );
289 else if( prefixDiff < 0 )
320 else if( prefixDiff < 0 )
360 if ( aString.Find(
',' ) >= 0 || aString.Find(
'.' ) >= 0 )
362 while( aString.EndsWith(
'0' ) )
363 aString.RemoveLast();
365 if( aString.EndsWith(
'.' ) || aString.EndsWith(
',' ) )
366 aString.RemoveLast();
373 wxTextEntry*
const text = GetTextEntry();
378 if(
text->IsEmpty() )
383 DisplayError( aParent, wxString::Format(
_(
"Please, fill required fields" ) ) );
387 wxString svalue =
text->GetValue();
392 svalue.Replace(
",",
"." );
401 DisplayError( aParent, wxString::Format(
_(
"'%s' is not a valid Spice value." ),
402 text->GetValue() ) );
407 if( svalue !=
text->GetValue() )
408 text->SetValue( svalue );
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
bool m_emptyAllowed
< Is it valid to get an empty value?
bool Validate(wxWindow *aParent) override
Helper class to recognize Spice formatted values.
SPICE_VALUE operator+(const SPICE_VALUE &aOther) const
SPICE_VALUE operator-(const SPICE_VALUE &aOther) const
UNIT_PREFIX m_prefix
Was the value defined using the Spice notation?
static UNIT_PREFIX ParseSIPrefix(wxChar c)
void Normalize()
Normalize the value.
double ToNormalizedDouble(wxString *aPrefix)
wxString ToString() const
Return string value as when converting double to string (e.g.
SPICE_VALUE operator/(const SPICE_VALUE &aOther) const
Remove redundant zeros from the end of a string.
wxString ToSpiceString() const
Return string value in Spice format (e.g.
SPICE_VALUE operator*(const SPICE_VALUE &aOther) const
SPICE_VALUE()
Parses the string to create a Spice value (e.g. 100n)
static void StripZeros(wxString &aString)
VECTOR3< T > Normalize()
Compute the normalized vector.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
This file is part of the common library.
T clamp(T min, T value, T max)
wxString si_prefix(SPICE_VALUE::UNIT_PREFIX aPrefix)
wxString spice_prefix(SPICE_VALUE::UNIT_PREFIX aPrefix)
std::vector< FAB_LAYER_COLOR > dummy
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".