Remove duplicated TestDanglingEnds routines.

Also adds a changedItemHandler so that the single remaining version
can update the view.

Fixes https://gitlab.com/kicad/code/kicad/issues/6581
This commit is contained in:
Jeff Young 2020-12-06 21:23:16 +00:00
parent d0f9503ee0
commit ad281f7538
10 changed files with 35 additions and 75 deletions

View File

@ -66,25 +66,15 @@ std::vector<wxPoint> SCH_EDIT_FRAME::GetSchematicConnections()
}
bool SCH_EDIT_FRAME::TestDanglingEnds()
void SCH_EDIT_FRAME::TestDanglingEnds()
{
std::vector<DANGLING_END_ITEM> endPoints;
bool hasStateChanged = false;
std::function<void( SCH_ITEM* )> changeHandler =
[&]( SCH_ITEM* aChangedItem ) -> void
{
GetCanvas()->GetView()->Update( aChangedItem, KIGFX::REPAINT );
};
for( auto item : GetScreen()->Items() )
item->GetEndPoints( endPoints );
for( auto item : GetScreen()->Items() )
{
if( item->UpdateDanglingState( endPoints ) )
{
GetCanvas()->GetView()->Update( item, KIGFX::REPAINT );
hasStateChanged = true;
}
item->GetEndPoints( endPoints );
}
return hasStateChanged;
GetScreen()->TestDanglingEnds( nullptr, &changeHandler );
}

View File

@ -424,7 +424,8 @@ void CONNECTION_GRAPH::Reset()
}
void CONNECTION_GRAPH::Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnconditional )
void CONNECTION_GRAPH::Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnconditional,
std::function<void( SCH_ITEM* )>* aChangedItemHandler )
{
PROF_COUNTER recalc_time( "CONNECTION_GRAPH::Recalculate" );
@ -450,7 +451,7 @@ void CONNECTION_GRAPH::Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnco
updateItemConnectivity( sheet, items );
// UpdateDanglingState() also adds connected items for SCH_TEXT
sheet.LastScreen()->TestDanglingEnds( &sheet );
sheet.LastScreen()->TestDanglingEnds( &sheet, aChangedItemHandler );
}
if( wxLog::IsAllowedTraceMask( ConnProfileMask ) )

View File

