KiCad PCB EDA Suite
Loading...
Searching...
No Matches
junction_helpers.cpp
Go to the documentation of this file.
1#include "junction_helpers.h"
2
3#include <sch_line.h>
4
5using namespace JUNCTION_HELPERS;
6
8 bool aBreakCrossings )
9{
10 enum layers
11 {
12 WIRES = 0,
13 BUSES
14 };
15
17 info.hasBusEntry = false;
18 info.hasExplicitJunctionDot = false;
19 info.isJunction = false;
20 info.hasBusEntryToMultipleWires = false;
21
22 bool breakLines[2] = { false };
23 std::unordered_set<int> exitAngles[2];
24 std::vector<const SCH_LINE*> midPointLines[2];
25
26 // A pin at 90° still shouldn't match a line at 90° so just give pins unique numbers
27 int uniqueAngle = 10000;
28
29 for( const SCH_ITEM* item : aItems.Overlapping( aPosition ) )
30 {
31 if( item->GetEditFlags() & STRUCT_DELETED )
32 continue;
33
34 switch( item->Type() )
35 {
36 case SCH_JUNCTION_T:
37 if( item->HitTest( aPosition, -1 ) )
38 info.hasExplicitJunctionDot = true;
39
40 break;
41
42 case SCH_LINE_T:
43 {
44 const SCH_LINE* line = static_cast<const SCH_LINE*>( item );
45 int layer;
46
47 if( line->GetStartPoint() == line->GetEndPoint() )
48 break;
49 else if( line->GetLayer() == LAYER_WIRE )
50 layer = WIRES;
51 else if( line->GetLayer() == LAYER_BUS )
52 layer = BUSES;
53 else
54 break;
55
56 if( line->IsConnected( aPosition ) )
57 {
58 breakLines[layer] = true;
59 exitAngles[layer].insert( line->GetAngleFrom( aPosition ) );
60 }
61 else if( line->HitTest( aPosition, -1 ) )
62 {
63 if( aBreakCrossings )
64 breakLines[layer] = true;
65
66 // Defer any line midpoints until we know whether or not we're breaking them
67 midPointLines[layer].push_back( line );
68 }
69 }
70 break;
71
73 if( item->IsConnected( aPosition ) )
74 {
75 breakLines[BUSES] = true;
76 exitAngles[BUSES].insert( uniqueAngle++ );
77 breakLines[WIRES] = true;
78 exitAngles[WIRES].insert( uniqueAngle++ );
79 info.hasBusEntry = true;
80 }
81
82 break;
83
84 case SCH_SYMBOL_T:
85 case SCH_SHEET_T:
86 if( item->IsConnected( aPosition ) )
87 {
88 breakLines[WIRES] = true;
89 exitAngles[WIRES].insert( uniqueAngle++ );
90 }
91
92 break;
93
94 default: break;
95 }
96 }
97
98 for( int layer : { WIRES, BUSES } )
99 {
100 if( breakLines[layer] )
101 {
102 for( const SCH_LINE* line : midPointLines[layer] )
103 {
104 exitAngles[layer].insert( line->GetAngleFrom( aPosition ) );
105 exitAngles[layer].insert( line->GetReverseAngleFrom( aPosition ) );
106 }
107 }
108 }
109
110 if( info.hasBusEntry )
111 {
112 // The bus entry and one wire is 2 wires, and the one entry is exactly one bus
113 // Any more wires must be multiple wires, but any more buses means a wire
114 // crossing at the bus entry root.
115 info.hasBusEntryToMultipleWires =
116 exitAngles[WIRES].size() > 2 && exitAngles[BUSES].size() == 1;
117 }
118
119 // Any three things of the same type is a junction of some sort
120 info.isJunction = exitAngles[WIRES].size() >= 3 || exitAngles[BUSES].size() >= 3;
121
122 return info;
123}
Implements an R-tree for fast spatial and type indexing of schematic items.
Definition: sch_rtree.h:40
EE_TYPE Overlapping(const BOX2I &aRect) const
Definition: sch_rtree.h:243
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:281
bool IsConnected(const VECTOR2I &aPoint) const
Test the item to see if it is connected to aPoint.
Definition: sch_item.cpp:207
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
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:809
int GetAngleFrom(const VECTOR2I &aPoint) const
Definition: sch_line.cpp:422
VECTOR2I GetEndPoint() const
Definition: sch_line.h:141
VECTOR2I GetStartPoint() const
Definition: sch_line.h:136
#define STRUCT_DELETED
flag indication structures to be erased
@ LAYER_WIRE
Definition: layer_ids.h:356
@ LAYER_BUS
Definition: layer_ids.h:357
POINT_INFO AnalyzePoint(const EE_RTREE &aItem, const VECTOR2I &aPosition, bool aBreakCrossings)
Check a tree of items for a confluence at a given point and work out what kind of junction it is,...
A selection of information about a point in the schematic that might be eligible for turning into a j...
@ SCH_LINE_T
Definition: typeinfo.h:163
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ SCH_SHEET_T
Definition: typeinfo.h:174
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:161
@ SCH_JUNCTION_T
Definition: typeinfo.h:159