29#include <wx/textentry.h>
30#include <wx/numformatter.h>
39 if( aString.IsEmpty() )
47 aString.Left( 1 ).ToLong( &val );
49 Range = aString.Right( aString.Length() - 1 );
56 return wxString::Format( wxS(
"%d%s" ), std::clamp(
Precision, 0, 9 ),
Range );
62 if(
Range.GetChar( 0 ) ==
'~' )
76 if( aString.IsEmpty() )
79 char units[8] = { 0, };
82 sscanf( (
const char*) aString.c_str(),
"%lf%7s", &
m_base, units );
92 for(
char* bufPtr = units; *bufPtr; ++bufPtr )
93 *bufPtr = tolower( *bufPtr );
95 if( strcmp( units,
"meg" ) == 0 )
121 while( std::fabs(
m_base ) >= 1000.0 )
157 return wxEmptyString;
177 return wxEmptyString;
220 wxString
res( wxString::Format(
"%.3f",
ToDouble() ) );
229 wxString range( aFormat.
Range );
231 if( range.EndsWith( wxS(
"°" ) ) )
238 if( range.StartsWith( wxS(
"~" ) ) )
253 while( std::fabs( mantissa ) >= 10.0 )
259 while( mantissa != 0.0 && std::fabs( mantissa ) < 1.0 )
268 wxString
res = wxString::FromCDouble( mantissa, std::max( 0, aFormat.
Precision -
scale - 1 ) );
271 if( ssize_t(
res.length() ) > aFormat.
Precision +
static_cast<long long>(
scale ) + 1 )
272 res = wxString::FromCDouble( mantissa );
280 wxString
res = wxString::FromCDouble(
m_base );
301 else if( prefixDiff < 0 )
332 else if( prefixDiff < 0 )
372 if ( aString.Find(
',' ) >= 0 || aString.Find(
'.' ) >= 0 )
374 while( aString.EndsWith(
'0' ) )
375 aString.RemoveLast();
377 if( aString.EndsWith(
'.' ) || aString.EndsWith(
',' ) )
378 aString.RemoveLast();
385 wxTextEntry*
const text = GetTextEntry();
390 if(
text->IsEmpty() )
395 DisplayError( aParent, wxString::Format(
_(
"Please, fill required fields" ) ) );
399 wxString svalue =
text->GetValue();
404 svalue.Replace(
",",
"." );
413 DisplayError( aParent, wxString::Format(
_(
"'%s' is not a valid SPICE value." ),
414 text->GetValue() ) );
419 if( svalue !=
text->GetValue() )
420 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)
void DisplayError(wxWindow *aParent, const wxString &aText)
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