KiCad PCB EDA Suite
SPICE_VALIDATOR Class Reference

#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

Definition at line 148 of file spice_value.h.

Constructor & Destructor Documentation

◆ SPICE_VALIDATOR()

SPICE_VALIDATOR::SPICE_VALIDATOR ( bool  aEmptyAllowed = false)
inline

Definition at line 151 of file spice_value.h.

152  : m_emptyAllowed( aEmptyAllowed )
153  {
154  }
bool m_emptyAllowed
< Is it valid to get an empty value?
Definition: spice_value.h:165

Referenced by Clone().

Member Function Documentation

◆ Clone()

wxObject* SPICE_VALIDATOR::Clone ( ) const
inlineoverride

Definition at line 156 of file spice_value.h.

157  {
158  return new SPICE_VALIDATOR( *this );
159  }
SPICE_VALIDATOR(bool aEmptyAllowed=false)
Definition: spice_value.h:151

References SPICE_VALIDATOR().

◆ Validate()

bool SPICE_VALIDATOR::Validate ( wxWindow *  aParent)
override

Definition at line 247 of file spice_value.cpp.

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

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

Member Data Documentation

◆ m_emptyAllowed

bool SPICE_VALIDATOR::m_emptyAllowed
private

< Is it valid to get an empty value?

Definition at line 165 of file spice_value.h.

Referenced by Validate().


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