Keep netnames on tracks within the viewport when possible.

Fixes https://gitlab.com/kicad/code/kicad/issues/2032
This commit is contained in:
Jeff Young 2021-10-24 11:14:54 +01:00
parent 9de62d1dd4
commit 58d4ac2a97
7 changed files with 90 additions and 14 deletions

View File

@ -50,6 +50,14 @@ public:
m_init( true ) m_init( true )
{ } { }
template<class T>
EDA_RECT( const BOX2<T> aBox )
{
m_pos = (wxPoint) aBox.GetPosition();
m_size.x = aBox.GetWidth();
m_size.y = aBox.GetHeight();
}
virtual ~EDA_RECT() { }; virtual ~EDA_RECT() { };
wxPoint Centre() const wxPoint Centre() const

View File

@ -451,6 +451,9 @@ public:
} }
} }
/**
* Set a layer display-only (ie: to be rendered but not returned by hit test queries).
*/
inline void SetLayerDisplayOnly( int aLayer, bool aDisplayOnly = true ) inline void SetLayerDisplayOnly( int aLayer, bool aDisplayOnly = true )
{ {
wxCHECK( aLayer < (int) m_layers.size(), /*void*/ ); wxCHECK( aLayer < (int) m_layers.size(), /*void*/ );

View File

@ -389,15 +389,13 @@ void PCB_DRAW_PANEL_GAL::SetTopLayer( PCB_LAYER_ID aLayer )
m_view->GetLayerOrder( LAYER_MARKER_SHADOWS ) + 4 ); m_view->GetLayerOrder( LAYER_MARKER_SHADOWS ) + 4 );
} }
} }
else if( IsCopperLayer( aLayer ) )
if( IsCopperLayer( aLayer ) )
{ {
m_view->SetTopLayer( ZONE_LAYER_FOR( aLayer ) );
// Display labels for copper layers on the top // Display labels for copper layers on the top
m_view->SetTopLayer( GetNetnameLayer( aLayer ) ); m_view->SetTopLayer( GetNetnameLayer( aLayer ) );
m_view->SetTopLayer( ZONE_LAYER_FOR( aLayer ) );
}
else
{
m_view->SetTopLayer( ZONE_LAYER_FOR( aLayer ) );
} }
m_view->EnableTopLayer( true ); m_view->EnableTopLayer( true );

View File

@ -177,7 +177,8 @@ END_EVENT_TABLE()
PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB_EDITOR, _( "PCB Editor" ), wxDefaultPosition, PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB_EDITOR, _( "PCB Editor" ), wxDefaultPosition,
wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, PCB_EDIT_FRAME_NAME ), wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, PCB_EDIT_FRAME_NAME ),
m_exportNetlistAction( nullptr ), m_findDialog( nullptr ) m_exportNetlistAction( nullptr ),
m_findDialog( nullptr )
{ {
m_maximizeByDefault = true; m_maximizeByDefault = true;
m_showBorderAndTitleBlock = true; // true to display sheet references m_showBorderAndTitleBlock = true; // true to display sheet references
@ -309,6 +310,22 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
// to calculate the wrong zoom size. See PCB_EDIT_FRAME::onSize(). // to calculate the wrong zoom size. See PCB_EDIT_FRAME::onSize().
Bind( wxEVT_SIZE, &PCB_EDIT_FRAME::onSize, this ); Bind( wxEVT_SIZE, &PCB_EDIT_FRAME::onSize, this );
// Redraw netnames (so that they fall within the current viewport) after the viewport
// has stopped changing. Redrawing them without the timer moves them smoothly with scrolling,
// making it look like the tracks are being dragged -- which we don't want.
m_redrawNetnamesTimer.SetOwner( this );
Connect( wxEVT_TIMER, wxTimerEventHandler( PCB_EDIT_FRAME::redrawNetnames ), nullptr, this );
Bind( wxEVT_IDLE,
[this]( wxIdleEvent& aEvent )
{
if( GetCanvas()->GetView()->GetViewport() != m_lastViewport )
{
m_lastViewport = GetCanvas()->GetView()->GetViewport();
m_redrawNetnamesTimer.StartOnce( 100 );
}
} );
resolveCanvasType(); resolveCanvasType();
setupUnits( config() ); setupUnits( config() );
@ -438,6 +455,20 @@ BOARD_ITEM_CONTAINER* PCB_EDIT_FRAME::GetModel() const
} }
void PCB_EDIT_FRAME::redrawNetnames( wxTimerEvent& aEvent )
{
KIGFX::VIEW* view = GetCanvas()->GetView();
for( PCB_TRACK* track : GetBoard()->Tracks() )
{
if( track->ViewGetLOD( GetNetnameLayer( track->GetLayer() ), view ) < view->GetScale() )
view->Update( track, KIGFX::REPAINT );
}
GetCanvas()->Refresh();
}
void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings ) void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
{ {
PCB_BASE_FRAME::SetPageSettings( aPageSettings ); PCB_BASE_FRAME::SetPageSettings( aPageSettings );

View File

@ -760,6 +760,8 @@ protected:
int inferLegacyEdgeClearance( BOARD* aBoard ); int inferLegacyEdgeClearance( BOARD* aBoard );
void redrawNetnames( wxTimerEvent& aEvent );
public: public:
PCB_LAYER_BOX_SELECTOR* m_SelLayerBox; // a combo box to display and select active layer PCB_LAYER_BOX_SELECTOR* m_SelLayerBox; // a combo box to display and select active layer
@ -785,7 +787,13 @@ private:
DIALOG_FIND* m_findDialog; DIALOG_FIND* m_findDialog;
wxTimer* m_eventCounterTimer; /**
* Keep track of viewport so that track net labels can be adjusted when it changes.
*/
BOX2D m_lastViewport;
wxTimer m_redrawNetnamesTimer;
wxTimer* m_eventCounterTimer;
}; };
#endif // __PCB_EDIT_FRAME_H__ #endif // __PCB_EDIT_FRAME_H__

