eeschema: Ensure all wires are joined

When running the cleanup routine, we should check that we haven't
changed our lines during the process.  If we have, we run again to pick
up the new merges

Fixes https://gitlab.com/kicad/code/kicad/issues/5265
This commit is contained in:
Seth Hillbrand 2020-08-20 06:48:01 -07:00
parent 2deefdd9ce
commit ee5c991d2f
1 changed files with 54 additions and 46 deletions

View File

@ -147,12 +147,14 @@ bool SCH_EDIT_FRAME::SchematicCleanUp( SCH_SCREEN* aScreen )
std::vector<SCH_LINE*> lines; std::vector<SCH_LINE*> lines;
std::vector<SCH_JUNCTION*> junctions; std::vector<SCH_JUNCTION*> junctions;
std::vector<SCH_NO_CONNECT*> ncs; std::vector<SCH_NO_CONNECT*> ncs;
bool changed = true;
if( aScreen == nullptr ) if( aScreen == nullptr )
aScreen = GetScreen(); aScreen = GetScreen();
auto remove_item = [&itemList, &deletedItems, &aScreen]( SCH_ITEM* aItem ) -> void auto remove_item = [&]( SCH_ITEM* aItem ) -> void
{ {
changed = true;
aItem->SetFlags( STRUCT_DELETED ); aItem->SetFlags( STRUCT_DELETED );
itemList.PushItem( ITEM_PICKER( aScreen, aItem, UR_DELETED ) ); itemList.PushItem( ITEM_PICKER( aScreen, aItem, UR_DELETED ) );
deletedItems.push_back( aItem ); deletedItems.push_back( aItem );
@ -160,12 +162,6 @@ bool SCH_EDIT_FRAME::SchematicCleanUp( SCH_SCREEN* aScreen )
BreakSegmentsOnJunctions( aScreen ); BreakSegmentsOnJunctions( aScreen );
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_LINE_T ) )
{
if( item->GetLayer() == LAYER_WIRE || item->GetLayer() == LAYER_BUS )
lines.push_back( static_cast<SCH_LINE*>( item ) );
}
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_JUNCTION_T ) ) for( SCH_ITEM* item : aScreen->Items().OfType( SCH_JUNCTION_T ) )
{ {
if( !aScreen->IsJunctionNeeded( item->GetPosition() ) ) if( !aScreen->IsJunctionNeeded( item->GetPosition() ) )
@ -205,6 +201,18 @@ bool SCH_EDIT_FRAME::SchematicCleanUp( SCH_SCREEN* aScreen )
remove_item( aSecond ); remove_item( aSecond );
} ); } );
while( changed )
{
changed = false;
lines.clear();
for( SCH_ITEM* item : aScreen->Items().OfType( SCH_LINE_T ) )
{
if( item->GetLayer() == LAYER_WIRE || item->GetLayer() == LAYER_BUS )
lines.push_back( static_cast<SCH_LINE*>( item ) );
}
for( auto it1 = lines.begin(); it1 != lines.end(); ++it1 ) for( auto it1 = lines.begin(); it1 != lines.end(); ++it1 )
{ {
SCH_LINE* firstLine = *it1; SCH_LINE* firstLine = *it1;
@ -264,7 +272,7 @@ bool SCH_EDIT_FRAME::SchematicCleanUp( SCH_SCREEN* aScreen )
} }
} }
} }
}
for( auto item : deletedItems ) for( auto item : deletedItems )
{ {