From b968bac3181f74d15738600a1f9ac42fdcb1bf77 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 23 May 2023 09:42:24 +0200 Subject: [PATCH] Eeschema: fix block mirroring of fields attached to labels (all types) Fix incorrect orientation of the graphic shape of SCH_DIRECTIVE_LABEL items after mirroring the item. Similar to commit 898d88cc, but for block mirroring. Fixes #14758 https://gitlab.com/kicad/code/kicad/-/issues/14758 --- eeschema/sch_label.cpp | 179 ++++++++++++++++++++++++----------------- eeschema/sch_label.h | 11 +-- 2 files changed, 111 insertions(+), 79 deletions(-) diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 7455b4d5ed..6d14f09154 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -402,6 +403,52 @@ void SCH_LABEL_BASE::MirrorSpinStyle( bool aLeftRight ) } +void SCH_LABEL_BASE::MirrorHorizontally( int aCenter ) +{ + VECTOR2I old_pos = GetPosition(); + SCH_TEXT::MirrorHorizontally( aCenter ); + + for( SCH_FIELD& field : m_fields ) + { + switch( field.GetHorizJustify() ) + { + case GR_TEXT_H_ALIGN_LEFT: + field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); + break; + + case GR_TEXT_H_ALIGN_CENTER: + break; + + case GR_TEXT_H_ALIGN_RIGHT: + field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); + break; + } + + VECTOR2I pos = field.GetTextPos(); + VECTOR2I delta = old_pos - pos; + pos.x = GetPosition().x + delta.x; + + field.SetPosition( pos ); + } +} + + +void SCH_LABEL_BASE::MirrorVertically( int aCenter ) +{ + VECTOR2I old_pos = GetPosition(); + SCH_TEXT::MirrorVertically( aCenter ); + + for( SCH_FIELD& field : m_fields ) + { + VECTOR2I pos = field.GetTextPos(); + VECTOR2I delta = old_pos - pos; + pos.y = GetPosition().y + delta.y; + + field.SetPosition( pos ); + } +} + + bool SCH_LABEL_BASE::IncrementLabel( int aIncrement ) { wxString text = GetText(); @@ -1183,6 +1230,64 @@ void SCH_DIRECTIVE_LABEL::MirrorSpinStyle( bool aLeftRight ) } +void SCH_DIRECTIVE_LABEL::MirrorHorizontally( int aCenter ) +{ + VECTOR2I old_pos = GetPosition(); + // 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 + // Text is NOT really mirrored; it is moved to a suitable horizontal position + SetTextSpinStyle( GetTextSpinStyle().MirrorX() ); + + SetTextX( MIRRORVAL( GetTextPos().x, aCenter ) ); + + for( SCH_FIELD& field : m_fields ) + { + switch( field.GetHorizJustify() ) + { + case GR_TEXT_H_ALIGN_LEFT: + field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); + break; + + case GR_TEXT_H_ALIGN_CENTER: + break; + + case GR_TEXT_H_ALIGN_RIGHT: + field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); + break; + } + + VECTOR2I pos = field.GetTextPos(); + VECTOR2I delta = old_pos - pos; + pos.x = GetPosition().x + delta.x; + + field.SetPosition( pos ); + } +} + + +void SCH_DIRECTIVE_LABEL::MirrorVertically( int aCenter ) +{ + VECTOR2I old_pos = GetPosition(); + // 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 + // Text is NOT really mirrored; it is moved to a suitable vertical position + SetTextSpinStyle( GetTextSpinStyle().MirrorY() ); + + SetTextY( MIRRORVAL( GetTextPos().y, aCenter ) ); + + for( SCH_FIELD& field : m_fields ) + { + VECTOR2I pos = field.GetTextPos(); + VECTOR2I delta = old_pos - pos; + pos.y = GetPosition().y + delta.y; + + field.SetPosition( pos ); + } +} + + void SCH_DIRECTIVE_LABEL::CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings, std::vector& aPoints, const VECTOR2I& aPos ) const @@ -1379,80 +1484,6 @@ void SCH_GLOBALLABEL::SetTextSpinStyle( TEXT_SPIN_STYLE aSpinStyle ) } -void SCH_GLOBALLABEL::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 ); - } -} - - -void SCH_GLOBALLABEL::MirrorHorizontally( int aCenter ) -{ - VECTOR2I old_pos = GetPosition(); - SCH_TEXT::MirrorHorizontally( aCenter ); - - for( SCH_FIELD& field : m_fields ) - { - switch( field.GetHorizJustify() ) - { - case GR_TEXT_H_ALIGN_LEFT: - field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); - break; - - case GR_TEXT_H_ALIGN_CENTER: - break; - - case GR_TEXT_H_ALIGN_RIGHT: - field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); - break; - } - - VECTOR2I pos = field.GetTextPos(); - VECTOR2I delta = old_pos - pos; - pos.x = GetPosition().x + delta.x; - - field.SetPosition( pos ); - } -} - - -void SCH_GLOBALLABEL::MirrorVertically( int aCenter ) -{ - VECTOR2I old_pos = GetPosition(); - SCH_TEXT::MirrorVertically( aCenter ); - - for( SCH_FIELD& field : m_fields ) - { - VECTOR2I pos = field.GetTextPos(); - VECTOR2I delta = old_pos - pos; - pos.y = GetPosition().y + delta.y; - - field.SetPosition( pos ); - } -} - - bool SCH_GLOBALLABEL::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth ) const { diff --git a/eeschema/sch_label.h b/eeschema/sch_label.h index 9c54cd4185..7c39c30542 100644 --- a/eeschema/sch_label.h +++ b/eeschema/sch_label.h @@ -118,6 +118,9 @@ public: void MirrorSpinStyle( bool aLeftRight ) override; + void MirrorHorizontally( int aCenter ) override; + void MirrorVertically( int aCenter ) override; + void SetPosition( const VECTOR2I& aPosition ) override; void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override; @@ -324,6 +327,9 @@ public: void MirrorSpinStyle( bool aLeftRight ) override; + void MirrorHorizontally( int aCenter ) override; + void MirrorVertically( int aCenter ) override; + private: int m_pinLength; int m_symbolSize; @@ -356,11 +362,6 @@ public: int GetMandatoryFieldCount() override { return 1; } - void MirrorSpinStyle( bool aLeftRight ) override; - - void MirrorHorizontally( int aCenter ) override; - void MirrorVertically( int aCenter ) override; - void SetTextSpinStyle( TEXT_SPIN_STYLE aSpinStyle ) override; VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const override;