From 63b5ad7df12790282fc8c4e038599c429053c777 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 19 Mar 2022 16:36:32 +0000 Subject: [PATCH] Fix some issues with global-label fields' bounding boxes. --- eeschema/sch_field.cpp | 12 ++++++++++ eeschema/sch_label.cpp | 35 +++++++++++++++++++++------- eeschema/tools/ee_selection_tool.cpp | 7 +++++- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index d768046e12..79ff9abf87 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -890,6 +890,12 @@ bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const rect.Inflate( aAccuracy ); + if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T ) + { + SCH_GLOBALLABEL* label = static_cast( GetParent() ); + rect.Offset( label->GetSchematicTextOffset( nullptr ) ); + } + return rect.Contains( aPosition ); } @@ -904,6 +910,12 @@ bool SCH_FIELD::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) rect.Inflate( aAccuracy ); + if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T ) + { + SCH_GLOBALLABEL* label = static_cast( GetParent() ); + rect.Offset( label->GetSchematicTextOffset( nullptr ) ); + } + if( aContained ) return rect.Contains( GetBoundingBox() ); diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index bdf1b2ebee..56c651e461 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -606,15 +606,21 @@ const EDA_RECT SCH_LABEL_BASE::GetBodyBoundingBox() const const EDA_RECT SCH_LABEL_BASE::GetBoundingBox() const { - // build the bounding box of the entire net class flag, including both the symbol and the - // net class reference text + // build the bounding box of the entire label, including its fields EDA_RECT box( GetBodyBoundingBox() ); for( const SCH_FIELD& field : m_fields ) { if( field.IsVisible() ) - box.Merge( field.GetBoundingBox() ); + { + EDA_RECT fieldBBox = field.GetBoundingBox(); + + if( Type() == SCH_GLOBAL_LABEL_T ) + fieldBBox.Offset( GetSchematicTextOffset( nullptr ) ); + + box.Merge( fieldBBox ); + } } box.Normalize(); @@ -635,11 +641,14 @@ bool SCH_LABEL_BASE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const { if( field.IsVisible() ) { - bbox = field.GetBoundingBox(); - bbox.Inflate( aAccuracy ); + EDA_RECT fieldBBox = field.GetBoundingBox(); + fieldBBox.Inflate( aAccuracy ); - if( bbox.Contains( aPosition ) ) - return bbox.Contains( aPosition ); + if( Type() == SCH_GLOBAL_LABEL_T ) + fieldBBox.Offset( GetSchematicTextOffset( nullptr ) ); + + if( fieldBBox.Contains( aPosition ) ) + return true; } } @@ -664,8 +673,16 @@ bool SCH_LABEL_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccur for( const SCH_FIELD& field : m_fields ) { - if( field.IsVisible() && rect.Intersects( field.GetBoundingBox() ) ) - return true; + if( field.IsVisible() ) + { + EDA_RECT fieldBBox = field.GetBoundingBox(); + + if( Type() == SCH_GLOBAL_LABEL_T ) + fieldBBox.Offset( GetSchematicTextOffset( nullptr ) ); + + if( rect.Intersects( fieldBBox ) ) + return true; + } } return false; diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 5fcff6e53c..cd1fc02b6e 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -1066,7 +1066,12 @@ void EE_SELECTION_TOOL::GuessSelectionCandidates( EE_COLLECTOR& collector, const rect.Collide( poss, collector.m_Threshold, &dist ); } - if( dist < closestDist ) + if( dist == closestDist ) + { + if( item->GetParent() == closest ) + closest = item; + } + else if( dist < closestDist ) { closestDist = dist; closest = item;