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 (LIB_ID::LIB_ID_TYPE aLibIdType, wxString *aValue=NULL)
 
virtual wxObject * Clone () const override
 
bool Validate (wxWindow *aParent) override
 

Protected Attributes

LIB_ID::LIB_ID_TYPE m_idType
 

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 173 of file validators.h.

Constructor & Destructor Documentation

◆ LIB_ID_VALIDATOR()

LIB_ID_VALIDATOR::LIB_ID_VALIDATOR ( LIB_ID::LIB_ID_TYPE  aLibIdType,
wxString *  aValue = NULL 
)
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 180 of file validators.h.

180  :
181  wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ),
182  m_idType( aLibIdType )
183  {
184  SetCharExcludes( "\r\n\t" );
185  }
LIB_ID::LIB_ID_TYPE m_idType
Definition: validators.h:195

Referenced by Clone().

Member Function Documentation

◆ Clone()

virtual wxObject* LIB_ID_VALIDATOR::Clone ( ) const
inlineoverridevirtual

Definition at line 187 of file validators.h.

188  {
189  return new LIB_ID_VALIDATOR( *this );
190  }
LIB_ID_VALIDATOR(LIB_ID::LIB_ID_TYPE aLibIdType, wxString *aValue=NULL)
Definition: validators.h:180

References LIB_ID_VALIDATOR().

◆ Validate()

bool LIB_ID_VALIDATOR::Validate ( wxWindow *  aParent)
override

Definition at line 277 of file validators.cpp.

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

References _, dummy(), and m_idType.

Member Data Documentation

◆ m_idType

LIB_ID::LIB_ID_TYPE LIB_ID_VALIDATOR::m_idType
protected

Definition at line 195 of file validators.h.

Referenced by Validate().


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