diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index c856c0a288..1da87ca3de 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1048,10 +1048,21 @@ void MODULE::Move( const wxPoint& aMoveVector ) void MODULE::Rotate( const wxPoint& aRotCentre, double aAngle ) { + double orientation = GetOrientation(); + double newOrientation = orientation + aAngle; wxPoint newpos = m_Pos; RotatePoint( &newpos, aRotCentre, aAngle ); SetPosition( newpos ); - SetOrientation( GetOrientation() + aAngle ); + SetOrientation( newOrientation ); + + m_Reference->KeepUpright( orientation, newOrientation ); + m_Value->KeepUpright( orientation, newOrientation ); + + for( EDA_ITEM* item = m_Drawings; item; item = item->Next() ) + { + if( item->Type() == PCB_MODULE_TEXT_T ) + static_cast( item )->KeepUpright( orientation, newOrientation ); + } } diff --git a/pcbnew/class_text_mod.cpp b/pcbnew/class_text_mod.cpp index 03c025fc8e..17874f46ae 100644 --- a/pcbnew/class_text_mod.cpp +++ b/pcbnew/class_text_mod.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -119,6 +119,33 @@ bool TEXTE_MODULE::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccu } +void TEXTE_MODULE::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( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT ) + SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); + else if( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT ) + SetHorizJustify(GR_TEXT_HJUSTIFY_LEFT ); + + SetTextAngle( GetTextAngle() + 1800.0 ); + SetDrawCoord(); + } +} + + void TEXTE_MODULE::Rotate( const wxPoint& aRotCentre, double aAngle ) { // Used in footprint editing @@ -148,9 +175,10 @@ void TEXTE_MODULE::Flip( const wxPoint& aCentre ) if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT || GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT ) { if( ( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT ) == IsMirrored() ) - m_Pos0.x -= GetTextBox().GetWidth(); + SetHorizJustify( (EDA_TEXT_HJUSTIFY_T)-GetHorizJustify() ); else - m_Pos0.x += GetTextBox().GetWidth(); + SetHorizJustify( (EDA_TEXT_HJUSTIFY_T)-GetHorizJustify() ); + SetDrawCoord(); } } diff --git a/pcbnew/class_text_mod.h b/pcbnew/class_text_mod.h index 70f6615728..92e0a48b02 100644 --- a/pcbnew/class_text_mod.h +++ b/pcbnew/class_text_mod.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -87,6 +87,11 @@ public: void SetTextAngle( double 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.