diff --git a/include/eda_text.h b/include/eda_text.h index 32e1dc105d..93a19d1de1 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -127,7 +127,7 @@ public: 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; } void SetItalic( bool aItalic ); diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 42f242a274..92c0ca33ba 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -1491,13 +1491,13 @@ void FOOTPRINT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) SetPosition( newpos ); SetOrientation( newOrientation ); - m_reference->KeepUpright( orientation.AsTenthsOfADegree(), newOrientation.AsTenthsOfADegree() ); - m_value->KeepUpright( orientation.AsTenthsOfADegree(), newOrientation.AsTenthsOfADegree() ); + m_reference->KeepUpright( orientation, newOrientation ); + m_value->KeepUpright( orientation, newOrientation ); for( BOARD_ITEM* item : m_drawings ) { if( item->Type() == PCB_FP_TEXT_T ) - static_cast( item )->KeepUpright( orientation.AsTenthsOfADegree(), newOrientation.AsTenthsOfADegree() ); + static_cast( item )->KeepUpright( orientation, newOrientation ); } m_boundingBoxCacheTimeStamp = 0; diff --git a/pcbnew/fp_text.cpp b/pcbnew/fp_text.cpp index 8e55e29a77..8a6b36bd6a 100644 --- a/pcbnew/fp_text.cpp +++ b/pcbnew/fp_text.cpp @@ -45,7 +45,7 @@ FP_TEXT::FP_TEXT( FOOTPRINT* aParentFootprint, TEXT_TYPE text_type ) : FOOTPRINT* parentFootprint = static_cast( m_parent ); m_Type = text_type; - m_keepUpright = true; + SetKeepUpright( true ); // Set text thickness to a default value 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() ) return; - double newAngle = GetTextAngle().AsTenthsOfADegree() + aNewOrientation; - NORMALIZE_ANGLE_POS( newAngle ); - bool needsFlipped = newAngle >= 1800.0; + EDA_ANGLE newAngle = GetTextAngle() + aNewOrientation; + newAngle.Normalize(); + + bool needsFlipped = newAngle >= ANGLE_180; if( needsFlipped ) { SetHorizJustify( static_cast( -GetHorizJustify() ) ); - SetTextAngle( GetTextAngle().AsTenthsOfADegree() + 1800.0 ); + SetTextAngle( GetTextAngle() + ANGLE_180 ); SetDrawCoord(); } } @@ -247,7 +248,7 @@ EDA_ANGLE FP_TEXT::GetDrawRotation() const if( parentFootprint ) rotation += parentFootprint->GetOrientation(); - if( m_keepUpright ) + if( IsKeepUpright() ) { // Keep angle between 0 .. 90 deg. Otherwise the text is not easy to read while( rotation > ANGLE_90 ) diff --git a/pcbnew/fp_text.h b/pcbnew/fp_text.h index 9be9c92c5d..fa051e1e94 100644 --- a/pcbnew/fp_text.h +++ b/pcbnew/fp_text.h @@ -96,20 +96,10 @@ public: SetLocalCoord(); } - void SetTextAngle( double aAngle ) override; - void SetTextAngle( const EDA_ANGLE& aAngle ); - /** * Called when rotating the parent footprint. */ - void KeepUpright( double aOldOrientation, double 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; } + void KeepUpright( const EDA_ANGLE& aOldOrientation, const EDA_ANGLE& aNewOrientation ); /// Rotate text, in footprint editor /// (for instance in footprint rotation transform) @@ -209,9 +199,6 @@ private: VECTOR2I m_Pos0; ///< text coordinates relative to the footprint anchor, orient 0. ///< 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