From a76a4f97882b970bb7b25589491c122e789194c8 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Wed, 25 Jan 2023 09:34:17 -0500 Subject: [PATCH] Router: don't unnecessarily change track widths on layer change Fixes: https://gitlab.com/kicad/code/kicad/-/issues/13546 --- pcbnew/router/router_tool.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 8d8984f8d1..866566db5d 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -714,12 +714,24 @@ void ROUTER_TOOL::updateSizesAfterLayerSwitch( PCB_LAYER_ID targetLayer ) if( !constraint.IsNull() ) { - sizes.SetTrackWidth( std::max( bds.m_TrackMinWidth, constraint.m_Value.Opt() ) ); + int width = sizes.TrackWidth(); - if( sizes.TrackWidth() == constraint.m_Value.Opt() ) - sizes.SetWidthSource( constraint.GetName() ); - else + // Only change the size if we're explicitly using the net class, or we're out of range for our + // new constraints. Otherwise, just leave the track width alone so we don't change for no reason. + if( bds.UseNetClassTrack() + || ( width < bds.m_TrackMinWidth ) + || ( width < constraint.m_Value.Min() ) + || ( width > constraint.m_Value.Max() ) ) + { + sizes.SetTrackWidth( std::max( bds.m_TrackMinWidth, constraint.m_Value.Opt() ) ); + } + + if( sizes.TrackWidth() == width ) + sizes.SetWidthSource( _( "existing track" ) ); + else if( sizes.TrackWidth() == bds.m_TrackMinWidth ) sizes.SetWidthSource( _( "board minimum track width" ) ); + else + sizes.SetWidthSource( constraint.GetName() ); } }