diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index 5ea82ae45b..fcf5d7cb00 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -325,24 +325,9 @@ bool SCH_EDIT_FRAME::BreakSegments( const VECTOR2I& aPoint, SCH_SCREEN* aScreen if( aScreen == nullptr ) aScreen = GetScreen(); - bool brokenSegments = false; - std::vector wires; + bool brokenSegments = false; - for( SCH_ITEM* item : aScreen->Items().Overlapping( SCH_LINE_T, aPoint ) ) - { - if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } ) ) - { - SCH_LINE* wire = static_cast( item ); - - if( IsPointOnSegment( wire->GetStartPoint(), wire->GetEndPoint(), aPoint ) - && !wire->IsEndPoint( aPoint ) ) - { - wires.push_back( wire ); - } - } - } - - for( SCH_LINE* wire : wires ) + for( SCH_LINE* wire : aScreen->GetBusesAndWires( aPoint, true ) ) { BreakSegment( wire, aPoint, nullptr, aScreen ); brokenSegments = true; diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 44ef16fb88..1f41ca6701 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -1382,6 +1382,29 @@ SCH_LINE* SCH_SCREEN::GetLine( const VECTOR2I& aPosition, int aAccuracy, int aLa } +std::vector SCH_SCREEN::GetBusesAndWires( const VECTOR2I& aPosition, + bool aIgnoreEndpoints ) const +{ + std::vector retVal; + + for( SCH_ITEM* item : Items().Overlapping( SCH_LINE_T, aPosition ) ) + { + if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } ) ) + { + SCH_LINE* wire = static_cast( item ); + + if( aIgnoreEndpoints && wire->IsEndPoint( aPosition ) ) + continue; + + if( IsPointOnSegment( wire->GetStartPoint(), wire->GetEndPoint(), aPosition ) ) + retVal.push_back( wire ); + } + } + + return retVal; +} + + SCH_LABEL_BASE* SCH_SCREEN::GetLabel( const VECTOR2I& aPosition, int aAccuracy ) const { for( SCH_ITEM* item : Items().Overlapping( aPosition, aAccuracy ) ) diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index 36dba2cf19..9ce15fbcd0 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -436,6 +436,15 @@ public: return GetLine( aPosition, aAccuracy, LAYER_BUS, aSearchType ); } + /** + * Return buses and wires passing through aPosition. + * + * @param aPosition Position to search for + * @param aIgnoreEndpoints If true, ignore wires/buses with end points matching aPosition + * @return Buses and wires + */ + std::vector GetBusesAndWires( const VECTOR2I& aPosition, bool aIgnoreEndpoints = false ) const; + /** * Return a label item located at \a aPosition. *