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
This commit is contained in:
Jon Evans 2023-03-04 12:13:12 -05:00
parent 4e99812145
commit eba0783b38
7 changed files with 52 additions and 15 deletions

View File

@ -50,6 +50,8 @@
#include <geometry/shape_simple.h>
#include <font/outline_font.h>
#include <geometry/shape_poly_set.h>
#include <properties/property_validators.h>
#include <pcbnew.h> // Text limits are in here for some reason
#include <wx/debug.h> // for wxASSERT
#include <wx/string.h>
@ -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<TEXTS_MIN_SIZE,
TEXTS_MAX_SIZE> );
propMgr.AddProperty( new PROPERTY<EDA_TEXT, int>( _HKI( "Height" ),
&EDA_TEXT::SetTextHeight,
&EDA_TEXT::GetTextHeight,
PROPERTY_DISPLAY::PT_SIZE ),
textProps );
textProps )
.SetValidator( PROPERTY_VALIDATORS::RangeIntValidator<TEXTS_MIN_SIZE,
TEXTS_MAX_SIZE> );
propMgr.AddProperty( new PROPERTY_ENUM<EDA_TEXT,
GR_TEXT_H_ALIGN_T>( _HKI( "Horizontal Justification" ),
&EDA_TEXT::SetHorizJustify,

View File

@ -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 )

View File

@ -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() );

View File

@ -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<VECTOR2I> FP_TEXTBOX::GetCorners() const
{
std::vector<VECTOR2I> 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<FP_TEXTBOX, wxString>( _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;

View File

@ -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

View File

@ -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<VECTOR2I> PCB_TEXTBOX::GetAnchorAndOppositeCorner() const
{
std::vector<VECTOR2I> 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() ) );

View File

@ -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: