Make grid snapping depend on grid visibility

Turning the grid view on enables snapping to the grid.  Turning it off
removes the snap and allows free draw
This commit is contained in:
Seth Hillbrand 2020-09-09 09:45:02 -07:00
parent 173b4ff588
commit 4026904cc4
22 changed files with 39 additions and 52 deletions

View File

@ -62,15 +62,12 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
m_frame->PushTool( tool ); m_frame->PushTool( tool );
Activate(); Activate();
// To many things are off-grid in LibEdit; turn snapping off.
bool snap = !m_frame->IsType( FRAME_SCH_LIB_EDITOR );
setControls(); setControls();
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {
m_frame->GetCanvas()->SetCurrentCursor( m_cursor ); m_frame->GetCanvas()->SetCurrentCursor( m_cursor );
VECTOR2D cursorPos = controls->GetCursorPosition( snap && !evt->Modifier( MD_ALT ) ); VECTOR2D cursorPos = controls->GetCursorPosition( m_frame->IsGridVisible() );
if( evt->IsCancelInteractive() || evt->IsActivate() ) if( evt->IsCancelInteractive() || evt->IsActivate() )
{ {

View File

@ -194,7 +194,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
} }
SyncView(); SyncView();
GetCanvas()->GetViewControls()->SetGridSnapping( true ); GetCanvas()->GetViewControls()->SetGridSnapping( IsGridVisible() );
GetCanvas()->SetCanFocus( false ); GetCanvas()->SetCanFocus( false );
// Set the working/draw area size to display a symbol to a reasonable value: // Set the working/draw area size to display a symbol to a reasonable value:

View File

@ -175,7 +175,7 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
Show( true ); Show( true );
SyncView(); SyncView();
GetCanvas()->GetViewControls()->SetGridSnapping( true ); GetCanvas()->GetViewControls()->SetGridSnapping( IsGridVisible() );
GetCanvas()->GetView()->UseDrawPriority( true ); GetCanvas()->GetView()->UseDrawPriority( true );
GetCanvas()->GetGAL()->SetAxesEnabled( true ); GetCanvas()->GetGAL()->SetAxesEnabled( true );

View File

@ -91,7 +91,7 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
// on updated viewport data. // on updated viewport data.
m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
m_viewControls->SetGridSnapping( true ); m_viewControls->SetGridSnapping( m_gal->GetGridVisibility() );
SetEvtHandlerEnabled( true ); SetEvtHandlerEnabled( true );
SetFocus(); SetFocus();

View File

@ -70,7 +70,7 @@ SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindo
m_gal->SetCursorEnabled( false ); m_gal->SetCursorEnabled( false );
m_gal->SetGridSize( VECTOR2D( Mils2iu( 100.0 ), Mils2iu( 100.0 ) ) ); m_gal->SetGridSize( VECTOR2D( Mils2iu( 100.0 ), Mils2iu( 100.0 ) ) );
m_viewControls->SetGridSnapping( true ); m_viewControls->SetGridSnapping( m_gal->GetGridVisibility() );
SetEvtHandlerEnabled( true ); SetEvtHandlerEnabled( true );
SetFocus(); SetFocus();

View File

@ -397,7 +397,7 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
int LIB_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent ) int LIB_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent )
{ {
getViewControls()->ShowCursor( true ); getViewControls()->ShowCursor( true );
getViewControls()->SetGridSnapping( true ); getViewControls()->SetGridSnapping( m_frame->IsGridVisible() );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );

View File

@ -70,7 +70,7 @@ void LIB_MOVE_TOOL::Reset( RESET_REASON aReason )
int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
{ {
KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW_CONTROLS* controls = getViewControls();
controls->SetGridSnapping( true ); controls->SetGridSnapping( m_frame->IsGridVisible() );
m_anchorPos = { 0, 0 }; m_anchorPos = { 0, 0 };
@ -103,7 +103,7 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
do do
{ {
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); controls->SetGridSnapping( m_frame->IsGridVisible() );
if( evt->IsAction( &EE_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) if( evt->IsAction( &EE_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
|| evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsAction( &ACTIONS::refreshPreview )
@ -271,7 +271,6 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
controls->ForceCursorPosition( false ); controls->ForceCursorPosition( false );
controls->ShowCursor( false ); controls->ShowCursor( false );
controls->SetGridSnapping( false );
controls->SetAutoPan( false ); controls->SetAutoPan( false );
if( !chain_commands ) if( !chain_commands )

View File

@ -449,7 +449,7 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true ); getViewControls()->ShowCursor( true );
getViewControls()->SetGridSnapping( true ); getViewControls()->SetGridSnapping( m_frame->IsGridVisible() );
SCH_ITEM* previewItem; SCH_ITEM* previewItem;
switch( type ) switch( type )

View File

@ -109,7 +109,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>(); EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW_CONTROLS* controls = getViewControls();
controls->SetGridSnapping( true ); controls->SetGridSnapping( m_frame->IsGridVisible() );
m_anchorPos.reset(); m_anchorPos.reset();
@ -171,7 +171,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
do do
{ {
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); controls->SetGridSnapping( m_frame->IsGridVisible() );
if( evt->IsAction( &EE_ACTIONS::moveActivate ) || evt->IsAction( &EE_ACTIONS::restartMove ) if( evt->IsAction( &EE_ACTIONS::moveActivate ) || evt->IsAction( &EE_ACTIONS::restartMove )
|| evt->IsAction( &EE_ACTIONS::move ) || evt->IsAction( &EE_ACTIONS::drag ) || evt->IsAction( &EE_ACTIONS::move ) || evt->IsAction( &EE_ACTIONS::drag )
@ -428,7 +428,6 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
controls->ForceCursorPosition( false ); controls->ForceCursorPosition( false );
controls->ShowCursor( false ); controls->ShowCursor( false );
controls->SetGridSnapping( false );
controls->SetAutoPan( false ); controls->SetAutoPan( false );
if( !chain_commands ) if( !chain_commands )

View File

@ -49,6 +49,7 @@ EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalTy
m_view->SetPainter( m_painter.get() ); m_view->SetPainter( m_painter.get() );
m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
m_viewControls->SetGridSnapping( m_gal->GetGridVisibility() );
setDefaultLayerDeps(); setDefaultLayerDeps();

View File

@ -571,7 +571,7 @@ int GERBVIEW_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
bool originSet = false; bool originSet = false;
controls.ShowCursor( true ); controls.ShowCursor( true );
controls.SetGridSnapping( true ); controls.SetGridSnapping( m_frame->IsGridVisible() );
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {

View File

@ -65,6 +65,7 @@ PL_DRAW_PANEL_GAL::PL_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindo
m_view->SetLayerVisible( LAYER_WORKSHEET_PAGEn, false ); m_view->SetLayerVisible( LAYER_WORKSHEET_PAGEn, false );
m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
m_viewControls->SetGridSnapping( m_gal->GetGridVisibility() );
} }

View File

@ -93,7 +93,7 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
{ {
KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW_CONTROLS* controls = getViewControls();
controls->SetGridSnapping( true ); controls->SetGridSnapping( m_frame->IsGridVisible() );
VECTOR2I originalCursorPos = controls->GetCursorPosition(); VECTOR2I originalCursorPos = controls->GetCursorPosition();
// Be sure that there is at least one item that we can move. If there's no selection try // Be sure that there is at least one item that we can move. If there's no selection try
@ -123,7 +123,7 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
do do
{ {
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); controls->SetGridSnapping( m_frame->IsGridVisible() );
if( evt->IsAction( &PL_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) if( evt->IsAction( &PL_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
|| evt->IsAction( &ACTIONS::refreshPreview ) ) || evt->IsAction( &ACTIONS::refreshPreview ) )
@ -236,7 +236,6 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
controls->ForceCursorPosition( false ); controls->ForceCursorPosition( false );
controls->ShowCursor( false ); controls->ShowCursor( false );
controls->SetGridSnapping( false );
controls->SetAutoPan( false ); controls->SetAutoPan( false );
if( !chain_commands ) if( !chain_commands )

View File

@ -126,6 +126,7 @@ PCB_DRAW_PANEL_GAL::PCB_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
// View controls is the first in the event handler chain, so the Tool Framework operates // View controls is the first in the event handler chain, so the Tool Framework operates
// on updated viewport data. // on updated viewport data.
m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
m_viewControls->SetGridSnapping( m_gal->GetGridVisibility() );
// Load display options (such as filled/outline display of items). // Load display options (such as filled/outline display of items).
// Can be made only if the parent window is an EDA_DRAW_FRAME (or a derived class) // Can be made only if the parent window is an EDA_DRAW_FRAME (or a derived class)

View File

@ -408,7 +408,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true ); m_controls->ShowCursor( true );
m_controls->SetGridSnapping( true ); m_controls->SetGridSnapping( m_frame->IsGridVisible() );
// do not capture or auto-pan until we start placing some text // do not capture or auto-pan until we start placing some text
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
@ -620,7 +620,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true ); m_controls->ShowCursor( true );
m_controls->SetGridSnapping( true ); m_controls->SetGridSnapping( m_frame->IsGridVisible() );
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION );
@ -650,8 +650,8 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); grid.SetUseGrid( m_frame->IsGridVisible() );
m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); m_controls->SetGridSnapping( m_frame->IsGridVisible() );
VECTOR2I cursorPos = grid.BestSnapAnchor( VECTOR2I cursorPos = grid.BestSnapAnchor(
evt->IsPrime() ? evt->Position() : m_controls->GetMousePosition(), nullptr ); evt->IsPrime() ? evt->Position() : m_controls->GetMousePosition(), nullptr );
m_controls->ForceCursorPosition( true, cursorPos ); m_controls->ForceCursorPosition( true, cursorPos );
@ -916,7 +916,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &newItems ); m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &newItems );
m_controls->ShowCursor( true ); m_controls->ShowCursor( true );
m_controls->SetGridSnapping( true ); m_controls->SetGridSnapping( m_frame->IsGridVisible() );
m_controls->ForceCursorPosition( false ); m_controls->ForceCursorPosition( false );
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
@ -1011,7 +1011,6 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
m_controls->ShowCursor( true ); m_controls->ShowCursor( true );
m_controls->SetGridSnapping( true );
m_controls->SetAutoPan( true ); m_controls->SetAutoPan( true );
m_controls->CaptureCursor( false ); m_controls->CaptureCursor( false );
@ -1020,8 +1019,8 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_BULLSEYE ); m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_BULLSEYE );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); grid.SetUseGrid( m_frame->IsGridVisible() );
m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); m_controls->SetGridSnapping( m_frame->IsGridVisible() );
VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), LSET::AllLayersMask() ); VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), LSET::AllLayersMask() );
m_controls->ForceCursorPosition( true, cursorPos ); m_controls->ForceCursorPosition( true, cursorPos );
@ -1124,8 +1123,8 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, DRAWSEGMEN
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); grid.SetUseGrid( m_frame->IsGridVisible() );
m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); m_controls->SetGridSnapping( m_frame->IsGridVisible() );
cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), m_frame->GetActiveLayer() ); cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), m_frame->GetActiveLayer() );
m_controls->ForceCursorPosition( true, cursorPos ); m_controls->ForceCursorPosition( true, cursorPos );
@ -1383,7 +1382,6 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT** aGraphic, bo
GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() ); GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
m_controls->ShowCursor( true ); m_controls->ShowCursor( true );
m_controls->SetGridSnapping( true );
bool firstPoint = false; bool firstPoint = false;
bool cancelled = false; bool cancelled = false;
@ -1402,8 +1400,8 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT** aGraphic, bo
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); grid.SetUseGrid( m_frame->IsGridVisible() );
m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); m_controls->SetGridSnapping( m_frame->IsGridVisible() );
VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), graphic ); VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), graphic );
m_controls->ForceCursorPosition( true, cursorPos ); m_controls->ForceCursorPosition( true, cursorPos );
@ -1623,7 +1621,6 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
Activate(); // register for events Activate(); // register for events
m_controls->ShowCursor( true ); m_controls->ShowCursor( true );
m_controls->SetGridSnapping( true );
bool started = false; bool started = false;
GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() ); GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
@ -1641,8 +1638,8 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
LSET layers( m_frame->GetActiveLayer() ); LSET layers( m_frame->GetActiveLayer() );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); grid.SetUseGrid( m_frame->IsGridVisible() );
m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); m_controls->SetGridSnapping( m_frame->IsGridVisible() );
VECTOR2I cursorPos = grid.BestSnapAnchor( evt->IsPrime() ? evt->Position() VECTOR2I cursorPos = grid.BestSnapAnchor( evt->IsPrime() ? evt->Position()
: m_controls->GetMousePosition(), : m_controls->GetMousePosition(),
layers ); layers );

