Snap common single-click tools

Fixes https://gitlab.com/kicad/code/kicad/issues/7362

Fixes https://gitlab.com/kicad/code/kicad/issues/7363
This commit is contained in:
Seth Hillbrand 2021-01-31 15:16:36 -08:00
parent bbb8173b61
commit ae5d2efe07
1 changed files with 16 additions and 3 deletions

View File

@ -502,8 +502,11 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
{
wxPoint cursorPos;
KICAD_T type = aEvent.Parameter<KICAD_T>();
wxPoint cursorPos;
KICAD_T type = aEvent.Parameter<KICAD_T>();
EE_GRID_HELPER grid( m_toolMgr );
KIGFX::VIEW_CONTROLS* controls = getViewControls();
if( m_inSingleClickPlace )
return 0;
@ -527,6 +530,9 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
cursorPos = aEvent.IsPrime() ? (wxPoint) aEvent.Position()
: (wxPoint) controls->GetMousePosition();
SCH_ITEM* previewItem;
switch( type )
{
@ -572,7 +578,14 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
while( TOOL_EVENT* evt = Wait() )
{
setCursor();
cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->Modifier( MD_ALT ) );
cursorPos = evt->IsPrime() ? (wxPoint) evt->Position()
: (wxPoint) controls->GetMousePosition();
cursorPos = wxPoint( grid.BestSnapAnchor( cursorPos, LAYER_CONNECTABLE, nullptr ) );
controls->ForceCursorPosition( true, cursorPos );
if( evt->IsCancelInteractive() )
{