From 3a9a6e22bc4d76e49070c767932fd1b346a64865 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 30 Nov 2020 12:14:22 +0000 Subject: [PATCH] Fix issues in reporting netclasses. 1) make sure we get the default netclass when we want it 2) escape for HTML (particularly important for "", but also for reporting user rule names, netclass names, etc.) --- common/string.cpp | 2 +- eeschema/generate_alias_info.cpp | 21 ++++++----- include/kicad_string.h | 2 +- pcbnew/drc/drc_engine.cpp | 53 ++++++++++++++-------------- pcbnew/drc/drc_item.cpp | 8 ----- pcbnew/generate_footprint_info.cpp | 10 +++--- pcbnew/tools/pcb_inspection_tool.cpp | 50 +++++++++++++++++--------- 7 files changed, 78 insertions(+), 68 deletions(-) diff --git a/common/string.cpp b/common/string.cpp index 38ba25b6ad..4c09c4f4a2 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -338,7 +338,7 @@ std::string EscapedUTF8( wxString aString ) } -wxString EscapedHTML( const wxString& aString ) +wxString EscapeHTML( const wxString& aString ) { wxString converted; diff --git a/eeschema/generate_alias_info.cpp b/eeschema/generate_alias_info.cpp index 9e60a8c79d..768db80dac 100644 --- a/eeschema/generate_alias_info.cpp +++ b/eeschema/generate_alias_info.cpp @@ -107,7 +107,7 @@ public: protected: void SetHtmlName() { - m_html.Replace( "__NAME__", EscapedHTML( m_symbol->GetName() ) ); + m_html.Replace( "__NAME__", EscapeHTML( m_symbol->GetName() ) ); } @@ -130,9 +130,9 @@ protected: root_desc = parent->GetDescription(); } - m_html.Replace( - "__ALIASOF__", wxString::Format( - AliasOfFormat, EscapedHTML( root_name ), EscapedHTML( root_desc ) ) ); + m_html.Replace( "__ALIASOF__", wxString::Format( AliasOfFormat, + EscapeHTML( root_name ), + EscapeHTML( root_desc ) ) ); } } @@ -141,7 +141,7 @@ protected: { wxString raw_desc = m_symbol->GetDescription(); - m_html.Replace( "__DESC__", wxString::Format( DescFormat, EscapedHTML( raw_desc ) ) ); + m_html.Replace( "__DESC__", wxString::Format( DescFormat, EscapeHTML( raw_desc ) ) ); } @@ -152,8 +152,7 @@ protected: if( keywords.empty() ) m_html.Replace( "__KEY__", wxEmptyString ); else - m_html.Replace( "__KEY__", - wxString::Format( KeywordsFormat, EscapedHTML( keywords ) ) ); + m_html.Replace( "__KEY__", wxString::Format( KeywordsFormat, EscapeHTML( keywords ) ) ); } @@ -163,7 +162,7 @@ protected: wxString text = aField.GetFullText( m_unit > 0 ? m_unit : 1 ); wxString fieldhtml = FieldFormat; - fieldhtml.Replace( "__NAME__", EscapedHTML( name ) ); + fieldhtml.Replace( "__NAME__", EscapeHTML( name ) ); switch( aField.GetId() ) { @@ -177,12 +176,12 @@ protected: else { wxString datasheetlink = DatasheetLinkFormat; - datasheetlink.Replace( "__HREF__", EscapedHTML( text ) ); + datasheetlink.Replace( "__HREF__", EscapeHTML( text ) ); if( text.Length() > 75 ) text = text.Left( 72 ) + wxT( "..." ); - datasheetlink.Replace( "__TEXT__", EscapedHTML( text ) ); + datasheetlink.Replace( "__TEXT__", EscapeHTML( text ) ); fieldhtml.Replace( "__VALUE__", datasheetlink ); } @@ -194,7 +193,7 @@ protected: return wxEmptyString; default: - fieldhtml.Replace( "__VALUE__", EscapedHTML( text ) ); + fieldhtml.Replace( "__VALUE__", EscapeHTML( text ) ); } return fieldhtml; diff --git a/include/kicad_string.h b/include/kicad_string.h index c3eec95961..4eede79419 100644 --- a/include/kicad_string.h +++ b/include/kicad_string.h @@ -106,7 +106,7 @@ std::string EscapedUTF8( wxString aString ); /** * Return a new wxString escaped for embedding in HTML. */ -wxString EscapedHTML( const wxString& aString ); +wxString EscapeHTML( const wxString& aString ); /** * Read one line line from \a aFile. diff --git a/pcbnew/drc/drc_engine.cpp b/pcbnew/drc/drc_engine.cpp index 2327c5fbb4..f120ea6155 100644 --- a/pcbnew/drc/drc_engine.cpp +++ b/pcbnew/drc/drc_engine.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -750,8 +751,8 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI REPORT( "" ) REPORT( wxString::Format( _( "Local override on %s; clearance: %s." ), - a->GetSelectMenuText( UNITS ), - MessageTextFromValue( UNITS, overrideA ) ) ) + EscapeHTML( a->GetSelectMenuText( UNITS ) ), + EscapeHTML( MessageTextFromValue( UNITS, overrideA ) ) ) ) } if( bc && !a_is_non_copper && bc->GetLocalClearanceOverrides( nullptr ) > 0 ) @@ -760,8 +761,8 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI REPORT( "" ) REPORT( wxString::Format( _( "Local override on %s; clearance: %s." ), - b->GetSelectMenuText( UNITS ), - MessageTextFromValue( UNITS, overrideB ) ) ) + EscapeHTML( b->GetSelectMenuText( UNITS ) ), + EscapeHTML( MessageTextFromValue( UNITS, overrideB ) ) ) ) } if( overrideA || overrideB ) @@ -781,38 +782,38 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI if( aConstraintId == CLEARANCE_CONSTRAINT ) { - int clearance = c->constraint.m_Value.Min(); + int val = c->constraint.m_Value.Min(); REPORT( wxString::Format( _( "Checking %s; clearance: %s." ), - c->constraint.GetName(), - MessageTextFromValue( UNITS, clearance ) ) ) + EscapeHTML( c->constraint.GetName() ), + EscapeHTML( MessageTextFromValue( UNITS, val ) ) ) ) } else if( aConstraintId == COURTYARD_CLEARANCE_CONSTRAINT ) { - int clearance = c->constraint.m_Value.Min(); + int val = c->constraint.m_Value.Min(); REPORT( wxString::Format( _( "Checking %s; courtyard clearance: %s." ), - c->constraint.GetName(), - MessageTextFromValue( UNITS, clearance ) ) ) + EscapeHTML( c->constraint.GetName() ), + EscapeHTML( MessageTextFromValue( UNITS, val ) ) ) ) } else if( aConstraintId == SILK_CLEARANCE_CONSTRAINT ) { - int clearance = c->constraint.m_Value.Min(); + int val = c->constraint.m_Value.Min(); REPORT( wxString::Format( _( "Checking %s; silk clearance: %s." ), - c->constraint.GetName(), - MessageTextFromValue( UNITS, clearance ) ) ) + EscapeHTML( c->constraint.GetName() ), + EscapeHTML( MessageTextFromValue( UNITS, val ) ) ) ) } else if( aConstraintId == HOLE_CLEARANCE_CONSTRAINT ) { - int clearance = c->constraint.m_Value.Min(); + int val = c->constraint.m_Value.Min(); REPORT( wxString::Format( _( "Checking %s; hole clearance: %s." ), - c->constraint.GetName(), - MessageTextFromValue( UNITS, clearance ) ) ) + EscapeHTML( c->constraint.GetName() ), + EscapeHTML( MessageTextFromValue( UNITS, val ) ) ) ) } else if( aConstraintId == EDGE_CLEARANCE_CONSTRAINT ) { - int clearance = c->constraint.m_Value.Min(); + int val = c->constraint.m_Value.Min(); REPORT( wxString::Format( _( "Checking %s; edge clearance: %s." ), - c->constraint.GetName(), - MessageTextFromValue( UNITS, clearance ) ) ) + EscapeHTML( c->constraint.GetName() ), + EscapeHTML( MessageTextFromValue( UNITS, val ) ) ) ) } else { @@ -882,7 +883,7 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI else if( c->parentRule ) { REPORT( wxString::Format( _( "Rule layer \"%s\" not matched." ), - c->parentRule->m_LayerSource ) ) + EscapeHTML( c->parentRule->m_LayerSource ) ) ) REPORT( "Rule ignored." ) } else @@ -904,7 +905,7 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI else if( c->parentRule ) { REPORT( wxString::Format( _( "Rule layer \"%s\" not matched." ), - c->parentRule->m_LayerSource ) ) + EscapeHTML( c->parentRule->m_LayerSource ) ) ) REPORT( "Rule ignored." ) } else @@ -933,7 +934,7 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI else { REPORT( wxString::Format( _( "Checking rule condition \"%s\"." ), - c->condition->GetExpression() ) ) + EscapeHTML( c->condition->GetExpression() ) ) ) } if( c->condition->EvaluateFor( a, b, aLayer, aReporter ) ) @@ -993,8 +994,8 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI { REPORT( "" ) REPORT( wxString::Format( _( "Local clearance on %s; clearance: %s." ), - a->GetSelectMenuText( UNITS ), - MessageTextFromValue( UNITS, localA ) ) ) + EscapeHTML( a->GetSelectMenuText( UNITS ) ), + EscapeHTML( MessageTextFromValue( UNITS, localA ) ) ) ) if( localA > clearance ) clearance = ac->GetLocalClearance( &m_msg ); @@ -1004,8 +1005,8 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI { REPORT( "" ) REPORT( wxString::Format( _( "Local clearance on %s; clearance: %s." ), - b->GetSelectMenuText( UNITS ), - MessageTextFromValue( UNITS, localB ) ) ) + EscapeHTML( b->GetSelectMenuText( UNITS ) ), + EscapeHTML( MessageTextFromValue( UNITS, localB ) ) ) ) if( localB > clearance ) clearance = bc->GetLocalClearance( &m_msg ); diff --git a/pcbnew/drc/drc_item.cpp b/pcbnew/drc/drc_item.cpp index 733718bdd6..cdb516903f 100644 --- a/pcbnew/drc/drc_item.cpp +++ b/pcbnew/drc/drc_item.cpp @@ -301,11 +301,3 @@ std::shared_ptr DRC_ITEM::Create( const wxString& aErrorKey ) } -wxString escapeHtml( wxString aString ) -{ - aString.Replace( wxT("<"), wxT("<") ); - aString.Replace( wxT(">"), wxT(">") ); - return aString; -} - - diff --git a/pcbnew/generate_footprint_info.cpp b/pcbnew/generate_footprint_info.cpp index 2486a4d9bc..24ec9e135c 100644 --- a/pcbnew/generate_footprint_info.cpp +++ b/pcbnew/generate_footprint_info.cpp @@ -104,19 +104,19 @@ public: desc.RemoveLast( 1 ); } - m_html.Replace( "__NAME__", EscapedHTML( name ) ); - m_html.Replace( "__DESC__", EscapedHTML( desc ) ); + m_html.Replace( "__NAME__", EscapeHTML( name ) ); + m_html.Replace( "__DESC__", EscapeHTML( desc ) ); wxString keywordsHtml = KeywordsFormat; - keywordsHtml.Replace( "__KEYWORDS__", EscapedHTML( keywords ) ); + keywordsHtml.Replace( "__KEYWORDS__", EscapeHTML( keywords ) ); wxString docHtml = DocFormat; - docHtml.Replace( "__HREF__", EscapedHTML( doc ) ); + docHtml.Replace( "__HREF__", EscapeHTML( doc ) ); if( doc.Length() > 75 ) doc = doc.Left( 72 ) + wxT( "..." ); - docHtml.Replace( "__TEXT__", EscapedHTML( doc ) ); + docHtml.Replace( "__TEXT__", EscapeHTML( doc ) ); m_html.Replace( "__FIELDS__", keywordsHtml + docHtml ); } diff --git a/pcbnew/tools/pcb_inspection_tool.cpp b/pcbnew/tools/pcb_inspection_tool.cpp index 3cea31587a..e9e2e95d99 100644 --- a/pcbnew/tools/pcb_inspection_tool.cpp +++ b/pcbnew/tools/pcb_inspection_tool.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "pcb_inspection_tool.h" @@ -304,7 +305,7 @@ int PCB_INSPECTION_TOOL::InspectClearance( const TOOL_EVENT& aEvent ) { BOARD_CONNECTED_ITEM* cItem = static_cast( aItem ); s += wxS( " " ) + wxString::Format( _( "[netclass %s]" ), - cItem->GetNetClassName() ); + cItem->GetNetClass()->GetName() ); } return s; @@ -316,9 +317,9 @@ int PCB_INSPECTION_TOOL::InspectClearance( const TOOL_EVENT& aEvent ) r->Report( wxString::Format( "
  • %s %s
  • %s
  • %s
", _( "Layer" ), - m_frame->GetBoard()->GetLayerName( layer ), - getItemDescription( a ), - getItemDescription( b ) ) ); + EscapeHTML( m_frame->GetBoard()->GetLayerName( layer ) ), + EscapeHTML( getItemDescription( a ) ), + EscapeHTML( getItemDescription( b ) ) ) ); reportClearance( SILK_CLEARANCE_CONSTRAINT, layer, a, b, r ); } @@ -340,9 +341,9 @@ int PCB_INSPECTION_TOOL::InspectClearance( const TOOL_EVENT& aEvent ) r->Report( wxString::Format( "
  • %s %s
  • %s
  • %s
", _( "Layer" ), - m_frame->GetBoard()->GetLayerName( layer ), - getItemDescription( a ), - getItemDescription( b ) ) ); + EscapeHTML( m_frame->GetBoard()->GetLayerName( layer ) ), + EscapeHTML( getItemDescription( a ) ), + EscapeHTML( getItemDescription( b ) ) ) ); BOARD_CONNECTED_ITEM* ac = a && a->IsConnected() ? static_cast( a ) : nullptr; @@ -429,12 +430,29 @@ int PCB_INSPECTION_TOOL::InspectConstraints( const TOOL_EVENT& aEvent ) courtyardError = true; } + WX_HTML_REPORT_BOX* r = nullptr; + + auto getItemDescription = + [&]( BOARD_ITEM* aItem ) + { + wxString s = aItem->GetSelectMenuText( r->GetUnits() ); + + if( aItem->IsConnected() ) + { + BOARD_CONNECTED_ITEM* cItem = static_cast( aItem ); + s += wxS( " " ) + wxString::Format( _( "[netclass %s]" ), + cItem->GetNetClass()->GetName() ); + } + + return s; + }; + if( item->Type() == PCB_TRACE_T ) { - WX_HTML_REPORT_BOX* r = m_inspectConstraintsDialog->AddPage( _( "Track Width" ) ); + r = m_inspectConstraintsDialog->AddPage( _( "Track Width" ) ); r->Report( "" + _( "Track width resolution for:" ) + "" ); - r->Report( "
  • " + item->GetSelectMenuText( r->GetUnits() ) + "
" ); + r->Report( "
  • " + EscapeHTML( getItemDescription( item ) ) + "
" ); r->Report( "" ); if( compileError ) @@ -468,10 +486,10 @@ int PCB_INSPECTION_TOOL::InspectConstraints( const TOOL_EVENT& aEvent ) if( item->Type() == PCB_VIA_T ) { - WX_HTML_REPORT_BOX* r = m_inspectConstraintsDialog->AddPage( _( "Via Diameter" ) ); + r = m_inspectConstraintsDialog->AddPage( _( "Via Diameter" ) ); r->Report( "" + _( "Via diameter resolution for:" ) + "" ); - r->Report( "
  • " + item->GetSelectMenuText( r->GetUnits() ) + "
" ); + r->Report( "
  • " + EscapeHTML( getItemDescription( item ) ) + "
" ); r->Report( "" ); if( compileError ) @@ -505,7 +523,7 @@ int PCB_INSPECTION_TOOL::InspectConstraints( const TOOL_EVENT& aEvent ) r = m_inspectConstraintsDialog->AddPage( _( "Via Annular Width" ) ); r->Report( "" + _( "Via annular width resolution for:" ) + "" ); - r->Report( "
  • " + item->GetSelectMenuText( r->GetUnits() ) + "
" ); + r->Report( "
  • " + EscapeHTML( getItemDescription( item ) ) + "
" ); r->Report( "" ); if( compileError ) @@ -540,10 +558,10 @@ int PCB_INSPECTION_TOOL::InspectConstraints( const TOOL_EVENT& aEvent ) if( ( item->Type() == PCB_PAD_T && static_cast( item )->GetDrillSize().x > 0 ) || item->Type() == PCB_VIA_T ) { - WX_HTML_REPORT_BOX* r = m_inspectConstraintsDialog->AddPage( _( "Hole Size" ) ); + r = m_inspectConstraintsDialog->AddPage( _( "Hole Size" ) ); r->Report( "" + _( "Hole diameter resolution for:" ) + "" ); - r->Report( "
  • " + item->GetSelectMenuText( r->GetUnits() ) + "
" ); + r->Report( "
  • " + EscapeHTML( getItemDescription( item ) ) + "
" ); r->Report( "" ); if( compileError ) @@ -569,10 +587,10 @@ int PCB_INSPECTION_TOOL::InspectConstraints( const TOOL_EVENT& aEvent ) r->Flush(); } - WX_HTML_REPORT_BOX* r = m_inspectConstraintsDialog->AddPage( _( "Keepouts" ) ); + r = m_inspectConstraintsDialog->AddPage( _( "Keepouts" ) ); r->Report( "" + _( "Keepout resolution for:" ) + "" ); - r->Report( "
  • " + item->GetSelectMenuText( r->GetUnits() ) + "
" ); + r->Report( "
  • " + EscapeHTML( getItemDescription( item ) ) + "
" ); r->Report( "" ); if( compileError )