KiCad PCB EDA Suite
SPICE_VALIDATOR Class Reference

Helper class to recognize Spice formatted values

More...

#include <spice_value.h>

Inheritance diagram for SPICE_VALIDATOR:

Public Member Functions

 SPICE_VALIDATOR (bool aEmptyAllowed=false)
 
wxObject * Clone () const override
 
bool Validate (wxWindow *aParent) override
 

Private Attributes

bool m_emptyAllowed
 

Is it valid to get an empty value?

More...
 

Detailed Description

Helper class to recognize Spice formatted values

Definition at line 146 of file spice_value.h.

Constructor & Destructor Documentation

SPICE_VALIDATOR::SPICE_VALIDATOR ( bool  aEmptyAllowed = false)
inline

Definition at line 149 of file spice_value.h.

150  : m_emptyAllowed( aEmptyAllowed )
151  {
152  }
bool m_emptyAllowed
Is it valid to get an empty value?
Definition: spice_value.h:163

Member Function Documentation

wxObject* SPICE_VALIDATOR::Clone ( ) const
inlineoverride

Definition at line 154 of file spice_value.h.

155  {
156  return new SPICE_VALIDATOR( *this );
157  }
SPICE_VALIDATOR(bool aEmptyAllowed=false)
Definition: spice_value.h:149
bool SPICE_VALIDATOR::Validate ( wxWindow *  aParent)
override

Definition at line 240 of file spice_value.cpp.

References DisplayError(), and Format().

241 {
242  wxTextEntry* const text = GetTextEntry();
243 
244  if( !text )
245  return false;
246 
247  if( text->IsEmpty() )
248  {
249  if( m_emptyAllowed )
250  return true;
251 
252  DisplayError( aParent, wxString::Format( _( "Please, fill required fields" ) ) );
253  return false;
254  }
255 
256  wxString svalue = text->GetValue();
257 
258  // In countries where the decimal separator is not a point, if the user
259  // has not used a point, replace the decimal separator by the point, as needed
260  // by spice simulator which uses the "C" decimal separator
261  svalue.Replace(",", "." );
262 
263  try
264  {
265  // If SPICE_VALUE can be constructed, then it is a valid Spice value
266  SPICE_VALUE val( svalue );
267  }
268  catch( ... )
269  {
270  DisplayError( aParent,
271  wxString::Format( _( "\"%s\" is not a valid Spice value" ), text->GetValue() ) );
272 
273  return false;
274  }
275 
276  if( svalue != text->GetValue() )
277  text->SetValue( svalue );
278 
279  return true;
280 }
bool m_emptyAllowed
Is it valid to get an empty value?
Definition: spice_value.h:163
Helper class to handle Spice way of expressing values (e.g. 10.5 Meg)
Definition: spice_value.h:32
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:185

Member Data Documentation

bool SPICE_VALIDATOR::m_emptyAllowed
private

Is it valid to get an empty value?

Definition at line 163 of file spice_value.h.


The documentation for this class was generated from the following files: