From 9605dd8e1de3179643d075fa587efb26e31ca883 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 12 Jun 2018 10:36:41 +0200 Subject: [PATCH] Fix selection clearance for via and tracks - fixed via bounding box calculation in TRACK::GetBoundingBox() - moved clearance to TRACK::ViewBBox() - modified the Selection Tool to use EDA_ITEM::GetBoundingBox() rather than VIEW_ITEM::ViewBBox() to determine selection Fixes: lp:1776314 * https://bugs.launchpad.net/kicad/+bug/1776314 --- pcbnew/class_track.cpp | 29 ++++++++++------------------- pcbnew/class_track.h | 2 ++ pcbnew/tools/selection_tool.cpp | 4 +++- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index ccb0ac4735..98623fbad3 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -290,23 +290,11 @@ STATUS_FLAGS TRACK::IsPointOnEnds( const wxPoint& point, int min_dist ) const EDA_RECT TRACK::GetBoundingBox() const { // end of track is round, this is its radius, rounded up - int radius; - - int ymax; - int xmax; - - int ymin; - int xmin; + int radius = ( m_Width + 1 ) / 2; + int ymax, xmax, ymin, xmin; if( Type() == PCB_VIA_T ) { - // Because vias are sometimes drawn larger than their m_Width would - // provide, erasing them using a dirty rect must also compensate for this - // possibility (that the via is larger on screen than its m_Width would provide). - // Because it is cheap to return a larger BoundingBox, do it so that - // the via gets erased properly. Do not divide width by 2 for this reason. - radius = m_Width; - ymax = m_Start.y; xmax = m_Start.x; @@ -315,8 +303,6 @@ const EDA_RECT TRACK::GetBoundingBox() const } else { - radius = ( m_Width + 1 ) / 2; - ymax = std::max( m_Start.y, m_End.y ); xmax = std::max( m_Start.x, m_End.x ); @@ -324,9 +310,6 @@ const EDA_RECT TRACK::GetBoundingBox() const xmin = std::min( m_Start.x, m_End.x ); } - // + 1 is for the clearance line itself. - radius += GetClearance() + 1; - ymax += radius; xmax += radius; @@ -822,6 +805,14 @@ unsigned int TRACK::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const } +const BOX2I TRACK::ViewBBox() const +{ + BOX2I bbox( GetBoundingBox() ); + bbox.Inflate( 2 * GetClearance() ); + return bbox; +} + + void VIA::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, const wxPoint& aOffset ) { wxCHECK_RET( panel != NULL, wxT( "VIA::Draw panel cannot be NULL." ) ); diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h index a227cd8341..bf0751e161 100644 --- a/pcbnew/class_track.h +++ b/pcbnew/class_track.h @@ -304,6 +304,8 @@ public: virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; + const BOX2I ViewBBox() const override; + virtual void SwapData( BOARD_ITEM* aImage ) override; #if defined (DEBUG) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index e429a79c12..af9619c1de 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -624,7 +624,9 @@ bool SELECTION_TOOL::selectMultiple() if( windowSelection ) { - if( selectionBox.Contains( item->ViewBBox() ) ) + BOX2I bbox( item->GetBoundingBox() ); + + if( selectionBox.Contains( bbox ) ) { if( m_subtractive ) unselect( item );