30 #include <wx/textentry.h> 31 #include <wx/numformatter.h> 39 if( aString.IsEmpty() )
40 throw std::invalid_argument(
"Spice value cannot be empty" );
44 if( sscanf( (
const char*) aString.c_str(),
"%lf%7s", &
m_base, buf ) == 0 )
45 throw std::invalid_argument(
"Invalid Spice value string" );
57 for(
char* bufPtr = buf; *bufPtr; ++bufPtr )
58 *bufPtr = tolower( *bufPtr );
60 if( !strcmp( buf,
"meg" ) )
78 throw std::invalid_argument(
"Invalid unit prefix" );
88 while( std::fabs(
m_base ) >= 1000.0 )
107 res *= std::pow( 10, (
int)
m_prefix );
123 wxString res = wxString::FromCDouble(
m_base );
157 else if( prefixDiff < 0 )
188 else if( prefixDiff < 0 )
228 if ( aString.Find(
',' ) >= 0 || aString.Find(
'.' ) >= 0 )
230 while( aString.EndsWith(
'0' ) )
231 aString.RemoveLast();
233 if( aString.EndsWith(
'.' ) || aString.EndsWith(
',' ) )
234 aString.RemoveLast();
241 wxTextEntry*
const text = GetTextEntry();
246 if( text->IsEmpty() )
255 wxString svalue = text->GetValue();
260 svalue.Replace(
",",
"." );
270 wxString::Format( _(
"\"%s\" is not a valid Spice value" ), text->GetValue() ) );
275 if( svalue != text->GetValue() )
276 text->SetValue( svalue );
bool Validate(wxWindow *aParent) override
SPICE_VALUE operator/(const SPICE_VALUE &aOther) const
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
wxString ToSpiceString() const
Returns string value in Spice format (e.g.
This file is part of the common library.
void Normalize()
Normalizes the value.
SPICE_VALUE operator*(const SPICE_VALUE &aOther) const
static void stripZeros(wxString &aString)
Removes redundant zeros from the end of a string.
SPICE_VALUE operator+(const SPICE_VALUE &aOther) const
Helper class to handle Spice way of expressing values (e.g. 10.5 Meg)
wxString ToString() const
Returns string value as when converting double to string (e.g.
bool m_spiceStr
Was the value defined using the Spice notation?
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
SPICE_VALUE operator-(const SPICE_VALUE &aOther) const
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.