Reimplementation of 513486b0ec.

(For https://gitlab.com/kicad/code/kicad/-/issues/11020.)
This commit is contained in:
Jeff Young 2022-03-03 15:05:59 +00:00
parent 912c2eac09
commit 191558e2d7
1 changed files with 112 additions and 110 deletions

View File

@ -910,17 +910,36 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
if( IsNetnameLayer( aLayer ) )
{
// Is anything that we can display enabled?
if( m_pcbSettings.m_netNamesOnPads || m_pcbSettings.m_padNumbers )
wxString netname;
wxString padNumber;
if( m_pcbSettings.m_padNumbers )
padNumber = UnescapeString( aPad->GetNumber() );
if( m_pcbSettings.m_netNamesOnPads )
netname = UnescapeString( aPad->GetShortNetname() );
if( aPad->GetBoard()->IsElementVisible( LAYER_NO_CONNECTS )
&& aPad->GetShortNetname().StartsWith( wxT( "unconnected-(" ) ) )
{
bool displayNetname = ( m_pcbSettings.m_netNamesOnPads && !aPad->GetNetname().empty() );
wxString pinType = aPad->GetPinType();
if( pinType == wxT( "no_connect" ) || pinType.EndsWith( wxT( "+no_connect" ) ) )
netname = wxT( "x" );
else if( pinType == wxT( "free" ) )
netname = wxT( "*" );
}
if( netname.IsEmpty() && padNumber.IsEmpty() )
return;
EDA_RECT padBBox = aPad->GetBoundingBox();
VECTOR2D position = padBBox.Centre();
VECTOR2D padsize = VECTOR2D( padBBox.GetSize() );
if( aPad->GetShape() != PAD_SHAPE::CUSTOM )
{
// Don't allow a 45º rotation to bloat a pad's bounding box unnecessarily
// Don't allow a 45° rotation to bloat a pad's bounding box unnecessarily
double limit = std::min( aPad->GetSize().x, aPad->GetSize().y ) * 1.1;
if( padsize.x > limit && padsize.y > limit )
@ -965,29 +984,14 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
// Divide the space, to display both pad numbers and netnames and set the Y text
// position to display 2 lines
if( displayNetname && m_pcbSettings.m_padNumbers )
if( !netname.IsEmpty() && !padNumber.IsEmpty() )
{
size = size / 2.5;
textpos.y = size / 1.7;
}
if( displayNetname )
if( !netname.IsEmpty() )
{
wxString netname = UnescapeString( aPad->GetShortNetname() );
wxString pinType = aPad->GetPinType();
// If the pad is actually not connected (unique pad in the net),
// shorten the displayed netname (actual name not useful)
// Can happen if the pad netname is edited inside the board editor, therefore
// having a netname not coming from schematic
if( netname.StartsWith( wxT( "unconnected-(" ) ) )
{
if( pinType == wxT( "no_connect" ) || pinType.EndsWith( wxT( "+no_connect" ) ) )
netname = wxT( "x" );
else if( pinType == wxT( "free" ) )
netname = wxT( "*" );
}
// approximate the size of net name text:
double tsize = 1.5 * padsize.x / std::max( PrintableCharCount( netname ), 1 );
tsize = std::min( tsize, size );
@ -1001,9 +1005,8 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
m_gal->BitmapText( netname, textpos, 0.0 );
}
if( m_pcbSettings.m_padNumbers )
if( !padNumber.IsEmpty() )
{
const wxString& padNumber = aPad->GetNumber();
textpos.y = -textpos.y;
// approximate the size of the pad number text:
@ -1021,7 +1024,6 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
}
m_gal->Restore();
}
return;
}