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, you may find one here:
18 * https://www.gnu.org/licenses/gpl-3.0.en.html
19 * or you may search the http://www.gnu.org website for the version 32 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
26
27#include <connection_graph.h>
28#include <schematic.h>
29#include <sch_pin.h>
30#include <sch_screen.h>
31#include <sch_sheet.h>
32#include <sch_symbol.h>
34#include <locale_io.h>
35
36
45
46
81{
83
84 KI_TEST::LoadSchematic( m_settingsManager, "issue23719/issue23719", m_schematic );
85
86 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
87
88 struct PIN_NET
89 {
90 int code;
91 wxString name;
92 };
93
94 // For each (symbol-ref, pin-number) pair, capture the netcode and net name.
95 // We don't assume which physical pin numbers wind up wired in the symbol's
96 // local frame; only cross-sheet net consolidation matters here.
97 std::map<wxString, std::map<wxString, PIN_NET>> symbolPins;
98
99 for( const auto& [key, subgraphs] : graph->GetNetMap() )
100 {
101 for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
102 {
103 for( SCH_ITEM* item : subgraph->GetItems() )
104 {
105 if( item->Type() != SCH_PIN_T )
106 continue;
107
108 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
109 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
110
111 if( !symbol )
112 continue;
113
114 wxString ref = symbol->GetRef( &subgraph->GetSheet() );
115 wxString pinNum = pin->GetNumber();
116
117 symbolPins[ref][pinNum] = { key.Netcode, key.Name };
118 }
119 }
120 }
121
122 BOOST_REQUIRE_MESSAGE( symbolPins.count( "J1" ),
123 "J1 connector should appear in the netlist" );
124 BOOST_REQUIRE_MESSAGE( symbolPins.count( "TP1" ),
125 "TP1 testpoint should appear in the netlist" );
126
127 const auto& j1Pins = symbolPins["J1"];
128 const auto& tp1Pins = symbolPins["TP1"];
129
130 // J1 has two wired-up pins (the other two are NC / dangling). Both wired
131 // pins live on globally-labeled sheets and must end up on the shared net.
132 BOOST_REQUIRE_MESSAGE( j1Pins.size() >= 2,
133 wxString::Format( "J1 should have >= 2 connected pins, found %zu",
134 j1Pins.size() ).ToStdString() );
135
136 // TP1 has exactly one pin and it must be on the shared net.
137 BOOST_REQUIRE_MESSAGE( tp1Pins.size() == 1,
138 wxString::Format( "TP1 should have exactly 1 connected pin, found %zu",
139 tp1Pins.size() ).ToStdString() );
140
141 const auto& tp1Pin = *tp1Pins.begin();
142 const auto& j1PinA = *j1Pins.begin();
143 const auto& j1PinB = *std::next( j1Pins.begin() );
144
145 auto sameNetMsg =
146 []( const wxString& aRefA, const auto& aPinA, const wxString& aRefB, const auto& aPinB )
147 {
148 return wxString::Format(
149 "%s-%s (%s, code=%d) and %s-%s (%s, code=%d) should share a net",
150 aRefA, aPinA.first, aPinA.second.name, aPinA.second.code,
151 aRefB, aPinB.first, aPinB.second.name, aPinB.second.code )
152 .ToStdString();
153 };
154
155 BOOST_CHECK_MESSAGE( j1PinA.second.code == tp1Pin.second.code,
156 sameNetMsg( "J1", j1PinA, "TP1", tp1Pin ) );
157
158 BOOST_CHECK_MESSAGE( j1PinB.second.code == tp1Pin.second.code,
159 sameNetMsg( "J1", j1PinB, "TP1", tp1Pin ) );
160
161 BOOST_CHECK_MESSAGE( j1PinA.second.code == j1PinB.second.code,
162 sameNetMsg( "J1", j1PinA, "J1", j1PinB ) );
163}
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:41
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:168
Schematic symbol object.
Definition sch_symbol.h:76
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:154