From 19c49fa82b36bb1b12ff47e68a2a280ec393c980 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Tue, 13 Aug 2013 19:04:41 -0400 Subject: [PATCH] Eeschema bus label test bug fixes. (fixes lp:1209424) * Use a regular expression to enforce more stringent bus label testing. * Add validator to edit label dialog to prevent space character from being used in labels. --- eeschema/class_netlist_object.cpp | 39 ++++++++++++++++----- eeschema/class_netlist_object.h | 6 +--- eeschema/dialogs/dialog_edit_label.cpp | 10 ++++-- eeschema/dialogs/dialog_edit_label_base.cpp | 7 +++- eeschema/dialogs/dialog_edit_label_base.fbp | 8 ++--- eeschema/dialogs/dialog_edit_label_base.h | 6 +++- 6 files changed, 54 insertions(+), 22 deletions(-) diff --git a/eeschema/class_netlist_object.cpp b/eeschema/class_netlist_object.cpp index 5cb1dfed27..e5e73c7e46 100644 --- a/eeschema/class_netlist_object.cpp +++ b/eeschema/class_netlist_object.cpp @@ -35,6 +35,26 @@ #include #include +#include + + +/** + * The regular expression string for label bus notation. Valid bus labels are defined as + * one or more non-whitespace characters from the beginning of the string followed by the + * bus notation [nn...mm] with no characters after the closing bracket. + */ +static wxRegEx busLabelRe( wxT( "^([^[:space:]]+)(\\[[\\d]+\\.+[\\d]+\\])$" ), wxRE_ADVANCED ); + + +bool IsBusLabel( const wxString& aLabel ) +{ + wxCHECK_MSG( busLabelRe.IsValid(), false, + wxT( "Invalid regular expression in IsBusLabel()." ) ); + + return busLabelRe.Matches( aLabel ); +} + + #if defined(DEBUG) #include @@ -220,31 +240,32 @@ void NETLIST_OBJECT::ConvertBusToNetListItems( NETLIST_OBJECT_LIST& aNetListItem wxCHECK_RET( false, wxT( "Net list object type is not valid." ) ); unsigned i; - wxString tmp, busName; + wxString tmp, busName, busNumber; long begin, end, member; - /* Search for '[' because a bus label is like "busname[nn..mm]" */ - i = m_Label.Find( '[' ); + busName = busLabelRe.GetMatch( m_Label, 1 ); + busNumber = busLabelRe.GetMatch( m_Label, 2 ); - busName = m_Label.Left( i ); + /* Search for '[' because a bus label is like "busname[nn..mm]" */ + i = busNumber.Find( '[' ); i++; - while( m_Label[i] != '.' && i < m_Label.Len() ) + while( busNumber[i] != '.' && i < busNumber.Len() ) { - tmp.Append( m_Label[i] ); + tmp.Append( busNumber[i] ); i++; } tmp.ToLong( &begin ); - while( m_Label[i] == '.' && i < m_Label.Len() ) + while( busNumber[i] == '.' && i < busNumber.Len() ) i++; tmp.Empty(); - while( m_Label[i] != ']' && i < m_Label.Len() ) + while( busNumber[i] != ']' && i < busNumber.Len() ) { - tmp.Append( m_Label[i] ); + tmp.Append( busNumber[i] ); i++; } diff --git a/eeschema/class_netlist_object.h b/eeschema/class_netlist_object.h index b28dad9346..aca521468d 100644 --- a/eeschema/class_netlist_object.h +++ b/eeschema/class_netlist_object.h @@ -96,11 +96,7 @@ enum NET_CONNECTION_T { * @param aLabel A wxString object containing the label to test. * @return true if text is a bus notation format otherwise false is returned. */ -inline bool IsBusLabel( const wxString& aLabel ) -{ - /* Search for '[' because a bus label is like "busname[nn..mm]" */ - return aLabel.Find( '[' ) != wxNOT_FOUND; -} +extern bool IsBusLabel( const wxString& aLabel ); class NETLIST_OBJECT diff --git a/eeschema/dialogs/dialog_edit_label.cpp b/eeschema/dialogs/dialog_edit_label.cpp index edc191d350..addeb7cee6 100644 --- a/eeschema/dialogs/dialog_edit_label.cpp +++ b/eeschema/dialogs/dialog_edit_label.cpp @@ -102,13 +102,19 @@ void DIALOG_LABEL_EDITOR::InitDialog() if( m_CurrentText->IsMultilineAllowed() ) { m_textLabel = m_textLabelMultiLine; - m_textLabelSingleLine->Show(false); + m_textLabelSingleLine->Show( false ); multiLine = true; } else { m_textLabel = m_textLabelSingleLine; - m_textLabelMultiLine->Show(false); + m_textLabelMultiLine->Show( false ); + wxTextValidator* validator = (wxTextValidator*) m_textLabel->GetValidator(); + wxArrayString excludes; + + // Add invalid label characters to this list. + excludes.Add( wxT( " " ) ); + validator->SetExcludes( excludes ); } m_textLabel->SetValue( m_CurrentText->GetText() ); diff --git a/eeschema/dialogs/dialog_edit_label_base.cpp b/eeschema/dialogs/dialog_edit_label_base.cpp index 1384ffec8c..739f6a03d0 100644 --- a/eeschema/dialogs/dialog_edit_label_base.cpp +++ b/eeschema/dialogs/dialog_edit_label_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 10 2012) +// C++ code generated with wxFormBuilder (version Apr 30 2013) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -32,9 +32,13 @@ DIALOG_LABEL_EDITOR_BASE::DIALOG_LABEL_EDITOR_BASE( wxWindow* parent, wxWindowID bSizeText = new wxBoxSizer( wxVERTICAL ); m_textLabelSingleLine = new wxTextCtrl( this, wxID_VALUESINGLE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); + m_textLabelSingleLine->SetMaxLength( 0 ); + m_textLabelSingleLine->SetValidator( wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, &m_labelText ) ); + bSizeText->Add( m_textLabelSingleLine, 0, wxEXPAND|wxLEFT, 3 ); m_textLabelMultiLine = new wxTextCtrl( this, wxID_VALUEMULTI, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_PROCESS_ENTER ); + m_textLabelMultiLine->SetMaxLength( 0 ); m_textLabelMultiLine->SetMinSize( wxSize( -1,60 ) ); bSizeText->Add( m_textLabelMultiLine, 1, wxEXPAND|wxLEFT, 3 ); @@ -50,6 +54,7 @@ DIALOG_LABEL_EDITOR_BASE::DIALOG_LABEL_EDITOR_BASE( wxWindow* parent, wxWindowID bSizeCtrlSizer = new wxBoxSizer( wxHORIZONTAL ); m_TextSize = new wxTextCtrl( this, wxID_SIZE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_TextSize->SetMaxLength( 0 ); bSizeCtrlSizer->Add( m_TextSize, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxLEFT|wxRIGHT, 3 ); m_staticSizeUnits = new wxStaticText( this, wxID_ANY, _("units"), wxDefaultPosition, wxDefaultSize, 0 ); diff --git a/eeschema/dialogs/dialog_edit_label_base.fbp b/eeschema/dialogs/dialog_edit_label_base.fbp index b9c2ab73a0..3008bf2acc 100644 --- a/eeschema/dialogs/dialog_edit_label_base.fbp +++ b/eeschema/dialogs/dialog_edit_label_base.fbp @@ -253,10 +253,10 @@ 0 - - wxFILTER_NONE - wxDefaultValidator - + wxString + wxFILTER_EXCLUDE_CHAR_LIST + wxTextValidator + m_labelText diff --git a/eeschema/dialogs/dialog_edit_label_base.h b/eeschema/dialogs/dialog_edit_label_base.h index 689550b57d..c704426370 100644 --- a/eeschema/dialogs/dialog_edit_label_base.h +++ b/eeschema/dialogs/dialog_edit_label_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 10 2012) +// C++ code generated with wxFormBuilder (version Apr 30 2013) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -11,6 +11,8 @@ #include #include #include +class DIALOG_SHIM; + #include "dialog_shim.h" #include #include @@ -19,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +65,7 @@ class DIALOG_LABEL_EDITOR_BASE : public DIALOG_SHIM public: + wxString m_labelText; DIALOG_LABEL_EDITOR_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Text Editor"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_LABEL_EDITOR_BASE();