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