KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_implicit_power.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#include <advanced_config.h>
23#include <erc/erc.h>
24#include <locale_io.h>
25#include <sch_line.h>
26#include <sch_marker.h>
27#include <sch_pin.h>
28#include <sch_symbol.h>
29#include <schematic.h>
31#include <scoped_set_reset.h>
32
33BOOST_AUTO_TEST_CASE( ERCWiredImplicitPowerReportsWiredHiddenPin )
34{
35 LOCALE_IO locale;
36 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
37 SCOPED_SET_RESET restore( enabled, true );
38 SETTINGS_MANAGER settings;
39 std::unique_ptr<SCHEMATIC> schematic;
40 KI_TEST::LoadSchematic( settings, "netlists/legacy_power/legacy_power", schematic );
41 const SCH_SHEET_PATH path = schematic->Hierarchy().front();
42 SCH_SCREEN* screen = path.LastScreen();
43 SCH_PIN* pin = nullptr;
44 std::unique_ptr<SCH_LINE> wire;
45
46 for( SCH_ITEM* item : screen->Items() )
47 {
48 if( !wire && item->Type() == SCH_LINE_T && item->GetLayer() == LAYER_WIRE )
49 wire.reset( static_cast<SCH_LINE*>( item->Duplicate( false ) ) );
50
51 if( pin || item->Type() != SCH_SYMBOL_T )
52 continue;
53
54 auto* symbol = static_cast<SCH_SYMBOL*>( item );
55
56 if( symbol->IsPower() )
57 continue;
58
59 for( SCH_PIN* candidate : symbol->GetPins( &path ) )
60 {
61 if( candidate->IsGlobalPower() && !candidate->IsVisible()
62 && candidate->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
63 {
64 pin = candidate;
65 break;
66 }
67 }
68 }
69
71 BOOST_REQUIRE( wire );
72 auto* symbol = static_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
73
74 // Move clear of the drawing so only the added wire touches the hidden pin
75 symbol->SetPosition( VECTOR2I( 100000000, 100000000 ) );
76 screen->Update( symbol, false );
77 const VECTOR2I position = pin->GetPosition();
78 wire->SetStartPoint( position );
79 wire->SetEndPoint( position + VECTOR2I( 1000000, 0 ) );
80 screen->Append( wire.release() );
81
82 for( auto& [code, severity] : schematic->ErcSettings().m_ERCSeverities )
83 severity = RPT_SEVERITY_IGNORE;
84
85 schematic->ErcSettings().m_ERCSeverities[ERCE_WIRED_IMPLICIT_POWER] = RPT_SEVERITY_WARNING;
86 schematic->RebuildConnectivity();
87 const auto collect = [&]()
88 {
89 ERC_TESTER::TestConnectivity( *schematic );
90 std::vector<SCH_MARKER*> result;
91 std::vector<SCH_ITEM*> markers;
92
93 for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) )
94 {
95 auto* marker = static_cast<SCH_MARKER*>( item );
96
97 if( marker->GetRCItem()->GetErrorCode() == ERCE_WIRED_IMPLICIT_POWER
98 && marker->GetRCItem()->GetMainItemID() == pin->m_Uuid )
99 {
100 result.push_back( marker );
101 }
102
103 markers.push_back( item );
104 }
105
106 return std::make_pair( result, markers );
107 };
108
109 const auto [found, all] = collect();
110 BOOST_REQUIRE_EQUAL( found.size(), 1 );
111 BOOST_CHECK( found.front()->GetPosition() == position );
112
113 for( SCH_ITEM* marker : all )
114 screen->DeleteItem( marker );
115
116 schematic->ErcSettings().m_ERCSeverities[ERCE_WIRED_IMPLICIT_POWER] = RPT_SEVERITY_IGNORE;
117 BOOST_CHECK( collect().first.empty() );
118}
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
static int TestConnectivity(SCHEMATIC &aSchematic)
Definition erc.cpp:2215
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Refresh a changed item in the tree and invalidate connectivity.
void DeleteItem(SCH_ITEM *aItem)
Remove aItem from the linked list and deletes the object.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:74
void SetPosition(const VECTOR2I &aPosition) override
Definition sch_symbol.h:897
RAII class that sets an value at construction and resets it to the original value at destruction.
@ ERCE_WIRED_IMPLICIT_POWER
Wired hidden power input also joins its global net by name.
@ LAYER_WIRE
Definition layer_ids.h:474
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:42
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_IGNORE
BOOST_AUTO_TEST_CASE(ERCWiredImplicitPowerReportsWiredHiddenPin)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
std::string path
KIBIS_PIN * pin
wxString result
Test unit parsing edge cases and error handling.
@ SCH_LINE_T
Definition typeinfo.h:159
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_MARKER_T
Definition typeinfo.h:154
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683