Put cursor and pan control in libcommon/tool, enable in Gerbview

Put the cursor and pan control TOOL_ACTIONs in ACTION,
and refer to them in that way.

The handlers are currently identical in Pcbnew and Cvpcb,
and Gerbview (and all canvases) can benefit from them as well
if they are in libcommon. Also saves duplicated code.

Fixes: lp:1795855
* https://bugs.launchpad.net/kicad/+bug/1795855
This commit is contained in:
John Beard 2018-10-03 17:26:33 +01:00 committed by jean-pierre charras
parent 03e642a8db
commit 445a9fa963
11 changed files with 206 additions and 369 deletions

View File

@ -47,6 +47,66 @@ TOOL_ACTION ACTIONS::centerContents( "common.Control.centerContents",
AS_GLOBAL, 0, AS_GLOBAL, 0,
"", "" ); "", "" );
// Cursor control
TOOL_ACTION ACTIONS::cursorUp( "common.Control.cursorUp",
AS_GLOBAL, WXK_UP,
"", "", NULL, AF_NONE, (void*) CURSOR_UP );
TOOL_ACTION ACTIONS::cursorDown( "common.Control.cursorDown",
AS_GLOBAL, WXK_DOWN,
"", "" , NULL, AF_NONE, (void*) CURSOR_DOWN );
TOOL_ACTION ACTIONS::cursorLeft( "common.Control.cursorLeft",
AS_GLOBAL, WXK_LEFT,
"", "" , NULL, AF_NONE, (void*) CURSOR_LEFT );
TOOL_ACTION ACTIONS::cursorRight( "common.Control.cursorRight",
AS_GLOBAL, WXK_RIGHT,
"", "" , NULL, AF_NONE, (void*) CURSOR_RIGHT );
TOOL_ACTION ACTIONS::cursorUpFast( "common.Control.cursorUpFast",
AS_GLOBAL, MD_CTRL + WXK_UP,
"", "", NULL, AF_NONE, (void*) ( CURSOR_UP | CURSOR_FAST_MOVE ) );
TOOL_ACTION ACTIONS::cursorDownFast( "common.Control.cursorDownFast",
AS_GLOBAL, MD_CTRL + WXK_DOWN,
"", "" , NULL, AF_NONE, (void*) ( CURSOR_DOWN | CURSOR_FAST_MOVE ) );
TOOL_ACTION ACTIONS::cursorLeftFast( "common.Control.cursorLeftFast",
AS_GLOBAL, MD_CTRL + WXK_LEFT,
"", "" , NULL, AF_NONE, (void*) ( CURSOR_LEFT | CURSOR_FAST_MOVE ) );
TOOL_ACTION ACTIONS::cursorRightFast( "common.Control.cursorRightFast",
AS_GLOBAL, MD_CTRL + WXK_RIGHT,
"", "" , NULL, AF_NONE, (void*) ( CURSOR_RIGHT | CURSOR_FAST_MOVE ) );
TOOL_ACTION ACTIONS::cursorClick( "common.Control.cursorClick",
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_LEFT_CLICK ),
"", "", NULL, AF_NONE, (void*) CURSOR_CLICK );
TOOL_ACTION ACTIONS::cursorDblClick( "common.Control.cursorDblClick",
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_LEFT_DCLICK ),
"", "", NULL, AF_NONE, (void*) CURSOR_DBL_CLICK );
TOOL_ACTION ACTIONS::panUp( "common.Control.panUp",
AS_GLOBAL, MD_SHIFT + WXK_UP,
"", "", NULL, AF_NONE, (void*) CURSOR_UP );
TOOL_ACTION ACTIONS::panDown( "common.Control.panDown",
AS_GLOBAL, MD_SHIFT + WXK_DOWN,
"", "" , NULL, AF_NONE, (void*) CURSOR_DOWN );
TOOL_ACTION ACTIONS::panLeft( "common.Control.panLeft",
AS_GLOBAL, MD_SHIFT + WXK_LEFT,
"", "" , NULL, AF_NONE, (void*) CURSOR_LEFT );
TOOL_ACTION ACTIONS::panRight( "common.Control.panRight",
AS_GLOBAL, MD_SHIFT + WXK_RIGHT,
"", "" , NULL, AF_NONE, (void*) CURSOR_RIGHT );
// Grid control // Grid control
TOOL_ACTION ACTIONS::gridFast1( "common.Control.gridFast1", TOOL_ACTION ACTIONS::gridFast1( "common.Control.gridFast1",
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_SWITCH_GRID_TO_FASTGRID1 ), AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_SWITCH_GRID_TO_FASTGRID1 ),

