From b8920a9f5ad04e31b053742e27ac8015f559533e Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sat, 25 Jan 2020 09:32:05 -0800 Subject: [PATCH] Eeschema: Add protections to eeschema rtree Prevents items from being mistakenly added to the tree that should not be tracked in the tree. --- eeschema/sch_screen.cpp | 18 ++++++++++-------- eeschema/sch_screen.h | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 673ff1bf8a..969a73ff0a 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -174,8 +174,11 @@ void SCH_SCREEN::DecRefCount() void SCH_SCREEN::Append( SCH_ITEM* aItem ) { - m_rtree.insert( aItem ); - --m_modification_sync; + if( aItem->Type() != SCH_SHEET_PIN_T && aItem->Type() != SCH_FIELD_T ) + { + m_rtree.insert( aItem ); + --m_modification_sync; + } } @@ -186,9 +189,8 @@ void SCH_SCREEN::Append( SCH_SCREEN* aScreen ) // No need to descend the hierarchy. Once the top level screen is copied, all of it's // children are copied as well. for( auto aItem : aScreen->m_rtree ) - m_rtree.insert( aItem ); + Append( aItem ); - --m_modification_sync; aScreen->Clear( false ); } @@ -227,14 +229,14 @@ void SCH_SCREEN::FreeDrawList() void SCH_SCREEN::Update( SCH_ITEM* aItem ) { - Remove( aItem ); - Append( aItem ); + if( Remove( aItem ) ) + Append( aItem ); } -void SCH_SCREEN::Remove( SCH_ITEM* aItem ) +bool SCH_SCREEN::Remove( SCH_ITEM* aItem ) { - m_rtree.remove( aItem ); + return m_rtree.remove( aItem ); } diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index 15e100cf47..dc30e958bd 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -260,8 +260,9 @@ public: * * @note The removed item is not deleted. It is only unlinked from the item list. * @param aItem Item to be removed from schematic. + * @return True if we successfully removed the item */ - void Remove( SCH_ITEM* aItem ); + bool Remove( SCH_ITEM* aItem ); /** * Updates \a aItem's bounding box in the tree