KiCad PCB EDA Suite
SCH_FIELD_VALIDATOR Class Reference

class SCH_FILED_VALIDATOR More...

#include <sch_validators.h>

Inheritance diagram for SCH_FIELD_VALIDATOR:

Public Member Functions

 SCH_FIELD_VALIDATOR (bool aIsCmplibEditor, int aFieldId, wxString *aValue=NULL)
 
 SCH_FIELD_VALIDATOR (const SCH_FIELD_VALIDATOR &aValidator)
 
virtual wxObject * Clone () const override
 
virtual bool Validate (wxWindow *aParent) override
 Function Validate. More...
 

Private Attributes

int m_fieldId
 
bool m_isLibEditor
 

Detailed Description

class SCH_FILED_VALIDATOR

is the text control validator used for validating the text allowed in library and schematic component fields. Note Reference field does not accept spaces Value field does not accept spaces in Component Library Editor, because in .lib component libraries, the value field is the component name in lib, and spaces are not allowed in component names in lib

Definition at line 47 of file sch_validators.h.

Constructor & Destructor Documentation

SCH_FIELD_VALIDATOR::SCH_FIELD_VALIDATOR ( bool  aIsCmplibEditor,
int  aFieldId,
wxString *  aValue = NULL 
)

Definition at line 33 of file sch_validators.cpp.

References m_fieldId, m_isLibEditor, REFERENCE, and VALUE.

Referenced by Clone().

34  :
35  wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
36 {
37  m_fieldId = aFieldId;
38  m_isLibEditor = aIsCmplibEditor;
39 
40  // Fields cannot contain carriage returns, line feeds, or tabs.
41  wxString excludes( "\r\n\t" );
42 
43  // The reference field cannot contain spaces.
44  if( aFieldId == REFERENCE )
45  excludes += " ";
46  else if( aFieldId == VALUE && m_isLibEditor )
47  excludes += " ";
48 
49  long style = GetStyle();
50 
51  // The reference and value fields cannot be empty.
52  if( aFieldId == REFERENCE || aFieldId == VALUE )
53  style |= wxFILTER_EMPTY;
54 
55  SetStyle( style );
56  SetCharExcludes( excludes );
57 }
Field Reference of part, i.e. "IC21".
Field Value of part, i.e. "3.3K".
SCH_FIELD_VALIDATOR::SCH_FIELD_VALIDATOR ( const SCH_FIELD_VALIDATOR aValidator)

Definition at line 60 of file sch_validators.cpp.

References m_fieldId, and m_isLibEditor.

60  :
61  wxTextValidator( aValidator )
62 {
63  m_fieldId = aValidator.m_fieldId;
64  m_isLibEditor = aValidator.m_isLibEditor;
65 }

Member Function Documentation

virtual wxObject* SCH_FIELD_VALIDATOR::Clone ( ) const
inlineoverridevirtual

Definition at line 57 of file sch_validators.h.

References SCH_FIELD_VALIDATOR().

57 { return new SCH_FIELD_VALIDATOR( *this ); }
SCH_FIELD_VALIDATOR(bool aIsCmplibEditor, int aFieldId, wxString *aValue=NULL)
bool SCH_FIELD_VALIDATOR::Validate ( wxWindow *  aParent)
overridevirtual

Function Validate.

overrides the default Validate() function provided by wxTextValidate to provide better error messages.

Parameters
aParent- a pointer to the parent window of the error message dialog.
Returns
true if the text in the control is valid otherwise false.

Definition at line 68 of file sch_validators.cpp.

References DATASHEET, FOOTPRINT, m_fieldId, m_isLibEditor, REFERENCE, and VALUE.

69 {
70  // If window is disabled, simply return
71  if( !m_validatorWindow->IsEnabled() )
72  return true;
73 
74  wxTextEntry * const text = GetTextEntry();
75 
76  if( !text )
77  return false;
78 
79  wxString val( text->GetValue() );
80  wxString tmp = val.Clone(); // For trailing and leading white space tests.
81  wxString fieldName;
82 
83  switch( m_fieldId )
84  {
85  case REFERENCE: fieldName = _( "reference designator" ); break;
86  case VALUE: fieldName = _( "value" ); break;
87  case FOOTPRINT: fieldName = _( "footprint" ); break;
88  case DATASHEET: fieldName = _( "data sheet" ); break;
89  default: fieldName = _( "user defined" ); break;
90  };
91 
92  wxString errorMsg;
93 
94  // We can only do some kinds of validation once the input is complete, so
95  // check for them here:
96  if( HasFlag( wxFILTER_EMPTY ) && val.empty() )
97  errorMsg.Printf( _( "The %s field cannot be empty." ), fieldName );
98  else if( HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) && ContainsExcludedCharacters( val ) )
99  {
100  wxArrayString whiteSpace;
101  bool spaceIllegal = ( m_fieldId == REFERENCE ) ||
102  ( m_fieldId == VALUE && m_isLibEditor );
103 
104  if( val.Find( '\r' ) != wxNOT_FOUND )
105  whiteSpace.Add( _( "carriage return" ) );
106  if( val.Find( '\n' ) != wxNOT_FOUND )
107  whiteSpace.Add( _( "line feed" ) );
108  if( val.Find( '\t' ) != wxNOT_FOUND )
109  whiteSpace.Add( _( "tab" ) );
110  if( spaceIllegal && (val.Find( ' ' ) != wxNOT_FOUND) )
111  whiteSpace.Add( _( "space" ) );
112 
113  wxString badChars;
114 
115  if( whiteSpace.size() == 1 )
116  badChars = whiteSpace[0];
117  else if( whiteSpace.size() == 2 )
118  badChars.Printf( _( "%s or %s" ), whiteSpace[0], whiteSpace[1] );
119  else if( whiteSpace.size() == 3 )
120  badChars.Printf( _( "%s, %s, or %s" ), whiteSpace[0], whiteSpace[1], whiteSpace[2] );
121  else if( whiteSpace.size() == 4 )
122  badChars.Printf( _( "%s, %s, %s, or %s" ),
123  whiteSpace[0], whiteSpace[1], whiteSpace[2], whiteSpace[3] );
124  else
125  wxCHECK_MSG( false, true, wxT( "Invalid illegal character in field validator." ) );
126 
127  errorMsg.Printf( _( "The %s field cannot contain %s characters." ), fieldName, badChars );
128  }
129 
130  if ( !errorMsg.empty() )
131  {
132  m_validatorWindow->SetFocus();
133 
134  wxMessageBox( errorMsg, _( "Field Validation Error" ),
135  wxOK | wxICON_EXCLAMATION, aParent );
136 
137  return false;
138  }
139 
140  return true;
141 }
name of datasheet
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
Field Value of part, i.e. "3.3K".

Member Data Documentation

int SCH_FIELD_VALIDATOR::m_fieldId
private

Definition at line 49 of file sch_validators.h.

Referenced by SCH_FIELD_VALIDATOR(), and Validate().

bool SCH_FIELD_VALIDATOR::m_isLibEditor
private

Definition at line 50 of file sch_validators.h.

Referenced by SCH_FIELD_VALIDATOR(), and Validate().


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