Optimize redrawNetnames.

Using RTree is slower in this case.

RTree: 25 ms when moving cursor
This method: 5 ms when panning/zooming
This commit is contained in:
Alex Shvartzkop 2024-06-19 20:55:33 +03:00
parent 31ab276aaf
commit 62fb5697b4
1 changed files with 19 additions and 15 deletions

View File

@ -402,8 +402,13 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
Bind( wxEVT_IDLE, Bind( wxEVT_IDLE,
[this]( wxIdleEvent& aEvent ) [this]( wxIdleEvent& aEvent )
{ {
if( GetCanvas()->GetView()->GetViewport() != m_lastNetnamesViewport ) BOX2D viewport = GetCanvas()->GetView()->GetViewport();
if( viewport != m_lastNetnamesViewport )
{
redrawNetnames(); redrawNetnames();
m_lastNetnamesViewport = viewport;
}
// Do not forget to pass the Idle event to other clients: // Do not forget to pass the Idle event to other clients:
aEvent.Skip(); aEvent.Skip();
@ -595,24 +600,23 @@ void PCB_EDIT_FRAME::redrawNetnames()
KIGFX::VIEW* view = GetCanvas()->GetView(); KIGFX::VIEW* view = GetCanvas()->GetView();
BOX2D viewport = view->GetViewport(); BOX2D viewport = view->GetViewport();
double scale = view->GetScale();
m_lastNetnamesViewport = viewport; // Inflate to catch most of the track width
BOX2I_MINMAX clipbox( BOX2ISafe( viewport.Inflate( pcbIUScale.mmToIU( 2.0 ) ) ) );
view->Query( BOX2ISafe( viewport ), for( PCB_TRACK* track : GetBoard()->Tracks() )
[&]( KIGFX::VIEW_ITEM* viewItem ) -> bool
{ {
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( viewItem ); // Don't need to update vias
if( track->Type() == PCB_VIA_T )
continue;
if( item->IsConnected() // Don't update invisible tracks
&& ( item->Type() == PCB_TRACE_T || item->Type() == PCB_SHAPE_T ) if( !clipbox.Intersects( BOX2I_MINMAX( track->GetStart(), track->GetEnd() ) ) )
&& item->ViewGetLOD( GetNetnameLayer( item->GetLayer() ), view ) < scale ) continue;
{
view->Update( item, KIGFX::REPAINT ); if( track->ViewGetLOD( GetNetnameLayer( track->GetLayer() ), view ) < view->GetScale() )
view->Update( track, KIGFX::REPAINT );
} }
return true;
} );
} }