From 08c4a0bc7b7c5dc8586f64d6cc19ae921c839070 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 12 Jul 2017 09:34:20 +0200 Subject: [PATCH] Fixed SELECTION_TOOL::selectCursor() In the previous version the method did not work correctly when an action was invoked from context menu. In such case, the cursor position was obtained in the moment of selecting the action, instead of using the right click location. --- common/view/wx_view_controls.cpp | 4 ++-- include/view/view_controls.h | 16 ++++++++++++++-- include/view/wx_view_controls.h | 4 +++- pcbnew/tools/selection_tool.cpp | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index ffdcb12024..0699c471b2 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -362,7 +362,7 @@ VECTOR2D WX_VIEW_CONTROLS::GetMousePosition( bool aWorldCoordinates ) const } -VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition() const +VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition( bool aEnableSnapping ) const { if( m_settings.m_forceCursorPosition ) { @@ -372,7 +372,7 @@ VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition() const { VECTOR2D mousePosition = GetMousePosition(); - if( m_settings.m_snappingEnabled ) + if( aEnableSnapping ) return m_view->GetGAL()->GetGridPoint( mousePosition ); else return mousePosition; diff --git a/include/view/view_controls.h b/include/view/view_controls.h index 21e78f1b7a..7f64d5febe 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -166,14 +166,26 @@ public: virtual VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const = 0; /** - * Function GetCursorPosition() * Returns the current cursor position in world coordinates. Note, that it may be * different from the mouse pointer position if snapping is enabled or cursor position * is forced to a specific point. * * @return The current cursor position in world coordinates. */ - virtual VECTOR2D GetCursorPosition() const = 0; + VECTOR2D GetCursorPosition() const + { + return GetCursorPosition( m_settings.m_snappingEnabled ); + } + + /** + * Returns the current cursor position in world coordinates. Note, that it may be + * different from the mouse pointer position if snapping is enabled or cursor position + * is forced to a specific point. + * + * @param aEnableSnapping selects whether cursor position should be snapped to the grid. + * @return The current cursor position in world coordinates. + */ + virtual VECTOR2D GetCursorPosition( bool aEnableSnapping ) const = 0; /** * Function ForceCursorPosition() diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index 66ea86a3d8..5aaedcf4bc 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -73,8 +73,10 @@ public: /// @copydoc VIEW_CONTROLS::GetMousePosition() VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const override; + using VIEW_CONTROLS::GetCursorPosition; + /// @copydoc VIEW_CONTROLS::GetCursorPosition() - VECTOR2D GetCursorPosition() const override; + VECTOR2D GetCursorPosition( bool aSnappingEnabled ) const override; /// @copydoc VIEW_CONTROLS::CursorWarp() void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false, diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index f024b8ead1..8fa5c83ab9 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -472,7 +472,7 @@ bool SELECTION_TOOL::selectCursor( bool aSelectAlways ) if( aSelectAlways || m_selection.Empty() ) { clearSelection(); - selectPoint( getViewControls()->GetMousePosition() ); + selectPoint( getViewControls()->GetCursorPosition( false ) ); } return !m_selection.Empty();