pcbnew: Fix via snapping to multiple tracks

Rather than selecting an arbitrary track to snap, we select the closest
track to our point, allowing the via to be placed along the full track
length.

Fixes: lp:1813324
* https://bugs.launchpad.net/kicad/+bug/1813324
This commit is contained in:
Seth Hillbrand 2019-01-25 07:12:04 -08:00
parent ff9d814fbd
commit 184711beb4
2 changed files with 20 additions and 4 deletions

View File

@ -1507,6 +1507,7 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items; std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> items;
BOX2I bbox = aVia->GetBoundingBox(); BOX2I bbox = aVia->GetBoundingBox();
auto view = m_frame->GetGalCanvas()->GetView(); auto view = m_frame->GetGalCanvas()->GetView();
std::vector<TRACK*> possible_tracks;
view->Query( bbox, items ); view->Query( bbox, items );
@ -1521,11 +1522,26 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
{ {
if( TestSegmentHit( aVia->GetPosition(), track->GetStart(), track->GetEnd(), if( TestSegmentHit( aVia->GetPosition(), track->GetStart(), track->GetEnd(),
( track->GetWidth() + aVia->GetWidth() ) / 2 ) ) ( track->GetWidth() + aVia->GetWidth() ) / 2 ) )
return track; possible_tracks.push_back( track );
} }
} }
return nullptr; TRACK* return_track = nullptr;
int min_d = std::numeric_limits<int>::max();
for( auto track : possible_tracks )
{
SEG test( track->GetStart(), track->GetEnd() );
auto dist = ( test.NearestPoint( aVia->GetPosition() ) -
VECTOR2I( aVia->GetPosition() ) ).EuclideanNorm();
if( dist < min_d )
{
min_d = dist;
return_track = track;
}
}
return return_track;
} }

View File

@ -160,8 +160,8 @@ VECTOR2I GRID_HELPER::AlignToSegment( const VECTOR2I& aPoint, const SEG& aSeg )
pts[0] = aSeg.A; pts[0] = aSeg.A;
pts[1] = aSeg.B; pts[1] = aSeg.B;
pts[2] = aSeg.IntersectLines( SEG( nearest, nearest + VECTOR2I( 1, 0 ) ) ); pts[2] = aSeg.IntersectLines( SEG( nearest + VECTOR2I( -1, 1 ), nearest + VECTOR2I( 1, -1 ) ) );
pts[3] = aSeg.IntersectLines( SEG( nearest, nearest + VECTOR2I( 0, 1 ) ) ); pts[3] = aSeg.IntersectLines( SEG( nearest + VECTOR2I( -1, -1 ), nearest + VECTOR2I( 1, 1 ) ) );
int min_d = std::numeric_limits<int>::max(); int min_d = std::numeric_limits<int>::max();