Revert "Improved performance for Cleanup Tracks & Vias."

This reverts commit 14378812be.
This commit is contained in:
Seth Hillbrand 2022-03-17 16:21:34 -07:00
parent c90842dd08
commit 33f4fc9873
2 changed files with 19 additions and 37 deletions

View File

@ -270,7 +270,6 @@ void TRACKS_CLEANER::deleteTracksInPads()
void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegments,
bool aDeleteDuplicateSegments, bool aMergeSegments )
{
KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_ZONE_T };
DRC_RTREE rtree;
for( PCB_TRACK* track : m_brd->Tracks() )
@ -411,17 +410,12 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment
// merge collinear segments:
for( PCB_TRACK* segment : temp_segments )
{
// one can merge only collinear segments, not vias or arcs.
if( segment->Type() != PCB_TRACE_T )
if( segment->Type() != PCB_TRACE_T ) // one can merge only track collinear segments, not vias.
continue;
if( segment->HasFlag( IS_DELETED ) ) // already taken into account
if( segment->HasFlag( IS_DELETED ) ) // already taken in account
continue;
std::vector<BOARD_CONNECTED_ITEM*> connectedItems =
m_brd->GetConnectivity()->GetConnectedItems( segment, types );
// for each end of the segment:
for( CN_ITEM* citem : connectivity->ItemEntry( segment ).GetItems() )
{
// Do not merge an end which has different width tracks attached -- it's a
@ -434,34 +428,25 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment
if( !connected->Valid() )
continue;
BOARD_CONNECTED_ITEM* candidate = connected->Parent();
BOARD_CONNECTED_ITEM* candidateItem = connected->Parent();
if( candidate->Type() == PCB_TRACE_T && !candidate->HasFlag( IS_DELETED ) )
if( candidateItem->Type() == PCB_TRACE_T && !candidateItem->HasFlag( IS_DELETED ) )
{
PCB_TRACK* candidateSegment = static_cast<PCB_TRACK*>( candidate );
PCB_TRACK* candidateSegment = static_cast<PCB_TRACK*>( candidateItem );
if( candidateSegment->GetWidth() == segment->GetWidth() )
{
sameWidthCandidates.push_back( candidateSegment );
}
else
{
differentWidthCandidates.push_back( candidateSegment );
break;
}
}
}
if( !differentWidthCandidates.empty() )
continue;
for( PCB_TRACK* candidate : sameWidthCandidates )
if( differentWidthCandidates.size() == 0 )
{
if( segment->ApproxCollinear( *candidate )
&& mergeCollinearSegments( segment, candidate, connectedItems ) )
for( PCB_TRACK* candidate : sameWidthCandidates )
{
merged = true;
break;
if( segment->ApproxCollinear( *candidate ) )
merged |= mergeCollinearSegments( segment, candidate );
}
}
}
@ -474,29 +459,27 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment
}
bool TRACKS_CLEANER::mergeCollinearSegments( PCB_TRACK* aSeg1, PCB_TRACK* aSeg2,
const std::vector<BOARD_CONNECTED_ITEM*>& aSeg1Items )
bool TRACKS_CLEANER::mergeCollinearSegments( PCB_TRACK* aSeg1, PCB_TRACK* aSeg2 )
{
static KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_ZONE_T };
KICAD_T items[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_ZONE_T };
if( aSeg1->IsLocked() || aSeg2->IsLocked() )
return false;
std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_brd->GetConnectivity();
std::vector<BOARD_CONNECTED_ITEM*> tracks = aSeg1Items;
std::vector<BOARD_CONNECTED_ITEM*> tracks2 = connectivity->GetConnectedItems( aSeg2, types );
std::vector<BOARD_CONNECTED_ITEM*> tracks = connectivity->GetConnectedItems( aSeg1, items );
std::vector<BOARD_CONNECTED_ITEM*> tracks2 = connectivity->GetConnectedItems( aSeg2, items );
std::move( tracks2.begin(), tracks2.end(), std::back_inserter( tracks ) );
std::sort( tracks.begin(), tracks.end() );
tracks.erase( std::unique( tracks.begin(), tracks.end() ), tracks.end() );
tracks.erase( std::remove_if( tracks.begin(), tracks.end(),
[ aSeg1, aSeg2 ]( BOARD_CONNECTED_ITEM* aTest )
{
return ( aTest == aSeg1 ) || ( aTest == aSeg2 );
} ),
tracks.end() );
tracks.erase(
std::remove_if( tracks.begin(), tracks.end(), [ aSeg1, aSeg2 ]( BOARD_CONNECTED_ITEM* aTest )
{
return ( aTest == aSeg1 ) || ( aTest == aSeg2 );
} ), tracks.end() );
std::set<VECTOR2I> pts;

View File

@ -81,8 +81,7 @@ private:
* @param aSeg1 is the reference
* @param aSeg2 is the candidate, and after merging, the removed segment
*/
bool mergeCollinearSegments( PCB_TRACK* aSeg1, PCB_TRACK* aSeg2,
const std::vector<BOARD_CONNECTED_ITEM*>& aSeg1Items );
bool mergeCollinearSegments( PCB_TRACK* aSeg1, PCB_TRACK* aSeg2 );
/**
* @return true if a track end position is a node, i.e. a end connected