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 aIsLibEditor, 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 50 of file sch_validators.h.

Constructor & Destructor Documentation

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

Definition at line 34 of file sch_validators.cpp.

References FIELD_NAME, 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 = aIsLibEditor;
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 || aFieldId == FIELD_NAME )
53  style |= wxFILTER_EMPTY;
54 
55  SetStyle( style );
56  SetCharExcludes( excludes );
57 }
Field Reference of part, i.e. "IC21".
#define FIELD_NAME
#define VALUE
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 60 of file sch_validators.h.

References SCH_FIELD_VALIDATOR(), and Validate().

60 { return new SCH_FIELD_VALIDATOR( *this ); }
SCH_FIELD_VALIDATOR(bool aIsLibEditor, 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, FIELD_NAME, FOOTPRINT, m_fieldId, m_isLibEditor, REFERENCE, and VALUE.

Referenced by Clone().

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 FIELD_NAME: fieldName = _( "field name" ); break;
86  case REFERENCE: fieldName = _( "reference field" ); break;
87  case VALUE: fieldName = _( "value field" ); break;
88  case FOOTPRINT: fieldName = _( "footprint field" ); break;
89  case DATASHEET: fieldName = _( "datasheet field" ); break;
90  default: fieldName = _( "user defined field" ); break;
91  };
92 
93  wxString msg;
94 
95  // We can only do some kinds of validation once the input is complete, so
96  // check for them here:
97  if( HasFlag( wxFILTER_EMPTY ) && val.empty() )
98  msg.Printf( _( "The %s cannot be empty." ), fieldName );
99  else if( HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) && ContainsExcludedCharacters( val ) )
100  {
101  wxArrayString whiteSpace;
102  bool spaceIllegal = ( m_fieldId == REFERENCE ) ||
103  ( m_fieldId == VALUE && m_isLibEditor );
104 
105  if( val.Find( '\r' ) != wxNOT_FOUND )
106  whiteSpace.Add( _( "carriage return" ) );
107  if( val.Find( '\n' ) != wxNOT_FOUND )
108  whiteSpace.Add( _( "line feed" ) );
109  if( val.Find( '\t' ) != wxNOT_FOUND )
110  whiteSpace.Add( _( "tab" ) );
111  if( spaceIllegal && (val.Find( ' ' ) != wxNOT_FOUND) )
112  whiteSpace.Add( _( "space" ) );
113 
114  wxString badChars;
115 
116  if( whiteSpace.size() == 1 )
117  badChars = whiteSpace[0];
118  else if( whiteSpace.size() == 2 )
119  badChars.Printf( _( "%s or %s" ), whiteSpace[0], whiteSpace[1] );
120  else if( whiteSpace.size() == 3 )
121  badChars.Printf( _( "%s, %s, or %s" ), whiteSpace[0], whiteSpace[1], whiteSpace[2] );
122  else if( whiteSpace.size() == 4 )
123  badChars.Printf( _( "%s, %s, %s, or %s" ),
124  whiteSpace[0], whiteSpace[1], whiteSpace[2], whiteSpace[3] );
125  else
126  wxCHECK_MSG( false, true, wxT( "Invalid illegal character in field validator." ) );
127 
128  msg.Printf( _( "The %s cannot contain %s characters." ), fieldName, badChars );
129  }
130 
131  if ( !msg.empty() )
132  {
133  m_validatorWindow->SetFocus();
134 
135  wxMessageBox( msg, _( "Field Validation Error" ), 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".
#define FIELD_NAME
#define VALUE

Member Data Documentation

int SCH_FIELD_VALIDATOR::m_fieldId
private

Definition at line 52 of file sch_validators.h.

Referenced by SCH_FIELD_VALIDATOR(), and Validate().

bool SCH_FIELD_VALIDATOR::m_isLibEditor
private

Definition at line 53 of file sch_validators.h.

Referenced by SCH_FIELD_VALIDATOR(), and Validate().


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