From 62fb5697b4a54bd8cdb09420ca564eebd85e37a1 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Wed, 19 Jun 2024 20:55:33 +0300 Subject: [PATCH] Optimize redrawNetnames. Using RTree is slower in this case. RTree: 25 ms when moving cursor This method: 5 ms when panning/zooming --- pcbnew/pcb_edit_frame.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index e77d98088a..45b8eb1dcc 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -402,8 +402,13 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : Bind( wxEVT_IDLE, [this]( wxIdleEvent& aEvent ) { - if( GetCanvas()->GetView()->GetViewport() != m_lastNetnamesViewport ) + BOX2D viewport = GetCanvas()->GetView()->GetViewport(); + + if( viewport != m_lastNetnamesViewport ) + { redrawNetnames(); + m_lastNetnamesViewport = viewport; + } // Do not forget to pass the Idle event to other clients: aEvent.Skip(); @@ -595,24 +600,23 @@ void PCB_EDIT_FRAME::redrawNetnames() KIGFX::VIEW* view = GetCanvas()->GetView(); 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 ), - [&]( KIGFX::VIEW_ITEM* viewItem ) -> bool - { - BOARD_ITEM* item = static_cast( viewItem ); + for( PCB_TRACK* track : GetBoard()->Tracks() ) + { + // Don't need to update vias + if( track->Type() == PCB_VIA_T ) + continue; - if( item->IsConnected() - && ( item->Type() == PCB_TRACE_T || item->Type() == PCB_SHAPE_T ) - && item->ViewGetLOD( GetNetnameLayer( item->GetLayer() ), view ) < scale ) - { - view->Update( item, KIGFX::REPAINT ); - } + // Don't update invisible tracks + if( !clipbox.Intersects( BOX2I_MINMAX( track->GetStart(), track->GetEnd() ) ) ) + continue; - return true; - } ); + if( track->ViewGetLOD( GetNetnameLayer( track->GetLayer() ), view ) < view->GetScale() ) + view->Update( track, KIGFX::REPAINT ); + } }