View File

@ -23,6 +23,7 @@
*/ */
#include <tool/actions.h> #include <tool/actions.h>
#include <tool/tool_manager.h>
#include <draw_frame.h> #include <draw_frame.h>
#include <class_draw_panel_gal.h> #include <class_draw_panel_gal.h>
#include <view/view.h> #include <view/view.h>
@ -57,6 +58,107 @@ void COMMON_TOOLS::Reset( RESET_REASON aReason )
} }
// Cursor control
int COMMON_TOOLS::CursorControl( const TOOL_EVENT& aEvent )
{
long type = aEvent.Parameter<intptr_t>();
bool fastMove = type & ACTIONS::CURSOR_FAST_MOVE;
type &= ~ACTIONS::CURSOR_FAST_MOVE;
bool mirroredX = getView()->IsMirroredX();
VECTOR2D cursor = getViewControls()->GetRawCursorPosition( true );
VECTOR2I gridSize = VECTOR2D( m_frame->GetScreen()->GetGridSize() );
if( fastMove )
gridSize = gridSize * 10;
switch( type )
{
case ACTIONS::CURSOR_UP:
cursor -= VECTOR2D( 0, gridSize.y );
break;
case ACTIONS::CURSOR_DOWN:
cursor += VECTOR2D( 0, gridSize.y );
break;
case ACTIONS::CURSOR_LEFT:
cursor -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
break;
case ACTIONS::CURSOR_RIGHT:
cursor += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
break;
case ACTIONS::CURSOR_CLICK: // fall through
case ACTIONS::CURSOR_DBL_CLICK:
{
TOOL_ACTIONS action = TA_NONE;
int modifiers = 0;
modifiers |= wxGetKeyState( WXK_SHIFT ) ? MD_SHIFT : 0;
modifiers |= wxGetKeyState( WXK_CONTROL ) ? MD_CTRL : 0;
modifiers |= wxGetKeyState( WXK_ALT ) ? MD_ALT : 0;
if( type == ACTIONS::CURSOR_CLICK )
action = TA_MOUSE_CLICK;
else if( type == ACTIONS::CURSOR_DBL_CLICK )
action = TA_MOUSE_DBLCLICK;
else
wxFAIL;
TOOL_EVENT evt( TC_MOUSE, action, BUT_LEFT | modifiers );
evt.SetMousePosition( getViewControls()->GetCursorPosition() );
m_toolMgr->ProcessEvent( evt );
return 0;
}
break;
}
getViewControls()->SetCursorPosition( cursor );
return 0;
}
int COMMON_TOOLS::PanControl( const TOOL_EVENT& aEvent )
{
long type = aEvent.Parameter<intptr_t>();
KIGFX::VIEW* view = getView();
VECTOR2D center = view->GetCenter();
VECTOR2I gridSize = VECTOR2D( m_frame->GetScreen()->GetGridSize() ) * 10;
bool mirroredX = view->IsMirroredX();
switch( type )
{
case ACTIONS::CURSOR_UP:
center -= VECTOR2D( 0, gridSize.y );
break;
case ACTIONS::CURSOR_DOWN:
center += VECTOR2D( 0, gridSize.y );
break;
case ACTIONS::CURSOR_LEFT:
center -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
break;
case ACTIONS::CURSOR_RIGHT:
center += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
break;
default:
wxFAIL;
break;
}
view->SetCenter( center );
return 0;
}
int COMMON_TOOLS::ZoomInOut( const TOOL_EVENT& aEvent ) int COMMON_TOOLS::ZoomInOut( const TOOL_EVENT& aEvent )
{ {
bool direction = aEvent.IsAction( &ACTIONS::zoomIn ); bool direction = aEvent.IsAction( &ACTIONS::zoomIn );
@ -268,6 +370,26 @@ int COMMON_TOOLS::ToggleCursor( const TOOL_EVENT& aEvent )
void COMMON_TOOLS::setTransitions() void COMMON_TOOLS::setTransitions()
{ {
// Cursor control
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorUp.MakeEvent() );
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorDown.MakeEvent() );
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorLeft.MakeEvent() );
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorRight.MakeEvent() );
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorUpFast.MakeEvent() );
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorDownFast.MakeEvent() );
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorLeftFast.MakeEvent() );
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorRightFast.MakeEvent() );
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorClick.MakeEvent() );
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorDblClick.MakeEvent() );
// Pan control
Go( &COMMON_TOOLS::PanControl, ACTIONS::panUp.MakeEvent() );
Go( &COMMON_TOOLS::PanControl, ACTIONS::panDown.MakeEvent() );
Go( &COMMON_TOOLS::PanControl, ACTIONS::panLeft.MakeEvent() );
Go( &COMMON_TOOLS::PanControl, ACTIONS::panRight.MakeEvent() );
// Zoom control
Go( &COMMON_TOOLS::ZoomInOut, ACTIONS::zoomIn.MakeEvent() ); Go( &COMMON_TOOLS::ZoomInOut, ACTIONS::zoomIn.MakeEvent() );
Go( &COMMON_TOOLS::ZoomInOut, ACTIONS::zoomOut.MakeEvent() ); Go( &COMMON_TOOLS::ZoomInOut, ACTIONS::zoomOut.MakeEvent() );
Go( &COMMON_TOOLS::ZoomInOutCenter, ACTIONS::zoomInCenter.MakeEvent() ); Go( &COMMON_TOOLS::ZoomInOutCenter, ACTIONS::zoomInCenter.MakeEvent() );

