Hysteresis for track netnames.
Fixes https://gitlab.com/kicad/code/kicad/issues/10416
This commit is contained in:
parent
eb06ecab10
commit
69a6033905
|
@ -322,7 +322,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
||||||
if( GetCanvas()->GetView()->GetViewport() != m_lastViewport )
|
if( GetCanvas()->GetView()->GetViewport() != m_lastViewport )
|
||||||
{
|
{
|
||||||
m_lastViewport = GetCanvas()->GetView()->GetViewport();
|
m_lastViewport = GetCanvas()->GetView()->GetViewport();
|
||||||
m_redrawNetnamesTimer.StartOnce( 100 );
|
m_redrawNetnamesTimer.StartOnce( 200 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not forget to pass the Idle event to other clients:
|
// Do not forget to pass the Idle event to other clients:
|
||||||
|
|
|
@ -572,30 +572,40 @@ void PCB_PAINTER::draw( const PCB_TRACK* aTrack, int aLayer )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// When drawing netnames, clip the track to the viewport
|
// When drawing netnames, clip the track to the viewport
|
||||||
BOX2D viewport;
|
BOX2D viewport;
|
||||||
VECTOR2D screenSize = m_gal->GetScreenPixelSize();
|
VECTOR2D screenSize = m_gal->GetScreenPixelSize();
|
||||||
const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
|
const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
|
||||||
|
|
||||||
viewport.SetOrigin( VECTOR2D( matrix * VECTOR2D( 0, 0 ) ) );
|
viewport.SetOrigin( VECTOR2D( matrix * VECTOR2D( 0, 0 ) ) );
|
||||||
viewport.SetEnd( VECTOR2D( matrix * screenSize ) );
|
viewport.SetEnd( VECTOR2D( matrix * screenSize ) );
|
||||||
|
|
||||||
EDA_RECT clipBox( viewport.Normalize() );
|
EDA_RECT clipBox( viewport.Normalize() );
|
||||||
|
SEG visibleSeg( start, end );
|
||||||
|
|
||||||
ClipLine( &clipBox, start.x, start.y, end.x, end.y );
|
ClipLine( &clipBox, visibleSeg.A.x, visibleSeg.A.y, visibleSeg.B.x, visibleSeg.B.y );
|
||||||
|
|
||||||
VECTOR2I line = ( end - start );
|
|
||||||
double length = line.EuclideanNorm();
|
|
||||||
|
|
||||||
// Check if the track is long enough to have a netname displayed
|
// Check if the track is long enough to have a netname displayed
|
||||||
if( length < 6 * width )
|
if( visibleSeg.Length() < 6 * width )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const wxString& netName = UnescapeString( aTrack->GetShortNetname() );
|
const wxString& netName = UnescapeString( aTrack->GetShortNetname() );
|
||||||
double textSize = width;
|
double textSize = width;
|
||||||
double penWidth = width / 12.0;
|
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;
|
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
|
if( end.y == start.y ) // horizontal
|
||||||
{
|
{
|
||||||
textOrientation = ANGLE_HORIZONTAL;
|
textOrientation = ANGLE_HORIZONTAL;
|
||||||
|
@ -608,7 +618,8 @@ void PCB_PAINTER::draw( const PCB_TRACK* aTrack, int aLayer )
|
||||||
}
|
}
|
||||||
else
|
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.x += penWidth / 1.4;
|
||||||
textPosition.y += penWidth / 1.4;
|
textPosition.y += penWidth / 1.4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,11 +233,13 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void GetMsgPanelInfoBase_Common( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) const;
|
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
|
int m_Width; ///< Thickness of track, or via diameter
|
||||||
VECTOR2I m_Start; ///< Line start point
|
VECTOR2I m_Start; ///< Line start point
|
||||||
VECTOR2I m_End; ///< Line end point
|
VECTOR2I m_End; ///< Line end point
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue