Better cache invalidation for text objects with references.

Fixes https://gitlab.com/kicad/code/kicad/issues/13059
This commit is contained in:
Jeff Young 2022-12-03 13:25:20 +00:00
parent 8c97a7b8c6
commit 96819f6c01
14 changed files with 106 additions and 55 deletions

View File

@ -1500,6 +1500,17 @@ void VIEW::UpdateAllItemsConditionally( int aUpdateFlags,
} }
void VIEW::UpdateAllItemsConditionally( std::function<int( VIEW_ITEM* )> aItemFlagsProvider )
{
for( VIEW_ITEM* item : *m_allItems )
{
if( item->viewPrivData() )
item->viewPrivData()->m_requiredUpdate |= aItemFlagsProvider( item );
}
}
std::unique_ptr<VIEW> VIEW::DataReference() const std::unique_ptr<VIEW> VIEW::DataReference() const
{ {
std::unique_ptr<VIEW> ret = std::make_unique<VIEW>(); std::unique_ptr<VIEW> ret = std::make_unique<VIEW>();

View File

@ -29,6 +29,7 @@
#include <sch_io_mgr.h> #include <sch_io_mgr.h>
#include <locale_io.h> #include <locale_io.h>
#include <wx/app.h> #include <wx/app.h>
#include <sch_label.h>
#include <connection_graph.h> #include <connection_graph.h>
SCH_EDIT_FRAME* EESCHEMA_HELPERS::s_SchEditFrame = nullptr; SCH_EDIT_FRAME* EESCHEMA_HELPERS::s_SchEditFrame = nullptr;
@ -151,7 +152,13 @@ SCHEMATIC* EESCHEMA_HELPERS::LoadSchematic( wxString& aFileName, SCH_IO_MGR::SCH
schematic->ConnectionGraph()->Reset(); schematic->ConnectionGraph()->Reset();
schematic->SetSheetNumberAndCount(); schematic->SetSheetNumberAndCount();
schematic->RecomputeIntersheetRefs( true, []( SCH_GLOBALLABEL* ) { } ); schematic->RecomputeIntersheetRefs( []( SCH_GLOBALLABEL* aGlobal )
{
for( SCH_FIELD& field : aGlobal->GetFields() )
field.ClearBoundingBoxCache();
aGlobal->ClearBoundingBoxCache();
} );
for( SCH_SHEET_PATH& sheet : sheetList ) for( SCH_SHEET_PATH& sheet : sheetList )
{ {

View File

@ -481,7 +481,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
initScreenZoom(); initScreenZoom();
SetSheetNumberAndCount(); SetSheetNumberAndCount();
RecomputeIntersheetRefs( true ); RecomputeIntersheetRefs();
GetCurrentSheet().UpdateAllScreenReferences(); GetCurrentSheet().UpdateAllScreenReferences();
// re-create junctions if needed. Eeschema optimizes wires by merging // re-create junctions if needed. Eeschema optimizes wires by merging

View File

@ -1470,8 +1470,8 @@ void SCH_EDIT_FRAME::RecalculateConnections( SCH_CLEANUP_FLAGS aCleanupFlags )
Schematic().ConnectionGraph()->Recalculate( list, true, &changeHandler ); Schematic().ConnectionGraph()->Recalculate( list, true, &changeHandler );
GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT, GetCanvas()->GetView()->UpdateAllItemsConditionally(
[]( KIGFX::VIEW_ITEM* aItem ) []( KIGFX::VIEW_ITEM* aItem ) -> int
{ {
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ); SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem );
SCH_CONNECTION* connection = item ? item->Connection() : nullptr; SCH_CONNECTION* connection = item ? item->Connection() : nullptr;
@ -1479,15 +1479,19 @@ void SCH_EDIT_FRAME::RecalculateConnections( SCH_CLEANUP_FLAGS aCleanupFlags )
if( connection && connection->HasDriverChanged() ) if( connection && connection->HasDriverChanged() )
{ {
connection->ClearDriverChanged(); connection->ClearDriverChanged();
return true; return KIGFX::REPAINT;
} }
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ); EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
if( text && text->HasTextVars() ) if( text && text->HasTextVars() )
return true; {
text->ClearRenderCache();
text->ClearBoundingBoxCache();
return KIGFX::GEOMETRY | KIGFX::REPAINT;
}
return false; return 0;
} ); } );
if( highlightedItem ) if( highlightedItem )
@ -1495,20 +1499,22 @@ void SCH_EDIT_FRAME::RecalculateConnections( SCH_CLEANUP_FLAGS aCleanupFlags )
} }
void SCH_EDIT_FRAME::RecomputeIntersheetRefs( bool autoplaceUninitialized ) void SCH_EDIT_FRAME::RecomputeIntersheetRefs()
{ {
Schematic().RecomputeIntersheetRefs( autoplaceUninitialized, Schematic().RecomputeIntersheetRefs( [&]( SCH_GLOBALLABEL* label )
[&]( SCH_GLOBALLABEL* label )
{ {
for( SCH_FIELD& field : label->GetFields() )
field.ClearBoundingBoxCache();
label->ClearBoundingBoxCache();
GetCanvas()->GetView()->Update( label ); GetCanvas()->GetView()->Update( label );
}); } );
} }
void SCH_EDIT_FRAME::ShowAllIntersheetRefs( bool aShow ) void SCH_EDIT_FRAME::ShowAllIntersheetRefs( bool aShow )
{ {
if( aShow ) RecomputeIntersheetRefs();
RecomputeIntersheetRefs( true );
GetCanvas()->GetView()->SetLayerVisible( LAYER_INTERSHEET_REFS, aShow ); GetCanvas()->GetView()->SetLayerVisible( LAYER_INTERSHEET_REFS, aShow );
} }

