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> ret = std::make_unique<VIEW>();

View File

@ -29,6 +29,7 @@
#include <sch_io_mgr.h>
#include <locale_io.h>
#include <wx/app.h>
#include <sch_label.h>
#include <connection_graph.h>
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->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 )
{

View File

@ -481,7 +481,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
initScreenZoom();
SetSheetNumberAndCount();
RecomputeIntersheetRefs( true );
RecomputeIntersheetRefs();
GetCurrentSheet().UpdateAllScreenReferences();
// 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 );
GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT,
[]( KIGFX::VIEW_ITEM* aItem )
GetCanvas()->GetView()->UpdateAllItemsConditionally(
[]( KIGFX::VIEW_ITEM* aItem ) -> int
{
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem );
SCH_CONNECTION* connection = item ? item->Connection() : nullptr;
@ -1479,15 +1479,19 @@ void SCH_EDIT_FRAME::RecalculateConnections( SCH_CLEANUP_FLAGS aCleanupFlags )
if( connection && connection->HasDriverChanged() )
{
connection->ClearDriverChanged();
return true;
return KIGFX::REPAINT;
}
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
if( text && text->HasTextVars() )
return true;
{
text->ClearRenderCache();
text->ClearBoundingBoxCache();
return KIGFX::GEOMETRY | KIGFX::REPAINT;
}
return false;
return 0;
} );
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,
[&]( SCH_GLOBALLABEL* label )
Schematic().RecomputeIntersheetRefs( [&]( SCH_GLOBALLABEL* label )
{
for( SCH_FIELD& field : label->GetFields() )
field.ClearBoundingBoxCache();
label->ClearBoundingBoxCache();
GetCanvas()->GetView()->Update( label );
});
} );
}
void SCH_EDIT_FRAME::ShowAllIntersheetRefs( bool aShow )
{
if( aShow )
RecomputeIntersheetRefs( true );
RecomputeIntersheetRefs();
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
* so that they are redrawn with up-to-date references.
*/
void RecomputeIntersheetRefs( bool autoplaceUninitialized = false );
void RecomputeIntersheetRefs();
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();
@ -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
// 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 ) )
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();

View File

@ -200,8 +200,7 @@ public:
* 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.
*/
void RecomputeIntersheetRefs( bool autoplaceUninitialized,
const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback );
void RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback );
#if defined(DEBUG)
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() )
{
getView()->UpdateAllItemsConditionally( KIGFX::REPAINT,
[]( KIGFX::VIEW_ITEM* aItem ) -> bool
getView()->UpdateAllItemsConditionally(
[]( KIGFX::VIEW_ITEM* aItem ) -> int
{
// Netclass coloured items
//
if( dynamic_cast<SCH_LINE*>( aItem ) )
return true;
return KIGFX::REPAINT;
else if( dynamic_cast<SCH_JUNCTION*>( aItem ) )
return true;
return KIGFX::REPAINT;
else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem ) )
return true;
return KIGFX::REPAINT;
// Items that might reference an item's netclass name
//
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
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;
view->UpdateAllItemsConditionally( KIGFX::REPAINT, []( KIGFX::VIEW_ITEM* aItem )
{
GERBER_DRAW_ITEM* item = dynamic_cast<GERBER_DRAW_ITEM*>( aItem );
view->UpdateAllItemsConditionally( KIGFX::REPAINT,
[]( KIGFX::VIEW_ITEM* aItem )
{
GERBER_DRAW_ITEM* item = dynamic_cast<GERBER_DRAW_ITEM*>( aItem );
// GetLayerPolarity() returns true for negative items
return ( item && item->GetLayerPolarity() );
} );
// GetLayerPolarity() returns true for negative items
return ( item && item->GetLayerPolarity() );
} );
break;
}

View File

@ -674,6 +674,13 @@ public:
void UpdateAllItemsConditionally( int aUpdateFlags,
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.
*/

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.
int removedCode = i->GetNetCode();
m_frame->GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT,
[removedCode]( KIGFX::VIEW_ITEM* aItem ) -> bool
m_frame->GetCanvas()->GetView()->UpdateAllItemsConditionally(
[removedCode]( KIGFX::VIEW_ITEM* aItem ) -> int
{
auto boardItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem );
if( boardItem && boardItem->GetNetCode() == removedCode )
return true;
return KIGFX::REPAINT;
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
if( text && text->HasTextVars() )
return true;
{
text->ClearRenderCache();
text->ClearBoundingBoxCache();
return KIGFX::GEOMETRY | KIGFX::REPAINT;
}
return false;
return 0;
} );
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
int netNamesCfg = GetPcbNewSettings()->m_Display.m_NetNames;
GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT,
[&]( KIGFX::VIEW_ITEM* aItem ) -> bool
GetCanvas()->GetView()->UpdateAllItemsConditionally(
[&]( KIGFX::VIEW_ITEM* aItem ) -> int
{
if( dynamic_cast<PCB_TRACK*>( aItem ) )
{
if( netNamesCfg == 2 || netNamesCfg == 3 )
return true;
return KIGFX::REPAINT;
}
else if( dynamic_cast<PAD*>( aItem ) )
{
if( netNamesCfg == 1 || netNamesCfg == 3 )
return true;
return KIGFX::REPAINT;
}
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
if( text && text->HasTextVars() )
return true;
{
text->ClearRenderCache();
text->ClearBoundingBoxCache();
return KIGFX::GEOMETRY | KIGFX::REPAINT;
}
return false;
return 0;
} );
// Spread new footprints.

View File

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

View File

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