@ -254,8 +254,10 @@ public:
*
* @param aSheetList is the list of possibly modified sheets
* @param aUnconditional is true if an unconditional full recalculation should be done
* @param aChangedItemHandler an optional handler to receive any changed items
*/
void Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnconditional = false );
void Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnconditional = false,
std::function<void( SCH_ITEM* )>* aChangedItemHandler = nullptr );
/**
* Returns a bus alias pointer for the given name if it exists (from cache)

View File

@ -601,8 +601,7 @@ void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
case MAIL_SCH_REFRESH:
{
SCH_SCREENS schematic( Schematic().Root() );
schematic.TestDanglingEnds();
TestDanglingEnds();
GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL );
GetCanvas()->Refresh();

View File

@ -180,7 +180,7 @@ void DIALOG_MIGRATE_BUSES::onItemSelected( wxListEvent& aEvent )
{
sheet.UpdateAllScreenReferences();
m_frame->Schematic().SetCurrentSheet( sheet );
sheet.LastScreen()->TestDanglingEnds();
m_frame->TestDanglingEnds();
}
auto pos = driver->GetPosition();

View File

@ -527,7 +527,6 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
OnModify();
}
GetScreen()->TestDanglingEnds(); // Only perform the dangling end test on root sheet.
RecalculateConnections( GLOBAL_CLEANUP );
ClearUndoRedoList();
GetScreen()->m_Initialized = true;
@ -595,15 +594,12 @@ bool SCH_EDIT_FRAME::AppendSchematic()
if( !LoadSheetFromFile( GetCurrentSheet().Last(), &GetCurrentSheet(), fullFileName ) )
return false;
SCH_SCREENS screens( GetCurrentSheet().Last() );
screens.TestDanglingEnds();
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
SetSheetNumberAndCount();
SyncView();
HardRedraw(); // Full reinit of the current screen and the display.
OnModify();
HardRedraw(); // Full reinit of the current screen and the display.
return true;
}

View File

@ -1288,7 +1288,13 @@ void SCH_EDIT_FRAME::RecalculateConnections( SCH_CLEANUP_FLAGS aCleanupFlags )
if( settings.m_IntersheetRefsShow == true )
RecomputeIntersheetRefs();
Schematic().ConnectionGraph()->Recalculate( list, true );
std::function<void( SCH_ITEM* )> changeHandler =
[&]( SCH_ITEM* aChangedItem ) -> void
{
GetCanvas()->GetView()->Update( aChangedItem, KIGFX::REPAINT );
};
Schematic().ConnectionGraph()->Recalculate( list, true, &changeHandler );
}

View File

@ -320,7 +320,7 @@ public:
* Test all of the connectable objects in the schematic for unused connection points.
* @return True if any connection state changes were made.
*/
bool TestDanglingEnds();
void TestDanglingEnds();
/**
* Send a message to Pcbnew via a socket connection.

View File

@ -975,10 +975,10 @@ void SCH_SCREEN::GetSheets( std::vector<SCH_ITEM*>* aItems )
}
bool SCH_SCREEN::TestDanglingEnds( const SCH_SHEET_PATH* aPath )
void SCH_SCREEN::TestDanglingEnds( const SCH_SHEET_PATH* aPath,
std::function<void( SCH_ITEM* )>* aChangedHandler )
{
std::vector< DANGLING_END_ITEM > endPoints;
bool hasStateChanged = false;
std::vector<DANGLING_END_ITEM> endPoints;
for( SCH_ITEM* item : Items() )
item->GetEndPoints( endPoints );
@ -986,10 +986,11 @@ bool SCH_SCREEN::TestDanglingEnds( const SCH_SHEET_PATH* aPath )
for( SCH_ITEM* item : Items() )
{
if( item->UpdateDanglingState( endPoints, aPath ) )
hasStateChanged = true;
{
if( aChangedHandler )
(*aChangedHandler)( item );
}
}
return hasStateChanged;
}
@ -1317,46 +1318,12 @@ void SCH_SCREENS::UpdateSymbolLinks( REPORTER* aReporter )
SCH_SHEET_LIST sheets = sch->GetSheets();
// All of the library symbols have been replaced with copies so the connection graph
// pointer are stale.
// pointers are stale.
if( sch->ConnectionGraph() )
sch->ConnectionGraph()->Recalculate( sheets, true );
}
void SCH_SCREENS::TestDanglingEnds()
{
std::vector<SCH_SCREEN*> screens;
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
screens.push_back( screen );
size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency(),
screens.size() );
std::atomic<size_t> nextScreen( 0 );
std::vector<std::future<size_t>> returns( parallelThreadCount );
auto update_lambda = [&screens, &nextScreen]() -> size_t
{
for( auto i = nextScreen++; i < screens.size(); i = nextScreen++ )
screens[i]->TestDanglingEnds();
return 1;
};
if( parallelThreadCount == 1 )
update_lambda();
else
{
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
returns[ii] = std::async( std::launch::async, update_lambda );
// Finalize the threads
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
returns[ii].wait();
}
}
bool SCH_SCREENS::HasNoFullyDefinedLibIds()
{
SCH_SCREEN* screen;

View File

@ -319,9 +319,10 @@ public:
/**
* Test all of the connectable objects in the schematic for unused connection points.
* @param aPath is a sheet path to pass to UpdateDanglingState if desired
* @return True if any connection state changes were made.
* @param aChangedHandler an optional callback to make on each changed item
*/
bool TestDanglingEnds( const SCH_SHEET_PATH* aPath = nullptr );
void TestDanglingEnds( const SCH_SHEET_PATH* aPath = nullptr,
std::function<void( SCH_ITEM* )>* aChangedHandler = nullptr );
/**
* Return all wires and junctions connected to \a aSegment which are not connected any
@ -585,8 +586,6 @@ public:
*/
void UpdateSymbolLinks( REPORTER* aReporter = nullptr );
void TestDanglingEnds();
/**
* Test all of the schematic symbols to see if all #LIB_ID objects library nickname is not
* set.