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.
This commit is contained in:
parent
336d1b23f9
commit
761023f6bc
|
@ -35,6 +35,26 @@
|
|||
#include <general.h>
|
||||
#include <sch_component.h>
|
||||
|
||||
#include <wx/regex.h>
|
||||
|
||||
|
||||
/**
|
||||
* 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 <iostream>
|
||||
|
@ -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++;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() );
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -253,10 +253,10 @@
|
|||
<property name="subclass"></property>
|
||||
<property name="toolbar_pane">0</property>
|
||||
<property name="tooltip"></property>
|
||||
<property name="validator_data_type"></property>
|
||||
<property name="validator_style">wxFILTER_NONE</property>
|
||||
<property name="validator_type">wxDefaultValidator</property>
|
||||
<property name="validator_variable"></property>
|
||||
<property name="validator_data_type">wxString</property>
|
||||
<property name="validator_style">wxFILTER_EXCLUDE_CHAR_LIST</property>
|
||||
<property name="validator_type">wxTextValidator</property>
|
||||
<property name="validator_variable">m_labelText</property>
|
||||
<property name="value"></property>
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
|
|
|
@ -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 <wx/artprov.h>
|
||||
#include <wx/xrc/xmlres.h>
|
||||
#include <wx/intl.h>
|
||||
class DIALOG_SHIM;
|
||||
|
||||
#include "dialog_shim.h"
|
||||
#include <wx/string.h>
|
||||
#include <wx/stattext.h>
|
||||
|
@ -19,6 +21,7 @@
|
|||
#include <wx/colour.h>
|
||||
#include <wx/settings.h>
|
||||
#include <wx/textctrl.h>
|
||||
#include <wx/valtext.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/radiobox.h>
|
||||
#include <wx/button.h>
|
||||
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue