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.

Definition at line 170 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 177 of file validators.h.

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

Referenced by Clone().

Member Function Documentation

◆ Clone()

virtual wxObject* LIB_ID_VALIDATOR::Clone ( ) const
inlineoverridevirtual

Definition at line 184 of file validators.h.

185  {
186  return new LIB_ID_VALIDATOR( *this );
187  }
LIB_ID_VALIDATOR(LIB_ID::LIB_ID_TYPE aLibIdType, wxString *aValue=NULL)
Definition: validators.h:177

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  if( tmp.Trim() != val ) // Trailing white space.
295  {
296  msg = _( "Entry contains trailing white space." );
297  }
298  else if( tmp.Trim( false ) != val ) // Leading white space.
299  {
300  msg = _( "Entry contains leading white space." );
301  }
302  else if( dummy.Parse( val, m_idType ) != -1 || !dummy.IsValid() ) // Is valid LIB_ID.
303  {
304  msg.Printf( _( "\"%s\" is not a valid library identifier format." ), val );
305  }
306 
307  if( !msg.empty() )
308  {
309  m_validatorWindow->SetFocus();
310 
311  wxMessageBox( msg, _( "Library Identifier Validation Error" ),
312  wxOK | wxICON_EXCLAMATION, aParent );
313 
314  return false;
315  }
316 
317  return true;
318 }
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:192
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...

References dummy(), and m_idType.

Member Data Documentation

◆ m_idType

LIB_ID::LIB_ID_TYPE LIB_ID_VALIDATOR::m_idType
protected

Definition at line 192 of file validators.h.

Referenced by Validate().


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