Move FP_TEXT::KeepUpright() to EDA_ANGLE.

This commit is contained in:
Jeff Young 2022-01-13 20:23:38 +00:00
parent 5176512de3
commit 037dfb6e01
4 changed files with 13 additions and 25 deletions

View File

@ -127,7 +127,7 @@ public:
SetTextAngle( EDA_ANGLE( aAngleInTenthsOfADegree, TENTHS_OF_A_DEGREE_T ) ); SetTextAngle( EDA_ANGLE( aAngleInTenthsOfADegree, TENTHS_OF_A_DEGREE_T ) );
} }
void SetTextAngle( const EDA_ANGLE& aAngle ); virtual void SetTextAngle( const EDA_ANGLE& aAngle );
const EDA_ANGLE& GetTextAngle() const { return m_attributes.m_Angle; } const EDA_ANGLE& GetTextAngle() const { return m_attributes.m_Angle; }
void SetItalic( bool aItalic ); void SetItalic( bool aItalic );

View File

@ -1491,13 +1491,13 @@ void FOOTPRINT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
SetPosition( newpos ); SetPosition( newpos );
SetOrientation( newOrientation ); SetOrientation( newOrientation );
m_reference->KeepUpright( orientation.AsTenthsOfADegree(), newOrientation.AsTenthsOfADegree() ); m_reference->KeepUpright( orientation, newOrientation );
m_value->KeepUpright( orientation.AsTenthsOfADegree(), newOrientation.AsTenthsOfADegree() ); m_value->KeepUpright( orientation, newOrientation );
for( BOARD_ITEM* item : m_drawings ) for( BOARD_ITEM* item : m_drawings )
{ {
if( item->Type() == PCB_FP_TEXT_T ) if( item->Type() == PCB_FP_TEXT_T )
static_cast<FP_TEXT*>( item )->KeepUpright( orientation.AsTenthsOfADegree(), newOrientation.AsTenthsOfADegree() ); static_cast<FP_TEXT*>( item )->KeepUpright( orientation, newOrientation );
} }
m_boundingBoxCacheTimeStamp = 0; m_boundingBoxCacheTimeStamp = 0;

View File

@ -45,7 +45,7 @@ FP_TEXT::FP_TEXT( FOOTPRINT* aParentFootprint, TEXT_TYPE text_type ) :
FOOTPRINT* parentFootprint = static_cast<FOOTPRINT*>( m_parent ); FOOTPRINT* parentFootprint = static_cast<FOOTPRINT*>( m_parent );
m_Type = text_type; m_Type = text_type;
m_keepUpright = true; SetKeepUpright( true );
// Set text thickness to a default value // Set text thickness to a default value
SetTextThickness( Millimeter2iu( DEFAULT_TEXT_WIDTH ) ); SetTextThickness( Millimeter2iu( DEFAULT_TEXT_WIDTH ) );
@ -110,19 +110,20 @@ bool FP_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy
} }
void FP_TEXT::KeepUpright( double aOldOrientation, double aNewOrientation ) void FP_TEXT::KeepUpright( const EDA_ANGLE& aOldOrientation, const EDA_ANGLE& aNewOrientation )
{ {
if( !IsKeepUpright() ) if( !IsKeepUpright() )
return; return;
double newAngle = GetTextAngle().AsTenthsOfADegree() + aNewOrientation; EDA_ANGLE newAngle = GetTextAngle() + aNewOrientation;
NORMALIZE_ANGLE_POS( newAngle ); newAngle.Normalize();
bool needsFlipped = newAngle >= 1800.0;
bool needsFlipped = newAngle >= ANGLE_180;
if( needsFlipped ) if( needsFlipped )
{ {
SetHorizJustify( static_cast<GR_TEXT_H_ALIGN_T>( -GetHorizJustify() ) ); SetHorizJustify( static_cast<GR_TEXT_H_ALIGN_T>( -GetHorizJustify() ) );
SetTextAngle( GetTextAngle().AsTenthsOfADegree() + 1800.0 ); SetTextAngle( GetTextAngle() + ANGLE_180 );
SetDrawCoord(); SetDrawCoord();
} }
} }
@ -247,7 +248,7 @@ EDA_ANGLE FP_TEXT::GetDrawRotation() const
if( parentFootprint ) if( parentFootprint )
rotation += parentFootprint->GetOrientation(); rotation += parentFootprint->GetOrientation();
if( m_keepUpright ) if( IsKeepUpright() )
{ {
// Keep angle between 0 .. 90 deg. Otherwise the text is not easy to read // Keep angle between 0 .. 90 deg. Otherwise the text is not easy to read
while( rotation > ANGLE_90 ) while( rotation > ANGLE_90 )

View File

@ -96,20 +96,10 @@ public:
SetLocalCoord(); SetLocalCoord();
} }
void SetTextAngle( double aAngle ) override;
void SetTextAngle( const EDA_ANGLE& aAngle );
/** /**
* Called when rotating the parent footprint. * Called when rotating the parent footprint.
*/ */
void KeepUpright( double aOldOrientation, double aNewOrientation ); void KeepUpright( const EDA_ANGLE& aOldOrientation, const EDA_ANGLE& aNewOrientation );
/**
* @return force the text rotation to be always between -90 .. 90 deg. Otherwise the text
* is not easy to read if false, the text rotation is free.
*/
bool IsKeepUpright() const { return m_keepUpright; }
void SetKeepUpright( bool aKeepUpright ) { m_keepUpright = aKeepUpright; }
/// Rotate text, in footprint editor /// Rotate text, in footprint editor
/// (for instance in footprint rotation transform) /// (for instance in footprint rotation transform)
@ -209,9 +199,6 @@ private:
VECTOR2I m_Pos0; ///< text coordinates relative to the footprint anchor, orient 0. VECTOR2I m_Pos0; ///< text coordinates relative to the footprint anchor, orient 0.
///< text coordinate ref point is the text center ///< text coordinate ref point is the text center
bool m_keepUpright; ///< if true, keep rotation angle between -90 .. 90 deg.
///< to keep the text more easy to read
}; };
#endif // FP_TEXT_H #endif // FP_TEXT_H