mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Pcbnew: don't assume zones are in the UiOrder list
This can be false, for example when zones are being rescued, even if the LSET is non-zero-sized.
This commit is contained in:
parent
781cb0fb8e
commit
1662d7f546
@ -241,18 +241,32 @@ VECTOR2I ZONE::GetPosition() const
|
||||
PCB_LAYER_ID ZONE::GetLayer() const
|
||||
{
|
||||
if( m_layerSet.count() == 1 )
|
||||
return m_layerSet.UIOrder()[0];
|
||||
else
|
||||
return UNDEFINED_LAYER;
|
||||
{
|
||||
return GetFirstLayer();
|
||||
}
|
||||
return UNDEFINED_LAYER;
|
||||
}
|
||||
|
||||
|
||||
PCB_LAYER_ID ZONE::GetFirstLayer() const
|
||||
{
|
||||
if( m_layerSet.count() )
|
||||
return m_layerSet.UIOrder()[0];
|
||||
else
|
||||
if( m_layerSet.count() == 0 )
|
||||
{
|
||||
return UNDEFINED_LAYER;
|
||||
}
|
||||
|
||||
const LSEQ uiLayers = m_layerSet.UIOrder();
|
||||
|
||||
// This can't use m_layerSet.count() because it's possible to have a zone on
|
||||
// a rescue layer that is not in the UI order.
|
||||
if( uiLayers.size() )
|
||||
{
|
||||
return uiLayers[0];
|
||||
}
|
||||
|
||||
// If it's not in the UI set at all, just return the first layer in the set.
|
||||
// (we know the count > 0)
|
||||
return m_layerSet.Seq()[0];
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,6 +48,7 @@ set( QA_PCBNEW_SRCS
|
||||
test_tracks_cleaner.cpp
|
||||
test_triangulation.cpp
|
||||
test_multichannel.cpp
|
||||
test_zone.cpp
|
||||
test_zone_filler.cpp
|
||||
|
||||
drc/test_custom_rule_severities.cpp
|
||||
|
83
qa/tests/pcbnew/test_zone.cpp
Normal file
83
qa/tests/pcbnew/test_zone.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2024 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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <qa_utils/wx_utils/unit_test_utils.h>
|
||||
#include <pcbnew_utils/board_test_utils.h>
|
||||
|
||||
#include <board.h>
|
||||
#include <zone.h>
|
||||
|
||||
|
||||
struct ZONE_TEST_FIXTURE
|
||||
{
|
||||
BOARD m_board;
|
||||
};
|
||||
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE( Zone, ZONE_TEST_FIXTURE )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( SingleLayer )
|
||||
{
|
||||
ZONE zone( &m_board );
|
||||
|
||||
zone.SetLayer( F_Cu );
|
||||
|
||||
BOOST_CHECK( zone.GetLayer() == F_Cu );
|
||||
BOOST_CHECK( zone.GetLayer() == zone.GetFirstLayer() );
|
||||
|
||||
BOOST_CHECK( zone.IsOnCopperLayer() == true );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( MultipleLayers )
|
||||
{
|
||||
ZONE zone( &m_board );
|
||||
|
||||
zone.SetLayerSet( { F_Cu, B_Cu } );
|
||||
|
||||
// There is no "the" layer in a multi-layer zone
|
||||
BOOST_CHECK( zone.GetLayer() == UNDEFINED_LAYER );
|
||||
// ... but there is a first layer
|
||||
BOOST_CHECK( zone.GetFirstLayer() == F_Cu );
|
||||
|
||||
BOOST_CHECK( zone.IsOnCopperLayer() == true );
|
||||
}
|
||||
|
||||
/**
|
||||
* During zone loading, the layer is set to Rescue if the layer is not found.
|
||||
* This is not a UI-visible layer, so make sure it can still be retreived.
|
||||
*
|
||||
* https://gitlab.com/kicad/code/kicad/-/issues/18553
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE( RescuedLayers )
|
||||
{
|
||||
ZONE zone( &m_board );
|
||||
|
||||
zone.SetLayer( Rescue );
|
||||
|
||||
BOOST_CHECK( zone.GetLayer() == Rescue );
|
||||
BOOST_CHECK( zone.GetLayer() == zone.GetFirstLayer() );
|
||||
|
||||
BOOST_CHECK( zone.IsOnCopperLayer() == false );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
Loading…
x
Reference in New Issue
Block a user