router: intelligently guess next layer when placing vias with ratnest

Chooses the layer of the closest ratsnest item
This commit is contained in:
Mike Williams 2025-05-19 14:55:30 -04:00
parent 8ec70ee92b
commit 2f94b241ab
3 changed files with 21 additions and 9 deletions

View File

@ -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();

View File

@ -236,6 +236,8 @@ public:
std::vector<PNS::ITEM*> 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;

View File

@ -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
{