From be294dabce4c6aa8241a67574c7d14091ec5a42a Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Mon, 28 Dec 2020 16:36:42 -0500 Subject: [PATCH] PNS: Snap back to last valid point when committing a drag Fixes https://gitlab.com/kicad/code/kicad/-/issues/6651 --- pcbnew/router/pns_dragger.cpp | 62 +++++++++++++++++++++-------------- pcbnew/router/pns_dragger.h | 1 + 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/pcbnew/router/pns_dragger.cpp b/pcbnew/router/pns_dragger.cpp index 417063f6fe..b77a18227a 100644 --- a/pcbnew/router/pns_dragger.cpp +++ b/pcbnew/router/pns_dragger.cpp @@ -151,6 +151,7 @@ bool DRAGGER::Start( const VECTOR2I& aP, ITEM_SET& aPrimitives ) m_draggedItems.Clear(); m_currentMode = Settings().Mode(); m_freeAngleMode = (m_mode & DM_FREE_ANGLE); + m_lastValidPoint = aP; if( m_currentMode == RM_Shove && !m_freeAngleMode ) { @@ -535,19 +536,16 @@ bool DRAGGER::FixRoute() // invalid). In other modes, we can only commit if "Allow DRC violations" is enabled. if( !m_dragStatus ) { - switch( m_currentMode ) - { - case RM_Shove: - case RM_Smart: - break; + Drag( m_lastValidPoint ); + node = CurrentNode(); - case RM_Walkaround: - default: - if( !Settings().CanViolateDRC() ) - return false; - } + if( !node ) + return false; } + if( !m_dragStatus && !Settings().CanViolateDRC() ) + return false; + Router()->CommitRouting( node ); return true; } @@ -558,24 +556,38 @@ bool DRAGGER::FixRoute() bool DRAGGER::Drag( const VECTOR2I& aP ) { + bool ret = false; + if( m_freeAngleMode ) - return dragMarkObstacles( aP ); - - switch( m_currentMode ) { - case RM_MarkObstacles: - return dragMarkObstacles( aP ); - - case RM_Shove: - case RM_Smart: - return dragShove( aP ); - - case RM_Walkaround: - return dragWalkaround( aP ); - - default: - return false; + ret = dragMarkObstacles( aP ); } + else + { + switch( m_currentMode ) + { + case RM_MarkObstacles: + ret = dragMarkObstacles( aP ); + break; + + case RM_Shove: + case RM_Smart: + ret = dragShove( aP ); + break; + + case RM_Walkaround: + ret = dragWalkaround( aP ); + break; + + default: + break; + } + } + + if( ret ) + m_lastValidPoint = aP; + + return ret; } diff --git a/pcbnew/router/pns_dragger.h b/pcbnew/router/pns_dragger.h index 8dc33a4de5..170253d285 100644 --- a/pcbnew/router/pns_dragger.h +++ b/pcbnew/router/pns_dragger.h @@ -137,6 +137,7 @@ private: int m_draggedSegmentIndex; bool m_dragStatus; PNS_MODE m_currentMode; + VECTOR2D m_lastValidPoint; ///< Contains the list of items that are currently modified by the dragger ITEM_SET m_draggedItems;