From 684bb62fd8edb4785caee33b189d73e68921942f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 19 Oct 2018 12:28:34 +0100 Subject: [PATCH] Escape slashes in labels and netnames. Also re-allows spaces, as they can already come in through sheet names. Fixes: lp:1798621 * https://bugs.launchpad.net/kicad/+bug/1798621 --- common/string.cpp | 131 +++++++++++------- common/widgets/net_selector.cpp | 21 ++- common/xnode.cpp | 8 +- eeschema/cross-probing.cpp | 2 +- eeschema/dialogs/dialog_edit_label.cpp | 14 +- eeschema/dialogs/dialog_edit_one_field.cpp | 4 +- .../dialogs/dialog_fields_editor_global.cpp | 4 +- eeschema/highlight_connection.cpp | 2 +- gerbview/events_called_functions.cpp | 4 +- gerbview/gbr_layout.cpp | 2 +- gerbview/gerber_draw_item.cpp | 10 +- gerbview/onrightclick.cpp | 4 +- gerbview/toolbars_gerber.cpp | 4 +- gerbview/tools/gerbview_control.cpp | 2 +- gerbview/tools/selection_tool.cpp | 2 +- include/eda_text.h | 3 +- include/kicad_string.h | 18 ++- pcbnew/board_connected_item.h | 5 +- pcbnew/board_netlist_updater.cpp | 18 +-- pcbnew/class_board.cpp | 17 +-- pcbnew/class_pad.cpp | 2 +- pcbnew/class_track.cpp | 25 ++-- pcbnew/class_zone.cpp | 2 +- pcbnew/dialogs/dialog_copper_zones.cpp | 5 +- .../dialogs/dialog_select_net_from_list.cpp | 6 +- pcbnew/dialogs/panel_setup_netclasses.cpp | 4 +- pcbnew/footprint_info_impl.cpp | 4 +- pcbnew/netinfo_list.cpp | 5 +- pcbnew/pad_draw_functions.cpp | 23 +-- pcbnew/pcb_netlist.cpp | 4 +- pcbnew/pcb_painter.cpp | 12 +- 31 files changed, 215 insertions(+), 152 deletions(-) diff --git a/common/string.cpp b/common/string.cpp index e60d6424e6..cc3ce95a29 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -40,78 +40,107 @@ static const char illegalFileNameChars[] = "\\/:\"<>|"; -wxString EscapeString( const wxString& aSource ) +/** + * These Escape/Unescape routines use HTML-entity-reference-style encoding to handle + * characters which are: + * (a) not legal in filenames + * (b) used as control characters in LIB_IDs + * (c) used to delineate hierarchical paths + */ +wxString EscapeString( const wxString& aSource, ESCAPE_CONTEXT aContext ) { -#if 1 - return aSource; -#else wxString converted; for( wxUniChar c: aSource ) { - if( c == '\"' ) - converted += """; - else if( c == '\'' ) - converted += "'"; - else if( c == '&' ) - converted += "&"; - else if( c == '<' ) - converted += "<"; - else if( c == '>' ) - converted += ">"; - else if( c == '\\' ) - converted += "∖"; - else if( c == '/' ) - converted += "⁄"; - else if( c == '|' ) - converted += "|"; - else if( c == ':' ) - converted += ":"; - else if( c == ' ' ) - converted += " "; - else if( c == '%' ) - converted += "%"; - else if( c == '$' ) - converted += "$"; - else if( c == '\t' ) - converted += "&tab;"; - else if( c == '\n' || c == '\r' ) - converted += "&Newline;"; + if( c == '{' ) + { + converted += "{brace}"; + } + else if( aContext == CTX_NETNAME ) + { + if( c == '/' ) + converted += "{slash}"; + else + converted += c; + } + else if( aContext == CTX_LIBID ) + { + if( c == ':' ) + converted += "{colon}"; + else + converted += c; + } + else if( aContext == CTX_QUOTED_STR ) + { + if( c == '\"' ) + converted += "{dblquote}"; + else + converted += c; + } + else if( aContext == CTX_DELIMITED_STR ) + { + if( c == ' ' ) + converted += "{space}"; + else if( c == '\t' ) + converted += "{tab}"; + else if( c == '\n' || c == '\r' ) + converted += "{return}"; + else + converted += c; + } + else if( aContext == CTX_FILENAME ) + { + if( c == '/' ) + converted += "{slash}"; + else if( c == '\\' ) + converted += "{backslash}"; + else if( c == '\"' ) + converted += "{dblquote}"; + else if( c == '<' ) + converted += "{lt}"; + else if( c == '>' ) + converted += "{gt}"; + else if( c == '|' ) + converted += "{bar}"; + else if( c == ':' ) + converted += "{colon}"; + else if( c == '\t' ) + converted += "{tab}"; + else if( c == '\n' || c == '\r' ) + converted += "{return}"; + else + converted += c; + } else converted += c; } return converted; -#endif } wxString UnescapeString( const wxString& aSource ) { -#if 1 - return aSource; -#else wxString converted = aSource; - converted.Replace( """, "\"" ); - converted.Replace( "'", "'" ); - converted.Replace( "<", "<" ); - converted.Replace( ">", ">" ); - converted.Replace( "∖", "\\" ); - converted.Replace( "⁄", "/" ); - converted.Replace( "|", "|" ); - converted.Replace( ":", ":" ); - converted.Replace( " ", " " ); - converted.Replace( "%", "%" ); - converted.Replace( "$", "$" ); - converted.Replace( "&tab;", "\t" ); - converted.Replace( "&Newline;", "\n" ); + converted.Replace( "{dblquote}", "\"" ); + converted.Replace( "{quote}", "'" ); + converted.Replace( "{lt}", "<" ); + converted.Replace( "{gt}", ">" ); + converted.Replace( "{backslash}", "\\" ); + converted.Replace( "{slash}", "/" ); + converted.Replace( "{bar}", "|" ); + converted.Replace( "{colon}", ":" ); + converted.Replace( "{space}", " " ); + converted.Replace( "{dollar}", "$" ); + converted.Replace( "{tab}", "\t" ); + converted.Replace( "{return}", "\n" ); // must be done last - converted.Replace( "&", "&" ); + converted.Replace( "{brace}", "{" ); return converted; -#endif } diff --git a/common/widgets/net_selector.cpp b/common/widgets/net_selector.cpp index 5203d17e62..c3a971c0b7 100644 --- a/common/widgets/net_selector.cpp +++ b/common/widgets/net_selector.cpp @@ -189,8 +189,19 @@ public: } else { - m_selectedNetcode = m_netinfoList->GetNetItem( selectedNetName )->GetNet(); - GetComboCtrl()->SetValue( selectedNetName ); + wxString netname = EscapeString( selectedNetName, CTX_NETNAME ); + NETINFO_ITEM* netInfo = m_netinfoList->GetNetItem( netname ); + + if( netInfo == nullptr || netInfo->GetNet() == 0 ) + { + m_selectedNetcode = 0; + GetComboCtrl()->SetValue( NO_NET ); + } + else + { + m_selectedNetcode = netInfo->GetNet(); + GetComboCtrl()->SetValue( selectedNetName ); + } } wxCommandEvent changeEvent( NET_SELECTED ); @@ -241,8 +252,10 @@ protected: { if( netinfo->GetNet() > 0 && netinfo->IsCurrent() ) { - if( filter.IsEmpty() || wxString( netinfo->GetNetname() ).MakeLower().Matches( filter ) ) - netNames.push_back( netinfo->GetNetname() ); + wxString netname = UnescapeString( netinfo->GetNetname() ); + + if( filter.IsEmpty() || wxString( netname ).MakeLower().Matches( filter ) ) + netNames.push_back( netname ); } } std::sort( netNames.begin(), netNames.end() ); diff --git a/common/xnode.cpp b/common/xnode.cpp index 74d31be9b8..0fb2854a87 100644 --- a/common/xnode.cpp +++ b/common/xnode.cpp @@ -34,7 +34,7 @@ void XNODE::Format( OUTPUTFORMATTER* out, int nestLevel ) switch( GetType() ) { case wxXML_ELEMENT_NODE: - out->Print( nestLevel, "(%s", out->Quotew( GetName() ).c_str() ); + out->Print( nestLevel, "(%s", TO_UTF8( GetName() ) ); FormatContents( out, nestLevel ); if( GetNext() ) out->Print( 0, ")\n" ); @@ -54,10 +54,8 @@ void XNODE::FormatContents( OUTPUTFORMATTER* out, int nestLevel ) for( XATTR* attr = (XATTR*) GetAttributes(); attr; attr = (XATTR*) attr->GetNext() ) { out->Print( 0, " (%s %s)", - // attr names should never need quoting, no spaces, we designed the file. - out->Quotew( attr->GetName() ).c_str(), - out->Quotew( attr->GetValue() ).c_str() - ); + TO_UTF8( attr->GetName() ), + out->Quotew( attr->GetValue() ).c_str() ); } // we only expect to have used one of two types here: diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index 7937507534..900e97e617 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -82,7 +82,7 @@ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) { m_SelectedNetName = FROM_UTF8( text ); - SetStatusText( _( "Selected net: " ) + m_SelectedNetName ); + SetStatusText( _( "Selected net: " ) + UnescapeString( m_SelectedNetName ) ); std::vector itemsToRedraw; SetCurrentSheetHighlightFlags( &itemsToRedraw ); diff --git a/eeschema/dialogs/dialog_edit_label.cpp b/eeschema/dialogs/dialog_edit_label.cpp index 8bf27b3e0e..d8bf6f1c49 100644 --- a/eeschema/dialogs/dialog_edit_label.cpp +++ b/eeschema/dialogs/dialog_edit_label.cpp @@ -42,6 +42,7 @@ #include #include +#include class SCH_EDIT_FRAME; class SCH_TEXT; @@ -153,10 +154,6 @@ DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTe SetInitialFocus( m_activeTextCtrl ); - // Enable validator for net names - if( m_CurrentText->Type() != SCH_TEXT_T ) - m_activeTextCtrl->SetValidator( m_netNameValidator ); - m_TextShape->Show( m_CurrentText->Type() == SCH_GLOBAL_LABEL_T || m_CurrentText->Type() == SCH_HIERARCHICAL_LABEL_T ); @@ -209,7 +206,7 @@ bool DIALOG_LABEL_EDITOR::TransferDataToWindow() if( !wxDialog::TransferDataToWindow() ) return false; - m_activeTextEntry->SetValue( m_CurrentText->GetText() ); + m_activeTextEntry->SetValue( UnescapeString( m_CurrentText->GetText() ) ); if( m_valueCombo->IsShown() ) { @@ -220,7 +217,10 @@ bool DIALOG_LABEL_EDITOR::TransferDataToWindow() for( SCH_SCREEN* screen = allScreens.GetFirst(); screen; screen = allScreens.GetNext() ) for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() ) if( item->Type() == m_CurrentText->Type() ) - existingLabels.insert( static_cast( item )->GetText() ); + { + auto textItem = static_cast( item ); + existingLabels.insert( UnescapeString( textItem->GetText() ) ); + } wxArrayString existingLabelArray; @@ -307,7 +307,7 @@ bool DIALOG_LABEL_EDITOR::TransferDataFromWindow() m_Parent->GetCanvas()->Refresh(); - text = m_activeTextEntry->GetValue(); + text = EscapeString( m_activeTextEntry->GetValue(), CTX_NETNAME ); if( !text.IsEmpty() ) m_CurrentText->SetText( text ); diff --git a/eeschema/dialogs/dialog_edit_one_field.cpp b/eeschema/dialogs/dialog_edit_one_field.cpp index 43e089cc37..83f919aeb4 100644 --- a/eeschema/dialogs/dialog_edit_one_field.cpp +++ b/eeschema/dialogs/dialog_edit_one_field.cpp @@ -162,7 +162,7 @@ void DIALOG_EDIT_ONE_FIELD::OnSetFocusText( wxFocusEvent& event ) bool DIALOG_EDIT_ONE_FIELD::TransferDataToWindow() { - m_TextValue->SetValue( UnescapeString( m_text ) ); + m_TextValue->SetValue( m_text ); m_posX.SetValue( m_position.x ); m_posY.SetValue( m_position.y ); @@ -180,7 +180,7 @@ bool DIALOG_EDIT_ONE_FIELD::TransferDataToWindow() bool DIALOG_EDIT_ONE_FIELD::TransferDataFromWindow() { - m_text = EscapeString( m_TextValue->GetValue() ); + m_text = m_TextValue->GetValue(); if( m_fieldId == REFERENCE ) { diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index 2099dd2099..3920badc56 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -316,7 +316,7 @@ public: fieldValue = wxString::Format( wxT( "%d" ), ( int )references.size() ); } - return UnescapeString( fieldValue ); + return fieldValue; } @@ -325,7 +325,7 @@ public: if( aCol == REFERENCE || aCol == QUANTITY_COLUMN ) return; // Can't modify references or quantity - wxString value = EscapeString( aValue ); + wxString value = aValue; DATA_MODEL_ROW& rowGroup = m_rows[ aRow ]; wxString fieldName = m_fieldNames[ aCol ]; diff --git a/eeschema/highlight_connection.cpp b/eeschema/highlight_connection.cpp index f0672e348f..347f3a2cf7 100644 --- a/eeschema/highlight_connection.cpp +++ b/eeschema/highlight_connection.cpp @@ -72,7 +72,7 @@ bool SCH_EDIT_FRAME::HighlightConnectionAtPosition( wxPoint aPosition ) } SendCrossProbeNetName( m_SelectedNetName ); - SetStatusText( _( "Selected net: " ) + m_SelectedNetName ); + SetStatusText( _( "Selected net: " ) + UnescapeString( m_SelectedNetName ) ); SetCurrentSheetHighlightFlags( &itemsToRedraw ); // Be sure hightlight change will be redrawn diff --git a/gerbview/events_called_functions.cpp b/gerbview/events_called_functions.cpp index 2b92533f8a..99d51325b5 100644 --- a/gerbview/events_called_functions.cpp +++ b/gerbview/events_called_functions.cpp @@ -274,7 +274,7 @@ void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_HIGHLIGHT_NET_ITEMS: - if( m_SelNetnameBox->SetStringSelection( currItem->GetNetAttributes().m_Netname ) ) + if( m_SelNetnameBox->SetStringSelection( UnescapeString( currItem->GetNetAttributes().m_Netname ) ) ) m_canvas->Refresh(); break; @@ -317,7 +317,7 @@ void GERBVIEW_FRAME::OnSelectHighlightChoice( wxCommandEvent& event ) break; case ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE: - settings->m_netHighlightString = m_SelNetnameBox->GetStringSelection(); + settings->m_netHighlightString = EscapeString( m_SelNetnameBox->GetStringSelection(), CTX_NETNAME ); break; case ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE: diff --git a/gerbview/gbr_layout.cpp b/gerbview/gbr_layout.cpp index ccb4d176e2..9c5f5aa397 100644 --- a/gerbview/gbr_layout.cpp +++ b/gerbview/gbr_layout.cpp @@ -99,7 +99,7 @@ void GBR_LAYOUT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMode, wxString netHighlight; if( gerbFrame->m_SelNetnameBox->GetSelection() > 0 ) - netHighlight = gerbFrame->m_SelNetnameBox->GetStringSelection(); + netHighlight = EscapeString( gerbFrame->m_SelNetnameBox->GetStringSelection(), CTX_NETNAME ); wxString aperAttrHighlight = gerbFrame->m_SelAperAttributesBox->GetStringSelection(); diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index a8e98c1773..289dceff84 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -39,7 +39,7 @@ #include #include #include - +#include GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( GERBER_FILE_IMAGE* aGerberImageFile ) : EDA_ITEM( (EDA_ITEM*)NULL, GERBER_DRAW_ITEM_T ) @@ -741,16 +741,16 @@ void GERBER_DRAW_ITEM::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PAN net_msg << " "; if( m_netAttributes.m_Netname.IsEmpty() ) - net_msg << ""; + net_msg << ""; else - net_msg << m_netAttributes.m_Netname; + net_msg << UnescapeString( m_netAttributes.m_Netname ); } if( ( m_netAttributes.m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_PAD ) ) { cmp_pad_msg.Printf( _( "Cmp: %s; Pad: %s" ), - GetChars( m_netAttributes.m_Cmpref ), - GetChars( m_netAttributes.m_Padname ) ); + m_netAttributes.m_Cmpref, + m_netAttributes.m_Padname ); } else if( ( m_netAttributes.m_NetAttribType & GBR_NETLIST_METADATA::GBR_NETINFO_CMP ) ) diff --git a/gerbview/onrightclick.cpp b/gerbview/onrightclick.cpp index ec5b9b300f..879f873d4a 100644 --- a/gerbview/onrightclick.cpp +++ b/gerbview/onrightclick.cpp @@ -30,7 +30,7 @@ #include #include #include - +#include /* Prepare the right-click pullup menu. * The menu already has a list of zoom commands. @@ -113,7 +113,7 @@ bool GERBVIEW_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* aPopMenu ) { AddMenuItem( aPopMenu, ID_HIGHLIGHT_NET_ITEMS, wxString::Format( _( "Highlight Items of Net \"%s\"" ), - GetChars( net_attr.m_Netname ) ), + UnescapeString( net_attr.m_Netname ) ), KiBitmap( general_ratsnest_xpm ) ); add_separator = true; } diff --git a/gerbview/toolbars_gerber.cpp b/gerbview/toolbars_gerber.cpp index 8ca4daecd8..87a55b9702 100644 --- a/gerbview/toolbars_gerber.cpp +++ b/gerbview/toolbars_gerber.cpp @@ -38,7 +38,7 @@ #include #include #include - +#include #include void GERBVIEW_FRAME::ReCreateHToolbar( void ) @@ -458,7 +458,7 @@ void GERBVIEW_FRAME::updateNetnameListSelectBox() // Now copy the list to the choice box for( auto ii = full_list.begin(); ii != full_list.end(); ++ii ) { - m_SelNetnameBox->Append( ii->first ); + m_SelNetnameBox->Append( UnescapeString( ii->first ) ); } m_SelNetnameBox->SetSelection( 0 ); diff --git a/gerbview/tools/gerbview_control.cpp b/gerbview/tools/gerbview_control.cpp index 71661d4d30..c85f5bd324 100644 --- a/gerbview/tools/gerbview_control.cpp +++ b/gerbview/tools/gerbview_control.cpp @@ -135,7 +135,7 @@ int GERBVIEW_CONTROL::HighlightControl( const TOOL_EVENT& aEvent ) { auto string = item->GetNetAttributes().m_Netname; settings->m_netHighlightString = string; - m_frame->m_SelNetnameBox->SetStringSelection( string ); + m_frame->m_SelNetnameBox->SetStringSelection( UnescapeString( string ) ); } else if( item && aEvent.IsAction( &GERBVIEW_ACTIONS::highlightComponent ) ) { diff --git a/gerbview/tools/selection_tool.cpp b/gerbview/tools/selection_tool.cpp index 265e6be91f..1a0b49b310 100644 --- a/gerbview/tools/selection_tool.cpp +++ b/gerbview/tools/selection_tool.cpp @@ -110,7 +110,7 @@ private: { auto menuEntry = Add( GERBVIEW_ACTIONS::highlightNet ); menuEntry->SetItemLabel( wxString::Format( _( "Highlight Items of Net \"%s\"" ), - GetChars( net_attr.m_Netname ) ) ); + UnescapeString( net_attr.m_Netname ) ) ); addSeparator = true; } diff --git a/include/eda_text.h b/include/eda_text.h index d0936c5c53..4fad55c91b 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -37,6 +37,7 @@ #include // EDA_RECT #include +#include "kicad_string.h" class SHAPE_POLY_SET; @@ -149,7 +150,7 @@ public: /** * Returns the string actually shown after processing of the base * text. Default is no processing */ - virtual wxString GetShownText() const { return m_Text; } + virtual wxString GetShownText() const { return UnescapeString( m_Text ); } /** * Returns a shortened version (max 15 characters) of the shown text */ diff --git a/include/kicad_string.h b/include/kicad_string.h index d0db7a13bb..e0c4e53164 100644 --- a/include/kicad_string.h +++ b/include/kicad_string.h @@ -37,13 +37,19 @@ /** - * These Escape/Unescape routines use HTML-entity-reference-style encoding to handle - * characters which are: - * (a) not legal in filenames - * (b) used as control characters in LIB_IDs - * (c) used to delineate hierarchical paths + * Escape/Unescape routines to safely encode reserved-characters in various + * contexts. */ -wxString EscapeString( const wxString& aSource ); +enum ESCAPE_CONTEXT +{ + CTX_NETNAME, + CTX_LIBID, + CTX_QUOTED_STR, + CTX_DELIMITED_STR, + CTX_FILENAME +}; + +wxString EscapeString( const wxString& aSource, ESCAPE_CONTEXT aContext ); wxString UnescapeString( const wxString& aSource ); diff --git a/pcbnew/board_connected_item.h b/pcbnew/board_connected_item.h index 4459b54bea..dbba3d818c 100644 --- a/pcbnew/board_connected_item.h +++ b/pcbnew/board_connected_item.h @@ -33,6 +33,7 @@ #include #include +#include class NETCLASS; class TRACK; @@ -139,9 +140,9 @@ public: if( !netname.length() ) return wxT( "[]" ); else if( GetNetCode() < 0 ) - return wxT( "[" + netname + "](" + _( "Not Found" ) + ")" ); + return wxT( "[" + UnescapeString( netname ) + "](" + _( "Not Found" ) + ")" ); else - return wxT( "[" + netname + "]" ); + return wxT( "[" + UnescapeString( netname ) + "]" ); } /** diff --git a/pcbnew/board_netlist_updater.cpp b/pcbnew/board_netlist_updater.cpp index 604c4a2e43..70c07e966b 100644 --- a/pcbnew/board_netlist_updater.cpp +++ b/pcbnew/board_netlist_updater.cpp @@ -333,7 +333,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent } m_addedNets[netName] = netinfo; - msg.Printf( _( "Add net %s." ), netName ); + msg.Printf( _( "Add net %s." ), UnescapeString( netName ) ); m_reporter->Report( msg, REPORTER::RPT_ACTION ); } @@ -344,15 +344,15 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent msg.Printf( _( "Reconnect %s pin %s from %s to %s."), aPcbComponent->GetReference(), pad->GetName(), - pad->GetNetname(), - netName ); + UnescapeString( pad->GetNetname() ), + UnescapeString( netName ) ); } else { msg.Printf( _( "Connect %s pin %s to %s."), aPcbComponent->GetReference(), pad->GetName(), - netName ); + UnescapeString( netName ) ); } m_reporter->Report( msg, REPORTER::RPT_ACTION ); @@ -439,8 +439,8 @@ bool BOARD_NETLIST_UPDATER::updateCopperZoneNets( NETLIST& aNetlist ) if( !updatedNetname.IsEmpty() ) { msg.Printf( _( "Reconnect copper zone from %s to %s." ), - zone->GetNetname(), - updatedNetname ); + UnescapeString( zone->GetNetname() ), + UnescapeString( updatedNetname ) ); m_reporter->Report( msg, REPORTER::RPT_ACTION ); if( !m_isDryRun ) @@ -459,7 +459,8 @@ bool BOARD_NETLIST_UPDATER::updateCopperZoneNets( NETLIST& aNetlist ) } else { - msg.Printf( _( "Copper zone (%s) has no pads connected." ), zone->GetNetname() ); + msg.Printf( _( "Copper zone (%s) has no pads connected." ), + UnescapeString( zone->GetNetname() ) ); m_reporter->Report( msg, REPORTER::RPT_WARNING ); ++m_warningCount; } @@ -552,7 +553,8 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets() if( count == 1 ) // Really one pad, and nothing else { - msg.Printf( _( "Remove single pad net %s." ), getNetname( previouspad ) ); + msg.Printf( _( "Remove single pad net %s." ), + UnescapeString( getNetname( previouspad ) ) ); m_reporter->Report( msg, REPORTER::RPT_ACTION ); if( !m_isDryRun ) diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index e01afc5e87..8c1d1c466d 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -1512,7 +1512,7 @@ int BOARD::SortedNetnamesList( wxArrayString& aNames, bool aSortbyPadsCount ) { auto netcode = net->GetNet(); - if( netcode > 0 ) + if( netcode > 0 && net->IsCurrent() ) { netBuffer.push_back( net ); max_netcode = std::max( netcode, max_netcode); @@ -1539,7 +1539,7 @@ int BOARD::SortedNetnamesList( wxArrayString& aNames, bool aSortbyPadsCount ) } for( NETINFO_ITEM* net : netBuffer ) - aNames.Add( net->GetNetname() ); + aNames.Add( UnescapeString( net->GetNetname() ) ); return netBuffer.size(); } @@ -2502,8 +2502,8 @@ void BOARD::updateComponentPadConnections( NETLIST& aNetlist, MODULE* footprint, msg.Printf( _( "Changing footprint %s pad %s net from %s to %s." ), footprint->GetReference(), pad->GetName(), - pad->GetNetname(), - netName ); + UnescapeString( pad->GetNetname() ), + UnescapeString( netName ) ); aReporter.Report( msg, REPORTER::RPT_ACTION ); if( !aNetlist.IsDryRun() ) @@ -2825,7 +2825,8 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets, if( pad && zoneCount == 0 ) { - msg.Printf( _( "Remove single pad net %s." ), GetChars( pad->GetNetname() ) ); + msg.Printf( _( "Remove single pad net %s." ), + UnescapeString( pad->GetNetname() ) ); aReporter.Report( msg, REPORTER::RPT_ACTION ); m_connectivity->Remove( pad ); @@ -2900,14 +2901,14 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets, if( updatedNet ) { msg.Printf( _( "Updating copper zone from net %s to %s." ), - zone->GetNetname(), - updatedNet->GetNetname() ); + UnescapeString( zone->GetNetname() ), + UnescapeString( updatedNet->GetNetname() ) ); aReporter.Report( msg, REPORTER::RPT_ACTION ); } else { msg.Printf( _( "Copper zone (net %s) has no pads connected." ), - zone->GetNetname() ); + UnescapeString( zone->GetNetname() ) ); aReporter.Report( msg, REPORTER::RPT_WARNING ); } diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index 4509f1e8f2..16f1501252 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -781,7 +781,7 @@ void D_PAD::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM>& a aList.push_back( MSG_PANEL_ITEM( _( "Pad" ), m_name, BROWN ) ); } - aList.push_back( MSG_PANEL_ITEM( _( "Net" ), GetNetname(), DARKCYAN ) ); + aList.push_back( MSG_PANEL_ITEM( _( "Net" ), UnescapeString( GetNetname() ), DARKCYAN ) ); board = GetBoard(); diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index 2050c9aa32..faa66123dc 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -122,7 +122,9 @@ EDA_ITEM* SEGZONE::Clone() const wxString SEGZONE::GetSelectMenuText( EDA_UNITS_T aUnits ) const { - return wxString::Format( _( "Zone [%s] on %s" ), GetNetnameMsg(), GetLayerName() ); + return wxString::Format( _( "Zone [%s] on %s" ), + UnescapeString( GetNetnameMsg() ), + GetLayerName() ); } @@ -571,7 +573,8 @@ void TRACK::DrawShortNetname( EDA_DRAW_PANEL* panel, if( net == NULL ) return; - int textlen = net->GetShortNetname().Len(); + wxString text = UnescapeString( net->GetShortNetname() ); + int textlen = text.Len(); if( textlen > 0 ) { @@ -615,11 +618,10 @@ void TRACK::DrawShortNetname( EDA_DRAW_PANEL* panel, tsize = (tsize * 7) / 10; // small reduction to give a better look DrawGraphicHaloText( panel->GetClipBox(), aDC, tpos, - aBgColor, BLACK, WHITE, net->GetShortNetname(), angle, - wxSize( tsize, tsize ), + aBgColor, BLACK, WHITE, + text, angle, wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, - tsize / 7, - false, false ); + tsize / 7, false, false ); } } } @@ -972,7 +974,8 @@ void VIA::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, const w if( net == NULL ) return; - int len = net->GetShortNetname().Len(); + wxString text = UnescapeString( net->GetShortNetname() ); + int len = text.Len(); if( len > 0 ) { @@ -988,8 +991,8 @@ void VIA::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, const w EDA_RECT* clipbox = panel->GetClipBox(); DrawGraphicHaloText( clipbox, aDC, m_Start, - color, WHITE, BLACK, net->GetShortNetname(), 0, - wxSize( tsize, tsize ), + color, WHITE, BLACK, + text, 0, wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false ); } @@ -1114,9 +1117,9 @@ void TRACK::GetMsgPanelInfoBase_Common( EDA_UNITS_T aUnits, std::vector< MSG_PAN NETINFO_ITEM* net = GetNet(); if( net ) - msg = net->GetNetname(); + msg = UnescapeString( net->GetNetname() ); else - msg = wxT( "" ); + msg = wxT( "" ); aList.push_back( MSG_PANEL_ITEM( _( "NetName" ), msg, RED ) ); diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index cbd4233431..4c114062d7 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -852,7 +852,7 @@ void ZONE_CONTAINER::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL NETINFO_ITEM* net = GetNet(); if( net ) - msg = net->GetNetname(); + msg = UnescapeString( net->GetNetname() ); else // Should not occur msg = _( "" ); } diff --git a/pcbnew/dialogs/dialog_copper_zones.cpp b/pcbnew/dialogs/dialog_copper_zones.cpp index a557ad62e6..f68bb50b0d 100644 --- a/pcbnew/dialogs/dialog_copper_zones.cpp +++ b/pcbnew/dialogs/dialog_copper_zones.cpp @@ -395,7 +395,10 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aUseExportableSetupOnly ) // Search net_code for this net, if a net was selected if( m_ListNetNameSelection->GetSelection() > 0 ) - net = m_Parent->GetBoard()->FindNet( m_ListNetNameSelection->GetStringSelection() ); + { + wxString netname = EscapeString( m_ListNetNameSelection->GetStringSelection(), CTX_NETNAME ); + net = m_Parent->GetBoard()->FindNet( netname ); + } m_settings.m_NetcodeSelection = net ? net->GetNet() : 0; diff --git a/pcbnew/dialogs/dialog_select_net_from_list.cpp b/pcbnew/dialogs/dialog_select_net_from_list.cpp index a8d5afe0ed..53aa8a5e14 100644 --- a/pcbnew/dialogs/dialog_select_net_from_list.cpp +++ b/pcbnew/dialogs/dialog_select_net_from_list.cpp @@ -131,7 +131,7 @@ void DIALOG_SELECT_NET_FROM_LIST::buildNetsList() if( !netFilter.IsEmpty() ) { - wxString netname = net->GetNetname(); + wxString netname = UnescapeString( net->GetNetname() ); if( filter.Find( netname.MakeUpper() ) == EDA_PATTERN_NOT_FOUND ) continue; } @@ -144,7 +144,7 @@ void DIALOG_SELECT_NET_FROM_LIST::buildNetsList() wxVector dataLine; dataLine.push_back( wxVariant( wxString::Format( "%.3d", netcode ) ) ); - dataLine.push_back( wxVariant( net->GetNetname() ) ); + dataLine.push_back( wxVariant( UnescapeString( net->GetNetname() ) ) ); if( netcode ) dataLine.push_back( wxVariant( wxString::Format( "%u", nodes ) ) ); @@ -208,7 +208,7 @@ void DIALOG_SELECT_NET_FROM_LIST::onSelChanged( wxDataViewEvent& ) if( selected_row >= 0 ) { - m_selection = m_netsList->GetTextValue( selected_row, 1 ); + m_selection = EscapeString( m_netsList->GetTextValue( selected_row, 1 ), CTX_NETNAME ); m_wasSelected = true; HighlightNet( m_selection ); diff --git a/pcbnew/dialogs/panel_setup_netclasses.cpp b/pcbnew/dialogs/panel_setup_netclasses.cpp index a89f575827..473aaa1375 100644 --- a/pcbnew/dialogs/panel_setup_netclasses.cpp +++ b/pcbnew/dialogs/panel_setup_netclasses.cpp @@ -170,7 +170,7 @@ bool PANEL_SETUP_NETCLASSES::TransferDataToWindow() for( NETINFO_ITEM* net : m_Pcb->GetNetInfo() ) { if( net->GetNet() > 0 && net->IsCurrent() ) - addNet( net->GetNetname(), net->GetNetClass()->GetName() ); + addNet( UnescapeString( net->GetNetname() ), net->GetNetClass()->GetName() ); } return true; @@ -261,7 +261,7 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow() NETCLASSPTR nc = netclasses.Find( m_membershipGrid->GetCellValue( row, 1 ) ); if( nc ) - nc->Add( m_membershipGrid->GetCellValue( row, 0 ) ); + nc->Add( EscapeString( m_membershipGrid->GetCellValue( row, 0 ), CTX_NETNAME ) ); } m_Pcb->SynchronizeNetsAndNetClasses(); diff --git a/pcbnew/footprint_info_impl.cpp b/pcbnew/footprint_info_impl.cpp index 0efbe27034..b6a6aed56b 100644 --- a/pcbnew/footprint_info_impl.cpp +++ b/pcbnew/footprint_info_impl.cpp @@ -357,8 +357,8 @@ void FOOTPRINT_LIST_IMPL::WriteCacheToFile( wxTextFile* aCacheFile ) { aCacheFile->AddLine( fpinfo->GetLibNickname() ); aCacheFile->AddLine( fpinfo->GetName() ); - aCacheFile->AddLine( EscapeString( fpinfo->GetDescription() ) ); - aCacheFile->AddLine( EscapeString( fpinfo->GetKeywords() ) ); + aCacheFile->AddLine( EscapeString( fpinfo->GetDescription(), CTX_DELIMITED_STR ) ); + aCacheFile->AddLine( EscapeString( fpinfo->GetKeywords(), CTX_DELIMITED_STR ) ); aCacheFile->AddLine( wxString::Format( "%d", fpinfo->GetOrderNum() ) ); aCacheFile->AddLine( wxString::Format( "%u", fpinfo->GetPadCount() ) ); aCacheFile->AddLine( wxString::Format( "%u", fpinfo->GetUniquePadCount() ) ); diff --git a/pcbnew/netinfo_list.cpp b/pcbnew/netinfo_list.cpp index 96e2c98762..44fa6244d9 100644 --- a/pcbnew/netinfo_list.cpp +++ b/pcbnew/netinfo_list.cpp @@ -172,8 +172,9 @@ void NETINFO_LIST::Show() const for( it = m_netNames.begin(), itEnd = m_netNames.end(); it != itEnd; ++it ) { printf( "[%d]: netcode:%d netname:<%s>\n", - i++, it->second->GetNet(), - TO_UTF8( it->second->GetNetname() ) ); + i++, + it->second->GetNet(), + TO_UTF8( it->second->GetNetname() ) ); } } #endif diff --git a/pcbnew/pad_draw_functions.cpp b/pcbnew/pad_draw_functions.cpp index bdbe42d57e..6a63b2d18a 100644 --- a/pcbnew/pad_draw_functions.cpp +++ b/pcbnew/pad_draw_functions.cpp @@ -653,13 +653,17 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) if( !aDrawInfo.m_Display_padnum && !aDrawInfo.m_Display_netname ) return; - wxPoint tpos0 = shape_pos; // Position of the centre of text - wxPoint tpos = tpos0; - wxSize AreaSize; // size of text area, normalized to AreaSize.y < AreaSize.x - int shortname_len = 0; + wxPoint tpos0 = shape_pos; // Position of the centre of text + wxPoint tpos = tpos0; + wxSize AreaSize; // size of text area, normalized to AreaSize.y < AreaSize.x + wxString shortname; + int shortname_len = 0; if( aDrawInfo.m_Display_netname ) - shortname_len = GetShortNetname().Len(); + { + shortname = UnescapeString( GetShortNetname() ); + shortname_len = shortname.Len(); + } if( GetShape() == PAD_SHAPE_CIRCLE ) angle = 0; @@ -695,8 +699,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) constexpr int MIN_CHAR_COUNT = 3; unsigned int tsize; - EDA_RECT* clipBox = aDrawInfo.m_DrawPanel? - aDrawInfo.m_DrawPanel->GetClipBox() : NULL; + EDA_RECT* clipBox = aDrawInfo.m_DrawPanel ? aDrawInfo.m_DrawPanel->GetClipBox() : NULL; if( aDrawInfo.m_Display_padnum ) { @@ -736,9 +739,9 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) tsize = ( tsize * 7 ) / 10; DrawGraphicHaloText( clipBox, aDC, tpos, aDrawInfo.m_Color, BLACK, WHITE, - GetShortNetname(), t_angle, - wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER, - GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false ); + shortname, t_angle, wxSize( tsize, tsize ), + GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, + tsize / 7, false, false ); } } diff --git a/pcbnew/pcb_netlist.cpp b/pcbnew/pcb_netlist.cpp index 6b0b5a1b46..ab576ac72e 100644 --- a/pcbnew/pcb_netlist.cpp +++ b/pcbnew/pcb_netlist.cpp @@ -39,8 +39,8 @@ int COMPONENT_NET::Format( OUTPUTFORMATTER* aOut, int aNestLevel, int aCtl ) { return aOut->Print( aNestLevel, "(pin_net %s %s)", - aOut->Quotew( m_pinName ).c_str(), - aOut->Quotew( m_netName ).c_str() ); + aOut->Quotew( m_pinName ).c_str(), + aOut->Quotew( m_netName ).c_str() ); } diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index e04250d031..077c8151bf 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -382,7 +382,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) if( length < 10 * width ) return; - const wxString& netName = aTrack->GetShortNetname(); + const wxString& netName = UnescapeString( aTrack->GetShortNetname() ); VECTOR2D textPosition = start + line / 2.0; // center of the track double textOrientation; @@ -470,8 +470,9 @@ void PCB_PAINTER::draw( const VIA* aVia, int aLayer ) if( displayNetname ) { + wxString netname = UnescapeString( aVia->GetShortNetname() ); // calculate the size of net name text: - double tsize = 1.5 * size / aVia->GetShortNetname().Length(); + double tsize = 1.5 * size / netname.Length(); tsize = std::min( tsize, size ); // Use a smaller text size to handle interline, pen size.. tsize *= 0.7; @@ -479,7 +480,7 @@ void PCB_PAINTER::draw( const VIA* aVia, int aLayer ) m_gal->SetGlyphSize( namesize ); m_gal->SetLineWidth( namesize.x / 12.0 ); - m_gal->BitmapText( aVia->GetShortNetname(), textpos, 0.0 ); + m_gal->BitmapText( netname, textpos, 0.0 ); } @@ -655,8 +656,9 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) if( displayNetname ) { + wxString netname = UnescapeString( aPad->GetShortNetname() ); // calculate the size of net name text: - double tsize = 1.5 * padsize.x / aPad->GetShortNetname().Length(); + double tsize = 1.5 * padsize.x / netname.Length(); tsize = std::min( tsize, size ); // Use a smaller text size to handle interline, pen size.. tsize *= 0.7; @@ -664,7 +666,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) m_gal->SetGlyphSize( namesize ); m_gal->SetLineWidth( namesize.x / 12.0 ); - m_gal->BitmapText( aPad->GetShortNetname(), textpos, 0.0 ); + m_gal->BitmapText( netname, textpos, 0.0 ); } if( m_pcbSettings.m_padNumbers )