View File

@ -50,25 +50,6 @@ public:
static TOOL_ACTION no_selectionTool; static TOOL_ACTION no_selectionTool;
static TOOL_ACTION measureTool; static TOOL_ACTION measureTool;
/// Cursor control with keyboard
static TOOL_ACTION cursorUp;
static TOOL_ACTION cursorDown;
static TOOL_ACTION cursorLeft;
static TOOL_ACTION cursorRight;
static TOOL_ACTION cursorUpFast;
static TOOL_ACTION cursorDownFast;
static TOOL_ACTION cursorLeftFast;
static TOOL_ACTION cursorRightFast;
static TOOL_ACTION cursorClick;
// Panning with keyboard
static TOOL_ACTION panUp;
static TOOL_ACTION panDown;
static TOOL_ACTION panLeft;
static TOOL_ACTION panRight;
// Miscellaneous // Miscellaneous
static TOOL_ACTION zoomTool; static TOOL_ACTION zoomTool;
static TOOL_ACTION resetCoords; static TOOL_ACTION resetCoords;

View File

@ -42,37 +42,6 @@
#include <functional> #include <functional>
using namespace std::placeholders; using namespace std::placeholders;
// Cursor control
TOOL_ACTION CVPCB_ACTIONS::cursorUp( "cvpcb.Control.cursorUp",
AS_GLOBAL, WXK_UP, "", "", NULL, AF_NONE, (void*) CURSOR_UP );
TOOL_ACTION CVPCB_ACTIONS::cursorDown( "cvpcb.Control.cursorDown",
AS_GLOBAL, WXK_DOWN, "", "" , NULL, AF_NONE, (void*) CURSOR_DOWN );
TOOL_ACTION CVPCB_ACTIONS::cursorLeft( "cvpcb.Control.cursorLeft",
AS_GLOBAL, WXK_LEFT, "", "" , NULL, AF_NONE, (void*) CURSOR_LEFT );
TOOL_ACTION CVPCB_ACTIONS::cursorRight( "cvpcb.Control.cursorRight",
AS_GLOBAL, WXK_RIGHT, "", "" , NULL, AF_NONE, (void*) CURSOR_RIGHT );
TOOL_ACTION CVPCB_ACTIONS::cursorUpFast( "cvpcb.Control.cursorUpFast",
AS_GLOBAL, MD_CTRL + WXK_UP, "", "", NULL, AF_NONE, (void*) ( CURSOR_UP | CURSOR_FAST_MOVE ) );
TOOL_ACTION CVPCB_ACTIONS::cursorDownFast( "cvpcb.Control.cursorDownFast",
AS_GLOBAL, MD_CTRL + WXK_DOWN, "", "" , NULL, AF_NONE, (void*) ( CURSOR_DOWN | CURSOR_FAST_MOVE ) );
TOOL_ACTION CVPCB_ACTIONS::cursorLeftFast( "cvpcb.Control.cursorLeftFast",
AS_GLOBAL, MD_CTRL + WXK_LEFT, "", "" , NULL, AF_NONE, (void*) ( CURSOR_LEFT | CURSOR_FAST_MOVE ) );
TOOL_ACTION CVPCB_ACTIONS::cursorRightFast( "cvpcb.Control.cursorRightFast",
AS_GLOBAL, MD_CTRL + WXK_RIGHT, "", "" , NULL, AF_NONE, (void*) ( CURSOR_RIGHT | CURSOR_FAST_MOVE ) );
TOOL_ACTION CVPCB_ACTIONS::cursorClick( "cvpcb.Control.cursorClick",
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_LEFT_CLICK ),
"", "", NULL, AF_NONE, (void*) CURSOR_CLICK );
TOOL_ACTION CVPCB_ACTIONS::panUp( "cvpcb.Control.panUp",
AS_GLOBAL, MD_SHIFT + WXK_UP, "", "", NULL, AF_NONE, (void*) CURSOR_UP );
TOOL_ACTION CVPCB_ACTIONS::panDown( "cvpcb.Control.panDown",
AS_GLOBAL, MD_SHIFT + WXK_DOWN, "", "" , NULL, AF_NONE, (void*) CURSOR_DOWN );
TOOL_ACTION CVPCB_ACTIONS::panLeft( "cvpcb.Control.panLeft",
AS_GLOBAL, MD_SHIFT + WXK_LEFT, "", "" , NULL, AF_NONE, (void*) CURSOR_LEFT );
TOOL_ACTION CVPCB_ACTIONS::panRight( "cvpcb.Control.panRight",
AS_GLOBAL, MD_SHIFT + WXK_RIGHT, "", "" , NULL, AF_NONE, (void*) CURSOR_RIGHT );
// Miscellaneous // Miscellaneous
TOOL_ACTION CVPCB_ACTIONS::resetCoords( "cvpcb.Control.resetCoords", TOOL_ACTION CVPCB_ACTIONS::resetCoords( "cvpcb.Control.resetCoords",
@ -110,109 +79,6 @@ void CVPCB_CONTROL::Reset( RESET_REASON aReason )
} }
// Cursor control
int CVPCB_CONTROL::CursorControl( const TOOL_EVENT& aEvent )
{
long type = aEvent.Parameter<intptr_t>();
bool fastMove = type & CVPCB_ACTIONS::CURSOR_FAST_MOVE;
type &= ~CVPCB_ACTIONS::CURSOR_FAST_MOVE;
bool mirroredX = getView()->IsMirroredX();
GRID_HELPER gridHelper( m_frame );
VECTOR2D cursor = getViewControls()->GetRawCursorPosition( true );
VECTOR2I gridSize = gridHelper.GetGrid();
if( fastMove )
gridSize = gridSize * 10;
switch( type )
{
case CVPCB_ACTIONS::CURSOR_UP:
cursor -= VECTOR2D( 0, gridSize.y );
break;
case CVPCB_ACTIONS::CURSOR_DOWN:
cursor += VECTOR2D( 0, gridSize.y );
break;
case CVPCB_ACTIONS::CURSOR_LEFT:
cursor -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
break;
case CVPCB_ACTIONS::CURSOR_RIGHT:
cursor += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
break;
case CVPCB_ACTIONS::CURSOR_CLICK: // fall through
case CVPCB_ACTIONS::CURSOR_DBL_CLICK:
{
TOOL_ACTIONS action = TA_NONE;
int modifiers = 0;
modifiers |= wxGetKeyState( WXK_SHIFT ) ? MD_SHIFT : 0;
modifiers |= wxGetKeyState( WXK_CONTROL ) ? MD_CTRL : 0;
modifiers |= wxGetKeyState( WXK_ALT ) ? MD_ALT : 0;
if( type == CVPCB_ACTIONS::CURSOR_CLICK )
action = TA_MOUSE_CLICK;
else if( type == CVPCB_ACTIONS::CURSOR_DBL_CLICK )
action = TA_MOUSE_DBLCLICK;
else
wxFAIL;
TOOL_EVENT evt( TC_MOUSE, action, BUT_LEFT | modifiers );
evt.SetMousePosition( getViewControls()->GetCursorPosition() );
m_toolMgr->ProcessEvent( evt );
return 0;
}
break;
}
getViewControls()->SetCursorPosition( cursor );
return 0;
}
int CVPCB_CONTROL::PanControl( const TOOL_EVENT& aEvent )
{
long type = aEvent.Parameter<intptr_t>();
KIGFX::VIEW* view = getView();
GRID_HELPER gridHelper( m_frame );
VECTOR2D center = view->GetCenter();
VECTOR2I gridSize = gridHelper.GetGrid() * 10;
bool mirroredX = view->IsMirroredX();
switch( type )
{
case CVPCB_ACTIONS::CURSOR_UP:
center -= VECTOR2D( 0, gridSize.y );
break;
case CVPCB_ACTIONS::CURSOR_DOWN:
center += VECTOR2D( 0, gridSize.y );
break;
case CVPCB_ACTIONS::CURSOR_LEFT:
center -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
break;
case CVPCB_ACTIONS::CURSOR_RIGHT:
center += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
break;
default:
wxFAIL;
break;
}
view->SetCenter( center );
return 0;
}
// Miscellaneous // Miscellaneous
int CVPCB_CONTROL::ResetCoords( const TOOL_EVENT& aEvent ) int CVPCB_CONTROL::ResetCoords( const TOOL_EVENT& aEvent )
{ {
@ -258,23 +124,6 @@ int CVPCB_CONTROL::SwitchUnits( const TOOL_EVENT& aEvent )
void CVPCB_CONTROL::setTransitions() void CVPCB_CONTROL::setTransitions()
{ {
// Cursor control
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorUp.MakeEvent() );
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorDown.MakeEvent() );
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorLeft.MakeEvent() );
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorRight.MakeEvent() );
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorUpFast.MakeEvent() );
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorDownFast.MakeEvent() );
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorLeftFast.MakeEvent() );
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorRightFast.MakeEvent() );
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorClick.MakeEvent() );
// Pan control
Go( &CVPCB_CONTROL::PanControl, CVPCB_ACTIONS::panUp.MakeEvent() );
Go( &CVPCB_CONTROL::PanControl, CVPCB_ACTIONS::panDown.MakeEvent() );
Go( &CVPCB_CONTROL::PanControl, CVPCB_ACTIONS::panLeft.MakeEvent() );
Go( &CVPCB_CONTROL::PanControl, CVPCB_ACTIONS::panRight.MakeEvent() );
// Miscellaneous // Miscellaneous
Go( &CVPCB_CONTROL::ResetCoords, CVPCB_ACTIONS::resetCoords.MakeEvent() ); Go( &CVPCB_CONTROL::ResetCoords, CVPCB_ACTIONS::resetCoords.MakeEvent() );
Go( &CVPCB_CONTROL::SwitchCursor, CVPCB_ACTIONS::switchCursor.MakeEvent() ); Go( &CVPCB_CONTROL::SwitchCursor, CVPCB_ACTIONS::switchCursor.MakeEvent() );

