From c6fb799fcd4ea71b7ba895ca0c8ff18ea046f7c9 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 21 Sep 2020 11:36:07 +0100 Subject: [PATCH] Restore severity in saved DRC/ERC reports. Fixes https://gitlab.com/kicad/code/kicad/issues/5733 --- common/rc_item.cpp | 33 ++++++++++++++++++++++++++++----- common/rc_item.h | 3 ++- eeschema/dialogs/dialog_erc.cpp | 6 ++++-- pcbnew/dialogs/dialog_drc.cpp | 26 +++++++++++++++++++++----- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/common/rc_item.cpp b/common/rc_item.cpp index d333c8024b..773b4a6417 100644 --- a/common/rc_item.cpp +++ b/common/rc_item.cpp @@ -50,8 +50,23 @@ wxString RC_ITEM::ShowCoord( EDA_UNITS aUnits, const wxPoint& aPos ) } -wxString RC_ITEM::ShowReport( EDA_UNITS aUnits, const std::map& aItemMap ) const +wxString RC_ITEM::ShowReport( EDA_UNITS aUnits, SEVERITY aSeverity, + const std::map& aItemMap ) const { + wxString severity; + + switch( aSeverity ) + { + case RPT_SEVERITY_ERROR: severity = wxT( "Severity: error" ); + case RPT_SEVERITY_WARNING: severity = wxT( "Severity: warning" ); + case RPT_SEVERITY_ACTION: severity = wxT( "Severity: action" ); + case RPT_SEVERITY_INFO: severity = wxT( "Severity: info" ); + default: ; + }; + + if( m_parent && m_parent->IsExcluded() ) + severity += wxT( " (excluded)" ); + EDA_ITEM* mainItem = nullptr; EDA_ITEM* auxItem = nullptr; @@ -65,11 +80,17 @@ wxString RC_ITEM::ShowReport( EDA_UNITS aUnits, const std::map& if( ii != aItemMap.end() ) auxItem = ii->second; + // Note: some customers machine-process these. So: + // 1) don't translate + // 2) try not to re-order or change syntax + // 3) report numeric error code (which should be more stable) in addition to message + if( mainItem && auxItem ) { - return wxString::Format( wxT( "ErrType(%d): %s\n %s: %s\n %s: %s\n" ), + return wxString::Format( wxT( "ErrType(%d): %s %s\n %s: %s\n %s: %s\n" ), GetErrorCode(), GetErrorMessage(), + severity, ShowCoord( aUnits, mainItem->GetPosition() ), mainItem->GetSelectMenuText( aUnits ), ShowCoord( aUnits, auxItem->GetPosition() ), @@ -77,17 +98,19 @@ wxString RC_ITEM::ShowReport( EDA_UNITS aUnits, const std::map& } else if( mainItem ) { - return wxString::Format( wxT( "ErrType(%d): %s\n %s: %s\n" ), + return wxString::Format( wxT( "ErrType(%d): %s %s\n %s: %s\n" ), GetErrorCode(), GetErrorMessage(), + severity, ShowCoord( aUnits, mainItem->GetPosition() ), mainItem->GetSelectMenuText( aUnits ) ); } else { - return wxString::Format( wxT( "ErrType(%d): %s\n" ), + return wxString::Format( wxT( "ErrType(%d): %s %s\n" ), GetErrorCode(), - GetErrorMessage() ); + GetErrorMessage(), + severity ); } } diff --git a/common/rc_item.h b/common/rc_item.h index a49e7647a6..556e72ab5e 100644 --- a/common/rc_item.h +++ b/common/rc_item.h @@ -27,6 +27,7 @@ #include #include #include +#include class MARKER_BASE; class EDA_BASE_FRAME; @@ -150,7 +151,7 @@ public: * translates this object into a text string suitable for saving to disk in a report. * @return wxString - the simple multi-line report text. */ - virtual wxString ShowReport( EDA_UNITS aUnits, + virtual wxString ShowReport( EDA_UNITS aUnits, SEVERITY aSeverity, const std::map& aItemMap ) const; int GetErrorCode() const { return m_errorCode; } diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index bbf02d2208..a60eee65fd 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -586,20 +586,22 @@ bool DIALOG_ERC::writeReport( const wxString& aFullFileName ) for( SCH_ITEM* aItem : sheetList[i].LastScreen()->Items().OfType( SCH_MARKER_T ) ) { const SCH_MARKER* marker = static_cast( aItem ); + RC_ITEM* item = marker->GetRCItem().get(); + SEVERITY severity = (SEVERITY)settings.GetSeverity( item->GetErrorCode() ); if( marker->GetMarkerType() != MARKER_BASE::MARKER_ERC ) continue; total_count++; - switch( settings.GetSeverity( marker->GetRCItem()->GetErrorCode() ) ) + switch( severity ) { case RPT_SEVERITY_ERROR: err_count++; break; case RPT_SEVERITY_WARNING: warn_count++; break; default: break; } - msg << marker->GetRCItem()->ShowReport( GetUserUnits(), itemMap ); + msg << marker->GetRCItem()->ShowReport( GetUserUnits(), severity, itemMap ); } } diff --git a/pcbnew/dialogs/dialog_drc.cpp b/pcbnew/dialogs/dialog_drc.cpp index 3b7deef039..8c6117ef3c 100644 --- a/pcbnew/dialogs/dialog_drc.cpp +++ b/pcbnew/dialogs/dialog_drc.cpp @@ -640,8 +640,9 @@ bool DIALOG_DRC::writeReport( const wxString& aFullFileName ) std::map itemMap; m_brdEditor->GetBoard()->FillItemMap( itemMap ); - int count; - EDA_UNITS units = GetUserUnits(); + EDA_UNITS units = GetUserUnits(); + BOARD_DESIGN_SETTINGS& bds = m_brdEditor->GetBoard()->GetDesignSettings(); + int count; fprintf( fp, "** Drc report for %s **\n", TO_UTF8( m_brdEditor->GetBoard()->GetFileName() ) ); @@ -654,21 +655,36 @@ bool DIALOG_DRC::writeReport( const wxString& aFullFileName ) fprintf( fp, "\n** Found %d DRC violations **\n", count ); for( int i = 0; i < count; ++i ) - fprintf( fp, "%s", TO_UTF8( m_markersProvider->GetItem( i )->ShowReport( units, itemMap ) ) ); + { + const std::shared_ptr& item = m_markersProvider->GetItem( i ); + SEVERITY severity = (SEVERITY) bds.GetSeverity( item->GetErrorCode() ); + + fprintf( fp, "%s", TO_UTF8( item->ShowReport( units, severity, itemMap ) ) ); + } count = m_unconnectedItemsProvider->GetCount(); fprintf( fp, "\n** Found %d unconnected pads **\n", count ); for( int i = 0; i < count; ++i ) - fprintf( fp, "%s", TO_UTF8( m_unconnectedItemsProvider->GetItem( i )->ShowReport( units, itemMap ) ) ); + { + const std::shared_ptr& item = m_unconnectedItemsProvider->GetItem( i ); + SEVERITY severity = (SEVERITY) bds.GetSeverity( item->GetErrorCode() ); + + fprintf( fp, "%s", TO_UTF8( item->ShowReport( units, severity, itemMap ) ) ); + } count = m_footprintWarningsProvider->GetCount(); fprintf( fp, "\n** Found %d Footprint errors **\n", count ); for( int i = 0; i < count; ++i ) - fprintf( fp, "%s", TO_UTF8( m_footprintWarningsProvider->GetItem( i )->ShowReport( units, itemMap ) ) ); + { + const std::shared_ptr& item = m_footprintWarningsProvider->GetItem( i ); + SEVERITY severity = (SEVERITY) bds.GetSeverity( item->GetErrorCode() ); + + fprintf( fp, "%s", TO_UTF8( item->ShowReport( units, severity, itemMap ) ) ); + } fprintf( fp, "\n** End of Report **\n" );