31 bool aBreakCrossings )
40 info.hasBusEntry =
false;
41 info.hasExplicitJunctionDot =
false;
42 info.isJunction =
false;
43 info.hasBusEntryToMultipleWires =
false;
44 info.hasBusAtPoint =
false;
46 bool breakLines[2] = {
false };
47 std::unordered_set<int> exitAngles[2];
48 std::vector<const SCH_LINE*> midPointLines[2];
51 std::list<std::unique_ptr<SCH_LINE>> mergedLines;
60 switch( item->Type() )
67 mergedLines.emplace_back(
new SCH_LINE( *line ) );
73 if( item->HitTest( aPosition, -1 ) )
74 info.hasExplicitJunctionDot =
true;
80 info.hasBusEntry =
true;
97 if( mergedLines.size() + filtered.
size() < 2 )
105 if(
info.hasExplicitJunctionDot || aBreakCrossings )
110 for(
auto it_i = mergedLines.begin(); it_i != mergedLines.end() && !merged; ++it_i )
112 for(
auto it_j = std::next( it_i ); it_j != mergedLines.end(); ++it_j )
114 if(
auto* line = ( *it_i )->MergeOverlap(
nullptr, it_j->get(),
false ) )
117 mergedLines.erase( it_j );
125 for(
const auto& line : mergedLines )
126 filtered.
insert( line.get() );
130 int uniqueAngle = 10000;
132 for(
const SCH_ITEM* item : filtered )
137 switch( item->Type() )
140 if( item->HitTest( aPosition, -1 ) )
141 info.hasExplicitJunctionDot =
true;
161 breakLines[layer] =
true;
162 exitAngles[layer].insert( line->
GetAngleFrom( aPosition ) );
164 else if( line->
HitTest( aPosition, -1 ) )
166 if( aBreakCrossings )
167 breakLines[layer] =
true;
170 midPointLines[layer].push_back( line );
173 if( layer == BUSES && line->
HitTest( aPosition, -1 ) )
174 info.hasBusAtPoint =
true;
179 if( item->IsConnected( aPosition ) )
181 breakLines[BUSES] =
true;
182 exitAngles[BUSES].insert( uniqueAngle++ );
183 breakLines[WIRES] =
true;
184 exitAngles[WIRES].insert( uniqueAngle++ );
185 info.hasBusEntry =
true;
192 if( item->IsConnected( aPosition ) )
194 breakLines[WIRES] =
true;
195 exitAngles[WIRES].insert( uniqueAngle++ );
201 if( item->IsConnected( aPosition ) )
204 breakLines[BUSES] =
true;
206 breakLines[WIRES] =
true;
213 if( item->IsConnected( aPosition ) )
214 breakLines[WIRES] =
true;
223 for(
int layer : { WIRES, BUSES } )
225 if( breakLines[layer] )
227 for(
const SCH_LINE* line : midPointLines[layer] )
229 exitAngles[layer].insert( line->GetAngleFrom( aPosition ) );
230 exitAngles[layer].insert( line->GetReverseAngleFrom( aPosition ) );
235 if(
info.hasBusEntry )
240 info.hasBusEntryToMultipleWires = exitAngles[WIRES].size() > 2 && exitAngles[BUSES].size() == 1;
244 info.isJunction = exitAngles[WIRES].size() >= 3 || exitAngles[BUSES].size() >= 3;
251 const std::vector<SCH_ITEM*>& aItems )
258 if( !item->IsConnectable() )
267 if( !item || !item->IsConnectable() )
273 std::vector<VECTOR2I> pts;
277 if( !item || !item->IsConnectable() )
280 std::vector<VECTOR2I> new_pts = item->GetConnectionPoints();
281 pts.insert( pts.end(), new_pts.begin(), new_pts.end() );
287 for(
const VECTOR2I& pt : connections )
295 std::sort( pts.begin(), pts.end(),
298 return a.x < b.x || ( a.x == b.x && a.y < b.y );
301 pts.erase( std::unique( pts.begin(), pts.end() ), pts.end() );
303 std::vector<SCH_JUNCTION*> jcts;
309 if(
info.isJunction && ( !
info.hasBusEntry ||
info.hasBusEntryToMultipleWires ) )
313 if(
info.hasBusAtPoint )
316 jcts.push_back( junction );
Implement an R-tree for fast spatial and type indexing of schematic items.
size_t size() const
Return the number of items in the tree.
EE_TYPE Overlapping(const BOX2I &aRect) const
void insert(SCH_ITEM *aItem)
Insert an item into the tree.
static bool IsBusLabel(const wxString &aLabel)
Test if aLabel has a bus notation.
Base class for any item which can be embedded within the SCHEMATIC container class,...
void SetLayer(SCH_LAYER_ID aLayer)
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
bool IsConnected(const VECTOR2I &aPoint) const
Test the item to see if it is connected to aPoint.
Segment description base class to describe items which have 2 end points (track, wire,...
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
int GetAngleFrom(const VECTOR2I &aPoint) const
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
bool IsConnectable() const override
EE_RTREE & Items()
Get the full RTree, usually for iterating.
std::vector< VECTOR2I > GetConnections() const
Collect a unique list of all possible connection points in the schematic.
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
std::vector< SCH_JUNCTION * > PreviewJunctions(const class SCH_SCREEN *aScreen, const std::vector< class SCH_ITEM * > &aItems)
Determine the points where explicit junctions would be required if the given temporary items were com...
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...
bool IsPointOnSegment(const VECTOR2I &aSegStart, const VECTOR2I &aSegEnd, const VECTOR2I &aTestPoint)
Test if aTestPoint is on line defined by aSegStart and aSegEnd.
VECTOR2< int32_t > VECTOR2I