Fix SCH_TEXT rotation around a reference point

Fixes https://gitlab.com/kicad/code/kicad/issues/9690
This commit is contained in:
Mikolaj Wielgus 2021-12-02 16:33:49 +01:00
parent 5cb2641142
commit bb08ef2f41
1 changed files with 14 additions and 5 deletions

View File

@ -299,13 +299,21 @@ void SCH_TEXT::MirrorVertically( int aCenter )
void SCH_TEXT::Rotate( const wxPoint& aCenter ) void SCH_TEXT::Rotate( const wxPoint& aCenter )
{ {
wxPoint pt = GetTextPos(); wxPoint pt = GetBoundingBox().GetCenter();
RotatePoint( &pt, aCenter, 900 );
wxPoint offset = pt - GetTextPos(); wxPoint offset = pt - GetTextPos();
RotatePoint( &pt, aCenter, 900 );
// `offset` compensates for `GetTextPos()` not being the item center.
SetTextPos( pt - offset );
pt = GetBoundingBox().GetCenter();
Rotate90( false ); Rotate90( false );
SetTextPos( GetTextPos() + offset ); // Compensate for `Rotate90()` shifting the item center.
offset = GetBoundingBox().GetCenter() - pt;
SetTextPos( GetTextPos() - offset );
} }
@ -556,7 +564,7 @@ const EDA_RECT SCH_TEXT::GetBoundingBox() const
{ {
EDA_RECT rect = GetTextBox(); EDA_RECT rect = GetTextBox();
if( GetTextAngle() != 0 ) // Rotate rect if( GetTextAngle() != 0 )
{ {
wxPoint pos = rect.GetOrigin(); wxPoint pos = rect.GetOrigin();
wxPoint end = rect.GetEnd(); wxPoint end = rect.GetEnd();
@ -566,9 +574,10 @@ const EDA_RECT SCH_TEXT::GetBoundingBox() const
rect.SetOrigin( pos ); rect.SetOrigin( pos );
rect.SetEnd( end ); rect.SetEnd( end );
rect.Normalize();
} }
rect.Normalize();
return rect; return rect;
} }