7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-18 21:51:40 +00:00

BOARD: add helper function GetCopperLayerStackMaxId() and remove dead code

GetCopperLayerStackMaxId() replaces GetCopperLayerCount()*2 and is more
understandable in code where the max allowed PCB_LAYER_ID value is needed.
Removed also a dead code related to GetCopperLayerCount() < 2, broken and not
allowed in Kicad.
This commit is contained in:
jean-pierre charras 2024-10-06 09:37:04 +02:00
parent df0de2b059
commit b193249d1c
4 changed files with 23 additions and 31 deletions

View File

@ -745,6 +745,19 @@ void BOARD::SetCopperLayerCount( int aCount )
}
PCB_LAYER_ID BOARD::GetCopperLayerStackMaxId() const
{
int imax = GetCopperLayerCount();
// layers IDs are F_Cu, B_Cu, and even IDs values (imax values)
if( imax <= 2 ) // at least 2 layers are expected
return B_Cu;
// For a 4 layer, last ID is In2_Cu = 6 (IDs are 0, 2, 4, 6)
return static_cast<PCB_LAYER_ID>( (imax-1) * 2 );
}
int BOARD::LayerDepth( PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer ) const
{
if( aStartLayer > aEndLayer )

View File

@ -570,6 +570,12 @@ public:
int GetCopperLayerCount() const;
void SetCopperLayerCount( int aCount );
/**
* @return The copper layer max PCB_LAYER_ID in the BOARD.
* similar to GetCopperLayerCount(), but returns the max PCB_LAYER_ID
*/
PCB_LAYER_ID GetCopperLayerStackMaxId() const;
PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayer ) const;
int LayerDepth( PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer ) const;

View File

@ -94,21 +94,8 @@ void PCB_EDIT_FRAME::SwitchLayer( PCB_LAYER_ID layer )
// enabled needs to be checked.
if( IsCopperLayer( layer ) )
{
// If only one copper layer is enabled, the only such layer that can be selected to is
// the "Back" layer (so the selection of any other copper layer is disregarded).
if( GetBoard()->GetCopperLayerCount() < 2 )
{
if( layer != B_Cu )
return;
}
// If more than one copper layer is enabled, the "Copper" and "Component" layers can be
// selected, but the total number of copper layers determines which internal layers are
// also capable of being selected.
else
{
if( layer != B_Cu && layer != F_Cu && layer >= GetBoard()->GetCopperLayerCount()*2 )
return;
}
if( layer > GetBoard()->GetCopperLayerStackMaxId() )
return;
}
// Is yet more checking required? E.g. when the layer to be selected is a non-copper layer,

View File

@ -723,22 +723,8 @@ void PCB_BASE_FRAME::SwitchLayer( PCB_LAYER_ID layer )
// currently enabled needs to be checked.
if( IsCopperLayer( layer ) )
{
// If only one copper layer is enabled, the only such layer that can be selected to
// is the "Copper" layer (so the selection of any other copper layer is disregarded).
if( m_pcb->GetCopperLayerCount() < 2 )
{
if( layer != B_Cu )
return;
}
// If more than one copper layer is enabled, the "Copper" and "Component" layers
// can be selected, but the total number of copper layers determines which internal
// layers are also capable of being selected.
else
{
if( layer != B_Cu && layer != F_Cu && layer >= m_pcb->GetCopperLayerCount()*2 )
return;
}
if( layer > m_pcb->GetCopperLayerStackMaxId() )
return;
}
// Is yet more checking required? E.g. when the layer to be selected is a non-copper