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, 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
33
35
36#include <connection_graph.h>
37#include <schematic.h>
38#include <sch_label.h>
39#include <sch_line.h>
40#include <sch_screen.h>
41#include <sch_sheet.h>
43
44
45BOOST_AUTO_TEST_SUITE( LabelBusConnectivity )
46
47
49{
51 m_mgr()
52 {
53 m_mgr.LoadProject( "" );
54 m_schematic = std::make_unique<SCHEMATIC>( &m_mgr.Prj() );
55 m_schematic->Reset();
56 SCH_SHEET* defaultSheet = m_schematic->GetTopLevelSheet( 0 );
57
58 m_screen = new SCH_SCREEN( m_schematic.get() );
59 m_sheet = new SCH_SHEET( m_schematic.get() );
60 m_sheet->SetScreen( m_screen );
61 m_schematic->AddTopLevelSheet( m_sheet );
62 m_schematic->RemoveTopLevelSheet( defaultSheet );
63 delete defaultSheet;
64 }
65
67 std::unique_ptr<SCHEMATIC> m_schematic;
70};
71
72
82{
83 // Create a bus wire
84 SCH_LINE* busWire = new SCH_LINE( VECTOR2I( 0, 0 ), LAYER_BUS );
85 busWire->SetEndPoint( VECTOR2I( 5000000, 0 ) );
86 m_screen->Append( busWire );
87
88 // Create a label with a non-bus name, positioned on the bus wire
89 SCH_LABEL* label = new SCH_LABEL( VECTOR2I( 2500000, 0 ), wxT( "test" ) );
90 m_screen->Append( label );
91
92 // Build initial connectivity
93 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
94 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
95
96 SCH_SHEET_PATH path = sheets[0];
97
98 // Verify initial state: bus wire should have BUS connection type but no members
99 // (because "test" is not a bus name)
100 SCH_CONNECTION* busConn = busWire->Connection( &path );
101 BOOST_REQUIRE( busConn != nullptr );
102 BOOST_CHECK( busConn->IsBus() );
103 BOOST_CHECK( busConn->Members().empty() );
104
105 // Now change the label text to a bus name
106 label->SetText( wxT( "test[0..7]" ) );
107
108 // Mark items dirty and recalculate connectivity (simulating incremental update)
109 label->SetConnectivityDirty( true );
110 busWire->SetConnectivityDirty( true );
111
112 m_schematic->ConnectionGraph()->Recalculate( sheets, false );
113
114 // Verify: bus wire should now have members from the bus label
115 busConn = busWire->Connection( &path );
116 BOOST_REQUIRE( busConn != nullptr );
117 BOOST_CHECK( busConn->IsBus() );
118 BOOST_CHECK_MESSAGE( !busConn->Members().empty(),
119 "Bus wire should have members after label changed to bus name" );
120
121 // Verify the correct number of members (test[0..7] = 8 members)
122 if( !busConn->Members().empty() )
123 {
124 BOOST_CHECK_EQUAL( busConn->Members().size(), 8 );
125 }
126}
127
128
134{
135 // Create a bus wire
136 SCH_LINE* busWire = new SCH_LINE( VECTOR2I( 0, 0 ), LAYER_BUS );
137 busWire->SetEndPoint( VECTOR2I( 5000000, 0 ) );
138 m_screen->Append( busWire );
139
140 // Create a label with a bus name, positioned on the bus wire
141 SCH_LABEL* label = new SCH_LABEL( VECTOR2I( 2500000, 0 ), wxT( "DATA[0..3]" ) );
142 m_screen->Append( label );
143
144 // Build connectivity
145 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
146 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
147
148 SCH_SHEET_PATH path = sheets[0];
149
150 // Verify: bus wire should have members from the bus label
151 SCH_CONNECTION* busConn = busWire->Connection( &path );
152 BOOST_REQUIRE( busConn != nullptr );
153 BOOST_CHECK( busConn->IsBus() );
154 BOOST_CHECK_MESSAGE( !busConn->Members().empty(),
155 "Bus wire should have members from bus label" );
156
157 // Verify the correct number of members (DATA[0..3] = 4 members)
158 if( !busConn->Members().empty() )
159 {
160 BOOST_CHECK_EQUAL( busConn->Members().size(), 4 );
161 }
162}
163
164
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:282
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:589
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:471
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:42
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:149
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:48
@ LAYER_BUS
Definition layer_ids.h:453
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_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695