mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 00:21:25 +00:00
Changed ERC Label caps check to check Power Symbols
Power symbols are implicit labels in KiCad, so we should check for their caps difference against other power symbols as well as against other labels Fixes https://gitlab.com/kicad/code/kicad/-/issues/16897
This commit is contained in:
parent
ffe496abf3
commit
ee78f3bf5b
eeschema/erc
qa
@ -44,6 +44,7 @@
|
||||
#include <sch_rule_area.h>
|
||||
#include <sch_sheet.h>
|
||||
#include <sch_sheet_pin.h>
|
||||
#include <sch_pin.h>
|
||||
#include <sch_textbox.h>
|
||||
#include <sch_line.h>
|
||||
#include <schematic.h>
|
||||
@ -1084,8 +1085,39 @@ int ERC_TESTER::TestMultUnitPinConflicts()
|
||||
int ERC_TESTER::TestSimilarLabels()
|
||||
{
|
||||
int errors = 0;
|
||||
std::unordered_map<wxString, std::tuple<wxString, SCH_ITEM*, SCH_SHEET_PATH>> generalMap;
|
||||
|
||||
std::unordered_map<wxString, std::pair<SCH_LABEL_BASE*, SCH_SHEET_PATH>> labelMap;
|
||||
auto logError = [&]( const wxString& normalized, SCH_ITEM* item, const SCH_SHEET_PATH& sheet )
|
||||
{
|
||||
auto& [otherText, otherItem, otherSheet] = generalMap.at( normalized );
|
||||
ERCE_T typeOfWarning = ERCE_SIMILAR_LABELS;
|
||||
|
||||
if( item->Type() == SCH_PIN_T && otherItem->Type() == SCH_PIN_T )
|
||||
{
|
||||
//Two Pins
|
||||
typeOfWarning = ERCE_SIMILAR_POWER;
|
||||
}
|
||||
else if( item->Type() == SCH_PIN_T || otherItem->Type() == SCH_PIN_T )
|
||||
{
|
||||
//Pin and Label
|
||||
typeOfWarning = ERCE_SIMILAR_LABEL_AND_POWER;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Two Labels
|
||||
typeOfWarning = ERCE_SIMILAR_LABELS;
|
||||
}
|
||||
|
||||
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( typeOfWarning );
|
||||
ercItem->SetItems( item, otherItem );
|
||||
ercItem->SetSheetSpecificPath( sheet );
|
||||
ercItem->SetItemsSheetPaths( sheet, otherSheet );
|
||||
|
||||
SCH_MARKER* marker = new SCH_MARKER( ercItem, item->GetPosition() );
|
||||
sheet.LastScreen()->Append( marker );
|
||||
};
|
||||
|
||||
const NET_MAP& nets = m_schematic->ConnectionGraph()->GetNetMap();
|
||||
|
||||
for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
|
||||
{
|
||||
@ -1102,27 +1134,47 @@ int ERC_TESTER::TestSimilarLabels()
|
||||
case SCH_GLOBAL_LABEL_T:
|
||||
{
|
||||
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
|
||||
wxString unnormalized = label->GetShownText( &sheet, false );
|
||||
wxString normalized = unnormalized.Lower();
|
||||
|
||||
wxString normalized = label->GetShownText( &sheet, false ).Lower();
|
||||
|
||||
if( !labelMap.count( normalized ) )
|
||||
if( !generalMap.count( normalized ) )
|
||||
{
|
||||
labelMap[normalized] = std::make_pair( label, sheet );
|
||||
break;
|
||||
generalMap[normalized] = std::make_tuple( unnormalized, label, sheet );
|
||||
}
|
||||
|
||||
auto& [ otherLabel, otherSheet ] = labelMap.at( normalized );
|
||||
auto& [otherText, otherItem, otherSheet] = generalMap.at( normalized );
|
||||
|
||||
if( otherLabel->GetShownText( &otherSheet, false )
|
||||
!= label->GetShownText( &sheet, false ) )
|
||||
if( unnormalized != otherText )
|
||||
{
|
||||
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMILAR_LABELS );
|
||||
ercItem->SetItems( label, labelMap.at( normalized ).first );
|
||||
ercItem->SetSheetSpecificPath( sheet );
|
||||
ercItem->SetItemsSheetPaths( sheet, labelMap.at( normalized ).second );
|
||||
logError( normalized, label, sheet );
|
||||
errors += 1;
|
||||
}
|
||||
|
||||
SCH_MARKER* marker = new SCH_MARKER( ercItem, label->GetPosition() );
|
||||
sheet.LastScreen()->Append( marker );
|
||||
break;
|
||||
}
|
||||
case SCH_PIN_T:
|
||||
{
|
||||
SCH_PIN* pin = static_cast<SCH_PIN*>( item );
|
||||
|
||||
if( !pin->IsGlobalPower() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
|
||||
wxString unnormalized = symbol->GetValue( true, &sheet, false );
|
||||
wxString normalized = unnormalized.Lower();
|
||||
|
||||
if( !generalMap.count( normalized ) )
|
||||
{
|
||||
generalMap[normalized] = std::make_tuple( unnormalized, pin, sheet );
|
||||
}
|
||||
|
||||
auto& [otherText, otherItem, otherSheet] = generalMap.at( normalized );
|
||||
|
||||
if( unnormalized != otherText )
|
||||
{
|
||||
logError( normalized, pin, sheet );
|
||||
errors += 1;
|
||||
}
|
||||
|
||||
@ -1135,7 +1187,6 @@ int ERC_TESTER::TestSimilarLabels()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
@ -1601,7 +1652,9 @@ void ERC_TESTER::RunTests( DS_PROXY_VIEW_ITEM* aDrawingSheet, SCH_EDIT_FRAME* aE
|
||||
|
||||
// Test similar labels (i;e. labels which are identical when
|
||||
// using case insensitive comparisons)
|
||||
if( m_settings.IsTestEnabled( ERCE_SIMILAR_LABELS ) )
|
||||
if( m_settings.IsTestEnabled( ERCE_SIMILAR_LABELS )
|
||||
|| m_settings.IsTestEnabled( ERCE_SIMILAR_POWER )
|
||||
|| m_settings.IsTestEnabled( ERCE_SIMILAR_LABEL_AND_POWER ) )
|
||||
{
|
||||
if( aProgressReporter )
|
||||
aProgressReporter->AdvancePhase( _( "Checking labels..." ) );
|
||||
|
@ -116,6 +116,14 @@ ERC_ITEM ERC_ITEM::similarLabels( ERCE_SIMILAR_LABELS,
|
||||
_( "Labels are similar (lower/upper case difference only)"),
|
||||
wxT( "similar_labels" ) );
|
||||
|
||||
ERC_ITEM ERC_ITEM::similarPower( ERCE_SIMILAR_POWER,
|
||||
_( "Power pins are similar (lower/upper case difference only)"),
|
||||
wxT( "similar_power" ) );
|
||||
|
||||
ERC_ITEM ERC_ITEM::similarLabelAndPower( ERCE_SIMILAR_LABEL_AND_POWER,
|
||||
_( "Power pin and label are similar (lower/upper case difference only)"),
|
||||
wxT( "similar_label_and_power" ) );
|
||||
|
||||
ERC_ITEM ERC_ITEM::singleGlobalLabel( ERCE_SINGLE_GLOBAL_LABEL,
|
||||
_( "Global label only appears once in the schematic"),
|
||||
wxT( "single_global_label" ) );
|
||||
@ -257,6 +265,8 @@ std::vector<std::reference_wrapper<RC_ITEM>> ERC_ITEM::allItemTypes(
|
||||
ERC_ITEM::unresolvedVariable,
|
||||
ERC_ITEM::simulationModelIssues,
|
||||
ERC_ITEM::similarLabels,
|
||||
ERC_ITEM::similarPower,
|
||||
ERC_ITEM::similarLabelAndPower,
|
||||
// Commented out until the logic for this element is coded
|
||||
// TODO: Add bus label syntax checking
|
||||
// ERC_ITEM::busLabelSyntax,
|
||||
@ -302,6 +312,8 @@ std::shared_ptr<ERC_ITEM> ERC_ITEM::Create( int aErrorCode )
|
||||
case ERCE_LABEL_MULTIPLE_WIRES: return std::make_shared<ERC_ITEM>( labelMultipleWires );
|
||||
case ERCE_LABEL_NOT_CONNECTED: return std::make_shared<ERC_ITEM>( labelDangling );
|
||||
case ERCE_SIMILAR_LABELS: return std::make_shared<ERC_ITEM>( similarLabels );
|
||||
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_DIFFERENT_UNIT_FP: return std::make_shared<ERC_ITEM>( differentUnitFootprint );
|
||||
case ERCE_DIFFERENT_UNIT_NET: return std::make_shared<ERC_ITEM>( differentUnitNet );
|
||||
|
@ -216,6 +216,8 @@ private:
|
||||
static ERC_ITEM globalLabelDangling;
|
||||
static ERC_ITEM singleGlobalLabel;
|
||||
static ERC_ITEM similarLabels;
|
||||
static ERC_ITEM similarPower;
|
||||
static ERC_ITEM similarLabelAndPower;
|
||||
static ERC_ITEM differentUnitFootprint;
|
||||
static ERC_ITEM differentUnitNet;
|
||||
static ERC_ITEM busDefinitionConflict;
|
||||
|
@ -97,6 +97,8 @@ ERC_SETTINGS::ERC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
|
||||
m_ERCSeverities[ERCE_ENDPOINT_OFF_GRID] = RPT_SEVERITY_WARNING;
|
||||
m_ERCSeverities[ERCE_PIN_TO_PIN_WARNING] = RPT_SEVERITY_WARNING;
|
||||
m_ERCSeverities[ERCE_SIMILAR_LABELS] = RPT_SEVERITY_WARNING;
|
||||
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_GLOBLABEL] = RPT_SEVERITY_WARNING;
|
||||
m_ERCSeverities[ERCE_DRIVER_CONFLICT] = RPT_SEVERITY_WARNING;
|
||||
|
@ -49,6 +49,8 @@ enum ERCE_T
|
||||
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_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_DIFFERENT_UNIT_FP, ///< Different units of the same symbol have different
|
||||
///< footprints assigned.
|
||||
|
qa/data/eeschema/issue16897.kicad_sch
Normal file
LOADING design file
@ -54,6 +54,7 @@ set( QA_EESCHEMA_SRCS
|
||||
erc/test_erc_four_way.cpp
|
||||
erc/test_erc_label_not_connected.cpp
|
||||
erc/test_erc_stacking_pins.cpp
|
||||
erc/test_erc_label_names.cpp
|
||||
erc/test_erc_global_labels.cpp
|
||||
erc/test_erc_no_connect.cpp
|
||||
erc/test_erc_hierarchical_schematics.cpp
|
||||
|
78
qa/tests/eeschema/erc/test_erc_label_names.cpp
Normal file
78
qa/tests/eeschema/erc/test_erc_label_names.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2024 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
|
||||
* as published by the Free Software Foundation; either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one at
|
||||
* http://www.gnu.org/licenses/
|
||||
*/
|
||||
|
||||
#include <qa_utils/wx_utils/unit_test_utils.h>
|
||||
#include <schematic_utils/schematic_file_util.h>
|
||||
|
||||
#include <connection_graph.h>
|
||||
#include <schematic.h>
|
||||
#include <erc/erc_settings.h>
|
||||
#include <erc/erc.h>
|
||||
#include <erc/erc_report.h>
|
||||
#include <settings/settings_manager.h>
|
||||
#include <locale_io.h>
|
||||
|
||||
struct ERC_REGRESSION_TEST_FIXTURE
|
||||
{
|
||||
ERC_REGRESSION_TEST_FIXTURE() : m_settingsManager( true /* headless */ ) {}
|
||||
|
||||
SETTINGS_MANAGER m_settingsManager;
|
||||
std::unique_ptr<SCHEMATIC> m_schematic;
|
||||
};
|
||||
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( ERCLabelCapitalization, ERC_REGRESSION_TEST_FIXTURE )
|
||||
{
|
||||
LOCALE_IO dummy;
|
||||
|
||||
// Check for Errors when using rule area netclass directives
|
||||
std::vector<std::pair<wxString, int>> tests = { { "issue16897", 3 } };
|
||||
|
||||
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_SIMILAR_LABELS] = RPT_SEVERITY_ERROR;
|
||||
settings.m_ERCSeverities[ERCE_SIMILAR_POWER] = RPT_SEVERITY_ERROR;
|
||||
settings.m_ERCSeverities[ERCE_SIMILAR_LABEL_AND_POWER] = RPT_SEVERITY_ERROR;
|
||||
|
||||
m_schematic->ConnectionGraph()->RunERC();
|
||||
|
||||
ERC_TESTER tester( m_schematic.get() );
|
||||
tester.TestSimilarLabels();
|
||||
|
||||
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() );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user