Optimize redrawNetnames.

Using RTree is slower in this case.

RTree: 25 ms when moving cursor
This method: 5 ms when panning/zooming

(cherry picked from commit 62fb5697b4)
This commit is contained in:
Alex Shvartzkop 2024-06-19 20:55:33 +03:00
parent 37dd7c6df9
commit d552ce00aa
1 changed files with 20 additions and 15 deletions

View File

@ -104,6 +104,7 @@
#include <widgets/wx_aui_utils.h>
#include <kiplatform/app.h>
#include <core/profile.h>
#include <math/box2_minmax.h>
#include <view/wx_view_controls.h>
#include <footprint_viewer_frame.h>
#include <footprint_chooser_frame.h>
@ -379,8 +380,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();
@ -556,24 +562,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<BOARD_ITEM*>( 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 );
}
}