View File

@ -117,7 +117,7 @@ void PCB_RENDER_SETTINGS::LoadColors( const COLOR_SETTINGS* aSettings )
// Netnames for copper layers // Netnames for copper layers
for( LSEQ cu = LSET::AllCuMask().CuStack(); cu; ++cu ) for( LSEQ cu = LSET::AllCuMask().CuStack(); cu; ++cu )
{ {
const COLOR4D lightLabel( 0.8, 0.8, 0.8, 0.7 ); const COLOR4D lightLabel( 1.0, 1.0, 1.0, 0.7 );
const COLOR4D darkLabel = lightLabel.Inverted(); const COLOR4D darkLabel = lightLabel.Inverted();
PCB_LAYER_ID layer = *cu; PCB_LAYER_ID layer = *cu;
@ -538,8 +538,8 @@ bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
void PCB_PAINTER::draw( const PCB_TRACK* aTrack, int aLayer ) void PCB_PAINTER::draw( const PCB_TRACK* aTrack, int aLayer )
{ {
VECTOR2D start( aTrack->GetStart() ); VECTOR2I start( aTrack->GetStart() );
VECTOR2D end( aTrack->GetEnd() ); VECTOR2I end( aTrack->GetEnd() );
int width = aTrack->GetWidth(); int width = aTrack->GetWidth();
COLOR4D color = m_pcbSettings.GetColor( aTrack, aLayer ); COLOR4D color = m_pcbSettings.GetColor( aTrack, aLayer );
@ -551,11 +551,23 @@ void PCB_PAINTER::draw( const PCB_TRACK* aTrack, int aLayer )
if( aTrack->GetNetCode() <= NETINFO_LIST::UNCONNECTED ) if( aTrack->GetNetCode() <= NETINFO_LIST::UNCONNECTED )
return; return;
VECTOR2D line = ( end - start ); // When drawing netnames, clip the track to the viewport
BOX2D viewport;
VECTOR2D screenSize = m_gal->GetScreenPixelSize();
const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
viewport.SetOrigin( VECTOR2D( matrix * VECTOR2D( 0, 0 ) ) );
viewport.SetEnd( VECTOR2D( matrix * screenSize ) );
EDA_RECT clipBox( viewport.Normalize() );
ClipLine( &clipBox, start.x, start.y, end.x, end.y );
VECTOR2I line = ( end - start );
double length = line.EuclideanNorm(); 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 < 10 * width ) if( length < 6 * width )
return; return;
const wxString& netName = UnescapeString( aTrack->GetShortNetname() ); const wxString& netName = UnescapeString( aTrack->GetShortNetname() );
@ -581,7 +593,6 @@ void PCB_PAINTER::draw( const PCB_TRACK* aTrack, int aLayer )
textPosition.y += penWidth / 1.4; textPosition.y += penWidth / 1.4;
} }
m_gal->SetIsStroke( true ); m_gal->SetIsStroke( true );
m_gal->SetIsFill( false ); m_gal->SetIsFill( false );
m_gal->SetStrokeColor( color ); m_gal->SetStrokeColor( color );

View File

@ -556,6 +556,9 @@ double PCB_TRACK::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
if( IsNetnameLayer( aLayer ) ) if( IsNetnameLayer( aLayer ) )
{ {
if( GetNetCode() <= NETINFO_LIST::UNCONNECTED )
return HIDE;
// Hide netnames on dimmed tracks // Hide netnames on dimmed tracks
if( renderSettings->GetHighContrast() ) if( renderSettings->GetHighContrast() )
{ {
@ -563,6 +566,20 @@ double PCB_TRACK::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
return HIDE; return HIDE;
} }
// When drawing netnames, clip the track to the viewport
VECTOR2I start( GetStart() );
VECTOR2I end( GetEnd() );
EDA_RECT clipBox( aView->GetViewport() );
ClipLine( &clipBox, start.x, start.y, end.x, end.y );
VECTOR2I line = ( end - start );
double length = line.EuclideanNorm();
// Check if the track is long enough to have a netname displayed
if( length < 6 * GetWidth() )
return HIDE;
// Netnames will be shown only if zoom is appropriate // Netnames will be shown only if zoom is appropriate
return ( double ) Millimeter2iu( 4 ) / ( m_Width + 1 ); return ( double ) Millimeter2iu( 4 ) / ( m_Width + 1 );
} }