KiCad PCB EDA Suite
LIB_ID_VALIDATOR Class Reference

Custom validator that verifies that a string defines a valid LIB_ID. More...

#include <validators.h>

Inheritance diagram for LIB_ID_VALIDATOR:

Public Member Functions

 LIB_ID_VALIDATOR (wxString *aValue=nullptr)
 
virtual wxObject * Clone () const override
 
bool Validate (wxWindow *aParent) override
 

Detailed Description

Custom validator that verifies that a string defines a valid LIB_ID.

The default validation allows empty LIB_ID strings to allow the LIB_ID to be cleared. Use SetStyle( wxFILTER_EMPTY ) to force a valid LIB_ID string.

Definition at line 172 of file validators.h.

Constructor & Destructor Documentation

◆ LIB_ID_VALIDATOR()

LIB_ID_VALIDATOR::LIB_ID_VALIDATOR ( wxString *  aValue = nullptr)
inline
Parameters
aLibIdTypeis the type of LIB_ID object to validate.
aValueis a pointer to a wxString containing the value to validate.

Definition at line 179 of file validators.h.

179  :
180  wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
181  {
182  SetCharExcludes( wxT( "\r\n\t" ) );
183  }

Referenced by Clone().

Member Function Documentation

◆ Clone()

virtual wxObject* LIB_ID_VALIDATOR::Clone ( ) const
inlineoverridevirtual

Definition at line 185 of file validators.h.

186  {
187  return new LIB_ID_VALIDATOR( *this );
188  }
LIB_ID_VALIDATOR(wxString *aValue=nullptr)
Definition: validators.h:179

References LIB_ID_VALIDATOR().

◆ Validate()

bool LIB_ID_VALIDATOR::Validate ( wxWindow *  aParent)
override

Definition at line 271 of file validators.cpp.

272 {
273  LIB_ID dummy;
274 
275  // If window is disabled, simply return
276  if( !m_validatorWindow->IsEnabled() )
277  return true;
278 
279  wxTextEntry* const text = GetTextEntry();
280 
281  if( !text )
282  return false;
283 
284  wxString msg;
285  wxString val( text->GetValue() );
286  wxString tmp = val.Clone(); // For trailing and leading white space tests.
287 
288  // Allow empty string if empty filter not set to allow clearing the LIB_ID.
289  if( !(GetStyle() & wxFILTER_EMPTY) && val.IsEmpty() )
290  return true;
291 
292  if( tmp.Trim() != val ) // Trailing white space.
293  {
294  msg = _( "Entry contains trailing white space." );
295  }
296  else if( tmp.Trim( false ) != val ) // Leading white space.
297  {
298  msg = _( "Entry contains leading white space." );
299  }
300  else if( dummy.Parse( val ) != -1 || !dummy.IsValid() ) // Is valid LIB_ID.
301  {
302  msg.Printf( _( "'%s' is not a valid library identifier format." ), val );
303  }
304 
305  if( !msg.empty() )
306  {
307  m_validatorWindow->SetFocus();
308 
309  wxMessageBox( msg, _( "Library Identifier Validation Error" ),
310  wxOK | wxICON_EXCLAMATION, aParent );
311 
312  return false;
313  }
314 
315  return true;
316 }
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
#define _(s)

References _, dummy(), and text.


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