View File

@ -48,9 +48,6 @@ public:
/// @copydoc TOOL_INTERACTIVE::Reset() /// @copydoc TOOL_INTERACTIVE::Reset()
void Reset( RESET_REASON aReason ) override; void Reset( RESET_REASON aReason ) override;
int CursorControl( const TOOL_EVENT& aEvent );
int PanControl( const TOOL_EVENT& aEvent );
// Miscellaneous // Miscellaneous
int ResetCoords( const TOOL_EVENT& aEvent ); int ResetCoords( const TOOL_EVENT& aEvent );
int SwitchCursor( const TOOL_EVENT& aEvent ); int SwitchCursor( const TOOL_EVENT& aEvent );

View File

@ -95,26 +95,10 @@ public:
static TOOL_ACTION gridResetOrigin; static TOOL_ACTION gridResetOrigin;
static TOOL_ACTION gridPreset; static TOOL_ACTION gridPreset;
/// Cursor control with keyboard /// Cursor control
static TOOL_ACTION cursorUp;
static TOOL_ACTION cursorDown;
static TOOL_ACTION cursorLeft;
static TOOL_ACTION cursorRight;
static TOOL_ACTION cursorUpFast;
static TOOL_ACTION cursorDownFast;
static TOOL_ACTION cursorLeftFast;
static TOOL_ACTION cursorRightFast;
static TOOL_ACTION cursorClick; static TOOL_ACTION cursorClick;
static TOOL_ACTION cursorDblClick; static TOOL_ACTION cursorDblClick;
// Panning with keyboard
static TOOL_ACTION panUp;
static TOOL_ACTION panDown;
static TOOL_ACTION panLeft;
static TOOL_ACTION panRight;
// Miscellaneous // Miscellaneous
static TOOL_ACTION selectionTool; static TOOL_ACTION selectionTool;
static TOOL_ACTION zoomTool; static TOOL_ACTION zoomTool;

