From af71308184a35ddf36ef06a5cc7baf0bace79493 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 27 Jun 2023 08:53:04 +0200 Subject: [PATCH] pcb_parser and pcb_plugin: fix incorrect handling of rotation of PCB_TEXTs in footprints when the text angle is 0 but the fp orientation is not 0. It was due to the fact angle 0 is not written in file and use the default value of the created PCB_TEXT in footprint, that is not always 0 Now the angle is always written in file. Fixes #15054 https://gitlab.com/kicad/code/kicad/-/issues/15054 --- pcbnew/plugins/kicad/pcb_parser.cpp | 8 +++++++- pcbnew/plugins/kicad/pcb_plugin.cpp | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index b61e74ca3f..ffb6115af3 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -3051,6 +3051,8 @@ PCB_TEXT* PCB_PARSER::parsePCB_TEXT( BOARD_ITEM* aParent ) void PCB_PARSER::parsePCB_TEXT_effects( PCB_TEXT* aText ) { FOOTPRINT* parentFP = dynamic_cast( aText->GetParent() ); + bool hasAngle = false; // Old files do not have a angle specified. + // in this case it is 0 expected to be 0 // By default, texts in footprints have a locked rotation (i.e. rot = -90 ... 90 deg) if( parentFP ) @@ -3072,10 +3074,10 @@ void PCB_PARSER::parsePCB_TEXT_effects( PCB_TEXT* aText ) aText->SetTextPos( pt ); token = NextTok(); - // If there is no orientation defined, then it is the default value of 0 degrees. if( CurTok() == T_NUMBER ) { aText->SetTextAngle( EDA_ANGLE( parseDouble(), DEGREES_T ) ); + hasAngle = true; token = NextTok(); } @@ -3133,6 +3135,10 @@ void PCB_PARSER::parsePCB_TEXT_effects( PCB_TEXT* aText ) } } + // If there is no orientation defined, then it is the default value of 0 degrees. + if( !hasAngle ) + aText->SetTextAngle( ANGLE_0 ); + if( parentFP ) { // make PCB_TEXT rotation relative to the parent footprint. diff --git a/pcbnew/plugins/kicad/pcb_plugin.cpp b/pcbnew/plugins/kicad/pcb_plugin.cpp index 7e8c08e4b4..b0baf18ce9 100644 --- a/pcbnew/plugins/kicad/pcb_plugin.cpp +++ b/pcbnew/plugins/kicad/pcb_plugin.cpp @@ -1795,8 +1795,8 @@ void PCB_PLUGIN::format( const PCB_TEXT* aText, int aNestLevel ) const m_out->Print( 0, " (at %s", formatInternalUnits( pos ).c_str() ); // Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle. - if( !aText->GetTextAngle().IsZero() ) - m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aText->GetTextAngle() ).c_str() ); + // To avoid issues in the future, always save the angle, even if it is 0 + m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aText->GetTextAngle() ).c_str() ); if( parentFP && !aText->IsKeepUpright() ) m_out->Print( 0, " unlocked" );