View File

@ -409,7 +409,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference )
editFrame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); editFrame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); controls->SetGridSnapping( frame()->IsGridVisible() );
if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
|| evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsAction( &ACTIONS::refreshPreview )
@ -616,7 +616,6 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference )
m_lockedSelected = false; m_lockedSelected = false;
controls->ForceCursorPosition( false ); controls->ForceCursorPosition( false );
controls->ShowCursor( false ); controls->ShowCursor( false );
controls->SetGridSnapping( false );
controls->SetAutoPan( false ); controls->SetAutoPan( false );
m_dragging = false; m_dragging = false;

View File

@ -322,9 +322,7 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLaye
if( nearest && m_enableSnap ) if( nearest && m_enableSnap )
{ {
double snapDist = nearest->Distance( aOrigin ); if( nearest->Distance( aOrigin ) <= snapRange )
if( !m_enableGrid || snapDist <= gridDist )
{ {
m_viewSnapPoint.SetPosition( wxPoint( nearest->pos ) ); m_viewSnapPoint.SetPosition( wxPoint( nearest->pos ) );
m_viewSnapLine.SetPosition( wxPoint( nearest->pos ) ); m_viewSnapLine.SetPosition( wxPoint( nearest->pos ) );

View File

@ -797,7 +797,7 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
controls->ShowCursor( true ); controls->ShowCursor( true );
controls->SetGridSnapping( true ); controls->SetGridSnapping( m_frame->IsGridVisible() );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
@ -1280,7 +1280,7 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent )
view->Add( &preview ); view->Add( &preview );
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
controls->SetGridSnapping( true ); controls->SetGridSnapping( frame()->IsGridVisible() );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
@ -1363,7 +1363,6 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent )
preview.Clear(); preview.Clear();
delete target; delete target;
view->Remove( &preview ); view->Remove( &preview );
controls->SetGridSnapping( false );
return 0; return 0;
} }