View File

@ -58,6 +58,26 @@ public:
static TOOL_ACTION zoomTool; static TOOL_ACTION zoomTool;
static TOOL_ACTION centerContents; static TOOL_ACTION centerContents;
/// Cursor control with keyboard
static TOOL_ACTION cursorUp;
static TOOL_ACTION cursorDown;
static TOOL_ACTION cursorLeft;
static TOOL_ACTION cursorRight;
static TOOL_ACTION cursorUpFast;
static TOOL_ACTION cursorDownFast;
static TOOL_ACTION cursorLeftFast;
static TOOL_ACTION cursorRightFast;
static TOOL_ACTION cursorClick;
static TOOL_ACTION cursorDblClick;
// Panning with keyboard
static TOOL_ACTION panUp;
static TOOL_ACTION panDown;
static TOOL_ACTION panLeft;
static TOOL_ACTION panRight;
// Grid control // Grid control
static TOOL_ACTION gridFast1; static TOOL_ACTION gridFast1;
static TOOL_ACTION gridFast2; static TOOL_ACTION gridFast2;

View File

@ -53,7 +53,10 @@ public:
int CenterContents( const TOOL_EVENT& aEvent ); int CenterContents( const TOOL_EVENT& aEvent );
int PanControl( const TOOL_EVENT& aEvent );
// Cursor control // Cursor control
int CursorControl( const TOOL_EVENT& aEvent );
int ToggleCursor( const TOOL_EVENT& aEvent ); int ToggleCursor( const TOOL_EVENT& aEvent );
// Grid control // Grid control

View File

@ -353,26 +353,6 @@ public:
static TOOL_ACTION microwaveCreateLine; static TOOL_ACTION microwaveCreateLine;
/// Cursor control with keyboard
static TOOL_ACTION cursorUp;
static TOOL_ACTION cursorDown;
static TOOL_ACTION cursorLeft;
static TOOL_ACTION cursorRight;
static TOOL_ACTION cursorUpFast;
static TOOL_ACTION cursorDownFast;
static TOOL_ACTION cursorLeftFast;
static TOOL_ACTION cursorRightFast;
static TOOL_ACTION cursorClick;
static TOOL_ACTION cursorDblClick;
// Panning with keyboard
static TOOL_ACTION panUp;
static TOOL_ACTION panDown;
static TOOL_ACTION panLeft;
static TOOL_ACTION panRight;
// Locking // Locking
static TOOL_ACTION toggleLock; static TOOL_ACTION toggleLock;
static TOOL_ACTION lock; static TOOL_ACTION lock;

View File

@ -174,41 +174,6 @@ TOOL_ACTION PCB_ACTIONS::layerChanged( "pcbnew.Control.layerChanged",
AS_GLOBAL, 0, AS_GLOBAL, 0,
"", "", NULL, AF_NOTIFY ); "", "", NULL, AF_NOTIFY );
// Cursor control
TOOL_ACTION PCB_ACTIONS::cursorUp( "pcbnew.Control.cursorUp",
AS_GLOBAL, WXK_UP, "", "", NULL, AF_NONE, (void*) CURSOR_UP );
TOOL_ACTION PCB_ACTIONS::cursorDown( "pcbnew.Control.cursorDown",
AS_GLOBAL, WXK_DOWN, "", "" , NULL, AF_NONE, (void*) CURSOR_DOWN );
TOOL_ACTION PCB_ACTIONS::cursorLeft( "pcbnew.Control.cursorLeft",
AS_GLOBAL, WXK_LEFT, "", "" , NULL, AF_NONE, (void*) CURSOR_LEFT );
TOOL_ACTION PCB_ACTIONS::cursorRight( "pcbnew.Control.cursorRight",
AS_GLOBAL, WXK_RIGHT, "", "" , NULL, AF_NONE, (void*) CURSOR_RIGHT );
TOOL_ACTION PCB_ACTIONS::cursorUpFast( "pcbnew.Control.cursorUpFast",
AS_GLOBAL, MD_CTRL + WXK_UP, "", "", NULL, AF_NONE, (void*) ( CURSOR_UP | CURSOR_FAST_MOVE ) );
TOOL_ACTION PCB_ACTIONS::cursorDownFast( "pcbnew.Control.cursorDownFast",
AS_GLOBAL, MD_CTRL + WXK_DOWN, "", "" , NULL, AF_NONE, (void*) ( CURSOR_DOWN | CURSOR_FAST_MOVE ) );
TOOL_ACTION PCB_ACTIONS::cursorLeftFast( "pcbnew.Control.cursorLeftFast",
AS_GLOBAL, MD_CTRL + WXK_LEFT, "", "" , NULL, AF_NONE, (void*) ( CURSOR_LEFT | CURSOR_FAST_MOVE ) );
TOOL_ACTION PCB_ACTIONS::cursorRightFast( "pcbnew.Control.cursorRightFast",
AS_GLOBAL, MD_CTRL + WXK_RIGHT, "", "" , NULL, AF_NONE, (void*) ( CURSOR_RIGHT | CURSOR_FAST_MOVE ) );
TOOL_ACTION PCB_ACTIONS::cursorClick( "pcbnew.Control.cursorClick",
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_LEFT_CLICK ),
"", "", NULL, AF_NONE, (void*) CURSOR_CLICK );
TOOL_ACTION PCB_ACTIONS::cursorDblClick( "pcbnew.Control.cursorDblClick",
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_LEFT_DCLICK ),
"", "", NULL, AF_NONE, (void*) CURSOR_DBL_CLICK );
TOOL_ACTION PCB_ACTIONS::panUp( "pcbnew.Control.panUp",
AS_GLOBAL, MD_SHIFT + WXK_UP, "", "", NULL, AF_NONE, (void*) CURSOR_UP );
TOOL_ACTION PCB_ACTIONS::panDown( "pcbnew.Control.panDown",
AS_GLOBAL, MD_SHIFT + WXK_DOWN, "", "" , NULL, AF_NONE, (void*) CURSOR_DOWN );
TOOL_ACTION PCB_ACTIONS::panLeft( "pcbnew.Control.panLeft",
AS_GLOBAL, MD_SHIFT + WXK_LEFT, "", "" , NULL, AF_NONE, (void*) CURSOR_LEFT );
TOOL_ACTION PCB_ACTIONS::panRight( "pcbnew.Control.panRight",
AS_GLOBAL, MD_SHIFT + WXK_RIGHT, "", "" , NULL, AF_NONE, (void*) CURSOR_RIGHT );
// Miscellaneous // Miscellaneous
TOOL_ACTION PCB_ACTIONS::selectionTool( "pcbnew.Control.selectionTool", TOOL_ACTION PCB_ACTIONS::selectionTool( "pcbnew.Control.selectionTool",
AS_GLOBAL, 0, AS_GLOBAL, 0,
@ -569,109 +534,6 @@ int PCBNEW_CONTROL::LayerAlphaDec( const TOOL_EVENT& aEvent )
} }
// Cursor control
int PCBNEW_CONTROL::CursorControl( const TOOL_EVENT& aEvent )
{
long type = aEvent.Parameter<intptr_t>();
bool fastMove = type & PCB_ACTIONS::CURSOR_FAST_MOVE;
type &= ~PCB_ACTIONS::CURSOR_FAST_MOVE;
bool mirroredX = getView()->IsMirroredX();
GRID_HELPER gridHelper( m_frame );
VECTOR2D cursor = getViewControls()->GetRawCursorPosition( true );
VECTOR2I gridSize = gridHelper.GetGrid();
if( fastMove )
gridSize = gridSize * 10;
switch( type )
{
case PCB_ACTIONS::CURSOR_UP:
cursor -= VECTOR2D( 0, gridSize.y );
break;
case PCB_ACTIONS::CURSOR_DOWN:
cursor += VECTOR2D( 0, gridSize.y );
break;
case PCB_ACTIONS::CURSOR_LEFT:
cursor -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
break;
case PCB_ACTIONS::CURSOR_RIGHT:
cursor += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
break;
case PCB_ACTIONS::CURSOR_CLICK: // fall through
case PCB_ACTIONS::CURSOR_DBL_CLICK:
{
TOOL_ACTIONS action = TA_NONE;
int modifiers = 0;
modifiers |= wxGetKeyState( WXK_SHIFT ) ? MD_SHIFT : 0;
modifiers |= wxGetKeyState( WXK_CONTROL ) ? MD_CTRL : 0;
modifiers |= wxGetKeyState( WXK_ALT ) ? MD_ALT : 0;
if( type == PCB_ACTIONS::CURSOR_CLICK )
action = TA_MOUSE_CLICK;
else if( type == PCB_ACTIONS::CURSOR_DBL_CLICK )
action = TA_MOUSE_DBLCLICK;
else
wxFAIL;
TOOL_EVENT evt( TC_MOUSE, action, BUT_LEFT | modifiers );
evt.SetMousePosition( getViewControls()->GetCursorPosition() );
m_toolMgr->ProcessEvent( evt );
return 0;
}
break;
}
getViewControls()->SetCursorPosition( cursor );
return 0;
}
int PCBNEW_CONTROL::PanControl( const TOOL_EVENT& aEvent )
{
long type = aEvent.Parameter<intptr_t>();
KIGFX::VIEW* view = getView();
GRID_HELPER gridHelper( m_frame );
VECTOR2D center = view->GetCenter();
VECTOR2I gridSize = gridHelper.GetGrid() * 10;
bool mirroredX = view->IsMirroredX();
switch( type )
{
case PCB_ACTIONS::CURSOR_UP:
center -= VECTOR2D( 0, gridSize.y );
break;
case PCB_ACTIONS::CURSOR_DOWN:
center += VECTOR2D( 0, gridSize.y );
break;
case PCB_ACTIONS::CURSOR_LEFT:
center -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
break;
case PCB_ACTIONS::CURSOR_RIGHT:
center += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
break;
default:
wxFAIL;
break;
}
view->SetCenter( center );
return 0;
}
// Grid control // Grid control
int PCBNEW_CONTROL::GridFast1( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::GridFast1( const TOOL_EVENT& aEvent )
{ {
@ -1161,24 +1023,6 @@ void PCBNEW_CONTROL::setTransitions()
Go( &PCBNEW_CONTROL::LayerAlphaInc, PCB_ACTIONS::layerAlphaInc.MakeEvent() ); Go( &PCBNEW_CONTROL::LayerAlphaInc, PCB_ACTIONS::layerAlphaInc.MakeEvent() );
Go( &PCBNEW_CONTROL::LayerAlphaDec, PCB_ACTIONS::layerAlphaDec.MakeEvent() ); Go( &PCBNEW_CONTROL::LayerAlphaDec, PCB_ACTIONS::layerAlphaDec.MakeEvent() );
// Cursor control
Go( &PCBNEW_CONTROL::CursorControl, PCB_ACTIONS::cursorUp.MakeEvent() );
Go( &PCBNEW_CONTROL::CursorControl, PCB_ACTIONS::cursorDown.MakeEvent() );
Go( &PCBNEW_CONTROL::CursorControl, PCB_ACTIONS::cursorLeft.MakeEvent() );
Go( &PCBNEW_CONTROL::CursorControl, PCB_ACTIONS::cursorRight.MakeEvent() );
Go( &PCBNEW_CONTROL::CursorControl, PCB_ACTIONS::cursorUpFast.MakeEvent() );
Go( &PCBNEW_CONTROL::CursorControl, PCB_ACTIONS::cursorDownFast.MakeEvent() );
Go( &PCBNEW_CONTROL::CursorControl, PCB_ACTIONS::cursorLeftFast.MakeEvent() );
Go( &PCBNEW_CONTROL::CursorControl, PCB_ACTIONS::cursorRightFast.MakeEvent() );
Go( &PCBNEW_CONTROL::CursorControl, PCB_ACTIONS::cursorClick.MakeEvent() );
Go( &PCBNEW_CONTROL::CursorControl, PCB_ACTIONS::cursorDblClick.MakeEvent() );
// Pan control
Go( &PCBNEW_CONTROL::PanControl, PCB_ACTIONS::panUp.MakeEvent() );
Go( &PCBNEW_CONTROL::PanControl, PCB_ACTIONS::panDown.MakeEvent() );
Go( &PCBNEW_CONTROL::PanControl, PCB_ACTIONS::panLeft.MakeEvent() );
Go( &PCBNEW_CONTROL::PanControl, PCB_ACTIONS::panRight.MakeEvent() );
// Grid control // Grid control
Go( &PCBNEW_CONTROL::GridFast1, ACTIONS::gridFast1.MakeEvent() ); Go( &PCBNEW_CONTROL::GridFast1, ACTIONS::gridFast1.MakeEvent() );
Go( &PCBNEW_CONTROL::GridFast2, ACTIONS::gridFast2.MakeEvent() ); Go( &PCBNEW_CONTROL::GridFast2, ACTIONS::gridFast2.MakeEvent() );

View File

@ -70,9 +70,6 @@ public:
int LayerAlphaInc( const TOOL_EVENT& aEvent ); int LayerAlphaInc( const TOOL_EVENT& aEvent );
int LayerAlphaDec( const TOOL_EVENT& aEvent ); int LayerAlphaDec( const TOOL_EVENT& aEvent );
int CursorControl( const TOOL_EVENT& aEvent );
int PanControl( const TOOL_EVENT& aEvent );
// Grid control // Grid control
int GridFast1( const TOOL_EVENT& aEvent ); int GridFast1( const TOOL_EVENT& aEvent );
int GridFast2( const TOOL_EVENT& aEvent ); int GridFast2( const TOOL_EVENT& aEvent );