|
|
|
@ -289,13 +289,14 @@ bool FIELD_VALIDATOR::Validate( wxWindow* aParent ) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool FIELD_VALIDATOR::DoValidate( const wxString& aValue, wxWindow* aParent ) |
|
|
|
wxString GetFieldValidationErrorMessage( FIELD_T aFieldId, const wxString& aValue ) |
|
|
|
{ |
|
|
|
wxString msg; |
|
|
|
FIELD_VALIDATOR validator( aFieldId ); |
|
|
|
wxString msg; |
|
|
|
|
|
|
|
if( HasFlag( wxFILTER_EMPTY ) && aValue.empty() ) |
|
|
|
if( validator.HasFlag( wxFILTER_EMPTY ) && aValue.empty() ) |
|
|
|
{ |
|
|
|
switch( m_fieldId ) |
|
|
|
switch( aFieldId ) |
|
|
|
{ |
|
|
|
case FIELD_T::SHEET_NAME: msg = _( "A sheet must have a name." ); break; |
|
|
|
case FIELD_T::SHEET_FILENAME: msg = _( "A sheet must have a file specified." ); break; |
|
|
|
@ -303,11 +304,11 @@ bool FIELD_VALIDATOR::DoValidate( const wxString& aValue, wxWindow* aParent ) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if( HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) && ContainsExcludedCharacters( aValue ) ) |
|
|
|
if( msg.empty() && validator.HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) ) |
|
|
|
{ |
|
|
|
wxArrayString badCharsFound; |
|
|
|
|
|
|
|
for( const wxUniCharRef& excludeChar : GetCharExcludes() ) |
|
|
|
for( const wxUniCharRef& excludeChar : validator.GetCharExcludes() ) |
|
|
|
{ |
|
|
|
if( aValue.Find( excludeChar ) != wxNOT_FOUND ) |
|
|
|
{ |
|
|
|
@ -324,68 +325,83 @@ bool FIELD_VALIDATOR::DoValidate( const wxString& aValue, wxWindow* aParent ) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
wxString badChars; |
|
|
|
|
|
|
|
for( size_t i = 0; i < badCharsFound.GetCount(); i++ ) |
|
|
|
if( !badCharsFound.IsEmpty() ) |
|
|
|
{ |
|
|
|
if( !badChars.IsEmpty() ) |
|
|
|
wxString badChars; |
|
|
|
|
|
|
|
for( size_t i = 0; i < badCharsFound.GetCount(); i++ ) |
|
|
|
{ |
|
|
|
if( badCharsFound.GetCount() == 2 ) |
|
|
|
{ |
|
|
|
badChars += _( " or " ); |
|
|
|
} |
|
|
|
else |
|
|
|
if( !badChars.IsEmpty() ) |
|
|
|
{ |
|
|
|
if( i < badCharsFound.GetCount() - 2 ) |
|
|
|
badChars += _( ", or " ); |
|
|
|
if( badCharsFound.GetCount() == 2 ) |
|
|
|
{ |
|
|
|
badChars += _( " or " ); |
|
|
|
} |
|
|
|
else |
|
|
|
badChars += wxT( ", " ); |
|
|
|
{ |
|
|
|
if( i < badCharsFound.GetCount() - 2 ) |
|
|
|
badChars += _( ", or " ); |
|
|
|
else |
|
|
|
badChars += wxT( ", " ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
badChars += badCharsFound.Item( i ); |
|
|
|
} |
|
|
|
|
|
|
|
badChars += badCharsFound.Item( i ); |
|
|
|
switch( aFieldId ) |
|
|
|
{ |
|
|
|
case FIELD_T::REFERENCE: |
|
|
|
msg.Printf( _( "The reference designator cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
|
|
|
|
case FIELD_T::VALUE: |
|
|
|
msg.Printf( _( "The value field cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
|
|
|
|
case FIELD_T::FOOTPRINT: |
|
|
|
msg.Printf( _( "The footprint field cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
|
|
|
|
case FIELD_T::DATASHEET: |
|
|
|
msg.Printf( _( "The datasheet field cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
|
|
|
|
case FIELD_T::SHEET_NAME: |
|
|
|
msg.Printf( _( "The sheet name cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
|
|
|
|
case FIELD_T::SHEET_FILENAME: |
|
|
|
msg.Printf( _( "The sheet filename cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
msg.Printf( _( "The field cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
switch( m_fieldId ) |
|
|
|
{ |
|
|
|
case FIELD_T::REFERENCE: |
|
|
|
msg.Printf( _( "The reference designator cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
|
|
|
|
case FIELD_T::VALUE: |
|
|
|
msg.Printf( _( "The value field cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
|
|
|
|
case FIELD_T::FOOTPRINT: |
|
|
|
msg.Printf( _( "The footprint field cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
|
|
|
|
case FIELD_T::DATASHEET: |
|
|
|
msg.Printf( _( "The datasheet field cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
|
|
|
|
case FIELD_T::SHEET_NAME: |
|
|
|
msg.Printf( _( "The sheet name cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
|
|
|
|
case FIELD_T::SHEET_FILENAME: |
|
|
|
msg.Printf( _( "The sheet filename cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
msg.Printf( _( "The field cannot contain %s character(s)." ), badChars ); |
|
|
|
break; |
|
|
|
}; |
|
|
|
} |
|
|
|
else if( m_fieldId == FIELD_T::REFERENCE && aValue.Contains( wxT( "${" ) ) ) |
|
|
|
{ |
|
|
|
msg.Printf( _( "The reference designator cannot contain text variable references" ) ); |
|
|
|
} |
|
|
|
else if( m_fieldId == FIELD_T::REFERENCE && UTIL::GetRefDesPrefix( aValue ).IsEmpty() ) |
|
|
|
|
|
|
|
if( msg.empty() ) |
|
|
|
{ |
|
|
|
msg.Printf( _( "References must start with a letter." ) ); |
|
|
|
if( aFieldId == FIELD_T::REFERENCE && aValue.Contains( wxT( "${" ) ) ) |
|
|
|
{ |
|
|
|
msg.Printf( _( "The reference designator cannot contain text variable references" ) ); |
|
|
|
} |
|
|
|
else if( aFieldId == FIELD_T::REFERENCE && UTIL::GetRefDesPrefix( aValue ).IsEmpty() ) |
|
|
|
{ |
|
|
|
msg.Printf( _( "References must start with a letter." ) ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return msg; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool FIELD_VALIDATOR::DoValidate( const wxString& aValue, wxWindow* aParent ) |
|
|
|
{ |
|
|
|
wxString msg = GetFieldValidationErrorMessage( m_fieldId, aValue ); |
|
|
|
|
|
|
|
if( !msg.empty() ) |
|
|
|
{ |
|
|
|
if( m_validatorWindow ) |
|
|
|
|