From 4440fe09351a4af16a629bc209aa53b3fbf6eda0 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 17 May 2024 18:30:45 +0100 Subject: [PATCH] Fix keep-upright algo for footprint text. Also removes PCB_FIELDs from rotation centre calc in footprint editor if there is other stuff selected. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16896 (cherry picked from commit 25bb3f77fac8f1b19af4db0931ba9519239a2d4b) --- pcbnew/footprint.cpp | 4 ++-- pcbnew/pcb_text.cpp | 5 +++-- pcbnew/pcb_text.h | 2 +- pcbnew/tools/edit_tool.cpp | 19 ++++++++++++++++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 2d0d678e71..c96917bb94 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -1982,12 +1982,12 @@ void FOOTPRINT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) SetOrientation( newOrientation ); for( PCB_FIELD* field : m_fields ) - field->KeepUpright( newOrientation ); + field->KeepUpright(); for( BOARD_ITEM* item : m_drawings ) { if( item->Type() == PCB_TEXT_T ) - static_cast( item )->KeepUpright( newOrientation ); + static_cast( item )->KeepUpright(); } m_boundingBoxCacheTimeStamp = 0; diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index 26e4965736..01e7f1db1c 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -263,12 +263,12 @@ void PCB_TEXT::StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) } -void PCB_TEXT::KeepUpright( const EDA_ANGLE& aNewOrientation ) +void PCB_TEXT::KeepUpright() { if( !IsKeepUpright() ) return; - EDA_ANGLE newAngle = GetTextAngle() + aNewOrientation; + EDA_ANGLE newAngle = GetTextAngle(); newAngle.Normalize(); bool needsFlipped = newAngle >= ANGLE_180; @@ -276,6 +276,7 @@ void PCB_TEXT::KeepUpright( const EDA_ANGLE& aNewOrientation ) if( needsFlipped ) { SetHorizJustify( static_cast( -GetHorizJustify() ) ); + SetVertJustify( static_cast( -GetVertJustify() ) ); SetTextAngle( GetTextAngle() + ANGLE_180 ); } } diff --git a/pcbnew/pcb_text.h b/pcbnew/pcb_text.h index fc65e003a7..14a3702c36 100644 --- a/pcbnew/pcb_text.h +++ b/pcbnew/pcb_text.h @@ -70,7 +70,7 @@ public: /** * Called when rotating the parent footprint. */ - void KeepUpright( const EDA_ANGLE& aNewOrientation ); + void KeepUpright(); wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index bed4e73df2..2b6c02f1c2 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -2697,7 +2697,24 @@ bool EDIT_TOOL::updateModificationPoint( PCB_SELECTION& aSelection ) else { PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() ); - aSelection.SetReferencePoint( grid.BestSnapAnchor( aSelection.GetCenter(), nullptr ) ); + VECTOR2I refPt = aSelection.GetCenter(); + + // Exclude text in the footprint editor if there's anything else selected + if( m_isFootprintEditor ) + { + BOX2I nonFieldsBBox; + + for( EDA_ITEM* item : aSelection.Items() ) + { + if( !item->IsType( { PCB_TEXT_T, PCB_FIELD_T } ) ) + nonFieldsBBox.Merge( item->GetBoundingBox() ); + } + + if( nonFieldsBBox.IsValid() ) + refPt = nonFieldsBBox.GetCenter(); + } + + aSelection.SetReferencePoint( grid.BestSnapAnchor( refPt, nullptr ) ); } return true;