From 416033e8e5967e0d89115bfebb73f0b93b6ac4fe Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 2 May 2024 10:56:13 -0700 Subject: [PATCH] Ignore hidden text fields when cross-probing Zoom-to-selection should only show the elements that we can see, so avoiding hidden fields in footprints keeps the zoom window appropriately sized Fixes https://gitlab.com/kicad/code/kicad/-/issues/15245 --- common/tool/selection.cpp | 2 +- eeschema/tools/ee_selection.cpp | 2 +- eeschema/tools/ee_selection.h | 2 +- include/tool/selection.h | 2 +- pcbnew/tools/pcb_selection.cpp | 22 ++++++++++++++++++++++ pcbnew/tools/pcb_selection.h | 4 +++- pcbnew/tools/pcb_selection_tool.cpp | 2 +- 7 files changed, 30 insertions(+), 6 deletions(-) diff --git a/common/tool/selection.cpp b/common/tool/selection.cpp index 6200d88c42..900900664a 100644 --- a/common/tool/selection.cpp +++ b/common/tool/selection.cpp @@ -130,7 +130,7 @@ VECTOR2I SELECTION::GetCenter() const } -BOX2I SELECTION::GetBoundingBox() const +BOX2I SELECTION::GetBoundingBox( bool aOnlyVisible ) const { BOX2I bbox; diff --git a/eeschema/tools/ee_selection.cpp b/eeschema/tools/ee_selection.cpp index 263cd9ae49..b1de067061 100644 --- a/eeschema/tools/ee_selection.cpp +++ b/eeschema/tools/ee_selection.cpp @@ -82,7 +82,7 @@ EDA_ITEM* EE_SELECTION::GetTopLeftItem( bool onlyModules ) const } -BOX2I EE_SELECTION::GetBoundingBox() const +BOX2I EE_SELECTION::GetBoundingBox( bool aOnlyVisible ) const { BOX2I bbox; diff --git a/eeschema/tools/ee_selection.h b/eeschema/tools/ee_selection.h index f50a941556..0d58c157bd 100644 --- a/eeschema/tools/ee_selection.h +++ b/eeschema/tools/ee_selection.h @@ -46,7 +46,7 @@ public: EDA_ITEM* GetTopLeftItem( bool onlyModules = false ) const override; - BOX2I GetBoundingBox() const override; + BOX2I GetBoundingBox( bool aOnlyVisible = false ) const override; void SetScreen( SCH_SCREEN* aScreen ) { m_screen = aScreen; } SCH_SCREEN* GetScreen() { return m_screen; } diff --git a/include/tool/selection.h b/include/tool/selection.h index 889657f70f..593295e942 100644 --- a/include/tool/selection.h +++ b/include/tool/selection.h @@ -154,7 +154,7 @@ public: return GetBoundingBox().GetPosition(); } - virtual BOX2I GetBoundingBox() const; + virtual BOX2I GetBoundingBox( bool aOnlyVisible = false ) const; virtual EDA_ITEM* GetTopLeftItem( bool onlyModules = false ) const { diff --git a/pcbnew/tools/pcb_selection.cpp b/pcbnew/tools/pcb_selection.cpp index 272f502f6c..5794d5c1f6 100644 --- a/pcbnew/tools/pcb_selection.cpp +++ b/pcbnew/tools/pcb_selection.cpp @@ -105,3 +105,25 @@ const std::vector PCB_SELECTION::updateDrawList() const return items; } + + +BOX2I PCB_SELECTION::GetBoundingBox( bool aOnlyVisible ) const +{ + BOX2I bbox; + + for( EDA_ITEM* item : m_items ) + { + if( item->Type() == PCB_FOOTPRINT_T ) + { + FOOTPRINT* footprint = static_cast( item ); + + bbox.Merge( footprint->GetBoundingBox( true, !aOnlyVisible ) ); + } + else + { + bbox.Merge( item->GetBoundingBox() ); + } + } + + return bbox; +} \ No newline at end of file diff --git a/pcbnew/tools/pcb_selection.h b/pcbnew/tools/pcb_selection.h index d4398ba53a..154a764440 100644 --- a/pcbnew/tools/pcb_selection.h +++ b/pcbnew/tools/pcb_selection.h @@ -32,7 +32,9 @@ class PCB_SELECTION : public SELECTION { public: EDA_ITEM* GetTopLeftItem( bool aFootprintsOnly = false ) const override; - + + BOX2I GetBoundingBox( bool aOnlyVisible = false ) const override; + const std::vector updateDrawList() const override; }; diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index a8a5d5ac58..65c46d3b83 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -2109,7 +2109,7 @@ void PCB_SELECTION_TOOL::doSyncSelection( const std::vector& aItems if( aWithNets ) selectConnections( aItems ); - BOX2I bbox = m_selection.GetBoundingBox(); + BOX2I bbox = m_selection.GetBoundingBox( true ); if( bbox.GetWidth() != 0 && bbox.GetHeight() != 0 ) {