View File

@ -801,7 +801,7 @@ public:
* Update the schematic's page reference map for all global labels, and refresh the labels * Update the schematic's page reference map for all global labels, and refresh the labels
* so that they are redrawn with up-to-date references. * so that they are redrawn with up-to-date references.
*/ */
void RecomputeIntersheetRefs( bool autoplaceUninitialized = false ); void RecomputeIntersheetRefs();
void ShowAllIntersheetRefs( bool aShow ); void ShowAllIntersheetRefs( bool aShow );

View File

@ -499,7 +499,7 @@ void SCHEMATIC::SetSheetNumberAndCount()
} }
void SCHEMATIC::RecomputeIntersheetRefs( bool autoplaceUninitialized, const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback ) void SCHEMATIC::RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback )
{ {
std::map<wxString, std::set<int>>& pageRefsMap = GetPageRefsMap(); std::map<wxString, std::set<int>>& pageRefsMap = GetPageRefsMap();
@ -538,12 +538,12 @@ void SCHEMATIC::RecomputeIntersheetRefs( bool autoplaceUninitialized, const std:
// Refresh all global labels. Note that we have to collect them first as the // Refresh all global labels. Note that we have to collect them first as the
// SCH_SCREEN::Update() call is going to invalidate the RTree iterator. // SCH_SCREEN::Update() call is going to invalidate the RTree iterator.
std::vector<SCH_GLOBALLABEL*> globalLabels; std::vector<SCH_GLOBALLABEL*> currentSheetGlobalLabels;
for( EDA_ITEM* item : CurrentSheet().LastScreen()->Items().OfType( SCH_GLOBAL_LABEL_T ) ) for( EDA_ITEM* item : CurrentSheet().LastScreen()->Items().OfType( SCH_GLOBAL_LABEL_T ) )
globalLabels.push_back( static_cast<SCH_GLOBALLABEL*>( item ) ); currentSheetGlobalLabels.push_back( static_cast<SCH_GLOBALLABEL*>( item ) );
for( SCH_GLOBALLABEL* globalLabel : globalLabels ) for( SCH_GLOBALLABEL* globalLabel : currentSheetGlobalLabels )
{ {
std::vector<SCH_FIELD>& fields = globalLabel->GetFields(); std::vector<SCH_FIELD>& fields = globalLabel->GetFields();

View File

@ -200,8 +200,7 @@ public:
* Update the schematic's page reference map for all global labels, and refresh the labels * Update the schematic's page reference map for all global labels, and refresh the labels
* so that they are redrawn with up-to-date references. * so that they are redrawn with up-to-date references.
*/ */
void RecomputeIntersheetRefs( bool autoplaceUninitialized, void RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback );
const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback );
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override {} void Show( int nestLevel, std::ostream& os ) const override {}

View File

@ -1281,26 +1281,30 @@ int SCH_EDITOR_CONTROL::AssignNetclass( const TOOL_EVENT& aEvent )
if( dlg.ShowModal() ) if( dlg.ShowModal() )
{ {
getView()->UpdateAllItemsConditionally( KIGFX::REPAINT, getView()->UpdateAllItemsConditionally(
[]( KIGFX::VIEW_ITEM* aItem ) -> bool []( KIGFX::VIEW_ITEM* aItem ) -> int
{ {
// Netclass coloured items // Netclass coloured items
// //
if( dynamic_cast<SCH_LINE*>( aItem ) ) if( dynamic_cast<SCH_LINE*>( aItem ) )
return true; return KIGFX::REPAINT;
else if( dynamic_cast<SCH_JUNCTION*>( aItem ) ) else if( dynamic_cast<SCH_JUNCTION*>( aItem ) )
return true; return KIGFX::REPAINT;
else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem ) ) else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem ) )
return true; return KIGFX::REPAINT;
// Items that might reference an item's netclass name // Items that might reference an item's netclass name
// //
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ); EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
if( text && text->HasTextVars() ) if( text && text->HasTextVars() )
return true; {
text->ClearRenderCache();
text->ClearBoundingBoxCache();
return KIGFX::GEOMETRY | KIGFX::REPAINT;
}
return false; return 0;
} ); } );
} }
} }

