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 along
17 * with this program. If not, see <http://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 SCH_LINE* h1 = new SCH_LINE( VECTOR2I( -100, 0 ), LAYER_WIRE );
36 h1->SetEndPoint( VECTOR2I( 100, 0 ) );
37 screen.Append( h1 );
38
39 SCH_LINE* v1 = new SCH_LINE( VECTOR2I( 0, -100 ), LAYER_WIRE );
40 v1->SetEndPoint( VECTOR2I( 0, 100 ) );
41 screen.Append( v1 );
42
43 SCH_LINE* v2 = new SCH_LINE( VECTOR2I( 20, -100 ), LAYER_WIRE );
44 v2->SetEndPoint( VECTOR2I( 20, 100 ) );
45 screen.Append( v2 );
46
47 TOOL_MANAGER mgr;
48 SCH_COMMIT commit( &mgr );
49
50 SCH_JUNCTION* j1 = new SCH_JUNCTION( VECTOR2I( 0, 0 ) );
51 screen.Append( j1 );
52 commit.Added( j1, &screen );
53
54 SCHEMATIC schematic( nullptr);
55 schematic.CleanUp( &commit, &screen );
56
57 BOOST_CHECK( screen.GetItem( VECTOR2I( 0, 0 ), 0, SCH_JUNCTION_T ) != nullptr );
58
59 SCH_COMMIT commit2( &mgr );
60
61 SCH_LINE* h2 = h1->BreakAt( &commit2, VECTOR2I( 20, 0 ) );
62 screen.Append( h2 );
63
64 SCH_LINE* v3 = v2->BreakAt( &commit2, VECTOR2I( 20, 0 ) );
65 screen.Append( v3 );
66
67 SCH_JUNCTION* j2 = new SCH_JUNCTION( VECTOR2I( 20, 0 ) );
68 screen.Append( j2 );
69 commit2.Added( j2, &screen );
70
71 schematic.CleanUp( &commit2, &screen );
72
73 BOOST_CHECK( screen.IsExplicitJunction( VECTOR2I( 20, 0 ) ) );
74 BOOST_CHECK_EQUAL( screen.GetBusesAndWires( VECTOR2I( 20, 0 ), false ).size(), 4 );
75}
76
78
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
Definition commit.h:84
Holds all the data relating to one schematic.
Definition schematic.h:88
void CleanUp(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen=nullptr)
Perform routine schematic cleaning including breaking wire and buses and deleting identical objects s...
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:42
SCH_LINE * BreakAt(SCH_COMMIT *aCommit, const VECTOR2I &aPoint)
Break this segment into two at the specified point.
Definition sch_line.cpp:550
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:145
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:
@ LAYER_WIRE
Definition layer_ids.h:451
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:161
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695