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.

Referenced by Clone().

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.

References SPICE_VALIDATOR().

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 239 of file spice_value.cpp.

References DisplayError(), Format(), and m_emptyAllowed.

240 {
241  wxTextEntry* const text = GetTextEntry();
242 
243  if( !text )
244  return false;
245 
246  if( text->IsEmpty() )
247  {
248  if( m_emptyAllowed )
249  return true;
250 
251  DisplayError( aParent, wxString::Format( _( "Please, fill required fields" ) ) );
252  return false;
253  }
254 
255  wxString svalue = text->GetValue();
256 
257  // In countries where the decimal separator is not a point, if the user
258  // has not used a point, replace the decimal separator by the point, as needed
259  // by spice simulator which uses the "C" decimal separator
260  svalue.Replace(",", "." );
261 
262  try
263  {
264  // If SPICE_VALUE can be constructed, then it is a valid Spice value
265  SPICE_VALUE val( svalue );
266  }
267  catch( ... )
268  {
269  DisplayError( aParent,
270  wxString::Format( _( "'%s' is not a valid Spice value" ), text->GetValue() ) );
271 
272  return false;
273  }
274 
275  if( svalue != text->GetValue() )
276  text->SetValue( svalue );
277 
278  return true;
279 }
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:69

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.

Referenced by Validate().


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