pcbnew: draw net labels on vias [wip]

This commit is contained in:
Tomasz Włostowski 2017-04-22 17:45:03 +02:00
parent 96865d45e3
commit 706db2a486
3 changed files with 63 additions and 1 deletions

View File

@ -153,6 +153,7 @@ enum NETNAMES_LAYER_ID: int
LAYER_PAD_FR_NETNAMES, LAYER_PAD_FR_NETNAMES,
LAYER_PAD_BK_NETNAMES, LAYER_PAD_BK_NETNAMES,
LAYER_PADS_NETNAMES, LAYER_PADS_NETNAMES,
LAYER_VIAS_NETNAMES,
NETNAMES_LAYER_ID_END NETNAMES_LAYER_ID_END
}; };
@ -750,6 +751,7 @@ inline int GetNetnameLayer( int aLayer )
return LAYER_PAD_FR_NETNAMES; return LAYER_PAD_FR_NETNAMES;
else if( aLayer == LAYER_PAD_BK ) else if( aLayer == LAYER_PAD_BK )
return LAYER_PAD_BK_NETNAMES; return LAYER_PAD_BK_NETNAMES;
// fixme :via names
// Fallback // Fallback
return Cmts_User; return Cmts_User;

View File

@ -393,6 +393,64 @@ void PCB_PAINTER::draw( const VIA* aVia, int aLayer )
VECTOR2D center( aVia->GetStart() ); VECTOR2D center( aVia->GetStart() );
double radius = 0.0; double radius = 0.0;
// Only draw the via if at least one of the layers it crosses is being displayed
BOARD* brd = aVia->GetBoard( );
if( !( brd->GetVisibleLayers() & aVia->GetLayerSet() ).any() )
return;
// Draw description layer
if( IsNetnameLayer( aLayer ) )
{
VECTOR2D position( center );
// Is anything that we can display enabled?
if( m_pcbSettings.m_netNamesOnVias )
{
bool displayNetname = ( !aVia->GetNetname().empty() );
double maxSize = PCB_RENDER_SETTINGS::MAX_FONT_SIZE;
double size = aVia->GetWidth();
// Font size limits
if( size > maxSize )
size = maxSize;
m_gal->Save();
m_gal->Translate( position );
// Default font settings
m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER );
m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER );
m_gal->SetFontBold( false );
m_gal->SetFontItalic( false );
m_gal->SetTextMirrored( false );
m_gal->SetStrokeColor( m_pcbSettings.GetColor( NULL, aLayer ) );
m_gal->SetIsStroke( true );
m_gal->SetIsFill( false );
// Set the text position to the pad shape position (the pad position is not the best place)
VECTOR2D textpos( 0.0, 0.0 );
if( displayNetname )
{
// calculate the size of net name text:
double tsize = 1.5 * size / aVia->GetShortNetname().Length();
tsize = std::min( tsize, size );
// Use a smaller text size to handle interline, pen size..
tsize *= 0.7;
VECTOR2D namesize( tsize, tsize );
m_gal->SetGlyphSize( namesize );
m_gal->SetLineWidth( namesize.x / 12.0 );
m_gal->BitmapText( aVia->GetShortNetname(), textpos, 0.0 );
}
m_gal->Restore();
}
return;
}
// Choose drawing settings depending on if we are drawing via's pad or hole // Choose drawing settings depending on if we are drawing via's pad or hole
if( aLayer == LAYER_VIAS_HOLES ) if( aLayer == LAYER_VIAS_HOLES )
radius = aVia->GetDrillValue() / 2.0; radius = aVia->GetDrillValue() / 2.0;

View File

@ -145,6 +145,9 @@ protected:
///> Flag determining if net names should be visible for tracks ///> Flag determining if net names should be visible for tracks
bool m_netNamesOnTracks; bool m_netNamesOnTracks;
///> Flag determining if net names should be visible for vias
bool m_netNamesOnVias = true;
///> Maximum font size for netnames (and other dynamically shown strings) ///> Maximum font size for netnames (and other dynamically shown strings)
static const double MAX_FONT_SIZE; static const double MAX_FONT_SIZE;
@ -208,4 +211,3 @@ protected:
} // namespace KIGFX } // namespace KIGFX
#endif /* __CLASS_PAINTER_H */ #endif /* __CLASS_PAINTER_H */