KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_label_bus_connectivity.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
29
31
32#include <connection_graph.h>
33#include <schematic.h>
34#include <sch_label.h>
35#include <sch_line.h>
36#include <sch_screen.h>
37#include <sch_sheet.h>
39
40
41BOOST_AUTO_TEST_SUITE( LabelBusConnectivity )
42
43
45{
47 m_mgr()
48 {
49 m_mgr.LoadProject( "" );
50 m_schematic = std::make_unique<SCHEMATIC>( &m_mgr.Prj() );
51 m_schematic->Reset();
52 SCH_SHEET* defaultSheet = m_schematic->GetTopLevelSheet( 0 );
53
54 m_screen = new SCH_SCREEN( m_schematic.get() );
55 m_sheet = new SCH_SHEET( m_schematic.get() );
56 m_sheet->SetScreen( m_screen );
57 m_schematic->AddTopLevelSheet( m_sheet );
58 m_schematic->RemoveTopLevelSheet( defaultSheet );
59 delete defaultSheet;
60 }
61
63 std::unique_ptr<SCHEMATIC> m_schematic;
66};
67
68
78{
79 // Create a bus wire
80 SCH_LINE* busWire = new SCH_LINE( VECTOR2I( 0, 0 ), LAYER_BUS );
81 busWire->SetEndPoint( VECTOR2I( 5000000, 0 ) );
82 m_screen->Append( busWire );
83
84 // Create a label with a non-bus name, positioned on the bus wire
85 SCH_LABEL* label = new SCH_LABEL( VECTOR2I( 2500000, 0 ), wxT( "test" ) );
86 m_screen->Append( label );
87
88 // Build initial connectivity
89 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
90 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
91
92 SCH_SHEET_PATH path = sheets[0];
93
94 // Verify initial state: bus wire should have BUS connection type but no members
95 // (because "test" is not a bus name)
96 SCH_CONNECTION* busConn = busWire->Connection( &path );
97 BOOST_REQUIRE( busConn != nullptr );
98 BOOST_CHECK( busConn->IsBus() );
99 BOOST_CHECK( busConn->Members().empty() );
100
101 // Now change the label text to a bus name
102 label->SetText( wxT( "test[0..7]" ) );
103
104 // Mark items dirty and recalculate connectivity (simulating incremental update)
105 label->SetConnectivityDirty( true );
106 busWire->SetConnectivityDirty( true );
107
108 m_schematic->ConnectionGraph()->Recalculate( sheets, false );
109
110 // Verify: bus wire should now have members from the bus label
111 busConn = busWire->Connection( &path );
112 BOOST_REQUIRE( busConn != nullptr );
113 BOOST_CHECK( busConn->IsBus() );
114 BOOST_CHECK_MESSAGE( !busConn->Members().empty(),
115 "Bus wire should have members after label changed to bus name" );
116
117 // Verify the correct number of members (test[0..7] = 8 members)
118 if( !busConn->Members().empty() )
119 {
120 BOOST_CHECK_EQUAL( busConn->Members().size(), 8 );
121 }
122}
123
124
130{
131 // Create a bus wire
132 SCH_LINE* busWire = new SCH_LINE( VECTOR2I( 0, 0 ), LAYER_BUS );
133 busWire->SetEndPoint( VECTOR2I( 5000000, 0 ) );
134 m_screen->Append( busWire );
135
136 // Create a label with a bus name, positioned on the bus wire
137 SCH_LABEL* label = new SCH_LABEL( VECTOR2I( 2500000, 0 ), wxT( "DATA[0..3]" ) );
138 m_screen->Append( label );
139
140 // Build connectivity
141 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
142 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
143
144 SCH_SHEET_PATH path = sheets[0];
145
146 // Verify: bus wire should have members from the bus label
147 SCH_CONNECTION* busConn = busWire->Connection( &path );
148 BOOST_REQUIRE( busConn != nullptr );
149 BOOST_CHECK( busConn->IsBus() );
150 BOOST_CHECK_MESSAGE( !busConn->Members().empty(),
151 "Bus wire should have members from bus label" );
152
153 // Verify the correct number of members (DATA[0..3] = 4 members)
154 if( !busConn->Members().empty() )
155 {
156 BOOST_CHECK_EQUAL( busConn->Members().size(), 4 );
157 }
158}
159
160
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:265
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
bool IsBus() const
const std::vector< std::shared_ptr< SCH_CONNECTION > > & Members() const
void SetConnectivityDirty(bool aDirty=true)
Definition sch_item.h:587
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition sch_item.cpp:487
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:38
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:145
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
@ LAYER_BUS
Definition layer_ids.h:451
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
std::string path
BOOST_FIXTURE_TEST_CASE(LabelNetToBusConnectivity, LABEL_BUS_CONNECTIVITY_FIXTURE)
Test that changing a label from a net name to a bus name properly updates the connected bus wire's co...
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683