From ebd8c44eeecf7e196fd19d7c8aa38a995b5f58a7 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 23 May 2019 18:04:22 +0100 Subject: [PATCH] Don't confuse SCH_ITEMs and LIB_ITEMs. Fixes: lp:1829826 * https://bugs.launchpad.net/kicad/+bug/1829826 --- eeschema/tools/selection.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/eeschema/tools/selection.cpp b/eeschema/tools/selection.cpp index f8481768ce..578509aaea 100644 --- a/eeschema/tools/selection.cpp +++ b/eeschema/tools/selection.cpp @@ -26,7 +26,7 @@ #include #include #include - +#include VECTOR2I SELECTION::GetPosition() const { @@ -57,23 +57,28 @@ EDA_RECT SELECTION::GetBoundingBox() const EDA_ITEM* SELECTION::GetTopLeftItem( bool onlyModules ) const { - SCH_ITEM* topLeftItem = nullptr; - SCH_ITEM* currentItem; - - wxPoint pos; + EDA_ITEM* topLeftItem = nullptr; + wxPoint topLeftPos; + wxPoint pos; // find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item in the selection for( auto item : m_items ) { - currentItem = static_cast( item ); - pos = currentItem->GetPosition(); + SCH_ITEM* sch_item = dynamic_cast( item ); + LIB_ITEM* lib_item = dynamic_cast( item ); - if( topLeftItem == nullptr ) - topLeftItem = currentItem; - else if( pos.x < topLeftItem->GetPosition().x ) - topLeftItem = currentItem; - else if( topLeftItem->GetPosition().x == pos.x && pos.y < topLeftItem->GetPosition().y ) - topLeftItem = currentItem; + if( sch_item ) + pos = sch_item->GetPosition(); + else if( lib_item ) + pos = lib_item->GetPosition(); + + if( ( topLeftItem == nullptr ) + || ( pos.x < topLeftPos.x ) + || ( topLeftPos.x == pos.x && pos.y < topLeftPos.y ) ) + { + topLeftItem = item; + topLeftPos = pos; + } } return static_cast( topLeftItem );