33#include <wx/textentry.h>
34#include <wx/numformatter.h>
43 if( aString.IsEmpty() )
51 aString.Left( 1 ).ToLong( &val );
53 Range = aString.Right( aString.Length() - 1 );
60 return wxString::Format( wxS(
"%d%s" ), std::clamp(
Precision, 0, 9 ),
Range );
66 if(
Range.GetChar( 0 ) ==
'~' )
80 if( aString.IsEmpty() )
83 char units[8] = { 0, };
86 sscanf( (
const char*) aString.c_str(),
"%lf%7s", &
m_base, units );
96 for(
char* bufPtr = units; *bufPtr; ++bufPtr )
97 *bufPtr = tolower( *bufPtr );
99 if( strcmp( units,
"meg" ) == 0 )
125 while( std::fabs(
m_base ) >= 1000.0 )
161 return wxEmptyString;
181 return wxEmptyString;
224 wxString
res( wxString::Format(
"%.3f",
ToDouble() ) );
233 wxString range( aFormat.
Range );
235 if( range.EndsWith( wxS(
"°" ) ) )
242 if( range.StartsWith( wxS(
"~" ) ) )
257 while( std::fabs( mantissa ) >= 10.0 )
263 while( mantissa != 0.0 && std::fabs( mantissa ) < 1.0 )
272 wxString
res = wxString::FromCDouble( mantissa, std::max( 0, aFormat.
Precision -
scale - 1 ) );
276 res = wxString::FromCDouble( mantissa );
284 wxString
res = wxString::FromCDouble(
m_base );
305 else if( prefixDiff < 0 )
336 else if( prefixDiff < 0 )
376 if ( aString.Find(
',' ) >= 0 || aString.Find(
'.' ) >= 0 )
378 while( aString.EndsWith(
'0' ) )
379 aString.RemoveLast();
381 if( aString.EndsWith(
'.' ) || aString.EndsWith(
',' ) )
382 aString.RemoveLast();
389 wxTextEntry*
const text = GetTextEntry();
394 if(
text->IsEmpty() )
399 DisplayError( aParent, wxString::Format(
_(
"Please, fill required fields" ) ) );
403 wxString svalue =
text->GetValue();
408 svalue.Replace(
",",
"." );
417 DisplayError( aParent, wxString::Format(
_(
"'%s' is not a valid SPICE value." ),
418 text->GetValue() ) );
423 if( svalue !=
text->GetValue() )
424 text->SetValue( svalue );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
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.
wxString si_prefix(SPICE_VALUE::UNIT_PREFIX aPrefix)
wxString spice_prefix(SPICE_VALUE::UNIT_PREFIX aPrefix)
std::vector< FAB_LAYER_COLOR > dummy