7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 14:41:42 +00:00

Pcbnew: apply same IPC rule in properties panel as in dialog

This means when you switch a pad to be roundable (round rect or
chamfered-with-round), you get the same behaviour as in the dialog
(and an IPC-compliant pad by default).

Also fixes the radius visibility in the properties panel for
chamfered pads (which can have radii).
This commit is contained in:
John Beard 2025-01-02 00:03:24 +08:00
parent 1f551ea0e4
commit e9f8b2ba77
6 changed files with 124 additions and 41 deletions

View File

@ -769,6 +769,7 @@ set( PCB_COMMON_SRCS
${CMAKE_SOURCE_DIR}/pcbnew/netinfo_item.cpp
${CMAKE_SOURCE_DIR}/pcbnew/netinfo_list.cpp
${CMAKE_SOURCE_DIR}/pcbnew/pad.cpp
${CMAKE_SOURCE_DIR}/pcbnew/pad_utils.cpp
${CMAKE_SOURCE_DIR}/pcbnew/padstack.cpp
${CMAKE_SOURCE_DIR}/pcbnew/pcb_target.cpp
${CMAKE_SOURCE_DIR}/pcbnew/pcb_reference_image.cpp

View File

@ -40,6 +40,7 @@
#include <dialogs/html_message_box.h>
#include <macros.h>
#include <pad.h>
#include <pad_utils.h>
#include <pcb_base_frame.h>
#include <footprint_edit_frame.h>
#include <pcb_painter.h>
@ -106,36 +107,6 @@ static PAD_ATTRIB code_type[] =
#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, PCB_LAYER_ID aLayer )
{
const PAD_SHAPE shape = aPad.GetShape( aLayer );
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, PCB_LAYER_ID aLayer )
{
const double defaultProportion = 0.25;
const double minimumSizeIU = pcbIUScale.mmToIU( 0.25 );
const VECTOR2I& size = aPad.GetSize( aLayer );
const int padMinSizeIU = std::min( size.x, size.y );
const double defaultRadiusIU = std::min( minimumSizeIU, padMinSizeIU * defaultProportion );
// Convert back to a ratio
return defaultRadiusIU / padMinSizeIU;
}
void PCB_BASE_FRAME::ShowPadPropertiesDialog( PAD* aPad )
{
DIALOG_PAD_PROPERTIES dlg( this, aPad );
@ -228,7 +199,7 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, PAD* aPad
m_previewPad->Padstack().ForEachUniqueLayer(
[&]( PCB_LAYER_ID aLayer )
{
if( !PadHasMeaningfulRoundingRadius( *m_previewPad, aLayer ) )
if( !PAD_UTILS::PadHasMeaningfulRoundingRadius( *m_previewPad, aLayer ) )
m_previewPad->SetRoundRectRadiusRatio( aLayer, 0.0 );
} );
@ -958,8 +929,9 @@ void DIALOG_PAD_PROPERTIES::OnPadShapeSelection( wxCommandEvent& event )
// Reasonable defaults
if( m_previewPad->GetRoundRectRadiusRatio( m_editLayer ) == 0.0 )
{
m_cornerRatio.ChangeDoubleValue(
GetDefaultIpcRoundingRatio( *m_previewPad, m_editLayer ) * 100 );
const double ipcRadiusRatio =
PAD_UTILS::GetDefaultIpcRoundingRatio( *m_previewPad, m_editLayer );
m_cornerRatio.ChangeDoubleValue( ipcRadiusRatio * 100 );
}
break;
@ -994,8 +966,9 @@ void DIALOG_PAD_PROPERTIES::OnPadShapeSelection( wxCommandEvent& event )
if( m_previewPad->GetRoundRectRadiusRatio( m_editLayer ) == 0.0
&& m_previewPad->GetChamferRectRatio( m_editLayer ) == 0.0 )
{
m_previewPad->SetRoundRectRadiusRatio(
m_editLayer, GetDefaultIpcRoundingRatio( *m_previewPad, m_editLayer ) );
const double ipcRadiusRatio =
PAD_UTILS::GetDefaultIpcRoundingRatio( *m_previewPad, m_editLayer );
m_previewPad->SetRoundRectRadiusRatio( m_editLayer, ipcRadiusRatio );
m_previewPad->SetChamferRectRatio( m_editLayer, 0.2 );
}

View File

@ -43,6 +43,7 @@
#include <footprint.h>
#include <lset.h>
#include <pad.h>
#include <pad_utils.h>
#include <pcb_shape.h>
#include <connectivity/connectivity_data.h>
#include <eda_units.h>
@ -879,6 +880,25 @@ void PAD::SetAttribute( PAD_ATTRIB aAttribute )
}
void PAD::SetFrontShape( PAD_SHAPE aShape )
{
const bool wasRoundable = PAD_UTILS::PadHasMeaningfulRoundingRadius( *this, F_Cu );
m_padStack.SetShape( aShape, F_Cu );
const bool isRoundable = PAD_UTILS::PadHasMeaningfulRoundingRadius( *this, F_Cu );
// If we have become roundable, set a sensible rounding default using the IPC rules.
if( !wasRoundable && isRoundable )
{
const double ipcRadiusRatio = PAD_UTILS::GetDefaultIpcRoundingRatio( *this, F_Cu );
m_padStack.SetRoundRectRadiusRatio( ipcRadiusRatio, F_Cu );
}
SetDirty();
}
void PAD::SetProperty( PAD_PROP aProperty )
{
m_property = aProperty;
@ -2619,7 +2639,7 @@ static struct PAD_DESC
if( pad->Padstack().Mode() != PADSTACK::MODE::NORMAL )
return false;
return pad->GetShape( F_Cu ) == PAD_SHAPE::ROUNDRECT;
return PAD_UTILS::PadHasMeaningfulRoundingRadius( *pad, F_Cu );
}
return false;

View File

@ -193,11 +193,7 @@ public:
PAD_SHAPE GetShape( PCB_LAYER_ID aLayer ) const { return m_padStack.Shape( aLayer ); }
// Used for the properties panel, which does not support padstacks at the moment
void SetFrontShape( PAD_SHAPE aShape )
{
m_padStack.SetShape( aShape, F_Cu );
SetDirty();
}
void SetFrontShape( PAD_SHAPE aShape );
PAD_SHAPE GetFrontShape() const { return m_padStack.Shape( F_Cu ); }

48
pcbnew/pad_utils.cpp Normal file
View File

@ -0,0 +1,48 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2025 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 "pad_utils.h"
double PAD_UTILS::GetDefaultIpcRoundingRatio( const PAD& aPad, PCB_LAYER_ID aLayer )
{
const double defaultProportion = 0.25;
const double minimumSizeIU = pcbIUScale.mmToIU( 0.25 );
const VECTOR2I& size = aPad.GetSize( aLayer );
const int padMinSizeIU = std::min( size.x, size.y );
const double defaultRadiusIU = std::min( minimumSizeIU, padMinSizeIU * defaultProportion );
// Convert back to a ratio
return defaultRadiusIU / padMinSizeIU;
}
/**
* @brief Returns true if the pad's rounding ratio is valid (i.e. the pad
* has a shape where that is meaningful)
*/
bool PAD_UTILS::PadHasMeaningfulRoundingRadius( const PAD& aPad, PCB_LAYER_ID aLayer )
{
const PAD_SHAPE shape = aPad.GetShape( aLayer );
return shape == PAD_SHAPE::ROUNDRECT || shape == PAD_SHAPE::CHAMFERED_RECT;
}

45
pcbnew/pad_utils.h Normal file
View File

@ -0,0 +1,45 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2025 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
*/
#pragma once
#include <pad.h>
namespace PAD_UTILS
{
/**
* @brief Returns true if the pad's rounding ratio is valid (i.e. the pad
* has a shape where that is meaningful)
*/
bool PadHasMeaningfulRoundingRadius( const PAD& aPad, PCB_LAYER_ID aLayer );
/**
* @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
*/
double GetDefaultIpcRoundingRatio( const PAD& aPad, PCB_LAYER_ID aLayer );
} // namespace PAD_UTILS