diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index 8ddcbe1bcf..93a2f66dca 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -489,7 +489,7 @@ bool ROUTER::Move( const VECTOR2I& aP, ITEM* endItem ) } -bool ROUTER::getNearestRatnestAnchor( VECTOR2I& aOtherEnd, PNS_LAYER_RANGE& aOtherEndLayers, +bool ROUTER::GetNearestRatnestAnchor( VECTOR2I& aOtherEnd, PNS_LAYER_RANGE& aOtherEndLayers, ITEM*& aOtherEndItem ) { // Can't finish something with no connections @@ -561,7 +561,7 @@ bool ROUTER::Finish() ITEM* otherEndItem = nullptr; // Get the anchor nearest to the end of the trace the user is routing - if( !getNearestRatnestAnchor( otherEnd, otherEndLayers, otherEndItem ) ) + if( !GetNearestRatnestAnchor( otherEnd, otherEndLayers, otherEndItem ) ) return false; // Keep moving until we don't change position or hit the limit @@ -607,7 +607,7 @@ bool ROUTER::ContinueFromEnd( ITEM** aNewStartItem ) ITEM* otherEndItem = nullptr; // Get the anchor nearest to the end of the trace the user is routing - if( !getNearestRatnestAnchor( otherEnd, otherEndLayers, otherEndItem ) ) + if( !GetNearestRatnestAnchor( otherEnd, otherEndLayers, otherEndItem ) ) return false; CommitRouting(); diff --git a/pcbnew/router/pns_router.h b/pcbnew/router/pns_router.h index 42c2cb4efa..3add02e8e4 100644 --- a/pcbnew/router/pns_router.h +++ b/pcbnew/router/pns_router.h @@ -236,6 +236,8 @@ public: std::vector GetLastCommittedLeaderSegments(); + bool GetNearestRatnestAnchor( VECTOR2I& aOtherEnd, PNS_LAYER_RANGE& aOtherEndLayers, + ITEM*& aOtherEndItem ); private: bool movePlacing( const VECTOR2I& aP, ITEM* aItem ); bool moveDragging( const VECTOR2I& aP, ITEM* aItem ); @@ -247,9 +249,6 @@ private: void markViolations( NODE* aNode, ITEM_SET& aCurrent, NODE::ITEM_VECTOR& aRemoved ); bool isStartingPointRoutable( const VECTOR2I& aWhere, ITEM* aItem, int aLayer ); - bool getNearestRatnestAnchor( VECTOR2I& aOtherEnd, PNS_LAYER_RANGE& aOtherEndLayers, - ITEM*& aOtherEndItem ); - private: BOX2I m_visibleViewArea; diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 821ae049b6..14c1da4cce 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -1088,9 +1088,22 @@ int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia ) // Implicit layer selection if( viaType == VIATYPE::THROUGH ) { - // use the default layer pair - currentLayer = pairTop; - targetLayer = pairBottom; + // Try to switch to the nearest ratnest item's layer if we have one + VECTOR2I otherEnd; + PNS_LAYER_RANGE otherEndLayers; + PNS::ITEM* otherEndItem = nullptr; + + if( !m_router->getNearestRatnestAnchor( otherEnd, otherEndLayers, otherEndItem ) ) + { + // use the default layer pair + currentLayer = pairTop; + targetLayer = pairBottom; + } + else + { + // use the layer of the other end + targetLayer = m_iface->GetBoardLayerFromPNSLayer( otherEndLayers.Start() ); + } } else {