PNS: Snap back to last valid point when committing a drag

Fixes https://gitlab.com/kicad/code/kicad/-/issues/6651
This commit is contained in:
Jon Evans 2020-12-28 16:36:42 -05:00
parent e5b7e7d2b2
commit be294dabce
2 changed files with 38 additions and 25 deletions

View File

@ -151,6 +151,7 @@ bool DRAGGER::Start( const VECTOR2I& aP, ITEM_SET& aPrimitives )
m_draggedItems.Clear(); m_draggedItems.Clear();
m_currentMode = Settings().Mode(); m_currentMode = Settings().Mode();
m_freeAngleMode = (m_mode & DM_FREE_ANGLE); m_freeAngleMode = (m_mode & DM_FREE_ANGLE);
m_lastValidPoint = aP;
if( m_currentMode == RM_Shove && !m_freeAngleMode ) if( m_currentMode == RM_Shove && !m_freeAngleMode )
{ {
@ -535,18 +536,15 @@ bool DRAGGER::FixRoute()
// invalid). In other modes, we can only commit if "Allow DRC violations" is enabled. // invalid). In other modes, we can only commit if "Allow DRC violations" is enabled.
if( !m_dragStatus ) if( !m_dragStatus )
{ {
switch( m_currentMode ) Drag( m_lastValidPoint );
{ node = CurrentNode();
case RM_Shove:
case RM_Smart:
break;
case RM_Walkaround: if( !node )
default:
if( !Settings().CanViolateDRC() )
return false; return false;
} }
}
if( !m_dragStatus && !Settings().CanViolateDRC() )
return false;
Router()->CommitRouting( node ); Router()->CommitRouting( node );
return true; return true;
@ -558,26 +556,40 @@ bool DRAGGER::FixRoute()
bool DRAGGER::Drag( const VECTOR2I& aP ) bool DRAGGER::Drag( const VECTOR2I& aP )
{ {
if( m_freeAngleMode ) bool ret = false;
return dragMarkObstacles( aP );
if( m_freeAngleMode )
{
ret = dragMarkObstacles( aP );
}
else
{
switch( m_currentMode ) switch( m_currentMode )
{ {
case RM_MarkObstacles: case RM_MarkObstacles:
return dragMarkObstacles( aP ); ret = dragMarkObstacles( aP );
break;
case RM_Shove: case RM_Shove:
case RM_Smart: case RM_Smart:
return dragShove( aP ); ret = dragShove( aP );
break;
case RM_Walkaround: case RM_Walkaround:
return dragWalkaround( aP ); ret = dragWalkaround( aP );
break;
default: default:
return false; break;
} }
} }
if( ret )
m_lastValidPoint = aP;
return ret;
}
NODE* DRAGGER::CurrentNode() const NODE* DRAGGER::CurrentNode() const
{ {

View File

@ -137,6 +137,7 @@ private:
int m_draggedSegmentIndex; int m_draggedSegmentIndex;
bool m_dragStatus; bool m_dragStatus;
PNS_MODE m_currentMode; PNS_MODE m_currentMode;
VECTOR2D m_lastValidPoint;
///< Contains the list of items that are currently modified by the dragger ///< Contains the list of items that are currently modified by the dragger
ITEM_SET m_draggedItems; ITEM_SET m_draggedItems;