From 2a0486845d619bbf693f22374423848b122ba840 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 31 Dec 2023 17:02:33 +0000 Subject: [PATCH] Restore legacy spin-style processing for text items. Post-V5 we only use it on labels, but earlier versions also used it for text. Also process spinStyle for CADSTAR imports. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16488 --- .../cadstar/cadstar_sch_archive_loader.cpp | 27 ++++++++- .../kicad_legacy/sch_io_kicad_legacy.cpp | 60 ++++++++++++++----- 2 files changed, 70 insertions(+), 17 deletions(-) diff --git a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp index 2348ecf4fe..9c8a10b399 100644 --- a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp @@ -3141,8 +3141,33 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( EDA_TEXT* aKiCadT } aKiCadTextItem->SetTextPos( pos ); + + switch( spin ) + { + case SPIN_STYLE::RIGHT: // Horiz Normal Orientation + aKiCadTextItem->SetTextAngle( ANGLE_HORIZONTAL ); + aKiCadTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); + break; + + case SPIN_STYLE::UP: // Vert Orientation UP + aKiCadTextItem->SetTextAngle( ANGLE_VERTICAL ); + aKiCadTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); + break; + + case SPIN_STYLE::LEFT: // Horiz Orientation - Right justified + aKiCadTextItem->SetTextAngle( ANGLE_HORIZONTAL ); + aKiCadTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); + break; + + case SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM + aKiCadTextItem->SetTextAngle( ANGLE_VERTICAL ); + aKiCadTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); + break; + } + + aKiCadTextItem->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM ); + break; } - KI_FALLTHROUGH; // We don't want to change position of net labels as that would break connectivity case SCH_LABEL_T: diff --git a/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy.cpp b/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy.cpp index 478f601ad0..08bca86edf 100644 --- a/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy.cpp +++ b/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy.cpp @@ -996,6 +996,23 @@ SCH_TEXT* SCH_IO_KICAD_LEGACY::loadText( LINE_READER& aReader ) } int spinStyle = parseInt( aReader, line, &line ); + + // Sadly we store the orientation of hierarchical and global labels using a different + // int encoding than that for local labels: + // Global Local + // Left justified 0 2 + // Up 1 3 + // Right justified 2 0 + // Down 3 1 + // So we must flip it as the enum is setup with the "global" numbering + if( textType != SCH_GLOBAL_LABEL_T && textType != SCH_HIER_LABEL_T ) + { + if( spinStyle == 0 ) + spinStyle = 2; + else if( spinStyle == 2 ) + spinStyle = 0; + } + int size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) ); text->SetTextSize( VECTOR2I( size, size ) ); @@ -1004,22 +1021,6 @@ SCH_TEXT* SCH_IO_KICAD_LEGACY::loadText( LINE_READER& aReader ) { SCH_LABEL_BASE* label = static_cast( text.get() ); - // Sadly we store the orientation of hierarchical and global labels using a different - // int encoding than that for local labels: - // Global Local - // Left justified 0 2 - // Up 1 3 - // Right justified 2 0 - // Down 3 1 - // So we must flip it as the enum is setup with the "global" numbering - if( textType == SCH_LABEL_T ) - { - if( spinStyle == 0 ) - spinStyle = 2; - else if( spinStyle == 2 ) - spinStyle = 0; - } - label->SetSpinStyle( static_cast( spinStyle ) ); // Parse the global and hierarchical label type. @@ -1037,6 +1038,33 @@ SCH_TEXT* SCH_IO_KICAD_LEGACY::loadText( LINE_READER& aReader ) SCH_PARSE_ERROR( "invalid label type", aReader, line ); } } + else if( textType == SCH_TEXT_T ) + { + switch( spinStyle ) + { + case SPIN_STYLE::RIGHT: // Horiz Normal Orientation + text->SetTextAngle( ANGLE_HORIZONTAL ); + text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); + break; + + case SPIN_STYLE::UP: // Vert Orientation UP + text->SetTextAngle( ANGLE_VERTICAL ); + text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); + break; + + case SPIN_STYLE::LEFT: // Horiz Orientation - Right justified + text->SetTextAngle( ANGLE_HORIZONTAL ); + text->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); + break; + + case SPIN_STYLE::BOTTOM: // Vert Orientation BOTTOM + text->SetTextAngle( ANGLE_VERTICAL ); + text->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); + break; + } + + text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM ); + } int penWidth = 0;