Eeschema: add ERC check for library symbol issues.

ADDED: ERC check for library symbols that have changed since they were
added to the schematic or have broken symbol library links.
This commit is contained in:
Wayne Stambaugh 2020-10-07 09:15:31 -04:00
parent b31ebae651
commit 5127d6c772
10 changed files with 152 additions and 68 deletions

View File

@ -36,6 +36,7 @@ class RC_ITEM;
/**
* Provide an abstract interface of a RC_ITEM* list manager.
*
* The details of the actual list architecture are hidden from the caller. Any class that
* implements this interface can then be used by a RC_TREE_MODEL class without it knowing
* the actual architecture of the list.
@ -48,14 +49,12 @@ public:
virtual int GetCount( int aSeverity = -1 ) = 0;
/**
* Function GetItem
* retrieves a RC_ITEM by index.
* Retrieve a RC_ITEM by index.
*/
virtual std::shared_ptr<RC_ITEM> GetItem( int aIndex ) = 0;
/**
* Function DeleteItem
* removes (and optionally deletes) the indexed item from the list.
* Remove (and optionally deletes) the indexed item from the list.
* @param aDeep If true, the source item should be deleted as well as its entry in the list.
*/
virtual void DeleteItem( int aIndex, bool aDeep ) = 0;
@ -67,25 +66,25 @@ public:
/**
* RC_ITEM
* is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item.
* A holder for a rule check item, DRC in Pcbnew or ERC in Eeschema.
*
* RC_ITEMs can have zero, one, or two related EDA_ITEMs.
*/
class RC_ITEM
{
public:
typedef std::vector<KIID> KIIDS;
protected:
int m_errorCode; // the error code's numeric value
int m_errorCode; ///< The error code's numeric value
wxString m_errorMessage; ///< A message describing the details of this specific error
wxString m_errorTitle; ///< The string describing the type of error
wxString m_settingsKey; ///< The key used to describe this type of error in settings
MARKER_BASE* m_parent; // The marker this item belongs to, if any
MARKER_BASE* m_parent; ///< The marker this item belongs to, if any
KIIDS m_ids;
public:
RC_ITEM() :
m_errorCode( 0 ),
m_parent( nullptr )
@ -120,7 +119,7 @@ public:
EDA_ITEM* dItem = nullptr )
{
m_ids.clear();
m_ids.push_back( aItem->m_Uuid );
if( bItem )
@ -137,7 +136,7 @@ public:
const KIID& dItem = niluuid )
{
m_ids.clear();
m_ids.push_back( aItem );
m_ids.push_back( bItem );
m_ids.push_back( cItem );
@ -154,8 +153,8 @@ public:
/**
* Function ShowReport
* translates this object into a text string suitable for saving to disk in a report.
* Translate 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, SEVERITY aSeverity,
@ -165,8 +164,7 @@ public:
void SetErrorCode( int aCode ) { m_errorCode = aCode; }
/**
* Function GetErrorMessage
* returns the error message of a RC_ITEM
* Return the error message of a RC_ITEM.
*/
virtual wxString GetErrorMessage() const;
@ -181,8 +179,7 @@ public:
}
/**
* Function ShowCoord
* formats a coordinate or position to text.
* Format a coordinate or position to text.
*/
static wxString ShowCoord( EDA_UNITS aUnits, const wxPoint& aPos );
};
@ -272,7 +269,7 @@ public:
}
/**
* Called by the wxDataView to fetch an item's formatting. Return true iff the
* Called by the wxDataView to fetch an item's formatting. Return true if the
* item has non-default attributes.
*/
bool GetAttr( wxDataViewItem const& aItem,
@ -302,6 +299,4 @@ private:
std::vector<RC_TREE_NODE*> m_tree; // I own this
};
#endif // RC_ITEM_H

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -293,10 +293,22 @@ void DIALOG_ERC::testErc( REPORTER& aReporter )
}
if( settings.IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) )
{
aReporter.ReportTail( _( "Checking for unresolved variables...\n" ) );
tester.TestTextVars( m_parent->GetCanvas()->GetView()->GetWorksheet() );
}
if( settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED ) )
{
aReporter.ReportTail( _( "Checking no connect pins for connections...\n" ) );
tester.TestNoConnectPins();
}
if( settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
{
aReporter.ReportTail( _( "Checking for library symbol issues...\n" ) );
tester.TestLibSymbolIssues();
}
// Display diags:
m_markerTreeModel->SetProvider( m_markerProvider );

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2014-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -31,6 +31,7 @@
#include <dialogs/panel_libedit_settings.h>
#include <dialogs/dialog_schematic_setup.h>
#include <eeschema_config.h>
#include <erc_settings.h>
#include <kiway.h>
#include <lib_edit_frame.h>
#include <panel_gal_display_options.h>

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -58,9 +58,12 @@
*/
/* Messages for conflicts :
* ELECTRICAL_PINTYPE::PT_INPUT, ELECTRICAL_PINTYPE::PT_OUTPUT, ELECTRICAL_PINTYPE:PT_:BIDI, ELECTRICAL_PINTYPE::PT_TRISTATE, ELECTRICAL_PINTYPE::PT_PASSIVE,
* ELECTRICAL_PINTYPE::PT_UNSPECIFIED, ELECTRICAL_PINTYPE::PT_POWER_IN, ELECTRICAL_PINTYPE::PT_POWER_OUT, ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR,
* ELECTRICAL_PINTYPE::PT_OPENEMITTER, ELECTRICAL_PINTYPE::PT_NC
* ELECTRICAL_PINTYPE::PT_INPUT, ELECTRICAL_PINTYPE::PT_OUTPUT, ELECTRICAL_PINTYPE:PT_:BIDI,
* ELECTRICAL_PINTYPE::PT_TRISTATE, ELECTRICAL_PINTYPE::PT_PASSIVE,
* ELECTRICAL_PINTYPE::PT_UNSPECIFIED, ELECTRICAL_PINTYPE::PT_POWER_IN,
* ELECTRICAL_PINTYPE::PT_POWER_OUT, ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR,
* ELECTRICAL_PINTYPE::PT_OPENEMITTER, ELECTRICAL_PINTYPE::PT_NC
*
* These messages are used to show the ERC matrix in ERC dialog
*/
@ -527,6 +530,7 @@ int ERC_TESTER::TestMultUnitPinConflicts()
SCH_MARKER* marker = new SCH_MARKER( ercItem,
pin->GetTransformedPosition() );
subgraph->m_sheet.LastScreen()->Append( marker );
errors += 1;
}
}
}
@ -574,6 +578,7 @@ int ERC_TESTER::TestSimilarLabels()
SCH_MARKER* marker = new SCH_MARKER( ercItem, text->GetPosition() );
subgraph->m_sheet.LastScreen()->Append( marker );
errors += 1;
}
break;
@ -588,3 +593,59 @@ int ERC_TESTER::TestSimilarLabels()
return errors;
}
int ERC_TESTER::TestLibSymbolIssues()
{
wxCHECK( m_schematic, 0 );
wxString msg;
int err_count = 0;
SCH_SCREENS screens( m_schematic->Root() );
for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
{
for( SCH_ITEM* item : screen->Items().OfType( SCH_COMPONENT_T ) )
{
SCH_COMPONENT* symbol = dynamic_cast<SCH_COMPONENT*>( item );
wxCHECK2( symbol, continue );
LIB_PART* libSymbolInSchematic = screen->GetLibSymbols()[
symbol->GetLibId().GetUniStringLibId() ];
wxCHECK2( libSymbolInSchematic, continue );
LIB_PART* libSymbol = SchGetLibPart( symbol->GetLibId(),
m_schematic->Prj().SchSymbolLibTable() );
if( libSymbol == nullptr )
{
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
ercItem->SetItems( symbol );
msg.Printf( "Library symbol link \"%s\" cannot be found in symbol library table",
symbol->GetLibId().GetUniStringLibId() );
ercItem->SetErrorMessage( msg );
SCH_MARKER* marker = new SCH_MARKER( ercItem, symbol->GetPosition() );
screen->Append( marker );
err_count += 1;
}
else if( *libSymbol != *libSymbolInSchematic )
{
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
ercItem->SetItems( symbol );
msg.Printf( "Library symbol \"%s\" has been modified",
symbol->GetLibId().GetUniStringLibId() );
ercItem->SetErrorMessage( msg );
SCH_MARKER* marker = new SCH_MARKER( ercItem, symbol->GetPosition() );
screen->Append( marker );
err_count += 1;
}
}
}
return err_count;
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2009-2020 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
@ -60,6 +60,7 @@ public:
/**
* Perform ERC testing for electrical conflicts between \a NetItemRef and other items
* (mainly pin) on the same net.
*
* @param aList = a reference to the list of connected objects
* @param aNetItemRef = index in list of the current object
* @param aNetStart = index in list of net objects of the first item
@ -70,8 +71,9 @@ public:
int* aMinConnexion );
/**
* inside a given sheet, one cannot have sheets with duplicate names (file
* Inside a given sheet, one cannot have sheets with duplicate names (file
* names can be duplicated).
*
* @return the error count
* @param aCreateMarker: true = create error markers in schematic,
* false = calculate error count only
@ -79,12 +81,12 @@ public:
int TestDuplicateSheetNames( bool aCreateMarker );
/**
* Checks for any unresolved text variable references.
* Check for any unresolved text variable references.
*/
void TestTextVars( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet );
/**
* Checks that there are not conflicting bus alias definitions in the schematic
* Check that there are no conflicting bus alias definitions in the schematic.
*
* (for example, two hierarchical sub-sheets contain different definitions for
* the same bus alias)
@ -124,6 +126,12 @@ public:
*/
int TestSimilarLabels();
/**
* Test symbols for changed library symbols and broken symbol library links.
* @return the number of issues found
*/
int TestLibSymbolIssues();
private:
SCHEMATIC* m_schematic;

View File

@ -120,6 +120,10 @@ ERC_ITEM ERC_ITEM::wireDangling( ERCE_WIRE_DANGLING,
_( "Wires not connected to anything" ),
wxT( "wire_dangling" ) );
ERC_ITEM ERC_ITEM::libSymbolIssues( ERCE_LIB_SYMBOL_ISSUES,
_( "Library symbol issue" ),
wxT( "lib_symbol_issues" ) );
std::vector<std::reference_wrapper<RC_ITEM>> ERC_ITEM::allItemTypes( {
ERC_ITEM::duplicateSheetName,
ERC_ITEM::pinNotConnected,
@ -140,7 +144,8 @@ std::vector<std::reference_wrapper<RC_ITEM>> ERC_ITEM::allItemTypes( {
ERC_ITEM::busLabelSyntax,
ERC_ITEM::busToBusConflict,
ERC_ITEM::busToNetConflict,
ERC_ITEM::unresolvedVariable
ERC_ITEM::unresolvedVariable,
ERC_ITEM::libSymbolIssues,
} );
@ -170,6 +175,7 @@ std::shared_ptr<ERC_ITEM> ERC_ITEM::Create( int aErrorCode )
case ERCE_GLOBLABEL: return std::make_shared<ERC_ITEM>( globalLabelDangling );
case ERCE_UNRESOLVED_VARIABLE: return std::make_shared<ERC_ITEM>( unresolvedVariable );
case ERCE_WIRE_DANGLING: return std::make_shared<ERC_ITEM>( wireDangling );
case ERCE_LIB_SYMBOL_ISSUES: return std::make_shared<ERC_ITEM>( libSymbolIssues );
case ERCE_UNSPECIFIED:
default:
wxFAIL_MSG( "Unknown ERC error code" );

View File

@ -73,6 +73,7 @@ private:
static ERC_ITEM busToNetConflict;
static ERC_ITEM unresolvedVariable;
static ERC_ITEM wireDangling;
static ERC_ITEM libSymbolIssues;
};

View File

@ -89,8 +89,14 @@ ERC_SETTINGS::ERC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
for( int i = ERCE_FIRST; i <= ERCE_LAST; ++i )
m_Severities[ i ] = RPT_SEVERITY_ERROR;
m_Severities[ERCE_UNSPECIFIED] = RPT_SEVERITY_UNDEFINED;
m_Severities[ERCE_PIN_TO_PIN_WARNING] = RPT_SEVERITY_WARNING;
// Error is the default setting so set non-error priorities here.
m_Severities[ERCE_UNSPECIFIED] = RPT_SEVERITY_UNDEFINED;
m_Severities[ERCE_PIN_TO_PIN_WARNING] = RPT_SEVERITY_WARNING;
m_Severities[ERCE_SIMILAR_LABELS] = RPT_SEVERITY_WARNING;
m_Severities[ERCE_GLOBLABEL] = RPT_SEVERITY_WARNING;
m_Severities[ERCE_DRIVER_CONFLICT] = RPT_SEVERITY_WARNING;
m_Severities[ERCE_BUS_ENTRY_CONFLICT] = RPT_SEVERITY_WARNING;
m_Severities[ERCE_LIB_SYMBOL_ISSUES] = RPT_SEVERITY_WARNING;
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "rule_severities",
[&]() -> nlohmann::json

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018 CERN
* Copyright (C) 2018-2020 CERN
* @author Jon Evans <jon@craftyjon.com>
*
* This program is free software; you can redistribute it and/or
@ -36,26 +36,32 @@ enum ERCE_T
{
ERCE_UNSPECIFIED = 0,
ERCE_FIRST,
ERCE_DUPLICATE_SHEET_NAME = ERCE_FIRST, // duplicate sheet names within a given sheet
ERCE_PIN_NOT_CONNECTED, // pin not connected and not no connect symbol
ERCE_PIN_NOT_DRIVEN, // pin connected to some others pins but no pin to drive it
ERCE_HIERACHICAL_LABEL, // mismatch between hierarchical labels and pins sheets
ERCE_NOCONNECT_CONNECTED, // a no connect symbol is connected to more than 1 pin
ERCE_NOCONNECT_NOT_CONNECTED, // a no connect symbol is not connected to anything
ERCE_LABEL_NOT_CONNECTED, // label not connected to anything
ERCE_SIMILAR_LABELS, // 2 labels are equal fir case insensitive comparisons
ERCE_DIFFERENT_UNIT_FP, // different units of the same component have different footprints assigned
ERCE_DIFFERENT_UNIT_NET, // a shared pin in a multi-unit component is connected to more than one net
ERCE_BUS_ALIAS_CONFLICT, // conflicting bus alias definitions across sheets
ERCE_DRIVER_CONFLICT, // conflicting drivers (labels, etc) on a subgraph
ERCE_BUS_ENTRY_CONFLICT, // a wire connected to a bus doesn't match the bus
ERCE_BUS_LABEL_ERROR, // a label attached to a bus isn't in bus format
ERCE_BUS_TO_BUS_CONFLICT, // a connection between bus objects doesn't share at least one net
ERCE_BUS_TO_NET_CONFLICT, // a bus wire is graphically connected to a net port/pin (or vice versa)
ERCE_GLOBLABEL, // a global label is unique
ERCE_UNRESOLVED_VARIABLE, // a text variable could not be resolved
ERCE_WIRE_DANGLING, // some wires are not connected to anything else
ERCE_LAST = ERCE_WIRE_DANGLING,
ERCE_DUPLICATE_SHEET_NAME = ERCE_FIRST, ///< Duplicate sheet names within a given sheet.
ERCE_PIN_NOT_CONNECTED, ///< Pin not connected and not no connect symbol.
ERCE_PIN_NOT_DRIVEN, ///< Pin connected to some others pins but no pin to drive it.
ERCE_HIERACHICAL_LABEL, ///< Mismatch between hierarchical labels and pins sheets.
ERCE_NOCONNECT_CONNECTED, ///< A no connect symbol is connected to more than 1 pin.
ERCE_NOCONNECT_NOT_CONNECTED, ///< A no connect symbol is not connected to anything.
ERCE_LABEL_NOT_CONNECTED, ///< Label not connected to anything.
ERCE_SIMILAR_LABELS, ///< 2 labels are equal for case insensitive comparisons.
ERCE_DIFFERENT_UNIT_FP, ///< Different units of the same component have different
///< footprints assigned.
ERCE_DIFFERENT_UNIT_NET, ///< Shared pin in a multi-unit component is connected to
///< more than one net.
ERCE_BUS_ALIAS_CONFLICT, ///< Conflicting bus alias definitions across sheets.
ERCE_DRIVER_CONFLICT, ///< Conflicting drivers (labels, etc) on a subgraph.
ERCE_BUS_ENTRY_CONFLICT, ///< A wire connected to a bus doesn't match the bus.
ERCE_BUS_LABEL_ERROR, ///< A label attached to a bus isn't in bus format.
ERCE_BUS_TO_BUS_CONFLICT, ///< A connection between bus objects doesn't share at least
///< one net.
ERCE_BUS_TO_NET_CONFLICT, ///< A bus wire is graphically connected to a net port/pin
///< (or vice versa).
ERCE_GLOBLABEL, ///< A global label is unique.
ERCE_UNRESOLVED_VARIABLE, ///< A text variable could not be resolved.
ERCE_WIRE_DANGLING, ///< Some wires are not connected to anything else.
ERCE_LIB_SYMBOL_ISSUES, ///< Library symbol changed from current symbol in schematic or
///< the library symbol link no longer valid.
ERCE_LAST = ERCE_LIB_SYMBOL_ISSUES,
// Errors after this point will not automatically appear in the Severities Panel
@ -92,16 +98,6 @@ public:
virtual ~ERC_SETTINGS();
void LoadDefaults()
{
m_Severities[ERCE_SIMILAR_LABELS] = RPT_SEVERITY_WARNING;
m_Severities[ERCE_GLOBLABEL] = RPT_SEVERITY_WARNING;
m_Severities[ERCE_DRIVER_CONFLICT] = RPT_SEVERITY_WARNING;
m_Severities[ERCE_BUS_ENTRY_CONFLICT] = RPT_SEVERITY_WARNING;
m_Severities[ERCE_BUS_TO_BUS_CONFLICT] = RPT_SEVERITY_ERROR;
m_Severities[ERCE_BUS_TO_NET_CONFLICT] = RPT_SEVERITY_ERROR;
}
bool operator==( const ERC_SETTINGS& other ) const
{
return ( other.m_Severities == m_Severities );
@ -167,8 +163,7 @@ private:
};
/**
* SHEETLIST_ERC_ITEMS_PROVIDER
* is an implementation of the RC_ITEM_LISTinterface which uses the global SHEETLIST
* An implementation of the RC_ITEM_LIST interface which uses the global SHEETLIST
* to fulfill the contract.
*/
class SHEETLIST_ERC_ITEMS_PROVIDER : public RC_ITEMS_PROVIDER

View File

@ -37,7 +37,6 @@
#include <config_params.h>
#include <core/typeinfo.h>
#include <eda_base_frame.h>
#include <erc_settings.h>
#include <eeschema_settings.h>
#include <math/box2.h>
#include <sch_base_frame.h>