Position relative: store discarded pad for use as the selection anchor

Fixes https://gitlab.com/kicad/code/kicad/-/issues/6996
This commit is contained in:
Jon Evans 2021-01-17 14:25:43 -05:00
parent 95ca5a0233
commit 6bb9aeab4b
2 changed files with 15 additions and 6 deletions

View File

@ -62,10 +62,16 @@ bool POSITION_RELATIVE_TOOL::Init()
}
// TODO: Clean up this global once TOOL_EVENT supports std::functions as parameters
BOARD_ITEM* g_PositionRelativePadAnchor;
int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent )
{
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
g_PositionRelativePadAnchor = nullptr;
const auto& selection = m_selectionTool->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
{
@ -86,6 +92,8 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent )
if( !aCollector.HasItem( item->GetParent() ) )
to_add.insert( item->GetParent() );
g_PositionRelativePadAnchor = item;
aCollector.Remove( item );
}
}
@ -100,6 +108,11 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent )
m_selection = selection;
if( g_PositionRelativePadAnchor )
m_selectionAnchor = static_cast<PAD*>( g_PositionRelativePadAnchor )->GetPosition();
else
m_selectionAnchor = m_selection.GetTopLeftItem()->GetPosition();
// The dialog is not modal and not deleted between calls.
// It means some options can have changed since the last call.
// Therefore we need to rebuild it in case UI units have changed since the last call.
@ -117,11 +130,6 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent )
return 0;
}
wxPoint POSITION_RELATIVE_TOOL::GetSelectionAnchorPosition() const
{
return m_selection.GetTopLeftItem()->GetPosition();
}
int POSITION_RELATIVE_TOOL::RelativeItemSelectionMove( wxPoint aPosAnchor, wxPoint aTranslation )
{

View File

@ -73,7 +73,7 @@ public:
* Returns the postion of the selected item(s)
*
*/
wxPoint GetSelectionAnchorPosition() const;
wxPoint GetSelectionAnchorPosition() const { return m_selectionAnchor; }
/**
* Function RelativeItemSelectionMove()
@ -91,6 +91,7 @@ private:
PCB_SELECTION_TOOL* m_selectionTool;
PCB_SELECTION m_selection;
wxPoint m_selectionAnchor;
std::unique_ptr<BOARD_COMMIT> m_commit;