From 965ab4293877ecda02793782fab504019ccb28b5 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Wed, 15 Dec 2021 01:46:03 +0100 Subject: [PATCH] router: when dragging segments, don't snap to other segments on the same layer. Fixes drag flickering for short segments. Fixes: https://gitlab.com/kicad/code/kicad/-/issues/9720 --- pcbnew/router/pns_router.cpp | 3 ++- pcbnew/router/pns_router.h | 1 + pcbnew/router/pns_tool_base.cpp | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index 8980626a55..12afdca5ac 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -161,6 +161,7 @@ bool ROUTER::StartDragging( const VECTOR2I& aP, ITEM_SET aStartItems, int aDragM { m_dragger = std::make_unique( this ); m_forceMarkObstaclesMode = true; + m_state = DRAG_COMPONENT; } else { @@ -170,6 +171,7 @@ bool ROUTER::StartDragging( const VECTOR2I& aP, ITEM_SET aStartItems, int aDragM m_forceMarkObstaclesMode = false; m_dragger = std::make_unique( this ); + m_state = DRAG_SEGMENT; } m_dragger->SetMode( aDragMode ); @@ -187,7 +189,6 @@ bool ROUTER::StartDragging( const VECTOR2I& aP, ITEM_SET aStartItems, int aDragM if( m_dragger->Start( aP, aStartItems ) ) { - m_state = DRAG_SEGMENT; return true; } else diff --git a/pcbnew/router/pns_router.h b/pcbnew/router/pns_router.h index 5053a472d9..5b47cdad97 100644 --- a/pcbnew/router/pns_router.h +++ b/pcbnew/router/pns_router.h @@ -119,6 +119,7 @@ public: { IDLE, DRAG_SEGMENT, + DRAG_COMPONENT, ROUTE_TRACK }; diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp index 984e92829e..c0c5a74177 100644 --- a/pcbnew/router/pns_tool_base.cpp +++ b/pcbnew/router/pns_tool_base.cpp @@ -243,6 +243,14 @@ bool TOOL_BASE::checkSnap( ITEM *aItem ) // Sync PNS engine settings with the general PCB editor options. auto& pnss = m_router->Settings(); + // If we're dragging a track segment, don't try to snap to items on the same copper layer. + // This way we avoid 'flickery' behaviour for short segments when the snap algo is trying to + // snap to the corners of the segments next to the one being dragged. + if( m_startItem && aItem && m_router->GetState() == ROUTER::DRAG_SEGMENT + && aItem->Layer() == m_startItem->Layer() && aItem->OfKind( ITEM::SEGMENT_T ) + && m_startItem->OfKind( ITEM::SEGMENT_T ) ) + return false; + pnss.SetSnapToPads( frame()->GetMagneticItemsSettings()->pads == MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL || frame()->GetMagneticItemsSettings()->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS );