From 496f3d49e4f48405a3a5f0cd001e1449d48bb3f3 Mon Sep 17 00:00:00 2001 From: Fabien Corona Date: Sun, 29 Dec 2019 23:37:25 +0000 Subject: [PATCH] pcbnew: When using '+' and '-' hotkeys, skip non-visible layers CHANGED: pcbnew: When using '+' and '-' hotkeys, skip non-visible layers Fixes https://gitlab.com/kicad/code/kicad/issues/3443 --- pcbnew/tools/pcbnew_control.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 358350dc4a..e2a400641c 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -327,19 +327,21 @@ int PCBNEW_CONTROL::LayerSwitch( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerNext( const TOOL_EVENT& aEvent ) { PCB_BASE_FRAME* editFrame = m_frame; + BOARD* brd = board(); LAYER_NUM layer = editFrame->GetActiveLayer(); + LAYER_NUM startLayer = layer; if( layer < F_Cu || layer > B_Cu ) return 0; - int layerCount = board()->GetCopperLayerCount(); + while( startLayer != ++layer ) + { + if( brd->IsLayerVisible( static_cast( layer ) ) && IsCopperLayer( layer ) ) + break; - if( layer == layerCount - 2 || layerCount < 2 ) - layer = B_Cu; - else if( layer == B_Cu ) - layer = F_Cu; - else - ++layer; + if( layer >= B_Cu ) + layer = F_Cu - 1; + } wxCHECK( IsCopperLayer( layer ), 0 ); editFrame->SwitchLayer( NULL, ToLAYER_ID( layer ) ); @@ -351,19 +353,22 @@ int PCBNEW_CONTROL::LayerNext( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerPrev( const TOOL_EVENT& aEvent ) { PCB_BASE_FRAME* editFrame = m_frame; + BOARD* brd = board(); LAYER_NUM layer = editFrame->GetActiveLayer(); + LAYER_NUM startLayer = layer; if( layer < F_Cu || layer > B_Cu ) return 0; - int layerCount = board()->GetCopperLayerCount(); + while( startLayer != --layer ) + { + if( brd->IsLayerVisible( static_cast( layer ) ) && IsCopperLayer( layer ) ) + break; + + if( layer <= F_Cu ) + layer = B_Cu + 1; + } - if( layer == F_Cu || layerCount < 2 ) - layer = B_Cu; - else if( layer == B_Cu ) - layer = layerCount - 2; - else - --layer; wxCHECK( IsCopperLayer( layer ), 0 ); editFrame->SwitchLayer( NULL, ToLAYER_ID( layer ) );