diff --git a/common/view/view.cpp b/common/view/view.cpp index b3c37afdd2..9b7a48cfca 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -1302,6 +1302,24 @@ void VIEW::UpdateAllItems( int aUpdateFlags ) } +void VIEW::UpdateAllItemsConditionally( int aUpdateFlags, + std::function aCondition ) +{ + for( VIEW_ITEM* item : m_allItems ) + { + if( aCondition( item ) ) + { + auto viewData = item->viewPrivData(); + + if( !viewData ) + continue; + + viewData->m_requiredUpdate |= aUpdateFlags; + } + } +} + + struct VIEW::extentsVisitor { BOX2I extents; diff --git a/gerbview/events_called_functions.cpp b/gerbview/events_called_functions.cpp index 8d5043e97f..1cfb594637 100644 --- a/gerbview/events_called_functions.cpp +++ b/gerbview/events_called_functions.cpp @@ -451,7 +451,6 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) int id = event.GetId(); bool state; bool needs_refresh = false; - bool needs_repaint = false; switch( id ) { @@ -473,17 +472,17 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) case ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH: m_DisplayOptions.m_DisplayFlashedItemsFill = not state; - needs_refresh = needs_repaint = true; + needs_refresh = true; break; case ID_TB_OPTIONS_SHOW_LINES_SKETCH: m_DisplayOptions.m_DisplayLinesFill = not state; - needs_refresh = needs_repaint = true; + needs_refresh = true; break; case ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH: m_DisplayOptions.m_DisplayPolygonsFill = not state; - needs_refresh = needs_repaint = true; + needs_refresh = true; break; case ID_TB_OPTIONS_SHOW_DCODES: @@ -532,10 +531,59 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) applyDisplaySettingsToGAL(); auto view = GetGalCanvas()->GetView(); - if( needs_repaint ) - view->UpdateAllItems( KIGFX::REPAINT ); - else + switch( id ) + { + case ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH: + view->UpdateAllItemsConditionally( KIGFX::REPAINT, + []( KIGFX::VIEW_ITEM* aItem ) { + auto item = static_cast( 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( 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( aItem ); + + return ( item->m_Shape == GBR_POLYGON ); + } ); + break; + + default: view->UpdateAllItems( KIGFX::COLOR ); + break; + } m_canvas->Refresh( true ); } diff --git a/include/view/view.h b/include/view/view.h index 15f851e13d..9029b7be28 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -616,6 +616,14 @@ public: */ 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 aCondition ); + const BOX2I CalculateExtents() ; /**