View File

@ -436,13 +436,14 @@ void GERBVIEW_FRAME::SetElementVisibility( int aLayerID, bool aNewState )
{ {
gvconfig()->m_Appearance.show_negative_objects = aNewState; gvconfig()->m_Appearance.show_negative_objects = aNewState;
view->UpdateAllItemsConditionally( KIGFX::REPAINT, []( KIGFX::VIEW_ITEM* aItem ) view->UpdateAllItemsConditionally( KIGFX::REPAINT,
{ []( KIGFX::VIEW_ITEM* aItem )
GERBER_DRAW_ITEM* item = dynamic_cast<GERBER_DRAW_ITEM*>( aItem ); {
GERBER_DRAW_ITEM* item = dynamic_cast<GERBER_DRAW_ITEM*>( aItem );
// GetLayerPolarity() returns true for negative items // GetLayerPolarity() returns true for negative items
return ( item && item->GetLayerPolarity() ); return ( item && item->GetLayerPolarity() );
} ); } );
break; break;
} }

View File

@ -674,6 +674,13 @@ public:
void UpdateAllItemsConditionally( int aUpdateFlags, void UpdateAllItemsConditionally( int aUpdateFlags,
std::function<bool( VIEW_ITEM* )> aCondition ); std::function<bool( VIEW_ITEM* )> aCondition );
/**
* Update items in the view according to the flags returned by the callback.
* @param aItemFlagsProvider is a function returning any KIGFX::VIEW_UPDATE_FLAGS that should
* be set on the VIEW_ITEM.
*/
void UpdateAllItemsConditionally( std::function<int( VIEW_ITEM* )> aItemFlagsProvider );
/** /**
* @return true if draw priority is being respected while redrawing. * @return true if draw priority is being respected while redrawing.
*/ */

View File

@ -2145,20 +2145,24 @@ void DIALOG_NET_INSPECTOR::onDeleteNet( wxCommandEvent& aEvent )
// outside the netlist updater where you can remove a net from a BOARD. // outside the netlist updater where you can remove a net from a BOARD.
int removedCode = i->GetNetCode(); int removedCode = i->GetNetCode();
m_frame->GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT, m_frame->GetCanvas()->GetView()->UpdateAllItemsConditionally(
[removedCode]( KIGFX::VIEW_ITEM* aItem ) -> bool [removedCode]( KIGFX::VIEW_ITEM* aItem ) -> int
{ {
auto boardItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem ); auto boardItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem );
if( boardItem && boardItem->GetNetCode() == removedCode ) if( boardItem && boardItem->GetNetCode() == removedCode )
return true; return KIGFX::REPAINT;
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ); EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
if( text && text->HasTextVars() ) if( text && text->HasTextVars() )
return true; {
text->ClearRenderCache();
text->ClearBoundingBoxCache();
return KIGFX::GEOMETRY | KIGFX::REPAINT;
}
return false; return 0;
} ); } );
m_brd->Remove( i->GetNet() ); m_brd->Remove( i->GetNet() );

View File

