Pad dialog: respect IPC maximum pad radius

The IPC-7351C rule (which may be IPC 7352 now), is 25%, or
0.25mm, whichever is smaller. Currently the default ratio is 25%, which
is incorrect for pads with shortest edges over 1mm.

This also means that the "25%" default is applied in one place:
previously sometimes the value came from the default set in PAD,
rather than the value set by this dialog. While the PAD default isn't
changed here, this dialog no longer relies on that value for its
behaviour.
This commit is contained in:
John Beard 2023-07-20 23:45:32 +01:00
parent 7f9742791a
commit a61b9f4459
1 changed files with 43 additions and 8 deletions

View File

@ -102,6 +102,35 @@ static PAD_ATTRIB code_type[] =
#define APERTURE_DLG_TYPE 4 #define APERTURE_DLG_TYPE 4
/**
* @brief Returns true if the pad's rounding ratio is valid (i.e. the pad
* has a shape where that is meaningful)
*/
static bool PadHasMeaningfulRoundingRadius( const PAD& aPad )
{
const PAD_SHAPE shape = aPad.GetShape();
return shape == PAD_SHAPE::ROUNDRECT || shape == PAD_SHAPE::CHAMFERED_RECT;
}
/**
* @brief Get a sensible default for a rounded rectangle pad's rounding ratio
*
* According to IPC-7351C, this is 25%, or 0.25mm, whichever is smaller
*/
static double GetDefaultIpcRoundingRatio( const PAD& aPad )
{
const double defaultProportion = 0.25;
const double minimumSizeIU = pcbIUScale.mmToIU( 0.25 );
const int padMinSizeIU = std::min( aPad.GetSizeX(), aPad.GetSizeY() );
const double defaultRadiusIU = std::min( minimumSizeIU, padMinSizeIU * defaultProportion );
// Convert back to a ratio
return defaultRadiusIU / padMinSizeIU;
}
void PCB_BASE_FRAME::ShowPadPropertiesDialog( PAD* aPad ) void PCB_BASE_FRAME::ShowPadPropertiesDialog( PAD* aPad )
{ {
DIALOG_PAD_PROPERTIES dlg( this, aPad ); DIALOG_PAD_PROPERTIES dlg( this, aPad );
@ -183,6 +212,14 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, PAD* aPad
m_previewPad->GetTeardropParams() = m_masterPad->GetTeardropParams(); m_previewPad->GetTeardropParams() = m_masterPad->GetTeardropParams();
} }
// Pads have a hardcoded internal rounding ratio which is 0.25 by default, even if
// they're not a rounded shape. This makes it hard to detect an intentional 0.25
// ratio, or one that's only there because it's the PAD default.
// Zero it out here to mark that we should recompute a better ratio if the user
// selects a pad shape which would need a default rounding ratio computed for it
if( !PadHasMeaningfulRoundingRadius( *m_previewPad ) )
m_previewPad->SetRoundRectRadiusRatio( 0.0 );
if( m_isFpEditor ) if( m_isFpEditor )
{ {
m_padNetLabel->Show( false ); m_padNetLabel->Show( false );
@ -828,9 +865,9 @@ void DIALOG_PAD_PROPERTIES::OnPadShapeSelection( wxCommandEvent& event )
{ {
m_shapePropsBook->SetSelection( 2 ); m_shapePropsBook->SetSelection( 2 );
// A reasonable default (from IPC-7351C) // Reasonable defaults
if( m_previewPad->GetRoundRectRadiusRatio() == 0.0 ) if( m_previewPad->GetRoundRectRadiusRatio() == 0.0 )
m_cornerRatio.ChangeDoubleValue( 25.0 ); m_cornerRatio.ChangeDoubleValue( GetDefaultIpcRoundingRatio( *m_previewPad ) * 100 );
break; break;
} }
@ -860,14 +897,12 @@ void DIALOG_PAD_PROPERTIES::OnPadShapeSelection( wxCommandEvent& event )
case CHOICE_SHAPE_CHAMFERED_ROUNDED_RECT: case CHOICE_SHAPE_CHAMFERED_ROUNDED_RECT:
m_shapePropsBook->SetSelection( 4 ); m_shapePropsBook->SetSelection( 4 );
// Reasonable defaults (corner radius from IPC-7351C) // Reasonable defaults
if( m_previewPad->GetRoundRectRadiusRatio() == 0.0 if( m_previewPad->GetRoundRectRadiusRatio() == 0.0
&& m_previewPad->GetChamferRectRatio() == 0.0 ) && m_previewPad->GetChamferRectRatio() == 0.0 )
{ {
if( m_previewPad->GetRoundRectRadiusRatio() == 0.0 ) m_previewPad->SetRoundRectRadiusRatio(
m_previewPad->SetRoundRectRadiusRatio( 0.25 ); GetDefaultIpcRoundingRatio( *m_previewPad ) );
if( m_previewPad->GetChamferRectRatio() == 0.0 )
m_previewPad->SetChamferRectRatio( 0.2 ); m_previewPad->SetChamferRectRatio( 0.2 );
} }