Hysteresis for track netnames.

Fixes https://gitlab.com/kicad/code/kicad/issues/10416
This commit is contained in:
Jeff Young 2022-02-28 20:34:30 +00:00
parent eb06ecab10
commit 69a6033905
3 changed files with 24 additions and 11 deletions

View File

@ -322,7 +322,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
if( GetCanvas()->GetView()->GetViewport() != m_lastViewport )
{
m_lastViewport = GetCanvas()->GetView()->GetViewport();
m_redrawNetnamesTimer.StartOnce( 100 );
m_redrawNetnamesTimer.StartOnce( 200 );
}
// Do not forget to pass the Idle event to other clients:

View File

@ -580,22 +580,32 @@ void PCB_PAINTER::draw( const PCB_TRACK* aTrack, int aLayer )
viewport.SetEnd( VECTOR2D( matrix * screenSize ) );
EDA_RECT clipBox( viewport.Normalize() );
SEG visibleSeg( start, end );
ClipLine( &clipBox, start.x, start.y, end.x, end.y );
VECTOR2I line = ( end - start );
double length = line.EuclideanNorm();
ClipLine( &clipBox, visibleSeg.A.x, visibleSeg.A.y, visibleSeg.B.x, visibleSeg.B.y );
// Check if the track is long enough to have a netname displayed
if( length < 6 * width )
if( visibleSeg.Length() < 6 * width )
return;
const wxString& netName = UnescapeString( aTrack->GetShortNetname() );
double textSize = width;
double penWidth = width / 12.0;
VECTOR2D textPosition = start + line / 2.0; // center of the track
VECTOR2D textPosition = ( visibleSeg.A + visibleSeg.B ) / 2.0; // center of the track
EDA_ANGLE textOrientation;
// If the last position is still on the track, and it's some reasonable distance inside
// the viewport then don't move the netname; just use the last position.
if( visibleSeg.Distance( aTrack->m_LastNetnamePosition ) < penWidth
&& clipBox.Inflate( -width * 6 ).Contains( aTrack->m_LastNetnamePosition ) )
{
textPosition = aTrack->m_LastNetnamePosition;
}
else
{
aTrack->m_LastNetnamePosition = textPosition;
}
if( end.y == start.y ) // horizontal
{
textOrientation = ANGLE_HORIZONTAL;
@ -608,7 +618,8 @@ void PCB_PAINTER::draw( const PCB_TRACK* aTrack, int aLayer )
}
else
{
textOrientation = EDA_ANGLE( -atan( line.y / line.x ), RADIANS_T );
textOrientation = EDA_ANGLE( visibleSeg.B - visibleSeg.A ) + ANGLE_90;
textOrientation.Normalize90();
textPosition.x += penWidth / 1.4;
textPosition.y += penWidth / 1.4;
}

View File

@ -233,11 +233,13 @@ public:
protected:
void GetMsgPanelInfoBase_Common( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) const;
public:
mutable VECTOR2I m_LastNetnamePosition;
protected:
int m_Width; ///< Thickness of track, or via diameter
VECTOR2I m_Start; ///< Line start point
VECTOR2I m_End; ///< Line end point
};