diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index 1e761f60a2..5ba35573b9 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -542,6 +542,38 @@ bool ROUTER::Finish() } +bool ROUTER::ContinueFromEnd() +{ + LINE_PLACER* placer = dynamic_cast( Placer() ); + + if( placer == nullptr ) + return false; + + LINE current = placer->Trace(); + int currentLayer = GetCurrentLayer(); + VECTOR2I currentEnd = placer->CurrentEnd(); + VECTOR2I otherEnd; + LAYER_RANGE otherEndLayers; + + // Get the anchor nearest to the end of the trace the user is routing + if( !getNearestRatnestAnchor( otherEnd, otherEndLayers ) ) + return false; + + CommitRouting(); + + // Commit whatever we've fixed and restart routing from the other end + int nextLayer = otherEndLayers.Overlaps( currentLayer ) ? currentLayer : otherEndLayers.Start(); + + if( !StartRouting( otherEnd, ¤t, nextLayer ) ) + return false; + + // Attempt to route to our current position + Move( currentEnd, ¤t ); + + return true; +} + + bool ROUTER::moveDragging( const VECTOR2I& aP, ITEM* aEndItem ) { m_iface->EraseView(); diff --git a/pcbnew/router/pns_router.h b/pcbnew/router/pns_router.h index 193fc9a492..62fdd593f4 100644 --- a/pcbnew/router/pns_router.h +++ b/pcbnew/router/pns_router.h @@ -144,6 +144,7 @@ public: bool StartRouting( const VECTOR2I& aP, ITEM* aItem, int aLayer ); bool Move( const VECTOR2I& aP, ITEM* aItem ); bool Finish(); + bool ContinueFromEnd(); bool FixRoute( const VECTOR2I& aP, ITEM* aItem, bool aForceFinish = false ); void BreakSegment( ITEM *aItem, const VECTOR2I& aP ); diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index c1eb9e8f3e..180f5b5d64 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -1293,50 +1293,18 @@ void ROUTER_TOOL::performRouting() } else if( evt->IsAction( &PCB_ACTIONS::routerContinueFromEnd ) ) { - PNS::LINE_PLACER* placer = dynamic_cast( m_router->Placer() ); + bool needsAppend = m_router->Placer()->HasPlacedAnything(); - if( placer == nullptr ) - break; - - // Get our current line and position and nearest ratsnest to them if it exists - PNS::LINE current = placer->Trace(); - VECTOR2I currentEnd = placer->CurrentEnd(); - VECTOR2I otherEnd; - LAYER_RANGE otherEndLayers; - - if( !getNearestRatnestAnchor( otherEnd, otherEndLayers ) ) - break; - - if( evt->IsAction( &PCB_ACTIONS::routerContinueFromEnd ) ) + if( m_router->ContinueFromEnd() ) { - // Commit routing will put the router on no layer, so save it - int currentLayer = m_router->GetCurrentLayer(); - - // Commit whatever we've fixed and restart routing from the other end - if( m_router->Placer()->HasPlacedAnything() ) - { - m_router->CommitRouting(); - m_iface->SetCommitFlags( APPEND_UNDO ); - } - else - m_router->StopRouting(); - - if( otherEndLayers.Overlaps( currentLayer ) ) - m_router->StartRouting( otherEnd, ¤t, currentLayer ); - else - { - m_router->StartRouting( otherEnd, ¤t, otherEndLayers.Start() ); - syncRouterAndFrameLayer(); - } - - m_startSnapPoint = otherEnd; - - // Attempt to route to our current position - m_router->Move( currentEnd, ¤t ); - VECTOR2I moveResultPoint = m_router->Placer()->CurrentEnd(); + syncRouterAndFrameLayer(); + m_startSnapPoint = m_router->Placer()->CurrentStart(); // Warp the mouse to wherever we actually ended up routing to - controls()->WarpMouseCursor( currentEnd, true, true ); + controls()->WarpMouseCursor( m_router->Placer()->CurrentEnd(), true, true ); + + // We want the next router commit to be one undo at the UI layer + m_iface->SetCommitFlags( needsAppend ? APPEND_UNDO : 0 ); } } else if( evt->IsClick( BUT_LEFT ) || evt->IsDrag( BUT_LEFT ) || evt->IsAction( &PCB_ACTIONS::routeSingleTrack ) )