diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index ba084b9645..bd951806a6 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -323,22 +323,7 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent ) dir = m_view->ToWorld( dir, false ); m_view->SetCenter( m_view->GetCenter() + dir * m_settings.m_autoPanSpeed ); - // Notify tools that the cursor position has changed in the world coordinates - wxMouseEvent moveEvent( EVT_REFRESH_MOUSE ); - - // Set the modifiers state -#if wxCHECK_VERSION( 3, 0, 0 ) - moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) ); - moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) ); - moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) ); -#else - // wx <3.0 do not have accessors, but the fields are exposed - moveEvent.m_controlDown = wxGetKeyState( WXK_CONTROL ); - moveEvent.m_shiftDown = wxGetKeyState( WXK_SHIFT ); - moveEvent.m_altDown = wxGetKeyState( WXK_ALT ); -#endif - - wxPostEvent( m_parentPanel, moveEvent ); + refreshMouse(); } break; @@ -477,6 +462,8 @@ void WX_VIEW_CONTROLS::WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordin { m_parentPanel->WarpPointer( aPosition.x, aPosition.y ); } + + refreshMouse(); } @@ -554,6 +541,27 @@ bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent ) } +void WX_VIEW_CONTROLS::refreshMouse() const +{ + // Notify tools that the cursor position has changed in the world coordinates + wxMouseEvent moveEvent( EVT_REFRESH_MOUSE ); + + // Set the modifiers state +#if wxCHECK_VERSION( 3, 0, 0 ) + moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) ); + moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) ); + moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) ); +#else + // wx <3.0 do not have accessors, but the fields are exposed + moveEvent.m_controlDown = wxGetKeyState( WXK_CONTROL ); + moveEvent.m_shiftDown = wxGetKeyState( WXK_SHIFT ); + moveEvent.m_altDown = wxGetKeyState( WXK_ALT ); +#endif + + wxPostEvent( m_parentPanel, moveEvent ); +} + + void WX_VIEW_CONTROLS::UpdateScrollbars() { const BOX2D viewport = m_view->GetViewport(); diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index f1506bcde8..f675caef1f 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -113,6 +113,13 @@ private: */ bool handleAutoPanning( const wxMouseEvent& aEvent ); + /** + * Sends an event to refresh mouse position. It is mostly used for notifying the tools + * that the cursor position in the world coordinates has changed, whereas the screen coordinates + * remained the same (e.g. frame edge autopanning). + */ + void refreshMouse() const; + /// Current state of VIEW_CONTROLS STATE m_state; diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 786414bd7f..210dbb13a2 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -1096,17 +1096,21 @@ int SELECTION_TOOL::findMove( const TOOL_EVENT& aEvent ) if( module ) { + KIGFX::VIEW_CONTROLS* viewCtrls = getViewControls(); clearSelection(); toggleSelection( module ); + auto cursorPosition = viewCtrls->GetCursorPosition( false ); + // Place event on module origin first, so the generic anchor snap // doesn't just choose the closest pin for us - // Don't warp the view - we want the component to - // "teleport" to cursor, not move to the components position - getViewControls()->ForceCursorPosition( true, module->GetPosition() ); + viewCtrls->ForceCursorPosition( true, module->GetPosition() ); // pick the component up and start moving m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" ); + + // restore the previous cursor position + viewCtrls->SetCursorPosition( cursorPosition, false ); } return 0;