From 57da733f5642771bf602ea2956a4ac4b129d498d Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 11 Oct 2020 19:02:38 +0200 Subject: [PATCH] Avoid loss of data when saving a board having duplicate UUID Some (old) boards used for panelisation can have duplicate UUID (timestamp). duplicate timestamps create loss of data when saving these boards. Fixes #5969 https://gitlab.com/kicad/code/kicad/issues/5969 --- pcbnew/class_board_item.cpp | 5 ++++- pcbnew/class_module.cpp | 10 ++++++++-- pcbnew/class_track.cpp | 5 ++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pcbnew/class_board_item.cpp b/pcbnew/class_board_item.cpp index 6d2b3a96fb..b44068908f 100644 --- a/pcbnew/class_board_item.cpp +++ b/pcbnew/class_board_item.cpp @@ -144,7 +144,10 @@ bool BOARD_ITEM::ptr_cmp::operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b if( a->GetLayer() != b->GetLayer() ) return a->GetLayer() < b->GetLayer(); - return a->m_Uuid < b->m_Uuid; + if( a->m_Uuid != b->m_Uuid ) // shopuld be always the case foer valid boards + return a->m_Uuid < b->m_Uuid; + + return a < b; } diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index a7708fd844..c049776d85 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1755,7 +1755,10 @@ bool MODULE::cmp_drawings::operator()( const BOARD_ITEM* aFirst, const BOARD_ITE return dwgA->GetShape() < dwgB->GetShape(); } - return aFirst->m_Uuid < aSecond->m_Uuid; + if( aFirst->m_Uuid != aSecond->m_Uuid ) // shopuld be always the case foer valid boards + return aFirst->m_Uuid < aSecond->m_Uuid; + + return aFirst < aSecond; } @@ -1764,7 +1767,10 @@ bool MODULE::cmp_pads::operator()( const D_PAD* aFirst, const D_PAD* aSecond ) c if( aFirst->GetName() != aSecond->GetName() ) return StrNumCmp( aFirst->GetName(), aSecond->GetName() ) < 0; - return aFirst->m_Uuid < aSecond->m_Uuid; + if( aFirst->m_Uuid != aSecond->m_Uuid ) // shopuld be always the case foer valid boards + return aFirst->m_Uuid < aSecond->m_Uuid; + + return aFirst < aSecond; } diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index e89ccea3a1..eff1c8ba25 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -968,7 +968,10 @@ bool TRACK::cmp_tracks::operator() ( const TRACK* a, const TRACK* b ) const if( a->Type() != b->Type() ) return a->Type() < b->Type(); - return a->m_Uuid < b->m_Uuid; + if( a->m_Uuid != b->m_Uuid ) + return a->m_Uuid < b->m_Uuid; + + return a < b; }