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

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

Referenced by Clone().

Member Function Documentation

◆ Clone()

virtual wxObject* LIB_ID_VALIDATOR::Clone ( ) const
inlineoverridevirtual

Definition at line 186 of file validators.h.

187  {
188  return new LIB_ID_VALIDATOR( *this );
189  }
LIB_ID_VALIDATOR(LIB_ID::LIB_ID_TYPE aLibIdType, wxString *aValue=NULL)
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, m_idType ) != -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
LIB_ID::LIB_ID_TYPE m_idType
Definition: validators.h:194
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
#define _(s)
Definition: 3d_actions.cpp:33

References _, dummy(), and m_idType.

Member Data Documentation

◆ m_idType

LIB_ID::LIB_ID_TYPE LIB_ID_VALIDATOR::m_idType
protected

Definition at line 194 of file validators.h.

Referenced by Validate().


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