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 25bb3f77fa)
This commit is contained in:
Jeff Young 2024-05-17 18:30:45 +01:00 committed by Seth Hillbrand
parent d1cd859765
commit 4440fe0935
4 changed files with 24 additions and 6 deletions

View File

@ -1982,12 +1982,12 @@ void FOOTPRINT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
SetOrientation( newOrientation ); SetOrientation( newOrientation );
for( PCB_FIELD* field : m_fields ) for( PCB_FIELD* field : m_fields )
field->KeepUpright( newOrientation ); field->KeepUpright();
for( BOARD_ITEM* item : m_drawings ) for( BOARD_ITEM* item : m_drawings )
{ {
if( item->Type() == PCB_TEXT_T ) if( item->Type() == PCB_TEXT_T )
static_cast<PCB_TEXT*>( item )->KeepUpright( newOrientation ); static_cast<PCB_TEXT*>( item )->KeepUpright();
} }
m_boundingBoxCacheTimeStamp = 0; m_boundingBoxCacheTimeStamp = 0;

View File

@ -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() ) if( !IsKeepUpright() )
return; return;
EDA_ANGLE newAngle = GetTextAngle() + aNewOrientation; EDA_ANGLE newAngle = GetTextAngle();
newAngle.Normalize(); newAngle.Normalize();
bool needsFlipped = newAngle >= ANGLE_180; bool needsFlipped = newAngle >= ANGLE_180;
@ -276,6 +276,7 @@ void PCB_TEXT::KeepUpright( const EDA_ANGLE& aNewOrientation )
if( needsFlipped ) if( needsFlipped )
{ {
SetHorizJustify( static_cast<GR_TEXT_H_ALIGN_T>( -GetHorizJustify() ) ); SetHorizJustify( static_cast<GR_TEXT_H_ALIGN_T>( -GetHorizJustify() ) );
SetVertJustify( static_cast<GR_TEXT_V_ALIGN_T>( -GetVertJustify() ) );
SetTextAngle( GetTextAngle() + ANGLE_180 ); SetTextAngle( GetTextAngle() + ANGLE_180 );
} }
} }

View File

@ -70,7 +70,7 @@ public:
/** /**
* Called when rotating the parent footprint. * Called when rotating the parent footprint.
*/ */
void KeepUpright( const EDA_ANGLE& aNewOrientation ); void KeepUpright();
wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override; wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;

View File

@ -2697,7 +2697,24 @@ bool EDIT_TOOL::updateModificationPoint( PCB_SELECTION& aSelection )
else else
{ {
PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() ); 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; return true;