From f3c6e1fb622dad5c18fa8978160114954dac380d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 24 Sep 2018 00:42:22 +0100 Subject: [PATCH] Change Position Relative To to use anchor, not centroid. Fixes: lp:1793984 * https://bugs.launchpad.net/kicad/+bug/1793984 --- pcbnew/dialogs/dialog_position_relative.cpp | 2 +- pcbnew/tools/position_relative_tool.cpp | 22 +++++++++++++-------- pcbnew/tools/position_relative_tool.h | 9 +++++---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pcbnew/dialogs/dialog_position_relative.cpp b/pcbnew/dialogs/dialog_position_relative.cpp index 0c2d9e5ed3..fe58ff1b49 100644 --- a/pcbnew/dialogs/dialog_position_relative.cpp +++ b/pcbnew/dialogs/dialog_position_relative.cpp @@ -192,7 +192,7 @@ void DIALOG_POSITION_RELATIVE::OnOkClick( wxCommandEvent& event ) POSITION_RELATIVE_TOOL* posrelTool = m_toolMgr->GetTool(); wxASSERT( posrelTool ); - posrelTool->RelativeItemSelectionMove( m_anchor_position, m_translation, 0.0 ); + posrelTool->RelativeItemSelectionMove( m_anchor_position, m_translation ); event.Skip(); } diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index d6ab6da654..f519d3990f 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -102,19 +102,25 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent ) } -int POSITION_RELATIVE_TOOL::RelativeItemSelectionMove( wxPoint anchor, wxPoint relativePosition, - double rotation ) +int POSITION_RELATIVE_TOOL::RelativeItemSelectionMove( wxPoint aPosAnchor, wxPoint aTranslation ) { - VECTOR2I rp = m_selection.GetCenter(); - wxPoint rotPoint( rp.x, rp.y ); - wxPoint translation = anchor + relativePosition - rotPoint; + wxPoint aSelAnchor( INT_MAX, INT_MAX ); + + // Find top-left item anchor in selection + for( auto item : m_selection ) + { + wxPoint itemAnchor = static_cast( item )->GetPosition(); + + if( EuclideanNorm( itemAnchor ) < EuclideanNorm( aSelAnchor ) ) + aSelAnchor = itemAnchor; + } + + wxPoint aggregateTranslation = aPosAnchor + aTranslation - aSelAnchor; for( auto item : m_selection ) { m_commit->Modify( item ); - - static_cast( item )->Rotate( rotPoint, rotation ); - static_cast( item )->Move( translation ); + static_cast( item )->Move( aggregateTranslation ); } m_commit->Push( _( "Position Relative" ) ); diff --git a/pcbnew/tools/position_relative_tool.h b/pcbnew/tools/position_relative_tool.h index 5297910c31..f65705b191 100644 --- a/pcbnew/tools/position_relative_tool.h +++ b/pcbnew/tools/position_relative_tool.h @@ -62,17 +62,18 @@ public: /** * Function SelectPositionRelativeItem() * - * Invokes the picker tool to select the item to which the previos selection will be placed relative to. + * Invokes the picker tool to select the item to which the previous selection will be placed + * relative to. */ int SelectPositionRelativeItem( const TOOL_EVENT& aEvent ); /** * Function RelativeItemSelectionMove() * - * Positions the m_position_relative_selection selection relative to anchorpostion using the given translation and rotation. - * Rotation is around the center of the selection. + * Positions the m_position_relative_selection selection relative to anchorpostion using + * the given translation. */ - int RelativeItemSelectionMove( wxPoint anchor, wxPoint translation, double rotation ); + int RelativeItemSelectionMove( wxPoint anchor, wxPoint translation ); ///> Sets up handlers for various events. void setTransitions() override;