Fix issues in reporting netclasses.

1) make sure we get the default netclass when we want it
2) escape for HTML (particularly important for "<invalid>", but also
for reporting user rule names, netclass names, etc.)
This commit is contained in:
Jeff Young 2020-11-30 12:14:22 +00:00
parent 3989c19c41
commit 3a9a6e22bc
7 changed files with 78 additions and 68 deletions

View File

@ -338,7 +338,7 @@ std::string EscapedUTF8( wxString aString )
}
wxString EscapedHTML( const wxString& aString )
wxString EscapeHTML( const wxString& aString )
{
wxString converted;

View File

@ -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;

View File

@ -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.

View File

@ -25,6 +25,7 @@
#include <reporter.h>
#include <widgets/progress_reporter.h>
#include <kicad_string.h>
#include <drc/drc_engine.h>
#include <drc/drc_rule_parser.h>
#include <drc/drc_rule.h>
@ -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 );

View File

@ -301,11 +301,3 @@ std::shared_ptr<DRC_ITEM> DRC_ITEM::Create( const wxString& aErrorKey )
}
wxString escapeHtml( wxString aString )
{
aString.Replace( wxT("<"), wxT("&lt;") );
aString.Replace( wxT(">"), wxT("&gt;") );
return aString;
}

View File

@ -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 );
}

View File

@ -34,6 +34,7 @@
#include <drc/drc_engine.h>
#include <dialogs/panel_setup_rules_base.h>
#include <dialogs/dialog_constraints_reporter.h>
#include <kicad_string.h>
#include "pcb_inspection_tool.h"
@ -304,7 +305,7 @@ int PCB_INSPECTION_TOOL::InspectClearance( const TOOL_EVENT& aEvent )
{
BOARD_CONNECTED_ITEM* cItem = static_cast<BOARD_CONNECTED_ITEM*>( 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( "<ul><li>%s %s</li><li>%s</li><li>%s</li></ul>",
_( "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( "<ul><li>%s %s</li><li>%s</li><li>%s</li></ul>",
_( "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<BOARD_CONNECTED_ITEM*>( 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<BOARD_CONNECTED_ITEM*>( 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( "<h7>" + _( "Track width resolution for:" ) + "</h7>" );
r->Report( "<ul><li>" + item->GetSelectMenuText( r->GetUnits() ) + "</li></ul>" );
r->Report( "<ul><li>" + EscapeHTML( getItemDescription( item ) ) + "</li></ul>" );
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( "<h7>" + _( "Via diameter resolution for:" ) + "</h7>" );
r->Report( "<ul><li>" + item->GetSelectMenuText( r->GetUnits() ) + "</li></ul>" );
r->Report( "<ul><li>" + EscapeHTML( getItemDescription( item ) ) + "</li></ul>" );
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( "<h7>" + _( "Via annular width resolution for:" ) + "</h7>" );
r->Report( "<ul><li>" + item->GetSelectMenuText( r->GetUnits() ) + "</li></ul>" );
r->Report( "<ul><li>" + EscapeHTML( getItemDescription( item ) ) + "</li></ul>" );
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<PAD*>( 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( "<h7>" + _( "Hole diameter resolution for:" ) + "</h7>" );
r->Report( "<ul><li>" + item->GetSelectMenuText( r->GetUnits() ) + "</li></ul>" );
r->Report( "<ul><li>" + EscapeHTML( getItemDescription( item ) ) + "</li></ul>" );
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( "<h7>" + _( "Keepout resolution for:" ) + "</h7>" );
r->Report( "<ul><li>" + item->GetSelectMenuText( r->GetUnits() ) + "</li></ul>" );
r->Report( "<ul><li>" + EscapeHTML( getItemDescription( item ) ) + "</li></ul>" );
r->Report( "" );
if( compileError )