KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_junction_place.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
21
22#include <sch_line.h>
23#include <sch_junction.h>
24#include <sch_screen.h>
25#include <schematic.h>
26#include <tool/tool_manager.h>
27#include <sch_commit.h>
28
29BOOST_AUTO_TEST_SUITE( JunctionPlacement )
30
31BOOST_AUTO_TEST_CASE( CrossingSegmentsKeepJunction )
32{
33 SCH_SCREEN screen;
34
35 /*
36 * Draw this:
37 * v1 v2
38 * | |
39 * j1(0,0)-\| |
40 * -------o--o----------- h1
41 * | |\-j2(20,0)
42 * | |
43 *
44 * j1 is at the intersection of the first two wires, but they're not broken
45 * j2 is at the intersection of the second set of wires, after they've been broken
46 */
47
48 SCH_LINE* h1 = new SCH_LINE( VECTOR2I( -100, 0 ), LAYER_WIRE );
49 h1->SetEndPoint( VECTOR2I( 100, 0 ) );
50 screen.Append( h1 );
51
52 SCH_LINE* v1 = new SCH_LINE( VECTOR2I( 0, -100 ), LAYER_WIRE );
53 v1->SetEndPoint( VECTOR2I( 0, 100 ) );
54 screen.Append( v1 );
55
56 SCH_LINE* v2 = new SCH_LINE( VECTOR2I( 20, -100 ), LAYER_WIRE );
57 v2->SetEndPoint( VECTOR2I( 20, 100 ) );
58 screen.Append( v2 );
59
60 TOOL_MANAGER mgr;
61 SCH_COMMIT commit( &mgr );
62
63 SCH_JUNCTION* j1 = new SCH_JUNCTION( VECTOR2I( 0, 0 ) );
64 screen.Append( j1 );
65 commit.Added( j1, &screen );
66
67 SCHEMATIC schematic( nullptr);
68 schematic.CleanUp( &commit, &screen );
69
70 // The wires cross without being split at j1.
71 // Make sure it's still present
72 BOOST_CHECK( screen.GetItem( VECTOR2I( 0, 0 ), 0, SCH_JUNCTION_T ) != nullptr );
73
74 // Cleanup must not mark it as deleted.
75 // See: https://gitlab.com/kicad/code/kicad/-/work_items/25844
76 BOOST_CHECK( !j1->HasFlag( STRUCT_DELETED ) );
77
78 SCH_COMMIT commit2( &mgr );
79
80 SCH_LINE* h2 = h1->BreakAt( &commit2, VECTOR2I( 20, 0 ) );
81 screen.Append( h2 );
82
83 SCH_LINE* v3 = v2->BreakAt( &commit2, VECTOR2I( 20, 0 ) );
84 screen.Append( v3 );
85
86 SCH_JUNCTION* j2 = new SCH_JUNCTION( VECTOR2I( 20, 0 ) );
87 screen.Append( j2 );
88 commit2.Added( j2, &screen );
89
90 schematic.CleanUp( &commit2, &screen );
91
92 BOOST_CHECK( screen.IsExplicitJunction( VECTOR2I( 20, 0 ) ) );
93
94 // There should be four wires connected at the explicit junction j2, the two
95 // original h1, v2 and the two new segments h2, v3 after break.
96 BOOST_CHECK_EQUAL( screen.GetBusesAndWires( VECTOR2I( 20, 0 ), false ).size(), 4 );
97}
98
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
Definition commit.h:80
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:168
Holds all the data relating to one schematic.
Definition schematic.h:149
void CleanUp(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen=nullptr)
Perform routine schematic cleaning including breaking wire and buses and deleting identical objects s...
Commit for the schematic and symbol editors.
Definition sch_commit.h:54
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
SCH_LINE * BreakAt(SCH_COMMIT *aCommit, const VECTOR2I &aPoint)
Break this segment into two at the specified point.
Definition sch_line.cpp:671
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:146
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
std::vector< SCH_LINE * > GetBusesAndWires(const VECTOR2I &aPosition, bool aIgnoreEndpoints=false) const
Return buses and wires passing through aPosition.
bool IsExplicitJunction(const VECTOR2I &aPosition) const
Indicate that a junction dot is necessary at the given location.
SCH_ITEM * GetItem(const VECTOR2I &aPosition, int aAccuracy=0, KICAD_T aType=SCH_LOCATE_ANY_T) const
Check aPosition within a distance of aAccuracy for items of type aFilter.
Master controller class:
#define STRUCT_DELETED
flag indication structures to be erased
@ LAYER_WIRE
Definition layer_ids.h:480
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I v1(5, 5, 5)
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2I v2(1, 0)
VECTOR2I v3(-2, 1)
@ SCH_JUNCTION_T
Definition typeinfo.h:155
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708