Move some functions out of SELECTION_TOOL that don't really belong there.

This commit is contained in:
Jeff Young 2019-08-13 13:29:18 +01:00
parent dd938b02df
commit 045f5f6a61
5 changed files with 37 additions and 45 deletions

View File

@ -37,6 +37,12 @@
#include <pcbnew_id.h>
#include <status_popup.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <tools/selection_tool.h>
#include <tools/edit_tool.h>
#include <tools/pcbnew_picker_tool.h>
#include <tools/tool_event_utils.h>
#include <tools/grid_helper.h>
#include <view/view_controls.h>
#include <connectivity/connectivity_data.h>
#include <confirm.h>
@ -44,16 +50,10 @@
#include <cassert>
#include <functional>
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 <router/router_tool.h>
#include <dialogs/dialog_move_exact.h>
#include <dialogs/dialog_track_via_properties.h>
#include <tools/tool_event_utils.h>
#include <preview_items/ruler_item.h>
#include <board_commit.h>
@ -192,9 +192,27 @@ bool EDIT_TOOL::Init()
}
int EDIT_TOOL::GetAndPlace( const TOOL_EVENT& aEvent )
{
SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
MODULE* module = getEditFrame<PCB_BASE_FRAME>()->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<ROUTER_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) );
ROUTER_TOOL* theRouter = m_toolMgr->GetTool<ROUTER_TOOL>();
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() );

View File

@ -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 );

View File

@ -28,7 +28,6 @@
#include <bitmaps.h>
#include <layers_id_colors_and_visibility.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <router/pns_router.h>
OPT<TOOL_EVENT> 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" ),

View File

@ -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() );

View File

@ -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 );