KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue19951_directive_label_coincident.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
30
33
34#include <connection_graph.h>
35#include <netclass.h>
36#include <project.h>
39#include <sch_connection.h>
40#include <sch_label.h>
41#include <sch_line.h>
42#include <sch_screen.h>
43#include <sch_sheet_path.h>
44#include <schematic.h>
46
47
49{
51 std::unique_ptr<SCHEMATIC> m_schematic;
52
53 SCH_LABEL* FindLabel( const wxString& aText ) const
54 {
55 for( SCH_ITEM* item : m_schematic->RootScreen()->Items().OfType( SCH_LABEL_T ) )
56 {
57 SCH_LABEL* label = static_cast<SCH_LABEL*>( item );
58
59 if( label->GetText() == aText )
60 return label;
61 }
62
63 return nullptr;
64 }
65
67 {
68 for( SCH_ITEM* item : m_schematic->RootScreen()->Items().OfType( SCH_DIRECTIVE_LABEL_T ) )
69 {
70 SCH_DIRECTIVE_LABEL* directive = static_cast<SCH_DIRECTIVE_LABEL*>( item );
71
72 if( directive->GetPosition() == aPos )
73 return directive;
74 }
75
76 return nullptr;
77 }
78
79 SCH_LINE* FindWireUnder( const VECTOR2I& aPos ) const
80 {
81 for( SCH_ITEM* item : m_schematic->RootScreen()->Items().OfType( SCH_LINE_T ) )
82 {
83 SCH_LINE* line = static_cast<SCH_LINE*>( item );
84
85 if( line->IsWire() && line->HitTest( aPos, 0 ) )
86 return line;
87 }
88
89 return nullptr;
90 }
91};
92
93
94BOOST_FIXTURE_TEST_SUITE( Issue19951DirectiveLabelCoincident, ISSUE19951_FIXTURE )
95
96
97// local_label01 and its directive sit at different points on the same wire, which always worked
98// This case guards the fix against regressing the ordinary topology
99BOOST_AUTO_TEST_CASE( DirectiveOnSeparatePointDrivesWire )
100{
101 KI_TEST::LoadSchematic( m_settingsManager, wxT( "issue19951/issue19951" ), m_schematic );
102
103 SCH_LABEL* label = FindLabel( wxT( "local_label01" ) );
104 BOOST_REQUIRE( label );
105
106 SCH_LINE* wire = FindWireUnder( label->GetPosition() );
107 BOOST_REQUIRE( wire );
108
109 // The directive is deliberately not coincident with the label in this stub
110 BOOST_REQUIRE( !FindDirectiveAt( label->GetPosition() ) );
111
112 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
113 CONNECTION_SUBGRAPH* labelSubgraph = graph->GetSubgraphForItem( label );
114 CONNECTION_SUBGRAPH* wireSubgraph = graph->GetSubgraphForItem( wire );
115
116 BOOST_REQUIRE( labelSubgraph );
117 BOOST_REQUIRE( wireSubgraph );
118 BOOST_CHECK( labelSubgraph == wireSubgraph );
119
120 const SCH_SHEET_PATH& sheet = wireSubgraph->GetSheet();
121
122 BOOST_REQUIRE( wire->Connection( &sheet ) );
123 BOOST_CHECK_EQUAL( wire->Connection( &sheet )->Name(), wxString( wxT( "/local_label01" ) ) );
124}
125
126
127// The reported failure, where local_label02 and its directive share one point in the middle of
128// the wire and neither recorded a connection to it
129BOOST_AUTO_TEST_CASE( CoincidentDirectiveAndLabelJoinWire )
130{
131 KI_TEST::LoadSchematic( m_settingsManager, wxT( "issue19951/issue19951" ), m_schematic );
132
133 SCH_LABEL* label = FindLabel( wxT( "local_label02" ) );
134 BOOST_REQUIRE( label );
135
136 SCH_DIRECTIVE_LABEL* directive = FindDirectiveAt( label->GetPosition() );
137 BOOST_REQUIRE( directive );
138
139 SCH_LINE* wire = FindWireUnder( label->GetPosition() );
140 BOOST_REQUIRE( wire );
141
142 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
143 CONNECTION_SUBGRAPH* labelSubgraph = graph->GetSubgraphForItem( label );
144 CONNECTION_SUBGRAPH* directiveSubgraph = graph->GetSubgraphForItem( directive );
145 CONNECTION_SUBGRAPH* wireSubgraph = graph->GetSubgraphForItem( wire );
146
147 BOOST_REQUIRE( labelSubgraph );
148 BOOST_REQUIRE( wireSubgraph );
149
150 BOOST_CHECK_MESSAGE( labelSubgraph == wireSubgraph,
151 "Label sharing a point with a netclass directive must still connect to "
152 "the wire under it (issue #19951)" );
153 BOOST_CHECK_MESSAGE( directiveSubgraph == wireSubgraph,
154 "Netclass directive sharing a point with a label must still connect to "
155 "the wire under it (issue #19951)" );
156
157 const SCH_SHEET_PATH& sheet = wireSubgraph->GetSheet();
158
159 BOOST_REQUIRE( wire->Connection( &sheet ) );
160
161 const wxString wireNet = wire->Connection( &sheet )->Name();
162
163 BOOST_CHECK_EQUAL( wireNet, wxString( wxT( "/local_label02" ) ) );
164
165 // The reported symptom was Default, because the wire's net was the auto-generated one the
166 // directive knows nothing about
167 std::shared_ptr<NET_SETTINGS>& netSettings =
168 m_schematic->Project().GetProjectFile().m_NetSettings;
169
170 BOOST_REQUIRE( netSettings );
171
172 std::shared_ptr<NETCLASS> netclass = netSettings->GetEffectiveNetClass( wireNet );
173
174 BOOST_REQUIRE( netclass );
175 BOOST_CHECK_EQUAL( netclass->GetName(), wxString( wxT( "netclass_2" ) ) );
176}
177
178
Calculate the connectivity of a schematic and generates netlists.
CONNECTION_SUBGRAPH * GetSubgraphForItem(SCH_ITEM *aItem) const
A subgraph is a set of items that are electrically connected on a single sheet.
const SCH_SHEET_PATH & GetSheet() const
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:110
wxString Name(bool aIgnoreSheet=false) const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
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
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition sch_line.cpp:855
bool IsWire() const
Return true if the line is a wire.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
VECTOR2I GetPosition() const override
Definition sch_text.h:146
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Test for issue #19951: netclass directive not applied when it shares a connection point with a local ...
SCH_DIRECTIVE_LABEL * FindDirectiveAt(const VECTOR2I &aPos) const
SCH_LINE * FindWireUnder(const VECTOR2I &aPos) const
SCH_LABEL * FindLabel(const wxString &aText) const
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(DirectiveOnSeparatePointDrivesWire)
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_LINE_T
Definition typeinfo.h:160
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:168
@ SCH_LABEL_T
Definition typeinfo.h:164
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683