From 2e4f50f206309132403a350def109b7ea0004f61 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 3 Apr 2018 21:57:31 +0100 Subject: [PATCH] Make sure segments read from file are in correct order. Fixes: lp:1752033 * https://bugs.launchpad.net/kicad/+bug/1752033 --- pcbnew/class_track.cpp | 17 ++++++++++------- pcbnew/pcb_parser.cpp | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index 1c5f69be75..ffee2c26be 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -498,15 +498,18 @@ TRACK* TRACK::GetBestInsertPoint( BOARD* aPcb ) { TRACK* track; - if( Type() == PCB_ZONE_T ) - track = aPcb->m_Zone; - else - track = aPcb->m_Track; + // When reading from a file most of the items will already be in the correct order. + // Searching from the back therefore takes us from n^2 to essentially 0. - for( ; track; track = track->Next() ) + if( Type() == PCB_ZONE_T ) + track = aPcb->m_Zone.GetLast(); + else + track = aPcb->m_Track.GetLast(); + + for( ; track; track = track->Back() ) { - if( GetNetCode() <= track->GetNetCode() ) - return track; + if( GetNetCode() >= track->GetNetCode() ) + return track->Next(); } return NULL; diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 1de9777f1b..bacf543e8f 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -558,11 +558,11 @@ BOARD* PCB_PARSER::parseBOARD_unchecked() break; case T_segment: - m_board->Add( parseTRACK(), ADD_APPEND ); + m_board->Add( parseTRACK(), ADD_INSERT ); break; case T_via: - m_board->Add( parseVIA(), ADD_APPEND ); + m_board->Add( parseVIA(), ADD_INSERT ); break; case T_zone: