7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-18 16:39:17 +00:00

Add ERC check for local and global labels with same name

Fixes https://gitlab.com/kicad/code/kicad/-/issues/9461
This commit is contained in:
JamesJCode 2024-07-21 23:25:35 +01:00
parent 5120a3bd82
commit 96977d44d9
9 changed files with 792 additions and 2 deletions

View File

@ -1082,6 +1082,65 @@ int ERC_TESTER::TestMultUnitPinConflicts()
}
int ERC_TESTER::TestSameLocalGlobalLabel()
{
int errCount = 0;
std::unordered_map<wxString, std::pair<SCH_ITEM*, SCH_SHEET_PATH>> globalLabels;
std::unordered_map<wxString, std::pair<SCH_ITEM*, SCH_SHEET_PATH>> localLabels;
for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
{
for( CONNECTION_SUBGRAPH* subgraph : net.second )
{
const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
for( SCH_ITEM* item : subgraph->GetItems() )
{
switch( item->Type() )
{
case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T:
{
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
wxString text = label->GetShownText( &sheet, false );
auto& map = item->Type() == SCH_LABEL_T ? localLabels : globalLabels;
if( !map.count( text ) )
{
map[text] = std::make_pair( label, sheet );
}
}
}
}
}
}
for( auto& [globalText, globalItem] : globalLabels )
{
for( auto& [localText, localItem] : localLabels )
{
if( globalText == localText )
{
std::shared_ptr<ERC_ITEM> ercItem =
ERC_ITEM::Create( ERCE_SAME_LOCAL_GLOBAL_LABEL );
ercItem->SetItems( globalItem.first, localItem.first );
ercItem->SetSheetSpecificPath( globalItem.second );
ercItem->SetItemsSheetPaths( globalItem.second, localItem.second );
SCH_MARKER* marker = new SCH_MARKER( ercItem, globalItem.first->GetPosition() );
globalItem.second.LastScreen()->Append( marker );
errCount++;
}
}
}
return errCount;
}
int ERC_TESTER::TestSimilarLabels()
{
int errors = 0;
@ -1652,12 +1711,14 @@ void ERC_TESTER::RunTests( DS_PROXY_VIEW_ITEM* aDrawingSheet, SCH_EDIT_FRAME* aE
// using case insensitive comparisons)
if( m_settings.IsTestEnabled( ERCE_SIMILAR_LABELS )
|| m_settings.IsTestEnabled( ERCE_SIMILAR_POWER )
|| m_settings.IsTestEnabled( ERCE_SIMILAR_LABEL_AND_POWER ) )
|| m_settings.IsTestEnabled( ERCE_SIMILAR_LABEL_AND_POWER )
|| m_settings.IsTestEnabled( ERCE_SAME_LOCAL_GLOBAL_LABEL ) )
{
if( aProgressReporter )
aProgressReporter->AdvancePhase( _( "Checking labels..." ) );
TestSimilarLabels();
TestSameLocalGlobalLabel();
}
if( m_settings.IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) )

View File

@ -112,6 +112,12 @@ public:
*/
int TestMultUnitPinConflicts();
/**
* Checks for global and local labels with the same name
* @return the error count
*/
int TestSameLocalGlobalLabel();
/**
* Checks for labels that differ only in capitalization
* @return the error count

View File

@ -128,6 +128,10 @@ ERC_ITEM ERC_ITEM::singleGlobalLabel( ERCE_SINGLE_GLOBAL_LABEL,
_( "Global label only appears once in the schematic"),
wxT( "single_global_label" ) );
ERC_ITEM ERC_ITEM::sameLocalGlobalLabel( ERCE_SAME_LOCAL_GLOBAL_LABEL,
_( "Local and global labels have same name" ),
wxT( "same_local_global_label" ) );
ERC_ITEM ERC_ITEM::differentUnitFootprint( ERCE_DIFFERENT_UNIT_FP,
_( "Different footprint assigned in another unit of the symbol" ),
wxT( "different_unit_footprint" ) );
@ -238,6 +242,7 @@ std::vector<std::reference_wrapper<RC_ITEM>> ERC_ITEM::allItemTypes(
ERC_ITEM::noConnectDangling,
ERC_ITEM::globalLabelDangling,
ERC_ITEM::singleGlobalLabel,
ERC_ITEM::sameLocalGlobalLabel,
ERC_ITEM::wireDangling,
ERC_ITEM::busEntryNeeded,
ERC_ITEM::endpointOffGrid,
@ -290,7 +295,6 @@ std::vector<std::reference_wrapper<RC_ITEM>> ERC_ITEM::allItemTypes(
} );
std::shared_ptr<ERC_ITEM> ERC_ITEM::Create( int aErrorCode )
{
switch( aErrorCode )
@ -315,6 +319,7 @@ std::shared_ptr<ERC_ITEM> ERC_ITEM::Create( int aErrorCode )
case ERCE_SIMILAR_POWER: return std::make_shared<ERC_ITEM>( similarPower );
case ERCE_SIMILAR_LABEL_AND_POWER: return std::make_shared<ERC_ITEM>( similarLabelAndPower );
case ERCE_SINGLE_GLOBAL_LABEL: return std::make_shared<ERC_ITEM>( singleGlobalLabel );
case ERCE_SAME_LOCAL_GLOBAL_LABEL: return std::make_shared<ERC_ITEM>( sameLocalGlobalLabel );
case ERCE_DIFFERENT_UNIT_FP: return std::make_shared<ERC_ITEM>( differentUnitFootprint );
case ERCE_DIFFERENT_UNIT_NET: return std::make_shared<ERC_ITEM>( differentUnitNet );
case ERCE_BUS_ALIAS_CONFLICT: return std::make_shared<ERC_ITEM>( busDefinitionConflict );

View File

@ -215,6 +215,7 @@ private:
static ERC_ITEM labelDangling;
static ERC_ITEM globalLabelDangling;
static ERC_ITEM singleGlobalLabel;
static ERC_ITEM sameLocalGlobalLabel;
static ERC_ITEM similarLabels;
static ERC_ITEM similarPower;
static ERC_ITEM similarLabelAndPower;

View File

@ -100,6 +100,7 @@ ERC_SETTINGS::ERC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
m_ERCSeverities[ERCE_SIMILAR_POWER] = RPT_SEVERITY_WARNING;
m_ERCSeverities[ERCE_SIMILAR_LABEL_AND_POWER] = RPT_SEVERITY_WARNING;
m_ERCSeverities[ERCE_SINGLE_GLOBAL_LABEL] = RPT_SEVERITY_IGNORE;
m_ERCSeverities[ERCE_SAME_LOCAL_GLOBAL_LABEL] = RPT_SEVERITY_WARNING;
m_ERCSeverities[ERCE_GLOBLABEL] = RPT_SEVERITY_WARNING;
m_ERCSeverities[ERCE_DRIVER_CONFLICT] = RPT_SEVERITY_WARNING;
m_ERCSeverities[ERCE_BUS_ENTRY_CONFLICT] = RPT_SEVERITY_WARNING;

View File

@ -52,6 +52,7 @@ enum ERCE_T
ERCE_SIMILAR_POWER, ///< 2 power pins are equal for case insensitive comparisons.
ERCE_SIMILAR_LABEL_AND_POWER, ///< label and pin are equal for case insensitive comparisons.
ERCE_SINGLE_GLOBAL_LABEL, ///< A global label only exists once in the schematic.
ERCE_SAME_LOCAL_GLOBAL_LABEL, ///< 2 labels are equal for case insensitive comparisons.
ERCE_DIFFERENT_UNIT_FP, ///< Different units of the same symbol have different
///< footprints assigned.
ERCE_MISSING_POWER_INPUT_PIN, ///< Symbol has power input pins that are not placed on the

View File

LOADING design file

View File

LOADING design file

View File

@ -76,3 +76,41 @@ BOOST_FIXTURE_TEST_CASE( ERCLabelCapitalization, ERC_REGRESSION_TEST_FIXTURE )
<< reportWriter.GetTextReport() );
}
}
BOOST_FIXTURE_TEST_CASE( ERCSameLocalGlobalLabel, ERC_REGRESSION_TEST_FIXTURE )
{
LOCALE_IO dummy;
// Check for Errors when using rule area netclass directives
std::vector<std::pair<wxString, int>> tests = { { "same_local_global_label", 1 } };
for( const std::pair<wxString, int>& test : tests )
{
KI_TEST::LoadSchematic( m_settingsManager, test.first, m_schematic );
ERC_SETTINGS& settings = m_schematic->ErcSettings();
SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
// Skip the "Modified symbol" warning
settings.m_ERCSeverities[ERCE_LIB_SYMBOL_ISSUES] = RPT_SEVERITY_IGNORE;
settings.m_ERCSeverities[ERCE_LIB_SYMBOL_MISMATCH] = RPT_SEVERITY_IGNORE;
// Configure the rules under test
settings.m_ERCSeverities[ERCE_SAME_LOCAL_GLOBAL_LABEL] = RPT_SEVERITY_ERROR;
m_schematic->ConnectionGraph()->RunERC();
ERC_TESTER tester( m_schematic.get() );
tester.TestSameLocalGlobalLabel();
errors.SetSeverities( RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING );
ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MILLIMETRES );
BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
"Expected " << test.second << " errors in " << test.first.ToStdString()
<< " but got " << errors.GetCount() << "\n"
<< reportWriter.GetTextReport() );
}
}