From a5a8b93a2e6817ba20d1dbf0cb7cd9db5cad1b67 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 18 May 2023 10:28:27 +0200 Subject: [PATCH] Eeschema, directive labels: fix some issues: - honor mirroring of fields attached to labels (all types) - fix incorrect orientation of the graphic shape of SCH_DIRECTIVE_LABEL items after mirroring the item. Form master branch Fixes #14758 https://gitlab.com/kicad/code/kicad/issues/14758 --- eeschema/sch_label.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++ eeschema/sch_label.h | 4 +++ 2 files changed, 63 insertions(+) diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index c217f1a622..7455b4d5ed 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -374,6 +374,34 @@ void SCH_LABEL_BASE::Rotate90( bool aClockwise ) } +void SCH_LABEL_BASE::MirrorSpinStyle( bool aLeftRight ) +{ + SCH_TEXT::MirrorSpinStyle( aLeftRight ); + + for( SCH_FIELD& field : m_fields ) + { + if( ( aLeftRight && field.GetTextAngle().IsHorizontal() ) + || ( !aLeftRight && field.GetTextAngle().IsVertical() ) ) + { + if( field.GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT ) + field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); + else + field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); + } + + VECTOR2I pos = field.GetTextPos(); + VECTOR2I delta = (VECTOR2I)GetPosition() - pos; + + if( aLeftRight ) + pos.x = GetPosition().x + delta.x; + else + pos.y = GetPosition().y + delta.y; + + field.SetTextPos( pos ); + } +} + + bool SCH_LABEL_BASE::IncrementLabel( int aIncrement ) { wxString text = GetText(); @@ -1124,6 +1152,37 @@ int SCH_DIRECTIVE_LABEL::GetPenWidth() const } +void SCH_DIRECTIVE_LABEL::MirrorSpinStyle( bool aLeftRight ) +{ + // The "text" is in fact a graphic shape. For a horizontal "text", it looks like a + // vertical shape (like a text reduced to only "I" letter). + // So the mirroring is not exactly similar to a SCH_TEXT item + SCH_TEXT::MirrorSpinStyle( !aLeftRight ); + + for( SCH_FIELD& field : m_fields ) + { + if( ( aLeftRight && field.GetTextAngle().IsHorizontal() ) + || ( !aLeftRight && field.GetTextAngle().IsVertical() ) ) + { + if( field.GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT ) + field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); + else + field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); + } + + VECTOR2I pos = field.GetTextPos(); + VECTOR2I delta = (VECTOR2I)GetPosition() - pos; + + if( aLeftRight ) + pos.x = GetPosition().x + delta.x; + else + pos.y = GetPosition().y + delta.y; + + field.SetTextPos( pos ); + } +} + + void SCH_DIRECTIVE_LABEL::CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings, std::vector& aPoints, const VECTOR2I& aPos ) const diff --git a/eeschema/sch_label.h b/eeschema/sch_label.h index db5f902d82..9c54cd4185 100644 --- a/eeschema/sch_label.h +++ b/eeschema/sch_label.h @@ -116,6 +116,8 @@ public: void Rotate( const VECTOR2I& aCenter ) override; void Rotate90( bool aClockwise ) override; + void MirrorSpinStyle( bool aLeftRight ) override; + void SetPosition( const VECTOR2I& aPosition ) override; void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override; @@ -320,6 +322,8 @@ public: bool AutoRotateOnPlacementSupported() const override { return false; } + void MirrorSpinStyle( bool aLeftRight ) override; + private: int m_pinLength; int m_symbolSize;