ADDED: ERC Test for labels on multiple wires

When a label overlaps two or more wires, it is not clear which one it
should connect to.  This is an ERC warning

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18346
This commit is contained in:
Seth Hillbrand 2024-07-09 10:05:30 -07:00
parent bfecb7891c
commit 4431246cbe
9 changed files with 531 additions and 1 deletions

View File

@ -700,6 +700,61 @@ int ERC_TESTER::TestMissingNetclasses()
}
int ERC_TESTER::TestLabelMultipleWires()
{
int err_count = 0;
for( const SCH_SHEET_PATH& sheet : m_sheetList )
{
std::map<VECTOR2I, std::vector<SCH_ITEM*>> connMap;
for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_LABEL_T ) )
{
SCH_LABEL* label = static_cast<SCH_LABEL*>( item );
for( const VECTOR2I& pt : label->GetConnectionPoints() )
connMap[pt].emplace_back( label );
}
for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
{
std::vector<SCH_ITEM*> lines;
for( SCH_ITEM* item : sheet.LastScreen()->Items().Overlapping( SCH_LINE_T, pair.first ) )
{
SCH_LINE* line = static_cast<SCH_LINE*>( item );
if( line->IsGraphicLine() )
continue;
// If the line is connected at the endpoint, then there will be a junction
if( !line->IsEndPoint( pair.first ) )
lines.emplace_back( line );
}
if( lines.size() > 1 )
{
err_count++;
lines.resize( 3 ); // Only show the first 3 lines and if there are only two, adds a nullptr
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LABEL_MULTIPLE_WIRES );
wxString msg = wxString::Format( _( "Label connects more than one wire at %d, %d" ),
pair.first.x, pair.first.y );
ercItem->SetItems( pair.second.front(), lines[0], lines[1], lines[2] );
ercItem->SetErrorMessage( msg );
ercItem->SetSheetSpecificPath( sheet );
SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
sheet.LastScreen()->Append( marker );
}
}
}
return err_count;
}
int ERC_TESTER::TestFourWayJunction()
{
int err_count = 0;
@ -1611,6 +1666,14 @@ void ERC_TESTER::RunTests( DS_PROXY_VIEW_ITEM* aDrawingSheet, SCH_EDIT_FRAME* aE
TestFourWayJunction();
}
if( m_settings.IsTestEnabled( ERCE_LABEL_MULTIPLE_WIRES ) )
{
if( aProgressReporter )
aProgressReporter->AdvancePhase( _( "Checking for labels on more than one wire..." ) );
TestLabelMultipleWires();
}
if( m_settings.IsTestEnabled( ERCE_UNDEFINED_NETCLASS ) )
{
if( aProgressReporter )

View File

@ -123,6 +123,11 @@ public:
*/
int TestFourWayJunction();
/**
* Test to see if there are labels that are connected to more than one wire.
*/
int TestLabelMultipleWires();
/**
* Test symbols for changed library symbols and broken symbol library links.
* @return the number of issues found

View File

@ -92,6 +92,10 @@ ERC_ITEM ERC_ITEM::fourWayJunction( ERCE_FOUR_WAY_JUNCTION,
_( "Four connection points are joined together" ),
wxT( "four_way_junction" ) );
ERC_ITEM ERC_ITEM::labelMultipleWires( ERCE_LABEL_MULTIPLE_WIRES,
_( "Label connects more than one wire" ),
wxT( "label_multiple_wires" ) );
ERC_ITEM ERC_ITEM::noConnectConnected( ERCE_NOCONNECT_CONNECTED,
_( "A pin with a \"no connection\" flag is connected" ),
wxT( "no_connect_connected" ) );
@ -294,6 +298,7 @@ std::shared_ptr<ERC_ITEM> ERC_ITEM::Create( int aErrorCode )
case ERCE_NOCONNECT_CONNECTED: return std::make_shared<ERC_ITEM>( noConnectConnected );
case ERCE_NOCONNECT_NOT_CONNECTED: return std::make_shared<ERC_ITEM>( noConnectDangling );
case ERCE_FOUR_WAY_JUNCTION: return std::make_shared<ERC_ITEM>( fourWayJunction );
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_SINGLE_GLOBAL_LABEL: return std::make_shared<ERC_ITEM>( singleGlobalLabel );

View File

@ -210,6 +210,7 @@ private:
static ERC_ITEM hierLabelMismatch;
static ERC_ITEM noConnectConnected;
static ERC_ITEM fourWayJunction;
static ERC_ITEM labelMultipleWires;
static ERC_ITEM noConnectDangling;
static ERC_ITEM labelDangling;
static ERC_ITEM globalLabelDangling;

View File

@ -111,6 +111,7 @@ ERC_SETTINGS::ERC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
m_ERCSeverities[ERCE_MISSING_BIDI_PIN] = RPT_SEVERITY_WARNING;
m_ERCSeverities[ERCE_SIMULATION_MODEL] = RPT_SEVERITY_IGNORE;
m_ERCSeverities[ERCE_FOUR_WAY_JUNCTION] = RPT_SEVERITY_IGNORE;
m_ERCSeverities[ERCE_LABEL_MULTIPLE_WIRES] = RPT_SEVERITY_WARNING;
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "rule_severities",
[&]() -> nlohmann::json

View File

@ -83,9 +83,10 @@ enum ERCE_T
ERCE_DUPLICATE_REFERENCE, ///< More than one symbol with the same reference.
ERCE_BUS_ENTRY_NEEDED, ///< Importer failed to auto-place a bus entry.
ERCE_FOUR_WAY_JUNCTION, ///< A four-way junction was found.
ERCE_LABEL_MULTIPLE_WIRES, ///< A label is connected to more than one wire.
ERCE_LAST = ERCE_FOUR_WAY_JUNCTION,
ERCE_LAST = ERCE_LABEL_MULTIPLE_WIRES,
// Errors after this point will not automatically appear in the Severities Panel

View File

@ -0,0 +1,378 @@
(kicad_sch
(version 20240602)
(generator "eeschema")
(generator_version "8.99")
(uuid "69309afb-88b0-4112-b019-2bea5a178880")
(paper "A4")
(lib_symbols
(symbol "Connector:Conn_01x02_Pin"
(pin_names
(offset 1.016) hide)
(exclude_from_sim no)
(in_bom yes)
(on_board yes)
(property "Reference" "J"
(at 0 2.54 0)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Value" "Conn_01x02_Pin"
(at 0 -5.08 0)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Footprint" ""
(at 0 0 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(property "Datasheet" "~"
(at 0 0 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(property "Description" "Generic connector, single row, 01x02, script generated"
(at 0 0 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(property "ki_locked" ""
(at 0 0 0)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "ki_keywords" "connector"
(at 0 0 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(property "ki_fp_filters" "Connector*:*_1x??_*"
(at 0 0 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(symbol "Conn_01x02_Pin_1_1"
(rectangle
(start 0.8636 0.127)
(end 0 -0.127)
(stroke
(width 0.1524)
(type default)
)
(fill
(type outline)
)
)
(rectangle
(start 0.8636 -2.413)
(end 0 -2.667)
(stroke
(width 0.1524)
(type default)
)
(fill
(type outline)
)
)
(polyline
(pts
(xy 1.27 0) (xy 0.8636 0)
)
(stroke
(width 0.1524)
(type default)
)
(fill
(type none)
)
)
(polyline
(pts
(xy 1.27 -2.54) (xy 0.8636 -2.54)
)
(stroke
(width 0.1524)
(type default)
)
(fill
(type none)
)
)
(pin passive line
(at 5.08 0 180)
(length 3.81)
(name "Pin_1"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "1"
(effects
(font
(size 1.27 1.27)
)
)
)
)
(pin passive line
(at 5.08 -2.54 180)
(length 3.81)
(name "Pin_2"
(effects
(font
(size 1.27 1.27)
)
)
)
(number "2"
(effects
(font
(size 1.27 1.27)
)
)
)
)
)
)
)
(junction
(at 106.68 74.93)
(diameter 0)
(color 0 0 0 0)
(uuid "4a56ee91-5004-412e-8909-01a9249bf883")
)
(wire
(pts
(xy 106.68 74.93) (xy 106.68 80.01)
)
(stroke
(width 0)
(type default)
)
(uuid "27bb77c8-bed9-4ec5-96d4-d73c5433079e")
)
(wire
(pts
(xy 102.87 77.47) (xy 123.19 77.47)
)
(stroke
(width 0)
(type default)
)
(uuid "75df03fc-db9c-4892-b2ff-4fdd989da01f")
)
(wire
(pts
(xy 106.68 74.93) (xy 123.19 74.93)
)
(stroke
(width 0)
(type default)
)
(uuid "e9df6ac6-8fc0-41b0-8640-c74e8cea4699")
)
(wire
(pts
(xy 102.87 74.93) (xy 106.68 74.93)
)
(stroke
(width 0)
(type default)
)
(uuid "f2962ffc-7611-4acf-99f0-0fa9b77a86b5")
)
(label "BAR"
(at 106.68 74.93 0)
(fields_autoplaced yes)
(effects
(font
(size 1.27 1.27)
)
(justify left bottom)
)
(uuid "1aa0e7d2-e570-49d9-9c60-6310e755abcd")
)
(label "FOO"
(at 106.68 77.47 0)
(fields_autoplaced yes)
(effects
(font
(size 1.27 1.27)
)
(justify left bottom)
)
(uuid "aca19205-a0bf-4ee3-bb76-dee6f12714b1")
)
(symbol
(lib_id "Connector:Conn_01x02_Pin")
(at 97.79 74.93 0)
(unit 1)
(exclude_from_sim no)
(in_bom yes)
(on_board yes)
(dnp no)
(fields_autoplaced yes)
(uuid "cc0918f1-8eae-4343-b7bb-78b5b2dc2bb2")
(property "Reference" "J1"
(at 98.425 69.85 0)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Value" "Conn_01x02_Pin"
(at 98.425 72.39 0)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Footprint" ""
(at 97.79 74.93 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(property "Datasheet" "~"
(at 97.79 74.93 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(property "Description" "Generic connector, single row, 01x02, script generated"
(at 97.79 74.93 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(pin "2"
(uuid "e55f0ad4-f58f-40b5-b01c-f61e46a18cb6")
)
(pin "1"
(uuid "0e477fe2-6c2b-4e1c-99a5-2ebc30352064")
)
(instances
(project ""
(path "/69309afb-88b0-4112-b019-2bea5a178880"
(reference "J1")
(unit 1)
)
)
)
)
(symbol
(lib_id "Connector:Conn_01x02_Pin")
(at 128.27 74.93 0)
(mirror y)
(unit 1)
(exclude_from_sim no)
(in_bom yes)
(on_board yes)
(dnp no)
(uuid "d1063ea8-90b1-4317-b030-2ae7c71614c3")
(property "Reference" "J2"
(at 127.635 69.85 0)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Value" "Conn_01x02_Pin"
(at 127.635 72.39 0)
(effects
(font
(size 1.27 1.27)
)
)
)
(property "Footprint" ""
(at 128.27 74.93 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(property "Datasheet" "~"
(at 128.27 74.93 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(property "Description" "Generic connector, single row, 01x02, script generated"
(at 128.27 74.93 0)
(effects
(font
(size 1.27 1.27)
)
(hide yes)
)
)
(pin "2"
(uuid "bebb5ef7-c8af-4a7b-bf8b-b797c6dad1eb")
)
(pin "1"
(uuid "8ae5c455-c7eb-4fd1-955a-f784c9e0e9b9")
)
(instances
(project "issue18346"
(path "/69309afb-88b0-4112-b019-2bea5a178880"
(reference "J2")
(unit 1)
)
)
)
)
(sheet_instances
(path "/"
(page "1")
)
)
)

View File

@ -57,6 +57,7 @@ set( QA_EESCHEMA_SRCS
erc/test_erc_global_labels.cpp
erc/test_erc_no_connect.cpp
erc/test_erc_hierarchical_schematics.cpp
erc/test_erc_label_multiple_wires.cpp
erc/test_erc_rule_areas.cpp
test_eagle_plugin.cpp

View File

@ -0,0 +1,75 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 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( ERCLabelMultipleWires, ERC_REGRESSION_TEST_FIXTURE )
{
LOCALE_IO dummy;
// Check for Errors when labels overlap multiple wires/buses
std::vector<std::pair<wxString, int>> tests =
{
{ "issue18346", 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() );
settings.m_ERCSeverities[ERCE_LABEL_MULTIPLE_WIRES] = RPT_SEVERITY_ERROR;
ERC_TESTER tester( m_schematic.get() );
tester.TestLabelMultipleWires();
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() );
}
}