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, see <https://www.gnu.org/licenses/>.
18 */
19
28
30
31#include <connection_graph.h>
32#include <sch_junction.h>
33#include <sch_line.h>
34#include <sch_sheet.h>
35#include <sch_sheet_path.h>
36#include <sch_screen.h>
37#include <schematic.h>
39#include <project.h>
40
41
42BOOST_AUTO_TEST_CASE( JunctionAtWireMidpointConnectsNet )
43{
44 // Reproduce issue #23143: a junction placed at the midpoint of a horizontal wire
45 // (without the wire being split) must connect a vertical wire that terminates at
46 // the junction to the same net as the horizontal wire.
47 //
48 // Topology:
49 // horizontal wire: (-1000, 0) -- (1000, 0) [not split at (0, 0)]
50 // junction at: (0, 0)
51 // vertical wire: (0, 0) -- (0, -1000)
52 //
53 // Expected: all three items in the same subgraph.
54
55 SETTINGS_MANAGER manager;
56 manager.LoadProject( "" );
57
58 SCHEMATIC schematic( &manager.Prj() );
59 schematic.Reset();
60 SCH_SHEET* defaultSheet = schematic.GetTopLevelSheet( 0 );
61
62 SCH_SCREEN* screen = new SCH_SCREEN( nullptr );
63 SCH_SHEET* sheet = new SCH_SHEET( nullptr, VECTOR2I( 0, 0 ), VECTOR2I( 2000, 2000 ) );
64 sheet->SetScreen( screen );
65 schematic.AddTopLevelSheet( sheet );
66 schematic.RemoveTopLevelSheet( defaultSheet );
67 delete defaultSheet;
68
69 SCH_SHEET_PATH sheetPath;
70 sheetPath.push_back( sheet );
71
72 // Horizontal wire spanning the junction point as a midpoint (not split)
73 SCH_LINE* hWire = new SCH_LINE( VECTOR2I( -1000, 0 ), LAYER_WIRE );
74 hWire->SetEndPoint( VECTOR2I( 1000, 0 ) );
75
76 // Junction at the midpoint of the horizontal wire
77 SCH_JUNCTION* junction = new SCH_JUNCTION( VECTOR2I( 0, 0 ) );
78
79 // Vertical wire with its endpoint at the junction
80 SCH_LINE* vWire = new SCH_LINE( VECTOR2I( 0, 0 ), LAYER_WIRE );
81 vWire->SetEndPoint( VECTOR2I( 0, -1000 ) );
82
83 screen->Append( hWire, false );
84 screen->Append( junction, false );
85 screen->Append( vWire, false );
86
87 CONNECTION_GRAPH graph;
88 graph.SetSchematic( &schematic );
89
90 SCH_SHEET_LIST sheets = schematic.BuildSheetListSortedByPageNumbers();
91 graph.Recalculate( sheets, true );
92
93 CONNECTION_SUBGRAPH* sgH = graph.GetSubgraphForItem( hWire );
94 CONNECTION_SUBGRAPH* sgJ = graph.GetSubgraphForItem( junction );
95 CONNECTION_SUBGRAPH* sgV = graph.GetSubgraphForItem( vWire );
96
97 BOOST_REQUIRE( sgH );
98 BOOST_REQUIRE( sgJ );
99 BOOST_REQUIRE( sgV );
100
101 BOOST_CHECK_MESSAGE( sgH == sgV,
102 "Vertical wire should be in the same subgraph as the horizontal wire "
103 "when a junction exists at the wire midpoint (issue #23143)" );
104 BOOST_CHECK_MESSAGE( sgJ == sgH,
105 "Junction should be in the same subgraph as the horizontal wire" );
106}
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:90
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
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:44
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:450
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.
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683