From eba0783b38620926cba666251a5c039d05f6cb34 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 4 Mar 2023 12:13:12 -0500 Subject: [PATCH] Fix rotation/flipping properties for text boxes Fixes https://gitlab.com/kicad/code/kicad/-/issues/14159 Fixes https://gitlab.com/kicad/code/kicad/-/issues/14164 --- common/eda_text.cpp | 12 ++++++++-- libs/kimath/include/geometry/eda_angle.h | 6 +++++ pcbnew/dialogs/dialog_textbox_properties.cpp | 7 ------ pcbnew/fp_textbox.cpp | 23 +++++++++++++++++--- pcbnew/fp_textbox.h | 2 ++ pcbnew/pcb_textbox.cpp | 15 ++++++++++--- pcbnew/pcb_textbox.h | 2 ++ 7 files changed, 52 insertions(+), 15 deletions(-) diff --git a/common/eda_text.cpp b/common/eda_text.cpp index b3eb6bae13..66abf665f0 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -50,6 +50,8 @@ #include #include #include +#include +#include // Text limits are in here for some reason #include // for wxASSERT #include @@ -1061,12 +1063,18 @@ static struct EDA_TEXT_DESC &EDA_TEXT::SetTextWidth, &EDA_TEXT::GetTextWidth, PROPERTY_DISPLAY::PT_SIZE ), - textProps ); + textProps ) + .SetValidator( PROPERTY_VALIDATORS::RangeIntValidator ); + propMgr.AddProperty( new PROPERTY( _HKI( "Height" ), &EDA_TEXT::SetTextHeight, &EDA_TEXT::GetTextHeight, PROPERTY_DISPLAY::PT_SIZE ), - textProps ); + textProps ) + .SetValidator( PROPERTY_VALIDATORS::RangeIntValidator ); + propMgr.AddProperty( new PROPERTY_ENUM( _HKI( "Horizontal Justification" ), &EDA_TEXT::SetHorizJustify, diff --git a/libs/kimath/include/geometry/eda_angle.h b/libs/kimath/include/geometry/eda_angle.h index ba71e1754f..f3e7fd4243 100644 --- a/libs/kimath/include/geometry/eda_angle.h +++ b/libs/kimath/include/geometry/eda_angle.h @@ -257,6 +257,12 @@ public: return *this; } + EDA_ANGLE Normalized() const + { + EDA_ANGLE ret( *this ); + return ret.Normalize(); + } + inline EDA_ANGLE NormalizeNegative() { while( m_value <= -360.0 ) diff --git a/pcbnew/dialogs/dialog_textbox_properties.cpp b/pcbnew/dialogs/dialog_textbox_properties.cpp index 3c07bb7791..1a14b4529e 100644 --- a/pcbnew/dialogs/dialog_textbox_properties.cpp +++ b/pcbnew/dialogs/dialog_textbox_properties.cpp @@ -356,13 +356,6 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow() m_edaText->SetTextThickness( maxPenWidth ); } - EDA_ANGLE delta = m_orientation.GetAngleValue().Normalize() - m_edaText->GetTextAngle(); - - if( m_fpTextBox ) - m_fpTextBox->Rotate( m_fpTextBox->GetPosition(), delta ); - else if( m_pcbTextBox ) - m_pcbTextBox->Rotate( m_pcbTextBox->GetPosition(), delta ); - m_edaText->SetTextAngle( m_orientation.GetAngleValue().Normalize() ); m_edaText->SetBold( m_bold->IsChecked() ); diff --git a/pcbnew/fp_textbox.cpp b/pcbnew/fp_textbox.cpp index 8657e2e336..eaed0b5c42 100644 --- a/pcbnew/fp_textbox.cpp +++ b/pcbnew/fp_textbox.cpp @@ -133,6 +133,13 @@ void FP_TEXTBOX::SetRight( int aVal ) } +void FP_TEXTBOX::SetTextAngle( const EDA_ANGLE& aAngle ) +{ + EDA_ANGLE delta = aAngle.Normalized() - GetTextAngle(); + Rotate( GetPosition(), delta ); +} + + std::vector FP_TEXTBOX::GetCorners() const { std::vector pts = FP_SHAPE::GetCorners(); @@ -217,6 +224,9 @@ VECTOR2I FP_TEXTBOX::GetDrawPos() const if( IsMirrored() != isFlipped ) { + std::swap( corners[0], corners[1] ); + std::swap( corners[2], corners[3] ); + switch( GetHorizJustify() ) { case GR_TEXT_H_ALIGN_LEFT: effectiveAlignment = GR_TEXT_H_ALIGN_RIGHT; break; @@ -280,7 +290,7 @@ void FP_TEXTBOX::Move( const VECTOR2I& aMoveVector ) void FP_TEXTBOX::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) { FP_SHAPE::Rotate( aRotCentre, aAngle ); - SetTextAngle( GetTextAngle() + aAngle ); + EDA_TEXT::SetTextAngle( ( GetTextAngle() + aAngle ).Normalized() ); } @@ -292,12 +302,12 @@ void FP_TEXTBOX::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) if( aFlipLeftRight ) { SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) ); - SetTextAngle( -GetTextAngle() ); + EDA_TEXT::SetTextAngle( -GetTextAngle() ); } else { SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) ); - SetTextAngle( ANGLE_180 - GetTextAngle() ); + EDA_TEXT::SetTextAngle( ANGLE_180 - GetTextAngle() ); } if( ( GetLayerSet() & LSET::SideSpecificMask() ).any() ) @@ -593,5 +603,12 @@ static struct FP_TEXTBOX_DESC propMgr.AddProperty( new PROPERTY( _HKI( "Parent" ), NO_SETTER( FP_TEXTBOX, wxString ), &FP_TEXTBOX::GetParentAsString ) ) .SetIsHiddenFromLibraryEditors(); + + propMgr.Mask( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Shape" ) ); + propMgr.Mask( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start X" ) ); + propMgr.Mask( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start Y" ) ); + propMgr.Mask( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "End X" ) ); + propMgr.Mask( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "End Y" ) ); + propMgr.Mask( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Width" ) ); } } _FP_TEXTBOX_DESC; diff --git a/pcbnew/fp_textbox.h b/pcbnew/fp_textbox.h index 4c4a79fe7e..8356155289 100644 --- a/pcbnew/fp_textbox.h +++ b/pcbnew/fp_textbox.h @@ -71,6 +71,8 @@ public: void SetRight( int aVal ) override; void SetBottom( int aVal ) override; + void SetTextAngle( const EDA_ANGLE& aAngle ) override; + wxString GetParentAsString() const; bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index 773ecf5767..ad369e8dfe 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -133,6 +133,13 @@ void PCB_TEXTBOX::SetRight( int aVal ) } +void PCB_TEXTBOX::SetTextAngle( const EDA_ANGLE& aAngle ) +{ + EDA_ANGLE delta = aAngle.Normalized() - GetTextAngle(); + Rotate( GetPosition(), delta ); +} + + std::vector PCB_TEXTBOX::GetAnchorAndOppositeCorner() const { std::vector pts; @@ -185,6 +192,8 @@ VECTOR2I PCB_TEXTBOX::GetDrawPos() const if( IsMirrored() ) { + std::swap( corners[0], corners[1] ); + switch( GetHorizJustify() ) { case GR_TEXT_H_ALIGN_LEFT: effectiveAlignment = GR_TEXT_H_ALIGN_RIGHT; break; @@ -313,7 +322,7 @@ void PCB_TEXTBOX::Move( const VECTOR2I& aMoveVector ) void PCB_TEXTBOX::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) { PCB_SHAPE::Rotate( aRotCentre, aAngle ); - SetTextAngle( GetTextAngle() + aAngle ); + EDA_TEXT::SetTextAngle( ( GetTextAngle() + aAngle ).Normalized() ); if( GetTextAngle().IsCardinal() && GetShape() != SHAPE_T::RECT ) { @@ -356,13 +365,13 @@ void PCB_TEXTBOX::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) { m_start.x = aCentre.x - ( m_start.x - aCentre.x ); m_end.x = aCentre.x - ( m_end.x - aCentre.x ); - SetTextAngle( -GetTextAngle() ); + EDA_TEXT::SetTextAngle( -GetTextAngle() ); } else { m_start.y = aCentre.y - ( m_start.y - aCentre.y ); m_end.y = aCentre.y - ( m_end.y - aCentre.y ); - SetTextAngle( ANGLE_180 - GetTextAngle() ); + EDA_TEXT::SetTextAngle( ANGLE_180 - GetTextAngle() ); } SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) ); diff --git a/pcbnew/pcb_textbox.h b/pcbnew/pcb_textbox.h index f9f72dfb62..0bd6f81e2d 100644 --- a/pcbnew/pcb_textbox.h +++ b/pcbnew/pcb_textbox.h @@ -74,6 +74,8 @@ public: VECTOR2I GetDrawPos() const override; + void SetTextAngle( const EDA_ANGLE& aAngle ) override; + wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override; /// PCB_TEXTBOXes are always visible: