Add a method to conditionally update VIEW_ITEMs (GerbView performance)
This commit is contained in:
parent
d7bb83ddcb
commit
4ec7a02ccd
|
@ -1302,6 +1302,24 @@ void VIEW::UpdateAllItems( int aUpdateFlags )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void VIEW::UpdateAllItemsConditionally( int aUpdateFlags,
|
||||||
|
std::function<bool( VIEW_ITEM* )> aCondition )
|
||||||
|
{
|
||||||
|
for( VIEW_ITEM* item : m_allItems )
|
||||||
|
{
|
||||||
|
if( aCondition( item ) )
|
||||||
|
{
|
||||||
|
auto viewData = item->viewPrivData();
|
||||||
|
|
||||||
|
if( !viewData )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
viewData->m_requiredUpdate |= aUpdateFlags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct VIEW::extentsVisitor
|
struct VIEW::extentsVisitor
|
||||||
{
|
{
|
||||||
BOX2I extents;
|
BOX2I extents;
|
||||||
|
|
|
@ -451,7 +451,6 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
|
||||||
int id = event.GetId();
|
int id = event.GetId();
|
||||||
bool state;
|
bool state;
|
||||||
bool needs_refresh = false;
|
bool needs_refresh = false;
|
||||||
bool needs_repaint = false;
|
|
||||||
|
|
||||||
switch( id )
|
switch( id )
|
||||||
{
|
{
|
||||||
|
@ -473,17 +472,17 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
|
||||||
|
|
||||||
case ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH:
|
case ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH:
|
||||||
m_DisplayOptions.m_DisplayFlashedItemsFill = not state;
|
m_DisplayOptions.m_DisplayFlashedItemsFill = not state;
|
||||||
needs_refresh = needs_repaint = true;
|
needs_refresh = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_TB_OPTIONS_SHOW_LINES_SKETCH:
|
case ID_TB_OPTIONS_SHOW_LINES_SKETCH:
|
||||||
m_DisplayOptions.m_DisplayLinesFill = not state;
|
m_DisplayOptions.m_DisplayLinesFill = not state;
|
||||||
needs_refresh = needs_repaint = true;
|
needs_refresh = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH:
|
case ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH:
|
||||||
m_DisplayOptions.m_DisplayPolygonsFill = not state;
|
m_DisplayOptions.m_DisplayPolygonsFill = not state;
|
||||||
needs_refresh = needs_repaint = true;
|
needs_refresh = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_TB_OPTIONS_SHOW_DCODES:
|
case ID_TB_OPTIONS_SHOW_DCODES:
|
||||||
|
@ -532,10 +531,59 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
|
||||||
applyDisplaySettingsToGAL();
|
applyDisplaySettingsToGAL();
|
||||||
auto view = GetGalCanvas()->GetView();
|
auto view = GetGalCanvas()->GetView();
|
||||||
|
|
||||||
if( needs_repaint )
|
switch( id )
|
||||||
view->UpdateAllItems( KIGFX::REPAINT );
|
{
|
||||||
else
|
case ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH:
|
||||||
|
view->UpdateAllItemsConditionally( KIGFX::REPAINT,
|
||||||
|
[]( KIGFX::VIEW_ITEM* aItem ) {
|
||||||
|
auto item = static_cast<GERBER_DRAW_ITEM*>( aItem );
|
||||||
|
|
||||||
|
switch( item->m_Shape )
|
||||||
|
{
|
||||||
|
case GBR_SPOT_CIRCLE:
|
||||||
|
case GBR_SPOT_RECT:
|
||||||
|
case GBR_SPOT_OVAL:
|
||||||
|
case GBR_SPOT_POLY:
|
||||||
|
case GBR_SPOT_MACRO:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ID_TB_OPTIONS_SHOW_LINES_SKETCH:
|
||||||
|
view->UpdateAllItemsConditionally( KIGFX::REPAINT,
|
||||||
|
[]( KIGFX::VIEW_ITEM* aItem ) {
|
||||||
|
auto item = static_cast<GERBER_DRAW_ITEM*>( aItem );
|
||||||
|
|
||||||
|
switch( item->m_Shape )
|
||||||
|
{
|
||||||
|
case GBR_CIRCLE:
|
||||||
|
case GBR_ARC:
|
||||||
|
case GBR_SEGMENT:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH:
|
||||||
|
view->UpdateAllItemsConditionally( KIGFX::REPAINT,
|
||||||
|
[]( KIGFX::VIEW_ITEM* aItem ) {
|
||||||
|
auto item = static_cast<GERBER_DRAW_ITEM*>( aItem );
|
||||||
|
|
||||||
|
return ( item->m_Shape == GBR_POLYGON );
|
||||||
|
} );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
view->UpdateAllItems( KIGFX::COLOR );
|
view->UpdateAllItems( KIGFX::COLOR );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
m_canvas->Refresh( true );
|
m_canvas->Refresh( true );
|
||||||
}
|
}
|
||||||
|
|
|
@ -616,6 +616,14 @@ public:
|
||||||
*/
|
*/
|
||||||
void UpdateAllItems( int aUpdateFlags );
|
void UpdateAllItems( int aUpdateFlags );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates items in the view according to the given flags and condition
|
||||||
|
* @param aUpdateFlags is is according to KIGFX::VIEW_UPDATE_FLAGS
|
||||||
|
* @param aCondition is a function returning true if the item should be updated
|
||||||
|
*/
|
||||||
|
void UpdateAllItemsConditionally( int aUpdateFlags,
|
||||||
|
std::function<bool( VIEW_ITEM* )> aCondition );
|
||||||
|
|
||||||
const BOX2I CalculateExtents() ;
|
const BOX2I CalculateExtents() ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue