KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_label_multiple_wires.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
22
23#include <connection_graph.h>
24#include <schematic.h>
25#include <erc/erc_settings.h>
26#include <erc/erc.h>
27#include <erc/erc_report.h>
29#include <locale_io.h>
30#include <advanced_config.h>
31#include <sch_marker.h>
32#include <sch_screen.h>
33
34#include <algorithm>
35#include <functional>
36#include <scoped_set_reset.h>
37
39{
42
44 std::unique_ptr<SCHEMATIC> m_schematic;
45};
46
47
49{
51
52 // Check for Errors when labels overlap multiple wires/buses
53 std::vector<std::pair<wxString, int>> tests =
54 {
55 { "issue18346", 1 }
56 };
57
58 for( const std::pair<wxString, int>& test : tests )
59 {
60 KI_TEST::LoadSchematic( m_settingsManager, test.first, m_schematic );
61
62 ERC_SETTINGS& settings = m_schematic->ErcSettings();
63 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
64
66
67 ERC_TESTER tester( m_schematic.get() );
69
71
72 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
73
74 BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
75 "Expected " << test.second << " errors in " << test.first.ToStdString()
76 << " but got " << errors.GetCount() << "\n"
77 << reportWriter.GetTextReport() );
78
79 }
80}
81
82
83BOOST_AUTO_TEST_CASE( ERCMultipleWireExclusionsSurviveCanonicalWitnesses )
84{
85 LOCALE_IO locale;
86 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
87 SCOPED_SET_RESET restore( enabled, false );
88 SETTINGS_MANAGER settings;
89 std::unique_ptr<SCHEMATIC> schematic;
90 KI_TEST::LoadSchematic( settings, "issue18346", schematic );
91 SCH_SCREEN* screen = schematic->RootScreen();
92 ERC_TESTER tester( schematic.get() );
93 BOOST_REQUIRE_EQUAL( tester.TestLabelMultipleWires(), 1 );
94 std::vector<SCH_ITEM*> markers;
95
96 for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) )
97 {
98 auto* marker = static_cast<SCH_MARKER*>( item );
99 auto ids = marker->GetRCItem()->GetIDs();
100 BOOST_REQUIRE_GE( ids.size(), 3 );
101 std::sort( ids.begin() + 1, ids.end(), std::greater<KIID>() );
102 marker->GetRCItem()->SetItems( ids );
103 marker->SetExcluded( true, "Retained crossing" );
104 markers.push_back( item );
105 }
106
107 schematic->RecordERCExclusions();
108
109 for( SCH_ITEM* item : markers )
110 screen->DeleteItem( item );
111
112 enabled = true;
113 schematic->RebuildConnectivity();
114 BOOST_REQUIRE_EQUAL( tester.TestLabelMultipleWires(), 1 );
115 schematic->ResolveERCExclusionsPostUpdate();
116 size_t count = 0;
117
118 for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) )
119 {
120 const auto* marker = static_cast<SCH_MARKER*>( item );
121 BOOST_CHECK( marker->IsExcluded() );
122 BOOST_CHECK_EQUAL( marker->GetComment(), wxString( "Retained crossing" ) );
123 ++count;
124 }
125
126 BOOST_CHECK_EQUAL( count, 1 );
127}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
wxString GetTextReport()
Returns the ERC report in "text" (human readable) format in the C-locale.
Container for ERC settings.
std::map< int, SEVERITY > m_ERCSeverities
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
Definition erc.h:60
int TestLabelMultipleWires()
Test to see if there are labels that are connected to more than one wire.
Definition erc.cpp:1124
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
std::shared_ptr< RC_ITEM > GetRCItem() const
std::vector< KIID > GetIDs() const
Definition rc_item.h:133
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
void DeleteItem(SCH_ITEM *aItem)
Remove aItem from the linked list and deletes the object.
RAII class that sets an value at construction and resets it to the original value at destruction.
An implementation of the RC_ITEM_LIST interface which uses the global SHEETLIST to fulfill the contra...
int GetCount(int aSeverity=-1) const override
void SetSeverities(int aSeverities) override
@ ERCE_LABEL_MULTIPLE_WIRES
A label is connected to more than one wire.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_AUTO_TEST_CASE(ERCMultipleWireExclusionsSurviveCanonicalWitnesses)
BOOST_FIXTURE_TEST_CASE(ERCLabelMultipleWires, ERC_REGRESSION_TEST_FIXTURE)
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_MARKER_T
Definition typeinfo.h:154