diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 647c73878e..82650c7f50 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -37,6 +37,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -44,16 +50,10 @@ #include #include using namespace std::placeholders; -#include "pcb_actions.h" -#include "selection_tool.h" -#include "edit_tool.h" -#include "pcbnew_picker_tool.h" -#include "grid_helper.h" #include "kicad_clipboard.h" #include #include #include -#include #include #include @@ -192,9 +192,27 @@ bool EDIT_TOOL::Init() } +int EDIT_TOOL::GetAndPlace( const TOOL_EVENT& aEvent ) +{ + SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + MODULE* module = getEditFrame()->GetFootprintFromBoardByReference(); + + if( module ) + { + m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); + m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, (void*) module ); + + selectionTool->GetSelection().SetReferencePoint( module->GetPosition() ); + m_toolMgr->RunAction( PCB_ACTIONS::move, true ); + } + + return 0; +} + + bool EDIT_TOOL::invokeInlineRouter( int aDragMode ) { - auto theRouter = static_cast( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) ); + ROUTER_TOOL* theRouter = m_toolMgr->GetTool(); if( !theRouter ) return false; @@ -1393,6 +1411,7 @@ int EDIT_TOOL::cutToClipboard( const TOOL_EVENT& aEvent ) void EDIT_TOOL::setTransitions() { + Go( &EDIT_TOOL::GetAndPlace, PCB_ACTIONS::getAndPlace.MakeEvent() ); Go( &EDIT_TOOL::Move, PCB_ACTIONS::move.MakeEvent() ); Go( &EDIT_TOOL::Drag, PCB_ACTIONS::drag45Degree.MakeEvent() ); Go( &EDIT_TOOL::Drag, PCB_ACTIONS::dragFreeAngle.MakeEvent() ); diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index 89a0fe3ca1..b5e23f727f 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -74,8 +74,11 @@ public: /// @copydoc TOOL_INTERACTIVE::Init() bool Init() override; + ///> Find an item and start moving. + int GetAndPlace( const TOOL_EVENT& aEvent ); + /** - * Function Main() + * Function Move() * Main loop in which events are handled. */ int Move( const TOOL_EVENT& aEvent ); diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index 1d19e360e5..7e26276cdd 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include OPT PCB_ACTIONS::TranslateLegacyId( int aId ) @@ -180,6 +179,13 @@ TOOL_ACTION PCB_ACTIONS::editFootprintInFpEditor( "pcbnew.InteractiveEdit.EditFp _( "Opens the selected footprint in the Footprint Editor" ), module_editor_xpm ); +TOOL_ACTION PCB_ACTIONS::getAndPlace( "pcbnew.InteractiveEdit.FindMove", + AS_GLOBAL, + 'T', LEGACY_HK_NAME( "Get and Move Footprint" ), + _( "Get and Move Footprint" ), + _( "Selects a footprint by reference and places it under the cursor for moving"), + move_xpm ); + TOOL_ACTION PCB_ACTIONS::move( "pcbnew.InteractiveMove.move", AS_GLOBAL, 'M', LEGACY_HK_NAME( "Move Item" ), @@ -1035,13 +1041,6 @@ TOOL_ACTION PCB_ACTIONS::selectSameSheet( "pcbnew.InteractiveSelection.SelectSam _( "Selects all modules and tracks in the same schematic sheet" ), select_same_sheet_xpm ); -TOOL_ACTION PCB_ACTIONS::getAndPlace( "pcbnew.InteractiveSelection.FindMove", - AS_GLOBAL, - 'T', LEGACY_HK_NAME( "Get and Move Footprint" ), - _( "Get and Move Footprint" ), - _( "Selects a footprint by reference and places it under the cursor for moving"), - move_xpm ); - TOOL_ACTION PCB_ACTIONS::filterSelection( "pcbnew.InteractiveSelection.FilterSelection", AS_GLOBAL, 0, "", _( "Filter Selection..." ), _( "Filter the types of items in the selection" ), diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 555ee117b4..bc25ec6bf2 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -1107,31 +1107,6 @@ int SELECTION_TOOL::find( const TOOL_EVENT& aEvent ) } -int SELECTION_TOOL::GetAndPlace( const TOOL_EVENT& aEvent ) -{ - MODULE* module = m_frame->GetFootprintFromBoardByReference(); - - if( module ) - { - KIGFX::VIEW_CONTROLS* viewCtrls = getViewControls(); - clearSelection(); - select( module ); - m_toolMgr->ProcessEvent( EVENTS::SelectedEvent ); - - auto cursorPosition = viewCtrls->GetCursorPosition( false ); - - // Set a reference point so InteractiveEdit will move it to the - // cursor before waiting for mouse move events - m_selection.SetReferencePoint( module->GetPosition() ); - - // pick the component up and start moving - m_toolMgr->RunAction( PCB_ACTIONS::move, true ); - } - - return 0; -} - - /** * Function itemIsIncludedByFilter() * @@ -2202,7 +2177,6 @@ void SELECTION_TOOL::setTransitions() Go( &SELECTION_TOOL::SelectionMenu, PCB_ACTIONS::selectionMenu.MakeEvent() ); Go( &SELECTION_TOOL::find, ACTIONS::find.MakeEvent() ); - Go( &SELECTION_TOOL::GetAndPlace, PCB_ACTIONS::getAndPlace.MakeEvent() ); Go( &SELECTION_TOOL::filterSelection, PCB_ACTIONS::filterSelection.MakeEvent() ); Go( &SELECTION_TOOL::selectConnection, PCB_ACTIONS::selectConnection.MakeEvent() ); diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index cf78b09f2a..a52b86b398 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -258,9 +258,6 @@ private: ///> Find an item. int find( const TOOL_EVENT& aEvent ); - ///> Find an item and start moving. - int GetAndPlace( const TOOL_EVENT& aEvent ); - ///> Invoke filter dialog and modify current selection int filterSelection( const TOOL_EVENT& aEvent );