From 9c80d63b5c8a613a77713eab0f5292520fa1bcc2 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 2 May 2017 16:44:41 +1000 Subject: [PATCH] Fixed HitTest for text and modules --- include/eda_text.h | 4 ++-- pcbnew/class_module.cpp | 22 +++++++++++++++++++++- pcbnew/class_text_mod.cpp | 29 +++++++++++++++++++++++++++++ pcbnew/class_text_mod.h | 4 ++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/include/eda_text.h b/include/eda_text.h index a20aacc950..e0bbf594e1 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -260,7 +260,7 @@ public: * @param aAccuracy - Amount to inflate the bounding box. * @return bool - true if a hit, else false */ - bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const; + virtual bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const; /** * Function TextHitTest (overloaded) @@ -271,7 +271,7 @@ public: * @param aAccuracy - Amount to inflate the bounding box. * @return bool - true if a hit, else false */ - bool TextHitTest( const EDA_RECT& aRect, bool aContains = false, int aAccuracy = 0 ) const; + virtual bool TextHitTest( const EDA_RECT& aRect, bool aContains = false, int aAccuracy = 0 ) const; /** * Function LenSize diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index ecfcd9a8f1..b79ae81acd 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -614,7 +614,27 @@ bool MODULE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) co if( aContained ) return arect.Contains( m_BoundaryBox ); else - return m_BoundaryBox.Intersects( arect ); + { + // If the rect does not intersect the bounding box, skip any tests + if( !aRect.Intersects( GetBoundingBox() ) ) + return false; + + // Determine if any elements in the MODULE intersect the rect + for( D_PAD* pad = m_Pads; pad; pad = pad->Next() ) + { + if( pad->HitTest( arect, false, 0 ) ) + return true; + } + + for( BOARD_ITEM* item = m_Drawings; item; item = item->Next() ) + { + if( item->HitTest( arect, false, 0 ) ) + return true; + } + + // No items were hit + return false; + } } diff --git a/pcbnew/class_text_mod.cpp b/pcbnew/class_text_mod.cpp index 8aec4465f1..9d807b5b59 100644 --- a/pcbnew/class_text_mod.cpp +++ b/pcbnew/class_text_mod.cpp @@ -89,6 +89,35 @@ void TEXTE_MODULE::SetTextAngle( double aAngle ) EDA_TEXT::SetTextAngle( NormalizeAngle360( aAngle ) ); } +bool TEXTE_MODULE::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const +{ + EDA_RECT rect = GetTextBox( -1 ); + wxPoint location = aPoint; + + rect.Inflate( aAccuracy ); + + RotatePoint( &location, GetTextPos(), -GetDrawRotation() ); + + return rect.Contains( location ); +} + +bool TEXTE_MODULE::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const +{ + EDA_RECT rect = aRect; + + rect.Inflate( aAccuracy ); + + if( aContains ) + { + return rect.Contains( GetBoundingBox() ); + } + else + { + return rect.Intersects( GetTextBox( -1 ), GetDrawRotation() ); + } + +} + void TEXTE_MODULE::Rotate( const wxPoint& aRotCentre, double aAngle ) { diff --git a/pcbnew/class_text_mod.h b/pcbnew/class_text_mod.h index 9c4c9ae217..80d24b7350 100644 --- a/pcbnew/class_text_mod.h +++ b/pcbnew/class_text_mod.h @@ -184,6 +184,10 @@ public: void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override; + virtual bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const override; + + virtual bool TextHitTest( const EDA_RECT& aRect, bool aContains = false, int aAccuracy = 0 ) const override; + virtual bool HitTest( const wxPoint& aPosition ) const override { return TextHitTest( aPosition );