@ -91,26 +91,30 @@ void PCB_EDIT_FRAME::OnNetlistChanged( BOARD_NETLIST_UPDATER& aUpdater, bool* aR
// netName or netClass // netName or netClass
int netNamesCfg = GetPcbNewSettings()->m_Display.m_NetNames; int netNamesCfg = GetPcbNewSettings()->m_Display.m_NetNames;
GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT, GetCanvas()->GetView()->UpdateAllItemsConditionally(
[&]( KIGFX::VIEW_ITEM* aItem ) -> bool [&]( KIGFX::VIEW_ITEM* aItem ) -> int
{ {
if( dynamic_cast<PCB_TRACK*>( aItem ) ) if( dynamic_cast<PCB_TRACK*>( aItem ) )
{ {
if( netNamesCfg == 2 || netNamesCfg == 3 ) if( netNamesCfg == 2 || netNamesCfg == 3 )
return true; return KIGFX::REPAINT;
} }
else if( dynamic_cast<PAD*>( aItem ) ) else if( dynamic_cast<PAD*>( aItem ) )
{ {
if( netNamesCfg == 1 || netNamesCfg == 3 ) if( netNamesCfg == 1 || netNamesCfg == 3 )
return true; return KIGFX::REPAINT;
} }
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ); EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
if( text && text->HasTextVars() ) if( text && text->HasTextVars() )
return true; {
text->ClearRenderCache();
text->ClearBoundingBoxCache();
return KIGFX::GEOMETRY | KIGFX::REPAINT;
}
return false; return 0;
} ); } );
// Spread new footprints. // Spread new footprints.

View File

@ -1148,29 +1148,33 @@ void PCB_EDIT_FRAME::ShowBoardSetupDialog( const wxString& aInitialPage )
PCBNEW_SETTINGS* settings = GetPcbNewSettings(); PCBNEW_SETTINGS* settings = GetPcbNewSettings();
static LSET maskAndPasteLayers = LSET( 4, F_Mask, F_Paste, B_Mask, B_Paste ); static LSET maskAndPasteLayers = LSET( 4, F_Mask, F_Paste, B_Mask, B_Paste );
GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT, GetCanvas()->GetView()->UpdateAllItemsConditionally(
[&]( KIGFX::VIEW_ITEM* aItem ) -> bool [&]( KIGFX::VIEW_ITEM* aItem ) -> int
{ {
if( dynamic_cast<PCB_TRACK*>( aItem ) ) if( dynamic_cast<PCB_TRACK*>( aItem ) )
{ {
if( settings->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS ) if( settings->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS )
return true; return KIGFX::REPAINT;
} }
else if( dynamic_cast<PAD*>( aItem ) ) else if( dynamic_cast<PAD*>( aItem ) )
{ {
if( settings->m_Display.m_PadClearance ) if( settings->m_Display.m_PadClearance )
return true; return KIGFX::REPAINT;
if( ( GetBoard()->GetVisibleLayers() & maskAndPasteLayers ).any() ) if( ( GetBoard()->GetVisibleLayers() & maskAndPasteLayers ).any() )
return true; return KIGFX::REPAINT;
} }
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ); EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
if( text && text->HasTextVars() ) if( text && text->HasTextVars() )
return true; {
text->ClearRenderCache();
text->ClearBoundingBoxCache();
return KIGFX::GEOMETRY | KIGFX::REPAINT;
}
return false; return 0;
} ); } );
GetCanvas()->Refresh(); GetCanvas()->Refresh();

View File

@ -301,15 +301,19 @@ int BOARD_EDITOR_CONTROL::PageSettings( const TOOL_EVENT& aEvent )
if( dlg.ShowModal() == wxID_OK ) if( dlg.ShowModal() == wxID_OK )
{ {
m_frame->GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT, m_frame->GetCanvas()->GetView()->UpdateAllItemsConditionally(
[&]( KIGFX::VIEW_ITEM* aItem ) -> bool [&]( KIGFX::VIEW_ITEM* aItem ) -> int
{ {
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ); EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
if( text && text->HasTextVars() ) if( text && text->HasTextVars() )
return true; {
text->ClearRenderCache();
text->ClearBoundingBoxCache();
return KIGFX::GEOMETRY | KIGFX::REPAINT;
}
return false; return 0;
} ); } );
m_frame->OnModify(); m_frame->OnModify();