From 5dd0099119e391c326d6ddb35201e4b9620bf50b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 23 Jun 2015 17:01:34 +0200 Subject: [PATCH] Eeschema: Remove backtracking (overlapping) wires when creating new connections. --- eeschema/bus-wire-junction.cpp | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index 62141bd93f..d0c6994e71 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -43,6 +43,7 @@ #include #include #include +#include static void AbortCreateNewLine( EDA_DRAW_PANEL* aPanel, wxDC* aDC ); @@ -52,6 +53,53 @@ static DLIST< SCH_ITEM > s_wires; // when creating a new set of wires, // stores here the new wires. +/** + * In a contiguous list of wires, remove wires that backtrack over the previous + * wire. Example: + * + * Wire is added: + * ----------------------------------------> + * + * A second wire backtracks over it: + * -------------------<====================> + * + * RemoveBacktracks is called: + * -------------------> + */ +static void RemoveBacktracks( DLIST& aWires ) +{ + SCH_LINE* last_line = NULL; + + EDA_ITEM* first = aWires.GetFirst(); + for( EDA_ITEM* p = first; p; ) + { + SCH_LINE *line = dynamic_cast( p ); + if( !line ) + { + wxFAIL_MSG( "RemoveBacktracks() requires SCH_LINE items" ); + break; + } + p = line->Next(); + + if( last_line ) + { + wxASSERT_MSG( last_line->GetEndPoint() == line->GetStartPoint(), + "RemoveBacktracks() requires contiguous lines" ); + if( IsPointOnSegment( last_line->GetStartPoint(), line->GetStartPoint(), + line->GetEndPoint() ) ) + { + last_line->SetEndPoint( line->GetEndPoint() ); + delete s_wires.Remove( line ); + } + else + last_line = line; + } + else + last_line = line; + } +} + + /** * Mouse capture callback for drawing line segments. */ @@ -261,6 +309,9 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC ) SaveCopyInUndoList( oldItems, UR_WIRE_IMAGE ); + // Remove segments backtracking over others + RemoveBacktracks( s_wires ); + // Add the new wires screen->Append( s_wires );