From 56ccaf6482b2b4fb66f6006d326e377e142e3e8d Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 6 Sep 2021 07:05:25 -0700 Subject: [PATCH] Constrain move tool when set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move tool works slightly differently from other tools when figuring out new locations. This uses the global 45 enable flag to set proper item locations when the user is requesting a 45° constraint on movement --- pcbnew/tools/edit_tool.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index eb139efb9b..9de4c9c744 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -838,6 +838,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) } bool restore_state = false; + VECTOR2I originalPos; VECTOR2I totalMovement; PCB_GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() ); TOOL_EVENT* evt = &aEvent; @@ -885,6 +886,15 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) m_cursor.x = prevPos.x; } + if( !selection.HasReferencePoint() ) + originalPos = m_cursor; + + if( Is45Limited() ) + { + VECTOR2I moveVector = m_cursor - originalPos; + m_cursor = originalPos + GetVectorSnapped45( moveVector ); + } + controls->ForceCursorPosition( true, m_cursor ); selection.SetReferencePoint( m_cursor ); @@ -965,6 +975,12 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) // start moving with the reference point attached to the cursor grid.SetAuxAxes( false ); + if( Is45Limited() ) + { + VECTOR2I moveVector = m_cursor - originalPos; + m_cursor = originalPos + GetVectorSnapped45( moveVector ); + } + movement = m_cursor - selection.GetReferencePoint(); // Drag items to the current cursor position @@ -1005,6 +1021,9 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) selection.SetReferencePoint( m_cursor ); grid.SetAuxAxes( true, m_cursor ); } + + originalPos = m_cursor; + } controls->SetCursorPosition( m_cursor, false );