From 534d635dd430aac19898beca8cda7cf138b84ff6 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 7 Jan 2022 12:53:10 +0100 Subject: [PATCH] DIALOG_DRC: avoid use UNDEFINED_LAYER when select or activate a physical layer. Although strangely it did not create issues on Linux, it does not work on Windows --- pcbnew/dialogs/dialog_drc.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/pcbnew/dialogs/dialog_drc.cpp b/pcbnew/dialogs/dialog_drc.cpp index 9f96414045..33643a519d 100644 --- a/pcbnew/dialogs/dialog_drc.cpp +++ b/pcbnew/dialogs/dialog_drc.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2009-2016 Dick Hollenbeck, dick@softplc.com - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -390,30 +390,34 @@ void DIALOG_DRC::OnDRCItemSelected( wxDataViewEvent& aEvent ) if( a || b || c || d ) violationLayers = LSET::AllLayersMask(); - if( a ) - violationLayers &= getActiveLayers( a ); + for( BOARD_ITEM* it: {a, b, c, d} ) + { + if( !it ) + continue; - if( b ) - violationLayers &= getActiveLayers( b ); - - if( c ) - violationLayers &= getActiveLayers( c ); - - if( d ) - violationLayers &= getActiveLayers( d ); + LSET layersList = getActiveLayers( it ); + violationLayers &= layersList; + // Try to initialize principalLayer to a valid layer + // Some markers have a layer set to UNDEFINED_LAYER, and setting + // principalLayer to a valid layer can be useful + if( principalLayer <= UNDEFINED_LAYER ) + principalLayer = layersList.Seq().front(); + } } if( violationLayers.count() ) principalLayer = violationLayers.Seq().front(); - else + else if( !(principalLayer <= UNDEFINED_LAYER ) ) violationLayers.set( principalLayer ); WINDOW_THAWER thawer( m_frame ); - if( ( violationLayers & board->GetVisibleLayers() ) == 0 ) + if( !(principalLayer <= UNDEFINED_LAYER ) + && ( violationLayers & board->GetVisibleLayers() ) == 0 ) m_frame->GetAppearancePanel()->SetLayerVisible( principalLayer, true ); - if( board->GetVisibleLayers().test( principalLayer ) ) + if( !(principalLayer <= UNDEFINED_LAYER ) + && board->GetVisibleLayers().test( principalLayer ) ) m_frame->SetActiveLayer( principalLayer ); if( m_centerMarkerOnIdle )