From 67b4ba022545e01219416e788e7fc16ed589018e Mon Sep 17 00:00:00 2001 From: Chris Pavlina Date: Tue, 29 Mar 2016 20:25:15 -0400 Subject: [PATCH] eeschema: improve RemoveBacktracks() algorithm (lp:1562521) Still isn't perfect, but removes an actual bug. It's still possible to get weird things if you try hard, but they're not corrupt and don't trip assertions. Consider a temporary fix. --- eeschema/bus-wire-junction.cpp | 45 +++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index 6de5e9960f..1c929de721 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -66,34 +66,45 @@ static DLIST< SCH_ITEM > s_wires; // when creating a new set of wires, */ static void RemoveBacktracks( DLIST& aWires ) { - SCH_LINE* last_line = NULL; - EDA_ITEM* first = aWires.GetFirst(); + std::vector last_lines; + for( EDA_ITEM* p = first; p; ) { - SCH_LINE *line = dynamic_cast( p ); - if( !line ) - { - wxFAIL_MSG( "RemoveBacktracks() requires SCH_LINE items" ); - break; - } + SCH_LINE *line = static_cast( p ); p = line->Next(); - if( last_line ) + if( !last_lines.empty() ) { - wxASSERT_MSG( last_line->GetEndPoint() == line->GetStartPoint(), - "RemoveBacktracks() requires contiguous lines" ); - if( IsPointOnSegment( last_line->GetStartPoint(), line->GetStartPoint(), - line->GetEndPoint() ) ) + SCH_LINE* last_line = last_lines[last_lines.size() - 1]; + bool contiguous = ( last_line->GetEndPoint() == line->GetStartPoint() ); + bool backtracks = IsPointOnSegment( last_line->GetStartPoint(), + last_line->GetEndPoint(), line->GetEndPoint() ); + bool total_backtrack = ( last_line->GetStartPoint() == line->GetEndPoint() ); + + if( contiguous && backtracks ) { - last_line->SetEndPoint( line->GetEndPoint() ); - delete s_wires.Remove( line ); + if( total_backtrack ) + { + delete s_wires.Remove( last_line ); + delete s_wires.Remove( line ); + last_lines.pop_back(); + } + else + { + last_line->SetEndPoint( line->GetEndPoint() ); + delete s_wires.Remove( line ); + } } else - last_line = line; + { + last_lines.push_back( line ); + } } else - last_line = line; + { + last_lines.push_back( line ); + } } }