View File

@ -50,7 +50,7 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const std::string& aTool,
// do not capture or auto-pan until we start placing an item // do not capture or auto-pan until we start placing an item
controls()->ShowCursor( true ); controls()->ShowCursor( true );
controls()->SetGridSnapping( true ); controls()->SetGridSnapping( frame()->IsGridVisible() );
// Add a VIEW_GROUP that serves as a preview for the new item // Add a VIEW_GROUP that serves as a preview for the new item
PCBNEW_SELECTION preview; PCBNEW_SELECTION preview;

View File

@ -225,7 +225,7 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
controls.SetGridSnapping( !evt->Modifier( MD_ALT ) ); controls.SetGridSnapping( frame()->IsGridVisible() );
const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr ); const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr );
controls.ForceCursorPosition(true, cursorPos ); controls.ForceCursorPosition(true, cursorPos );

View File

@ -59,7 +59,7 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); controls->SetGridSnapping( frame->IsGridVisible() );
VECTOR2I cursorPos = grid.BestSnapAnchor( controls->GetMousePosition(), nullptr ); VECTOR2I cursorPos = grid.BestSnapAnchor( controls->GetMousePosition(), nullptr );
controls->ForceCursorPosition(true, cursorPos ); controls->ForceCursorPosition(true, cursorPos );
@ -186,9 +186,6 @@ void PCBNEW_PICKER_TOOL::setControls()
{ {
KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW_CONTROLS* controls = getViewControls();
// Ensure that the view controls do not handle our snapping as we use the GRID_HELPER
controls->SetGridSnapping( false );
controls->CaptureCursor( false ); controls->CaptureCursor( false );
controls->SetAutoPan( false ); controls->SetAutoPan( false );
} }

View File

@ -382,8 +382,8 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {
grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); grid.SetUseGrid( editFrame->IsGridVisible() );
controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); controls->SetGridSnapping( editFrame->IsGridVisible() );
if( !m_editPoints || evt->IsSelectionEvent() ) if( !m_editPoints || evt->IsSelectionEvent() )
break; break;