diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index fd51fffb28..3a65c99f41 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -878,7 +878,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel() // may only delete user defined fields deleteFieldButton->Enable( fieldNdx >= MANDATORY_FIELDS ); - fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( field.GetId() ) ); + fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( false, field.GetId() ) ); fieldValueTextCtrl->SetValue( field.GetText() ); m_show_datasheet_button->Enable( fieldNdx == DATASHEET || fieldNdx == FOOTPRINT ); diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp index 50e413e51b..b2c824ee58 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp @@ -674,7 +674,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copySelectedFieldToPanel() // if fieldNdx == REFERENCE, VALUE, then disable delete button deleteFieldButton->Enable( fieldNdx >= MANDATORY_FIELDS ); - fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( field.GetId() ) ); + fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( true, field.GetId() ) ); fieldValueTextCtrl->SetValue( field.GetText() ); textSizeTextCtrl->SetValue( EDA_GRAPHIC_TEXT_CTRL::FormatSize( g_UserUnit, field.GetSize().x ) ); diff --git a/eeschema/dialogs/dialog_edit_one_field.cpp b/eeschema/dialogs/dialog_edit_one_field.cpp index 4341b16b30..3ee5f1e88f 100644 --- a/eeschema/dialogs/dialog_edit_one_field.cpp +++ b/eeschema/dialogs/dialog_edit_one_field.cpp @@ -102,7 +102,10 @@ void DIALOG_EDIT_ONE_FIELD::init() wxString msg; m_TextValue->SetFocus(); - m_TextValue->SetValidator( SCH_FIELD_VALIDATOR( m_fieldId, &m_text ) ); + SCH_BASE_FRAME* parent = static_cast( GetParent() ); + m_TextValue->SetValidator( SCH_FIELD_VALIDATOR( + parent->IsType( FRAME_SCH_LIB_EDITOR ), + m_fieldId, &m_text ) ); // Disable options for graphic text editing which are not needed for fields. m_CommonConvert->Show( false ); diff --git a/eeschema/dialogs/dialog_lib_new_component.cpp b/eeschema/dialogs/dialog_lib_new_component.cpp index b827d22f21..23ddad8ed1 100644 --- a/eeschema/dialogs/dialog_lib_new_component.cpp +++ b/eeschema/dialogs/dialog_lib_new_component.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009 Wayne Stambaugh - * Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,10 +23,15 @@ */ #include +#include +#include DIALOG_LIB_NEW_COMPONENT::DIALOG_LIB_NEW_COMPONENT( wxWindow* parent ) : DIALOG_LIB_NEW_COMPONENT_BASE( parent ) { + m_textName->SetValidator( SCH_FIELD_VALIDATOR( true, VALUE ) ); + m_textReference->SetValidator( SCH_FIELD_VALIDATOR( true, REFERENCE ) ); + // initial focus should be on first editable field. m_textName->SetFocus(); diff --git a/eeschema/sch_validators.cpp b/eeschema/sch_validators.cpp index 55a3779f2e..ff7252b769 100644 --- a/eeschema/sch_validators.cpp +++ b/eeschema/sch_validators.cpp @@ -30,10 +30,12 @@ #include #include -SCH_FIELD_VALIDATOR::SCH_FIELD_VALIDATOR( int aFieldId, wxString* aValue ) : +SCH_FIELD_VALIDATOR::SCH_FIELD_VALIDATOR( bool aIsCmplibEditor, + int aFieldId, wxString* aValue ) : wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ) { m_fieldId = aFieldId; + m_isLibEditor = aIsCmplibEditor; // Fields cannot contain carriage returns, line feeds, or tabs. wxString excludes( "\r\n\t" ); @@ -41,6 +43,8 @@ SCH_FIELD_VALIDATOR::SCH_FIELD_VALIDATOR( int aFieldId, wxString* aValue ) : // The reference field cannot contain spaces. if( aFieldId == REFERENCE ) excludes += " "; + else if( aFieldId == VALUE && m_isLibEditor ) + excludes += " "; long style = GetStyle(); @@ -57,6 +61,7 @@ SCH_FIELD_VALIDATOR::SCH_FIELD_VALIDATOR( const SCH_FIELD_VALIDATOR& aValidator wxTextValidator( aValidator ) { m_fieldId = aValidator.m_fieldId; + m_isLibEditor = aValidator.m_isLibEditor; } @@ -93,6 +98,8 @@ bool SCH_FIELD_VALIDATOR::Validate( wxWindow *aParent ) else if( HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) && ContainsExcludedCharacters( val ) ) { wxArrayString whiteSpace; + bool spaceIllegal = ( m_fieldId == REFERENCE ) || + ( m_fieldId == VALUE && m_isLibEditor ); if( val.Find( '\r' ) != wxNOT_FOUND ) whiteSpace.Add( _( "carriage return" ) ); @@ -100,7 +107,7 @@ bool SCH_FIELD_VALIDATOR::Validate( wxWindow *aParent ) whiteSpace.Add( _( "line feed" ) ); if( val.Find( '\t' ) != wxNOT_FOUND ) whiteSpace.Add( _( "tab" ) ); - if( (m_fieldId == REFERENCE) && (val.Find( ' ' ) != wxNOT_FOUND) ) + if( spaceIllegal && (val.Find( ' ' ) != wxNOT_FOUND) ) whiteSpace.Add( _( "space" ) ); wxString badChars; diff --git a/eeschema/sch_validators.h b/eeschema/sch_validators.h index e17e2ffbbf..6c34060c50 100644 --- a/eeschema/sch_validators.h +++ b/eeschema/sch_validators.h @@ -38,13 +38,19 @@ * * 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 */ class SCH_FIELD_VALIDATOR : public wxTextValidator { - int m_fieldId; + int m_fieldId; + bool m_isLibEditor; public: - SCH_FIELD_VALIDATOR( int aFieldId, wxString* aValue = NULL ); + SCH_FIELD_VALIDATOR( bool aIsCmplibEditor, int aFieldId, wxString* aValue = NULL ); SCH_FIELD_VALIDATOR( const SCH_FIELD_VALIDATOR& aValidator );