KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue22694_global_hier_label.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_sheet.h>
26#include <sch_screen.h>
27#include <sch_symbol.h>
28#include <sch_pin.h>
30#include <locale_io.h>
31
40
41
69{
71
72 KI_TEST::LoadSchematic( m_settingsManager, "issue22694/issue22694", m_schematic );
73
74 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
75
76 // Collect net codes for component pins we care about
77 std::map<wxString, int> pinNetCodes;
78
79 for( const auto& [key, subgraphs] : graph->GetNetMap() )
80 {
81 for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
82 {
83 for( SCH_ITEM* item : subgraph->GetItems() )
84 {
85 if( item->Type() == SCH_PIN_T )
86 {
87 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
88 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
89
90 if( !symbol )
91 continue;
92
93 wxString ref = symbol->GetRef( &subgraph->GetSheet() );
94 wxString pinNum = pin->GetNumber();
95 wxString pinKey = ref + wxT( "-" ) + pinNum;
96
97 pinNetCodes[pinKey] = key.Netcode;
98 }
99 }
100 }
101 }
102
103 // Verify we found the relevant pins
104 BOOST_REQUIRE_MESSAGE( pinNetCodes.count( "J2-1" ), "J2 Pin 1 should be in netlist" );
105 BOOST_REQUIRE_MESSAGE( pinNetCodes.count( "J2-2" ), "J2 Pin 2 should be in netlist" );
106 BOOST_REQUIRE_MESSAGE( pinNetCodes.count( "J3-1" ), "J3 Pin 1 should be in netlist" );
107
108 // J2-Pin1 connects through HL1, which is a separate net from HL2
109 // J2-Pin2..Pin6 connect through HL2, which also connects to "Global Label"
110 // J3-Pin1 connects to "Global Label" in the untitled sheet
111 // So J2-Pin2 and J3-Pin1 should be on the same net
112 BOOST_CHECK_MESSAGE( pinNetCodes["J2-2"] == pinNetCodes["J3-1"],
113 "J2-Pin2 and J3-Pin1 should be on the same net "
114 "(connected via HL2 + Global Label)" );
115
116 // J2-Pin1 (via HL1) should NOT be on the same net as J2-Pin2 (via HL2)
117 BOOST_CHECK_MESSAGE( pinNetCodes["J2-1"] != pinNetCodes["J2-2"],
118 "J2-Pin1 (HL1) and J2-Pin2 (HL2) should be on different nets" );
119
120 // All J2 pins connected via HL2 should be on the same net
121 for( int p = 3; p <= 6; p++ )
122 {
123 wxString pinKey = wxString::Format( "J2-%d", p );
124
125 if( pinNetCodes.count( pinKey ) )
126 {
127 BOOST_CHECK_MESSAGE( pinNetCodes["J2-2"] == pinNetCodes[pinKey],
128 wxString::Format( "J2-Pin2 and J2-Pin%d should be on "
129 "the same net (both via HL2)", p ) );
130 }
131 }
132}
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(Issue22694, ISSUE_22694_FIXTURE)
Test for issue #22694: Global labels and hierarchical labels not connected.
KIBIS_PIN * pin
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
@ SCH_PIN_T
Definition typeinfo.h:150