From 0629f502b51ef8da9e14cd2715b4c5f303ff0ad5 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Tue, 1 Aug 2023 19:03:04 -0400 Subject: [PATCH] PNS: Improve behavior of dragging vias - Fall back to walkaround when drag fails - Properly check collisions with holes Fixes https://gitlab.com/kicad/code/kicad/-/issues/15117 (cherry picked from commit cc7d470f8b68f7e7e102f534fe06240ed44402f1) --- pcbnew/router/pns_dragger.cpp | 5 +++++ pcbnew/router/pns_shove.cpp | 18 ++++++++++++++++-- pcbnew/router/router_tool.cpp | 4 +++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/pcbnew/router/pns_dragger.cpp b/pcbnew/router/pns_dragger.cpp index 349cc1ce18..604d961964 100644 --- a/pcbnew/router/pns_dragger.cpp +++ b/pcbnew/router/pns_dragger.cpp @@ -685,6 +685,11 @@ bool DRAGGER::dragShove( const VECTOR2I& aP ) m_draggedVia = newVia; m_draggedItems.Clear(); + + // If drag didn't work (i.e. dragged onto a collision) try walkaround instead + if( !ok ) + ok = dragViaWalkaround( m_draggedVia, m_lastNode, aP ); + break; } } diff --git a/pcbnew/router/pns_shove.cpp b/pcbnew/router/pns_shove.cpp index 6fc48db095..7285c42178 100644 --- a/pcbnew/router/pns_shove.cpp +++ b/pcbnew/router/pns_shove.cpp @@ -1342,7 +1342,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter ) PNS_DBG( Dbg(), AddItem, ¤tLine, RED, currentLine.Width(), wxString::Format( "current-coll-chk rank %d", currentLine.Rank() ) ); - for( ITEM::PnsKind search_order : { ITEM::SOLID_T, ITEM::VIA_T, ITEM::SEGMENT_T } ) + for( ITEM::PnsKind search_order : { ITEM::HOLE_T, ITEM::SOLID_T, ITEM::VIA_T, ITEM::SEGMENT_T } ) { COLLISION_SEARCH_OPTIONS opts; opts.m_kindMask = search_order; @@ -1376,6 +1376,12 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter ) ITEM* ni = nearest->m_item; + UNITS_PROVIDER up( pcbIUScale, EDA_UNITS::MILLIMETRES ); + PNS_DBG( Dbg(), Message, + wxString::Format( wxT( "NI: %s (%s)" ), ni->Format(), ni->Parent() + ? ni->Parent()->GetItemDescription( &up ) + : "null" ) ); + unwindLineStack( ni ); if( !ni->OfKind( ITEM::SOLID_T ) && ni->Rank() >= 0 && ni->Rank() > currentLine.Rank() ) @@ -1826,13 +1832,21 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveDraggingVia( const VIA_HANDLE aOldVia, const VEC st = shoveMainLoop(); if( st == SH_OK ) + { runOptimizer( m_currentNode ); + // m_draggedVia will only be updated if pushOrShoveVia makes progress... + // this should probably be refactored/cleaned up. + PNS::VIA* viaCheck = m_draggedVia ? m_draggedVia : viaToDrag; + + st = m_currentNode->CheckColliding( viaCheck ) ? SH_INCOMPLETE : SH_OK; + } + if( st == SH_OK || st == SH_HEAD_MODIFIED ) { wxLogTrace( "PNS","setNewV %p", m_draggedVia ); - if (!m_draggedVia) + if( !m_draggedVia ) m_draggedVia = viaToDrag; aNewVia = m_draggedVia->MakeHandle(); diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 223ada6c8e..396ad3b7ae 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -612,7 +612,9 @@ void ROUTER_TOOL::saveRouterDebugLog() for( auto item : removed ) { - fprintf(f, "removed %s\n", item->Parent()->m_Uuid.AsString().c_str().AsChar() ); + fprintf(f, "removed %s\n", item->Parent() ? + item->Parent()->m_Uuid.AsString().c_str().AsChar() : + item->Format().c_str() ); } for( auto item : added )