diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index 6019940d89..ff821be08c 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -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(); + 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( 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 ) { diff --git a/pcbnew/tools/position_relative_tool.h b/pcbnew/tools/position_relative_tool.h index 322be8a1ff..126457cb98 100644 --- a/pcbnew/tools/position_relative_tool.h +++ b/pcbnew/tools/position_relative_tool.h @@ -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 m_commit;