Rotate FP_TEST properly when flipping

The angle was `-angle` instead of `180 deg - angle` when flipping top to
bottom.

Fixing that, in turn, created some problems with justification, which
was modified both by `FP_TEXT::Flip()` and `FP_TEXT::KeepUpright()`.

What's worse, `FP_TEXT` has another mechanism for keeping the text
upright: `FP_TEXT::GetDrawRotation()` returns different angles if the
"keep upright" flag is set. But there is no analogous behavior for
justification, so the text would sometimes get shifted, and sometimes
not, depending on which mechanism was engaged. And both are used,
apparently.

Clearly, such an arrangement an open invitation to bugs and
inconsistencies. One of these mechanisms should be removed. I haven't
done this yet, and would prefer to postpone this until V6 is out.

I've fixed the justification problems, but this was by trial-and-error,
and I don't feel I really understand the behavior responsible. But I
think it's a good sign that most of my changes are line removals, not
additions. Flipping is a simple operation, it's just mirroring and layer
change. If something simple has a complicated routine, then it's
probably full of hacks.

Fixes https://gitlab.com/kicad/code/kicad/issues/7289
This commit is contained in:
Mikolaj Wielgus 2021-03-19 22:45:24 +01:00 committed by Seth Hillbrand
parent 0a660c2364
commit d7a95e2af4
1 changed files with 10 additions and 22 deletions

View File

@ -104,22 +104,13 @@ void FP_TEXT::KeepUpright( double aOldOrientation, double aNewOrientation )
if( !IsKeepUpright() )
return;
double currentAngle = GetTextAngle() + aOldOrientation;
double newAngle = GetTextAngle() + aNewOrientation;
NORMALIZE_ANGLE_POS( currentAngle );
NORMALIZE_ANGLE_POS( newAngle );
bool isFlipped = currentAngle >= 1800.0;
bool needsFlipped = newAngle >= 1800.0;
if( isFlipped != needsFlipped )
if( needsFlipped )
{
if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
else if( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
SetHorizJustify(GR_TEXT_HJUSTIFY_LEFT );
SetHorizJustify( static_cast<EDA_TEXT_HJUSTIFY_T>( -GetHorizJustify() ) );
SetTextAngle( GetTextAngle() + 1800.0 );
SetDrawCoord();
}
@ -144,22 +135,19 @@ void FP_TEXT::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
{
// flipping the footprint is relative to the X axis
if( aFlipLeftRight )
SetTextX( ::MIRRORVAL( GetTextPos().x, aCentre.x ) );
{
SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
SetTextAngle( -GetTextAngle() );
}
else
SetTextY( ::MIRRORVAL( GetTextPos().y, aCentre.y ) );
SetTextAngle( -GetTextAngle() );
{
SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
SetTextAngle( 1800 - GetTextAngle() );
}
SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) );
SetMirrored( IsBackLayer( GetLayer() ) );
SetLocalCoord();
// adjust justified text for mirroring
if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT || GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
{
SetHorizJustify( static_cast<EDA_TEXT_HJUSTIFY_T>( -GetHorizJustify() ) );
SetDrawCoord();
}
}
bool FP_TEXT::IsParentFlipped() const