From f58221ca98dc5f8f7b6944faa4454166132621bc Mon Sep 17 00:00:00 2001 From: PJM Date: Wed, 12 Aug 2020 23:50:41 -0700 Subject: [PATCH] Add 'GetBoundingBox' that optionally only calcs w visible fields Cross-probing from Pcbnew to Eeschema revealed that EEschema was including all fields, visible or not, when calculating the bounding box of the probed componentt. This caused problems with long strings such as URLs that were not set as visible. The cross-probing code tries to minimize 'Zoom to Fit' operations when it's not necessary, and the overly large bbox values often resulted in zooms not being performed and components displayed very small. This code adds a version of 'GetBoundingBox' that takes a boolean to tell it to include invisble fields or not. Addresses issue: https://gitlab.com/kicad/code/kicad/-/issues/5149 --- eeschema/cross-probing.cpp | 5 +++-- eeschema/sch_component.cpp | 14 ++++++++++++++ eeschema/sch_component.h | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index 6f8c454d8a..634ef2d931 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -126,7 +126,8 @@ SCH_ITEM* SCH_EDITOR_CONTROL::FindComponentAndItem( const wxString& aReference, if( crossProbingSettings.zoom_to_fit ) { - EDA_RECT bbox = component->GetBoundingBox(); + // Pass "false" to only include visible fields of component in bbox calculations + EDA_RECT bbox = component->GetBoundingBox( false ); wxSize bbSize = bbox.Inflate( bbox.GetWidth() * 0.2f ).GetSize(); VECTOR2D screenSize = getView()->GetViewport().GetSize(); @@ -583,6 +584,6 @@ void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) break; } default:; - + } } diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index 637ddcbd19..be160ecf3a 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -1177,6 +1177,20 @@ const EDA_RECT SCH_COMPONENT::GetBoundingBox() const } +const EDA_RECT SCH_COMPONENT::GetBoundingBox( bool aIncludeInvisibleText ) const +{ + EDA_RECT bbox = GetBodyBoundingBox(); + + for( const SCH_FIELD& field : m_Fields ) + { + if( field.IsVisible() || aIncludeInvisibleText ) + bbox.Merge( field.GetBoundingBox() ); + } + + return bbox; +} + + void SCH_COMPONENT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList ) { wxString msg; diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index 21ac625edc..66f93c8ed8 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -376,6 +376,8 @@ public: const EDA_RECT GetBoundingBox() const override; + const EDA_RECT GetBoundingBox( bool aIncludeInvisibleText ) const; + /** * Return a bounding box for the symbol body but not the fields. */