From 23fd4b64dd13a73340244feb85b89b42a24913df Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 22 Aug 2019 10:49:35 +0100 Subject: [PATCH] Remove curly braces from netname escaping context. They're now used for bus definition control characters. Also fixes the sheet pin edit dialog to correctly escape/unescape netnames. Fixes: lp:1840834 * https://bugs.launchpad.net/kicad/+bug/1840834 --- common/string.cpp | 22 +++++++++++-------- eeschema/CMakeLists.txt | 5 +++-- ...heet_pin.cpp => dialog_edit_sheet_pin.cpp} | 16 +++++++------- ...it_sheet_pin.h => dialog_edit_sheet_pin.h} | 19 +++++----------- ...ase.cpp => dialog_edit_sheet_pin_base.cpp} | 10 ++++----- ...ase.fbp => dialog_edit_sheet_pin_base.fbp} | 6 ++--- ...in_base.h => dialog_edit_sheet_pin_base.h} | 8 +++---- eeschema/sheet.cpp | 4 ++-- eeschema/tools/sch_edit_tool.cpp | 4 ++-- 9 files changed, 46 insertions(+), 48 deletions(-) rename eeschema/dialogs/{dialog_sch_edit_sheet_pin.cpp => dialog_edit_sheet_pin.cpp} (86%) rename eeschema/dialogs/{dialog_sch_edit_sheet_pin.h => dialog_edit_sheet_pin.h} (75%) rename eeschema/dialogs/{dialog_sch_edit_sheet_pin_base.cpp => dialog_edit_sheet_pin_base.cpp} (89%) rename eeschema/dialogs/{dialog_sch_edit_sheet_pin_base.fbp => dialog_edit_sheet_pin_base.fbp} (99%) rename eeschema/dialogs/{dialog_sch_edit_sheet_pin_base.h => dialog_edit_sheet_pin_base.h} (79%) diff --git a/common/string.cpp b/common/string.cpp index cc3ce95a29..70ec1859b0 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -53,11 +53,7 @@ wxString EscapeString( const wxString& aSource, ESCAPE_CONTEXT aContext ) for( wxUniChar c: aSource ) { - if( c == '{' ) - { - converted += "{brace}"; - } - else if( aContext == CTX_NETNAME ) + if( aContext == CTX_NETNAME ) { if( c == '/' ) converted += "{slash}"; @@ -66,21 +62,27 @@ wxString EscapeString( const wxString& aSource, ESCAPE_CONTEXT aContext ) } else if( aContext == CTX_LIBID ) { - if( c == ':' ) + if( c == '{' ) + converted += "{brace}"; + else if( c == ':' ) converted += "{colon}"; else converted += c; } else if( aContext == CTX_QUOTED_STR ) { - if( c == '\"' ) + if( c == '{' ) + converted += "{brace}"; + else if( c == '\"' ) converted += "{dblquote}"; else converted += c; } else if( aContext == CTX_DELIMITED_STR ) { - if( c == ' ' ) + if( c == '{' ) + converted += "{brace}"; + else if( c == ' ' ) converted += "{space}"; else if( c == '\t' ) converted += "{tab}"; @@ -91,7 +93,9 @@ wxString EscapeString( const wxString& aSource, ESCAPE_CONTEXT aContext ) } else if( aContext == CTX_FILENAME ) { - if( c == '/' ) + if( c == '{' ) + converted += "{brace}"; + else if( c == '/' ) converted += "{slash}"; else if( c == '\\' ) converted += "{backslash}"; diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 429ba84a61..ce290b4390 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -51,6 +51,8 @@ set( EESCHEMA_DLGS dialogs/dialog_edit_line_style.cpp dialogs/dialog_edit_line_style_base.cpp dialogs/dialog_edit_one_field.cpp + dialogs/dialog_edit_sheet_pin.cpp + dialogs/dialog_edit_sheet_pin_base.cpp dialogs/dialog_erc.cpp dialogs/dialog_erc_base.cpp dialogs/dialog_global_sym_lib_table_config.cpp @@ -76,8 +78,7 @@ set( EESCHEMA_DLGS dialogs/dialog_print_using_printer_base.cpp dialogs/dialog_rescue_each.cpp dialogs/dialog_rescue_each_base.cpp - dialogs/dialog_sch_edit_sheet_pin.cpp - dialogs/dialog_sch_edit_sheet_pin_base.cpp + dialogs/dialog_edit_sheet_pin.cpp dialogs/dialog_sch_sheet_props.cpp dialogs/dialog_sch_sheet_props_base.cpp dialogs/dialog_schematic_find.cpp diff --git a/eeschema/dialogs/dialog_sch_edit_sheet_pin.cpp b/eeschema/dialogs/dialog_edit_sheet_pin.cpp similarity index 86% rename from eeschema/dialogs/dialog_sch_edit_sheet_pin.cpp rename to eeschema/dialogs/dialog_edit_sheet_pin.cpp index 1c260f921c..d52c827c15 100644 --- a/eeschema/dialogs/dialog_sch_edit_sheet_pin.cpp +++ b/eeschema/dialogs/dialog_edit_sheet_pin.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include static wxString sheetPinTypes[] = @@ -38,8 +38,8 @@ static wxString sheetPinTypes[] = }; -DIALOG_SCH_EDIT_SHEET_PIN::DIALOG_SCH_EDIT_SHEET_PIN( SCH_EDIT_FRAME* parent, SCH_SHEET_PIN* aPin ) : - DIALOG_SCH_EDIT_SHEET_PIN_BASE( parent ), +DIALOG_EDIT_SHEET_PIN::DIALOG_EDIT_SHEET_PIN( SCH_EDIT_FRAME* parent, SCH_SHEET_PIN* aPin ) : + DIALOG_EDIT_SHEET_PIN_BASE( parent ), m_frame( parent ), m_sheetPin( aPin ), m_textWidth( parent, m_widthLabel, m_widthCtrl, m_widthUnits, true ), @@ -75,9 +75,9 @@ DIALOG_SCH_EDIT_SHEET_PIN::DIALOG_SCH_EDIT_SHEET_PIN( SCH_EDIT_FRAME* parent, SC } -bool DIALOG_SCH_EDIT_SHEET_PIN::TransferDataToWindow() +bool DIALOG_EDIT_SHEET_PIN::TransferDataToWindow() { - m_textName->SetValue( m_sheetPin->GetText() ); + m_textName->SetValue( UnescapeString( m_sheetPin->GetText() ) ); m_textName->SelectAll(); m_textWidth.SetValue( m_sheetPin->GetTextWidth() ); m_textHeight.SetValue( m_sheetPin->GetTextHeight() ); @@ -87,12 +87,12 @@ bool DIALOG_SCH_EDIT_SHEET_PIN::TransferDataToWindow() } -bool DIALOG_SCH_EDIT_SHEET_PIN::TransferDataFromWindow() +bool DIALOG_EDIT_SHEET_PIN::TransferDataFromWindow() { if( !m_sheetPin->IsNew() ) m_frame->SaveCopyInUndoList( (SCH_ITEM*) m_sheetPin->GetParent(), UR_CHANGED ); - m_sheetPin->SetText( m_textName->GetValue() ); + m_sheetPin->SetText( EscapeString( m_textName->GetValue(), CTX_NETNAME ) ); m_sheetPin->SetTextSize( wxSize( m_textWidth.GetValue(), m_textHeight.GetValue() ) ); auto shape = static_cast( m_choiceConnectionType->GetCurrentSelection() ); @@ -106,7 +106,7 @@ bool DIALOG_SCH_EDIT_SHEET_PIN::TransferDataFromWindow() } -void DIALOG_SCH_EDIT_SHEET_PIN::onOKButton( wxCommandEvent& event ) +void DIALOG_EDIT_SHEET_PIN::onOKButton( wxCommandEvent& event ) { event.Skip(); } diff --git a/eeschema/dialogs/dialog_sch_edit_sheet_pin.h b/eeschema/dialogs/dialog_edit_sheet_pin.h similarity index 75% rename from eeschema/dialogs/dialog_sch_edit_sheet_pin.h rename to eeschema/dialogs/dialog_edit_sheet_pin.h index e60a69cf50..0add3c6fc2 100644 --- a/eeschema/dialogs/dialog_sch_edit_sheet_pin.h +++ b/eeschema/dialogs/dialog_edit_sheet_pin.h @@ -22,25 +22,18 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef __dialog_sch_edit_sheet_pin__ -#define __dialog_sch_edit_sheet_pin__ +#ifndef DIALOG_EDIT_SHEET_PIN_H +#define DIALOG_EDIT_SHEET_PIN_H -/** - * @file - * Subclass of DIALOG_SCH_EDIT_SHEET_PIN_BASE, which is generated by wxFormBuilder. - */ - - -#include -#include // enum PINSHEETLABEL_SHAPE definition +#include #include class SCH_SHEET_PIN; -class DIALOG_SCH_EDIT_SHEET_PIN : public DIALOG_SCH_EDIT_SHEET_PIN_BASE +class DIALOG_EDIT_SHEET_PIN : public DIALOG_EDIT_SHEET_PIN_BASE { SCH_EDIT_FRAME* m_frame; SCH_SHEET_PIN* m_sheetPin; @@ -49,7 +42,7 @@ class DIALOG_SCH_EDIT_SHEET_PIN : public DIALOG_SCH_EDIT_SHEET_PIN_BASE UNIT_BINDER m_textHeight; public: - DIALOG_SCH_EDIT_SHEET_PIN( SCH_EDIT_FRAME* parent, SCH_SHEET_PIN* aPin ); + DIALOG_EDIT_SHEET_PIN( SCH_EDIT_FRAME* parent, SCH_SHEET_PIN* aPin ); bool TransferDataToWindow() override; bool TransferDataFromWindow() override; @@ -58,4 +51,4 @@ private: void onOKButton( wxCommandEvent& event ) override; }; -#endif // __dialog_sch_edit_sheet_pin__ +#endif // DIALOG_EDIT_SHEET_PIN_H diff --git a/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.cpp b/eeschema/dialogs/dialog_edit_sheet_pin_base.cpp similarity index 89% rename from eeschema/dialogs/dialog_sch_edit_sheet_pin_base.cpp rename to eeschema/dialogs/dialog_edit_sheet_pin_base.cpp index b86806cb16..d1dca63afa 100644 --- a/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.cpp +++ b/eeschema/dialogs/dialog_edit_sheet_pin_base.cpp @@ -5,11 +5,11 @@ // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#include "dialog_sch_edit_sheet_pin_base.h" +#include "dialog_edit_sheet_pin_base.h" /////////////////////////////////////////////////////////////////////////// -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 ) +DIALOG_EDIT_SHEET_PIN_BASE::DIALOG_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 ); @@ -97,12 +97,12 @@ DIALOG_SCH_EDIT_SHEET_PIN_BASE::DIALOG_SCH_EDIT_SHEET_PIN_BASE( wxWindow* parent this->Centre( wxBOTH ); // Connect Events - m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SCH_EDIT_SHEET_PIN_BASE::onOKButton ), NULL, this ); + m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_SHEET_PIN_BASE::onOKButton ), NULL, this ); } -DIALOG_SCH_EDIT_SHEET_PIN_BASE::~DIALOG_SCH_EDIT_SHEET_PIN_BASE() +DIALOG_EDIT_SHEET_PIN_BASE::~DIALOG_EDIT_SHEET_PIN_BASE() { // Disconnect Events - m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SCH_EDIT_SHEET_PIN_BASE::onOKButton ), NULL, this ); + m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_SHEET_PIN_BASE::onOKButton ), NULL, this ); } diff --git a/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.fbp b/eeschema/dialogs/dialog_edit_sheet_pin_base.fbp similarity index 99% rename from eeschema/dialogs/dialog_sch_edit_sheet_pin_base.fbp rename to eeschema/dialogs/dialog_edit_sheet_pin_base.fbp index 7506b3a9f9..1a5d5c8b19 100644 --- a/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.fbp +++ b/eeschema/dialogs/dialog_edit_sheet_pin_base.fbp @@ -11,12 +11,12 @@ res UTF-8 connect - dialog_sch_edit_sheet_pin_base + dialog_edit_sheet_pin_base 1000 none 1 - dialog_sch_edit_sheet_pin + dialog_edit_sheet_pin . @@ -43,7 +43,7 @@ wxID_ANY -1,-1 - DIALOG_SCH_EDIT_SHEET_PIN_BASE + DIALOG_EDIT_SHEET_PIN_BASE -1,-1 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER diff --git a/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.h b/eeschema/dialogs/dialog_edit_sheet_pin_base.h similarity index 79% rename from eeschema/dialogs/dialog_sch_edit_sheet_pin_base.h rename to eeschema/dialogs/dialog_edit_sheet_pin_base.h index a1417be9fd..d4bfcd3452 100644 --- a/eeschema/dialogs/dialog_sch_edit_sheet_pin_base.h +++ b/eeschema/dialogs/dialog_edit_sheet_pin_base.h @@ -28,9 +28,9 @@ /////////////////////////////////////////////////////////////////////////////// -/// Class DIALOG_SCH_EDIT_SHEET_PIN_BASE +/// Class DIALOG_EDIT_SHEET_PIN_BASE /////////////////////////////////////////////////////////////////////////////// -class DIALOG_SCH_EDIT_SHEET_PIN_BASE : public DIALOG_SHIM +class DIALOG_EDIT_SHEET_PIN_BASE : public DIALOG_SHIM { private: @@ -56,8 +56,8 @@ class DIALOG_SCH_EDIT_SHEET_PIN_BASE : public DIALOG_SHIM public: - 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(); + DIALOG_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_EDIT_SHEET_PIN_BASE(); }; diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 64dfa51d27..ad2cd4dda0 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include @@ -794,7 +794,7 @@ SCH_SHEET_PIN* SCH_EDIT_FRAME::CreateSheetPin( SCH_SHEET* aSheet, SCH_HIERLABEL* if( !aLabel ) { - DIALOG_SCH_EDIT_SHEET_PIN dlg( this, sheetPin ); + DIALOG_EDIT_SHEET_PIN dlg( this, sheetPin ); if( dlg.ShowModal() != wxID_OK || sheetPin->GetText().IsEmpty() ) { diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 870c0f2a65..510b04e4f0 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include "sch_drawing_tools.h" @@ -1214,7 +1214,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) case SCH_SHEET_PIN_T: { SCH_SHEET_PIN* pin = (SCH_SHEET_PIN*) item; - DIALOG_SCH_EDIT_SHEET_PIN dlg( m_frame, pin ); + DIALOG_EDIT_SHEET_PIN dlg( m_frame, pin ); if( dlg.ShowModal() == wxID_OK ) {