KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue23719_global_label_chain.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 <sch_pin.h>
26#include <sch_screen.h>
27#include <sch_sheet.h>
28#include <sch_symbol.h>
30#include <locale_io.h>
31
32
41
42
77{
79
80 KI_TEST::LoadSchematic( m_settingsManager, "issue23719/issue23719", m_schematic );
81
82 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
83
84 struct PIN_NET
85 {
86 int code;
87 wxString name;
88 };
89
90 // For each (symbol-ref, pin-number) pair, capture the netcode and net name.
91 // We don't assume which physical pin numbers wind up wired in the symbol's
92 // local frame; only cross-sheet net consolidation matters here.
93 std::map<wxString, std::map<wxString, PIN_NET>> symbolPins;
94
95 for( const auto& [key, subgraphs] : graph->GetNetMap() )
96 {
97 for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
98 {
99 for( SCH_ITEM* item : subgraph->GetItems() )
100 {
101 if( item->Type() != SCH_PIN_T )
102 continue;
103
104 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
105 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
106
107 if( !symbol )
108 continue;
109
110 wxString ref = symbol->GetRef( &subgraph->GetSheet() );
111 wxString pinNum = pin->GetNumber();
112
113 symbolPins[ref][pinNum] = { key.Netcode, key.Name };
114 }
115 }
116 }
117
118 BOOST_REQUIRE_MESSAGE( symbolPins.count( "J1" ),
119 "J1 connector should appear in the netlist" );
120 BOOST_REQUIRE_MESSAGE( symbolPins.count( "TP1" ),
121 "TP1 testpoint should appear in the netlist" );
122
123 const auto& j1Pins = symbolPins["J1"];
124 const auto& tp1Pins = symbolPins["TP1"];
125
126 // J1 has two wired-up pins (the other two are NC / dangling). Both wired
127 // pins live on globally-labeled sheets and must end up on the shared net.
128 BOOST_REQUIRE_MESSAGE( j1Pins.size() >= 2,
129 wxString::Format( "J1 should have >= 2 connected pins, found %zu",
130 j1Pins.size() ).ToStdString() );
131
132 // TP1 has exactly one pin and it must be on the shared net.
133 BOOST_REQUIRE_MESSAGE( tp1Pins.size() == 1,
134 wxString::Format( "TP1 should have exactly 1 connected pin, found %zu",
135 tp1Pins.size() ).ToStdString() );
136
137 const auto& tp1Pin = *tp1Pins.begin();
138 const auto& j1PinA = *j1Pins.begin();
139 const auto& j1PinB = *std::next( j1Pins.begin() );
140
141 auto sameNetMsg =
142 []( const wxString& aRefA, const auto& aPinA, const wxString& aRefB, const auto& aPinB )
143 {
144 return wxString::Format(
145 "%s-%s (%s, code=%d) and %s-%s (%s, code=%d) should share a net",
146 aRefA, aPinA.first, aPinA.second.name, aPinA.second.code,
147 aRefB, aPinB.first, aPinB.second.name, aPinB.second.code )
148 .ToStdString();
149 };
150
151 BOOST_CHECK_MESSAGE( j1PinA.second.code == tp1Pin.second.code,
152 sameNetMsg( "J1", j1PinA, "TP1", tp1Pin ) );
153
154 BOOST_CHECK_MESSAGE( j1PinB.second.code == tp1Pin.second.code,
155 sameNetMsg( "J1", j1PinB, "TP1", tp1Pin ) );
156
157 BOOST_CHECK_MESSAGE( j1PinA.second.code == j1PinB.second.code,
158 sameNetMsg( "J1", j1PinA, "J1", j1PinB ) );
159}
const char * name
Calculate the connectivity of a schematic and generates netlists.
const NET_MAP & GetNetMap() const
A subgraph is a set of items that are electrically connected on a single sheet.
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:162
Schematic symbol object.
Definition sch_symbol.h:69
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_FIXTURE_TEST_CASE(Issue23719, ISSUE_23719_FIXTURE)
Test for issue #23719 – global labels not combining nets across more than two sheets.
KIBIS_PIN * pin
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
@ SCH_PIN_T
Definition typeinfo.h:150