From 599a33a9c6afe168b843079ac75fa089b8999e73 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 2 Dec 2020 22:31:01 +0000 Subject: [PATCH] Make PLEditor greedy selections of rectangles sparse. Fixes https://gitlab.com/kicad/code/kicad/issues/6278 --- common/page_layout/ws_draw_item.cpp | 38 +++++++++++++++++++++++++++++ include/page_layout/ws_draw_item.h | 1 + 2 files changed, 39 insertions(+) diff --git a/common/page_layout/ws_draw_item.cpp b/common/page_layout/ws_draw_item.cpp index faad54cd26..70f581e11d 100644 --- a/common/page_layout/ws_draw_item.cpp +++ b/common/page_layout/ws_draw_item.cpp @@ -352,6 +352,44 @@ bool WS_DRAW_ITEM_RECT::HitTest( const wxPoint& aPosition, int aAccuracy ) const } +bool WS_DRAW_ITEM_RECT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const +{ + EDA_RECT sel = aRect; + + if ( aAccuracy ) + sel.Inflate( aAccuracy ); + + if( aContained ) + return sel.Contains( GetBoundingBox() ); + + // For greedy we need to check each side of the rect as we're pretty much always inside the + // rect which defines the worksheet frame. + EDA_RECT side = GetBoundingBox(); + side.SetHeight( 0 ); + + if( sel.Intersects( side ) ) + return true; + + side.SetY( GetBoundingBox().GetBottom() ); + + if( sel.Intersects( side ) ) + return true; + + side = GetBoundingBox(); + side.SetWidth( 0 ); + + if( sel.Intersects( side ) ) + return true; + + side.SetX( GetBoundingBox().GetRight() ); + + if( sel.Intersects( side ) ) + return true; + + return false; +} + + wxString WS_DRAW_ITEM_RECT::GetSelectMenuText( EDA_UNITS aUnits ) const { return wxString::Format( _( "Rectangle, width %s height %s" ), diff --git a/include/page_layout/ws_draw_item.h b/include/page_layout/ws_draw_item.h index 34c6b21c86..4c6e0ddc32 100644 --- a/include/page_layout/ws_draw_item.h +++ b/include/page_layout/ws_draw_item.h @@ -226,6 +226,7 @@ public: const EDA_RECT GetBoundingBox() const override; bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override; + bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override; wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;