From c5f8a6b26e548060bc0f8338dcafd534dbc9d911 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Mon, 20 May 2019 22:52:39 -0400 Subject: [PATCH] Add a nicer bus / net name validator --- eeschema/dialogs/dialog_edit_label.cpp | 14 +- eeschema/dialogs/dialog_edit_label_base.cpp | 72 ++-- eeschema/dialogs/dialog_edit_label_base.fbp | 352 +----------------- eeschema/dialogs/dialog_edit_label_base.h | 28 +- .../dialogs/dialog_sch_edit_sheet_pin.cpp | 10 +- .../dialog_sch_edit_sheet_pin_base.cpp | 64 ++-- .../dialog_sch_edit_sheet_pin_base.fbp | 326 +--------------- .../dialogs/dialog_sch_edit_sheet_pin_base.h | 22 +- eeschema/sch_validators.cpp | 81 ++++ eeschema/sch_validators.h | 26 ++ 10 files changed, 228 insertions(+), 767 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_label.cpp b/eeschema/dialogs/dialog_edit_label.cpp index 2fa80b15ba..328197843b 100644 --- a/eeschema/dialogs/dialog_edit_label.cpp +++ b/eeschema/dialogs/dialog_edit_label.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include @@ -87,7 +87,7 @@ private: wxWindow* m_activeTextCtrl; wxTextEntry* m_activeTextEntry; UNIT_BINDER m_textSize; - REGEX_VALIDATOR m_netNameValidator; + SCH_NETNAME_VALIDATOR m_netNameValidator; }; @@ -110,8 +110,7 @@ const int MAX_TEXTSIZE = INT_MAX; DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTextItem ) : DIALOG_LABEL_EDITOR_BASE( aParent ), m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, false ), - // first part matches single nets and bus vector, the second part matches complex buses - m_netNameValidator( "([^/ ]+)|({[^/]+})" ) + m_netNameValidator() { m_Parent = aParent; m_CurrentText = aTextItem; @@ -119,7 +118,7 @@ DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTe switch( m_CurrentText->Type() ) { case SCH_GLOBAL_LABEL_T: SetTitle( _( "Global Label Properties" ) ); break; - case SCH_HIER_LABEL_T: SetTitle( _( "Hierarchical Label Properties" ) ); break; + case SCH_HIER_LABEL_T: SetTitle( _( "Hierarchical Label Properties" ) ); break; case SCH_LABEL_T: SetTitle( _( "Label Properties" ) ); break; case SCH_SHEET_PIN_T: SetTitle( _( "Hierarchical Sheet Pin Properties" ) ); break; default: SetTitle( _( "Text Properties" ) ); break; @@ -142,6 +141,8 @@ DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTe m_labelSingleLine->Show( false ); m_valueSingleLine->Show( false ); m_labelMultiLine->Show( false ); m_valueMultiLine->Show( false ); + + m_valueCombo->SetValidator( m_netNameValidator ); } else { @@ -150,6 +151,9 @@ DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTe m_labelCombo->Show( false ); m_valueCombo->Show( false ); m_labelMultiLine->Show( false ); m_valueMultiLine->Show( false ); + + if( m_CurrentText->Type() != SCH_TEXT_T ) + m_valueSingleLine->SetValidator( m_netNameValidator ); } SetInitialFocus( m_activeTextCtrl ); diff --git a/eeschema/dialogs/dialog_edit_label_base.cpp b/eeschema/dialogs/dialog_edit_label_base.cpp index 1f77fbf8b4..1bee819d14 100644 --- a/eeschema/dialogs/dialog_edit_label_base.cpp +++ b/eeschema/dialogs/dialog_edit_label_base.cpp @@ -1,8 +1,8 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 17 2016) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // -// PLEASE DO "NOT" EDIT THIS FILE! +// PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// #include "dialog_edit_label_base.h" @@ -12,105 +12,103 @@ DIALOG_LABEL_EDITOR_BASE::DIALOG_LABEL_EDITOR_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); - + wxBoxSizer* bMainSizer; bMainSizer = new wxBoxSizer( wxVERTICAL ); - + m_textEntrySizer = new wxFlexGridSizer( 4, 2, 3, 3 ); m_textEntrySizer->AddGrowableCol( 1 ); m_textEntrySizer->AddGrowableRow( 1 ); m_textEntrySizer->SetFlexibleDirection( wxBOTH ); m_textEntrySizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - + m_labelSingleLine = new wxStaticText( this, wxID_ANY, _("Label:"), wxDefaultPosition, wxDefaultSize, 0 ); m_labelSingleLine->Wrap( -1 ); m_labelSingleLine->SetToolTip( _("Enter the text to be used within the schematic") ); - + m_textEntrySizer->Add( m_labelSingleLine, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 3 ); - + m_valueSingleLine = new wxTextCtrl( this, wxID_VALUESINGLE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER|wxTE_RICH ); m_valueSingleLine->SetMinSize( wxSize( 360,-1 ) ); - + m_textEntrySizer->Add( m_valueSingleLine, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 3 ); - + m_labelMultiLine = new wxStaticText( this, wxID_ANY, _("Text:"), wxDefaultPosition, wxDefaultSize, 0 ); m_labelMultiLine->Wrap( -1 ); m_textEntrySizer->Add( m_labelMultiLine, 0, wxRIGHT, 5 ); - + m_valueMultiLine = new wxTextCtrl( this, wxID_VALUEMULTI, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE ); m_valueMultiLine->SetMinSize( wxSize( 480,72 ) ); - + m_textEntrySizer->Add( m_valueMultiLine, 1, wxEXPAND|wxBOTTOM|wxLEFT, 3 ); - + m_labelCombo = new wxStaticText( this, wxID_ANY, _("Label:"), wxDefaultPosition, wxDefaultSize, 0 ); m_labelCombo->Wrap( -1 ); m_textEntrySizer->Add( m_labelCombo, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); - - m_valueCombo = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxTE_PROCESS_ENTER ); + + m_valueCombo = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxTE_PROCESS_ENTER ); m_valueCombo->SetMinSize( wxSize( 360,-1 ) ); - - m_valueCombo->SetValidator( wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, &m_comboText ) ); - + m_textEntrySizer->Add( m_valueCombo, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); - + m_textSizeLabel = new wxStaticText( this, wxID_ANY, _("Text Size:"), wxDefaultPosition, wxDefaultSize, 0 ); m_textSizeLabel->Wrap( -1 ); m_textEntrySizer->Add( m_textSizeLabel, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 3 ); - + wxBoxSizer* bSizeCtrlSizer; bSizeCtrlSizer = new wxBoxSizer( wxHORIZONTAL ); - + m_textSizeCtrl = new wxTextCtrl( this, wxID_SIZE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); bSizeCtrlSizer->Add( m_textSizeCtrl, 0, wxEXPAND|wxLEFT|wxRIGHT, 3 ); - + m_textSizeUnits = new wxStaticText( this, wxID_ANY, _("units"), wxDefaultPosition, wxDefaultSize, 0 ); m_textSizeUnits->Wrap( -1 ); bSizeCtrlSizer->Add( m_textSizeUnits, 0, wxALIGN_CENTER_VERTICAL, 2 ); - - + + m_textEntrySizer->Add( bSizeCtrlSizer, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL, 3 ); - - + + bMainSizer->Add( m_textEntrySizer, 1, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 12 ); - + wxBoxSizer* m_OptionsSizer; m_OptionsSizer = new wxBoxSizer( wxHORIZONTAL ); - + wxString m_TextOrientChoices[] = { _("Right"), _("Up"), _("Left"), _("Down") }; int m_TextOrientNChoices = sizeof( m_TextOrientChoices ) / sizeof( wxString ); m_TextOrient = new wxRadioBox( this, wxID_ANY, _("Orientation"), wxDefaultPosition, wxDefaultSize, m_TextOrientNChoices, m_TextOrientChoices, 1, wxRA_SPECIFY_COLS ); m_TextOrient->SetSelection( 0 ); m_OptionsSizer->Add( m_TextOrient, 1, wxRIGHT|wxTOP|wxEXPAND, 3 ); - + wxString m_TextStyleChoices[] = { _("Normal"), _("Italic"), _("Bold"), _("Bold and italic") }; int m_TextStyleNChoices = sizeof( m_TextStyleChoices ) / sizeof( wxString ); m_TextStyle = new wxRadioBox( this, wxID_ANY, _("Style"), wxDefaultPosition, wxDefaultSize, m_TextStyleNChoices, m_TextStyleChoices, 1, wxRA_SPECIFY_COLS ); m_TextStyle->SetSelection( 3 ); m_OptionsSizer->Add( m_TextStyle, 1, wxLEFT|wxRIGHT|wxTOP|wxEXPAND, 3 ); - + wxString m_TextShapeChoices[] = { _("Input"), _("Output"), _("Bidirectional"), _("Tri-state"), _("Passive") }; int m_TextShapeNChoices = sizeof( m_TextShapeChoices ) / sizeof( wxString ); m_TextShape = new wxRadioBox( this, wxID_ANY, _("Shape"), wxDefaultPosition, wxDefaultSize, m_TextShapeNChoices, m_TextShapeChoices, 1, wxRA_SPECIFY_COLS ); m_TextShape->SetSelection( 3 ); m_OptionsSizer->Add( m_TextShape, 1, wxEXPAND|wxTOP|wxLEFT, 3 ); - - + + bMainSizer->Add( m_OptionsSizer, 0, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 10 ); - + m_sdbSizer1 = new wxStdDialogButtonSizer(); m_sdbSizer1OK = new wxButton( this, wxID_OK ); m_sdbSizer1->AddButton( m_sdbSizer1OK ); m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL ); m_sdbSizer1->AddButton( m_sdbSizer1Cancel ); m_sdbSizer1->Realize(); - + bMainSizer->Add( m_sdbSizer1, 0, wxALL|wxEXPAND, 5 ); - - + + this->SetSizer( bMainSizer ); this->Layout(); bMainSizer->Fit( this ); - + // Connect Events m_valueSingleLine->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this ); m_valueCombo->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this ); @@ -121,5 +119,5 @@ DIALOG_LABEL_EDITOR_BASE::~DIALOG_LABEL_EDITOR_BASE() // Disconnect Events m_valueSingleLine->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this ); m_valueCombo->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this ); - + } diff --git a/eeschema/dialogs/dialog_edit_label_base.fbp b/eeschema/dialogs/dialog_edit_label_base.fbp index f718adde2a..1882c41b29 100644 --- a/eeschema/dialogs/dialog_edit_label_base.fbp +++ b/eeschema/dialogs/dialog_edit_label_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ dialog_edit_label_base 1000 none + 1 dialog_edit_label_base @@ -52,42 +53,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bMainSizer @@ -142,6 +107,7 @@ 0 wxID_ANY Label: + 0 0 @@ -167,29 +133,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -254,33 +197,7 @@ - - - - - - - - - - - - - - - - - - - - - - - OnEnterKey - - - @@ -316,6 +233,7 @@ 0 wxID_ANY Text: + 0 0 @@ -341,29 +259,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -428,33 +323,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -490,6 +358,7 @@ 0 wxID_ANY Label: + 0 0 @@ -515,29 +384,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -595,40 +441,15 @@ ; forward_declare 0 - wxString - wxFILTER_EXCLUDE_CHAR_LIST - wxTextValidator - m_comboText + + wxFILTER_NONE + wxDefaultValidator + - - - - - - - - - - - - - - - - - - - - - - - - OnEnterKey - @@ -664,6 +485,7 @@ 0 wxID_ANY Text Size: + 0 0 @@ -689,29 +511,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -785,33 +584,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -847,6 +619,7 @@ 0 wxID_ANY units + 0 0 @@ -872,29 +645,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -974,30 +724,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1064,30 +790,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1154,30 +856,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1198,14 +876,6 @@ m_sdbSizer1 protected - - - - - - - - diff --git a/eeschema/dialogs/dialog_edit_label_base.h b/eeschema/dialogs/dialog_edit_label_base.h index 5f5d1f080a..cc84ae606a 100644 --- a/eeschema/dialogs/dialog_edit_label_base.h +++ b/eeschema/dialogs/dialog_edit_label_base.h @@ -1,18 +1,15 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 17 2016) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // -// PLEASE DO "NOT" EDIT THIS FILE! +// PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#ifndef __DIALOG_EDIT_LABEL_BASE_H__ -#define __DIALOG_EDIT_LABEL_BASE_H__ +#pragma once #include #include #include -class DIALOG_SHIM; - #include "dialog_shim.h" #include #include @@ -22,7 +19,6 @@ class DIALOG_SHIM; #include #include #include -#include #include #include #include @@ -36,7 +32,7 @@ class DIALOG_SHIM; class DIALOG_LABEL_EDITOR_BASE : public DIALOG_SHIM { private: - + protected: enum { @@ -44,7 +40,7 @@ class DIALOG_LABEL_EDITOR_BASE : public DIALOG_SHIM wxID_VALUEMULTI, wxID_SIZE }; - + wxFlexGridSizer* m_textEntrySizer; wxStaticText* m_labelSingleLine; wxTextCtrl* m_valueSingleLine; @@ -61,17 +57,15 @@ class DIALOG_LABEL_EDITOR_BASE : public DIALOG_SHIM wxStdDialogButtonSizer* m_sdbSizer1; wxButton* m_sdbSizer1OK; wxButton* m_sdbSizer1Cancel; - + // Virtual event handlers, overide them in your derived class virtual void OnEnterKey( wxCommandEvent& event ) { event.Skip(); } - - + + public: - wxString m_comboText; - - 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( 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(); - + }; -#endif //__DIALOG_EDIT_LABEL_BASE_H__ diff --git a/eeschema/dialogs/dialog_sch_edit_sheet_pin.cpp b/eeschema/dialogs/dialog_sch_edit_sheet_pin.cpp index 9d769780ed..1c260f921c 100644 --- a/eeschema/dialogs/dialog_sch_edit_sheet_pin.cpp +++ b/eeschema/dialogs/dialog_sch_edit_sheet_pin.cpp @@ -24,6 +24,7 @@ #include #include +#include #include @@ -52,8 +53,8 @@ DIALOG_SCH_EDIT_SHEET_PIN::DIALOG_SCH_EDIT_SHEET_PIN( SCH_EDIT_FRAME* parent, SC m_sdbSizerOK->SetDefault(); // Set invalid label characters list: - wxTextValidator* validator = static_cast( m_textName->GetValidator() ); - validator->SetCharExcludes( " /" ); + SCH_NETNAME_VALIDATOR validator; + m_textName->SetValidator( validator ); // Now all widgets have the size fixed, call FinishDialogSettings FinishDialogSettings(); @@ -107,10 +108,5 @@ bool DIALOG_SCH_EDIT_SHEET_PIN::TransferDataFromWindow() void DIALOG_SCH_EDIT_SHEET_PIN::onOKButton( wxCommandEvent& event ) { - // Disable wxWidgets message if a pin name has not allowed chars - // (It happens only when editing a old sheet pin name that can contains not allowed chars) - wxTextValidator* validator = static_cast( m_textName->GetValidator() ); - validator->SetCharExcludes( "" ); - event.Skip(); } diff --git a/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.cpp b/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.cpp index fbf0c13379..b86806cb16 100644 --- a/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.cpp +++ b/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Dec 30 2017) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -12,92 +12,90 @@ DIALOG_SCH_EDIT_SHEET_PIN_BASE::DIALOG_SCH_EDIT_SHEET_PIN_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) { this->SetSizeHints( wxSize( -1,-1 ), wxDefaultSize ); - + wxBoxSizer* m_mainSizer; m_mainSizer = new wxBoxSizer( wxVERTICAL ); - + wxBoxSizer* m_nameSizer; m_nameSizer = new wxBoxSizer( wxHORIZONTAL ); - + wxFlexGridSizer* fgSizer1; fgSizer1 = new wxFlexGridSizer( 4, 3, 0, 0 ); fgSizer1->AddGrowableCol( 1 ); fgSizer1->SetFlexibleDirection( wxBOTH ); fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - + m_staticText1 = new wxStaticText( this, wxID_ANY, _("Name:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText1->Wrap( -1 ); fgSizer1->Add( m_staticText1, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - + m_textName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); m_textName->SetMinSize( wxSize( 160,-1 ) ); - - m_textName->SetValidator( wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, &m_labelString ) ); - + fgSizer1->Add( m_textName, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - - + + fgSizer1->Add( 0, 0, 1, wxEXPAND, 6 ); - + m_heightLabel = new wxStaticText( this, wxID_ANY, _("Text height:"), wxDefaultPosition, wxDefaultSize, 0 ); m_heightLabel->Wrap( -1 ); fgSizer1->Add( m_heightLabel, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT, 5 ); - + m_heightCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer1->Add( m_heightCtrl, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 ); - + m_heightUnits = new wxStaticText( this, wxID_ANY, _("units"), wxDefaultPosition, wxDefaultSize, 0 ); m_heightUnits->Wrap( -1 ); fgSizer1->Add( m_heightUnits, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); - + m_widthLabel = new wxStaticText( this, wxID_ANY, _("Text width:"), wxDefaultPosition, wxDefaultSize, 0 ); m_widthLabel->Wrap( -1 ); fgSizer1->Add( m_widthLabel, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT, 5 ); - + m_widthCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer1->Add( m_widthCtrl, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 ); - + m_widthUnits = new wxStaticText( this, wxID_ANY, _("units"), wxDefaultPosition, wxDefaultSize, 0 ); m_widthUnits->Wrap( -1 ); fgSizer1->Add( m_widthUnits, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); - + m_staticText3 = new wxStaticText( this, wxID_ANY, _("Connection type:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText3->Wrap( -1 ); fgSizer1->Add( m_staticText3, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT, 5 ); - + wxArrayString m_choiceConnectionTypeChoices; m_choiceConnectionType = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceConnectionTypeChoices, 0 ); m_choiceConnectionType->SetSelection( 0 ); fgSizer1->Add( m_choiceConnectionType, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 5 ); - - + + fgSizer1->Add( 0, 0, 1, wxEXPAND, 6 ); - - + + m_nameSizer->Add( fgSizer1, 1, wxEXPAND, 6 ); - - + + m_mainSizer->Add( m_nameSizer, 1, wxALL|wxEXPAND, 10 ); - + m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); m_mainSizer->Add( m_staticline1, 0, wxEXPAND|wxRIGHT|wxLEFT, 10 ); - + m_sdbSizer = new wxStdDialogButtonSizer(); m_sdbSizerOK = new wxButton( this, wxID_OK ); m_sdbSizer->AddButton( m_sdbSizerOK ); m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); m_sdbSizer->AddButton( m_sdbSizerCancel ); m_sdbSizer->Realize(); - + m_mainSizer->Add( m_sdbSizer, 0, wxALL|wxEXPAND, 6 ); - - + + this->SetSizer( m_mainSizer ); this->Layout(); m_mainSizer->Fit( this ); - + this->Centre( wxBOTH ); - + // Connect Events m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SCH_EDIT_SHEET_PIN_BASE::onOKButton ), NULL, this ); } @@ -106,5 +104,5 @@ DIALOG_SCH_EDIT_SHEET_PIN_BASE::~DIALOG_SCH_EDIT_SHEET_PIN_BASE() { // Disconnect Events m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SCH_EDIT_SHEET_PIN_BASE::onOKButton ), NULL, this ); - + } diff --git a/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.fbp b/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.fbp index 88eb5a41be..7506b3a9f9 100644 --- a/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.fbp +++ b/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ dialog_sch_edit_sheet_pin_base 1000 none + 1 dialog_sch_edit_sheet_pin @@ -52,42 +53,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - m_mainSizer @@ -151,6 +116,7 @@ 0 wxID_ANY Name: + 0 0 @@ -176,29 +142,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -255,41 +198,14 @@ 0 - wxString - wxFILTER_EXCLUDE_CHAR_LIST - wxTextValidator - m_labelString + + wxFILTER_NONE + wxDefaultValidator + - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -335,6 +251,7 @@ 0 wxID_ANY Text height: + 0 0 @@ -360,29 +277,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -447,33 +341,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -509,6 +376,7 @@ 0 wxID_ANY units + 0 0 @@ -534,29 +402,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -592,6 +437,7 @@ 0 wxID_ANY Text width: + 0 0 @@ -617,29 +463,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -704,33 +527,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -766,6 +562,7 @@ 0 wxID_ANY units + 0 0 @@ -791,29 +588,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -849,6 +623,7 @@ 0 wxID_ANY Connection type: + 0 0 @@ -874,29 +649,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -961,30 +713,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1057,29 +785,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -1098,14 +803,7 @@ m_sdbSizer protected - - - - - onOKButton - - diff --git a/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.h b/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.h index d4f138bb3e..a1417be9fd 100644 --- a/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.h +++ b/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.h @@ -1,12 +1,11 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Dec 30 2017) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#ifndef __DIALOG_SCH_EDIT_SHEET_PIN_BASE_H__ -#define __DIALOG_SCH_EDIT_SHEET_PIN_BASE_H__ +#pragma once #include #include @@ -19,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -35,7 +33,7 @@ class DIALOG_SCH_EDIT_SHEET_PIN_BASE : public DIALOG_SHIM { private: - + protected: wxStaticText* m_staticText1; wxTextCtrl* m_textName; @@ -51,17 +49,15 @@ class DIALOG_SCH_EDIT_SHEET_PIN_BASE : public DIALOG_SHIM wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; wxButton* m_sdbSizerCancel; - + // Virtual event handlers, overide them in your derived class virtual void onOKButton( wxCommandEvent& event ) { event.Skip(); } - - + + public: - wxString m_labelString; - - DIALOG_SCH_EDIT_SHEET_PIN_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Sheet Pin Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + + DIALOG_SCH_EDIT_SHEET_PIN_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Sheet Pin Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_SCH_EDIT_SHEET_PIN_BASE(); - + }; -#endif //__DIALOG_SCH_EDIT_SHEET_PIN_BASE_H__ diff --git a/eeschema/sch_validators.cpp b/eeschema/sch_validators.cpp index 58cfc1da08..7f48fec6b1 100644 --- a/eeschema/sch_validators.cpp +++ b/eeschema/sch_validators.cpp @@ -27,6 +27,8 @@ * @brief Implementation of control validators for schematic dialogs. */ +#include +#include #include #include @@ -139,3 +141,82 @@ bool SCH_FIELD_VALIDATOR::Validate( wxWindow *aParent ) return true; } + + +SCH_NETNAME_VALIDATOR::SCH_NETNAME_VALIDATOR( wxString *aVal ) : + wxValidator() +{ +} + + +SCH_NETNAME_VALIDATOR::SCH_NETNAME_VALIDATOR( const SCH_NETNAME_VALIDATOR& aValidator ) +{ +} + + +wxTextEntry *SCH_NETNAME_VALIDATOR::GetTextEntry() +{ +#if wxUSE_TEXTCTRL + if( wxDynamicCast( m_validatorWindow, wxTextCtrl ) ) + return static_cast( m_validatorWindow ); +#endif + +#if wxUSE_COMBOBOX + if( wxDynamicCast( m_validatorWindow, wxComboBox ) ) + return static_cast( m_validatorWindow ); +#endif + +#if wxUSE_COMBOCTRL + if( wxDynamicCast( m_validatorWindow, wxComboCtrl ) ) + return static_cast( m_validatorWindow ); +#endif + + wxFAIL_MSG( "SCH_NETNAME_VALIDATOR can only be used with wxTextCtrl, wxComboBox, or wxComboCtrl" ); + return nullptr; +} + + +bool SCH_NETNAME_VALIDATOR::Validate( wxWindow *aParent ) +{ + // If window is disabled, simply return + if ( !m_validatorWindow->IsEnabled() ) + return true; + + wxTextEntry * const text = GetTextEntry(); + + if ( !text ) + return false; + + const wxString& errormsg = IsValid( text->GetValue() ); + + if( !errormsg.empty() ) + { + m_validatorWindow->SetFocus(); + wxMessageBox( errormsg, _( "Invalid signal name" ), wxOK | wxICON_EXCLAMATION, aParent ); + return false; + } + + return true; +} + + +wxString SCH_NETNAME_VALIDATOR::IsValid( const wxString& str ) const +{ + if( SCH_CONNECTION::IsBusGroupLabel( str ) ) + return wxString(); + + if( str.Contains( '{' ) || str.Contains( '}' ) ) + return _( "Signal name contains '{' or '}' but is not a valid group bus name" ); + + if( ( str.Contains( '[' ) || str.Contains( ']' ) ) && + !SCH_CONNECTION::IsBusVectorLabel( str ) ) + return _( "Signal name contains '[' or ']' but is not a valid vector bus name" ); + + if( str.Contains( '\r' ) || str.Contains( '\n' ) ) + return _( "Signal names cannot contain CR or LF characters" ); + + if( str.Contains( ' ' ) || str.Contains( '\t' ) ) + return _( "Signal names cannot contain spaces" ); + + return wxString(); +} diff --git a/eeschema/sch_validators.h b/eeschema/sch_validators.h index 93c30e8b4a..ddbc11ef11 100644 --- a/eeschema/sch_validators.h +++ b/eeschema/sch_validators.h @@ -67,4 +67,30 @@ public: }; +class SCH_NETNAME_VALIDATOR : public wxValidator +{ +public: + SCH_NETNAME_VALIDATOR( wxString *aVal = nullptr ); + + SCH_NETNAME_VALIDATOR( const SCH_NETNAME_VALIDATOR& aValidator ); + + bool Copy( const SCH_NETNAME_VALIDATOR& val ); + + virtual wxObject* Clone() const override { return new SCH_NETNAME_VALIDATOR( *this ); } + + virtual bool TransferToWindow() override { return true; } + + virtual bool TransferFromWindow() override { return true; } + + wxTextEntry* GetTextEntry(); + + virtual bool Validate( wxWindow *aParent ) override; + +protected: + + // returns the error message if the contents of 'val' are invalid + virtual wxString IsValid( const wxString& aVal ) const; + +}; + #endif // _SCH_VALIDATORS_H_