KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue23143_junction_midpoint.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
32
34
35#include <connection_graph.h>
36#include <sch_junction.h>
37#include <sch_line.h>
38#include <sch_sheet.h>
39#include <sch_sheet_path.h>
40#include <sch_screen.h>
41#include <schematic.h>
43#include <project.h>
44
45
46BOOST_AUTO_TEST_CASE( JunctionAtWireMidpointConnectsNet )
47{
48 // Reproduce issue #23143: a junction placed at the midpoint of a horizontal wire
49 // (without the wire being split) must connect a vertical wire that terminates at
50 // the junction to the same net as the horizontal wire.
51 //
52 // Topology:
53 // horizontal wire: (-1000, 0) -- (1000, 0) [not split at (0, 0)]
54 // junction at: (0, 0)
55 // vertical wire: (0, 0) -- (0, -1000)
56 //
57 // Expected: all three items in the same subgraph.
58
59 SETTINGS_MANAGER manager;
60 manager.LoadProject( "" );
61
62 SCHEMATIC schematic( &manager.Prj() );
63 schematic.Reset();
64 SCH_SHEET* defaultSheet = schematic.GetTopLevelSheet( 0 );
65
66 SCH_SCREEN* screen = new SCH_SCREEN( nullptr );
67 SCH_SHEET* sheet = new SCH_SHEET( nullptr, VECTOR2I( 0, 0 ), VECTOR2I( 2000, 2000 ) );
68 sheet->SetScreen( screen );
69 schematic.AddTopLevelSheet( sheet );
70 schematic.RemoveTopLevelSheet( defaultSheet );
71 delete defaultSheet;
72
73 SCH_SHEET_PATH sheetPath;
74 sheetPath.push_back( sheet );
75
76 // Horizontal wire spanning the junction point as a midpoint (not split)
77 SCH_LINE* hWire = new SCH_LINE( VECTOR2I( -1000, 0 ), LAYER_WIRE );
78 hWire->SetEndPoint( VECTOR2I( 1000, 0 ) );
79
80 // Junction at the midpoint of the horizontal wire
81 SCH_JUNCTION* junction = new SCH_JUNCTION( VECTOR2I( 0, 0 ) );
82
83 // Vertical wire with its endpoint at the junction
84 SCH_LINE* vWire = new SCH_LINE( VECTOR2I( 0, 0 ), LAYER_WIRE );
85 vWire->SetEndPoint( VECTOR2I( 0, -1000 ) );
86
87 screen->Append( hWire, false );
88 screen->Append( junction, false );
89 screen->Append( vWire, false );
90
91 CONNECTION_GRAPH graph;
92 graph.SetSchematic( &schematic );
93
95 graph.Recalculate( sheets, true );
96
97 CONNECTION_SUBGRAPH* sgH = graph.GetSubgraphForItem( hWire );
98 CONNECTION_SUBGRAPH* sgJ = graph.GetSubgraphForItem( junction );
99 CONNECTION_SUBGRAPH* sgV = graph.GetSubgraphForItem( vWire );
100
101 BOOST_REQUIRE( sgH );
102 BOOST_REQUIRE( sgJ );
103 BOOST_REQUIRE( sgV );
104
105 BOOST_CHECK_MESSAGE( sgH == sgV,
106 "Vertical wire should be in the same subgraph as the horizontal wire "
107 "when a junction exists at the wire midpoint (issue #23143)" );
108 BOOST_CHECK_MESSAGE( sgJ == sgH,
109 "Junction should be in the same subgraph as the horizontal wire" );
110}
Calculate the connectivity of a schematic and generates netlists.
void SetSchematic(SCHEMATIC *aSchematic)
void Recalculate(const SCH_SHEET_LIST &aSheetList, bool aUnconditional=false, std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Update the connection graph for the given list of sheets.
CONNECTION_SUBGRAPH * GetSubgraphForItem(SCH_ITEM *aItem) const
A subgraph is a set of items that are electrically connected on a single sheet.
Holds all the data relating to one schematic.
Definition schematic.h:88
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
void AddTopLevelSheet(SCH_SHEET *aSheet)
Add a new top-level sheet to the schematic.
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
SCH_SHEET * GetTopLevelSheet(int aIndex=0) const
bool RemoveTopLevelSheet(SCH_SHEET *aSheet)
Remove a top-level sheet from the schematic.
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
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
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...
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
@ LAYER_WIRE
Definition layer_ids.h:452
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_CASE(JunctionAtWireMidpointConnectsNet)
Test for issue #23143: Pin appears connected but ERC reports it as unconnected.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695