From f29fc2a025e633973583940ee1c4864691d23410 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Tue, 9 Apr 2024 15:23:02 -0400 Subject: [PATCH] PCB Fields: fix v7 imported board hidden description field pos Fixes: https://gitlab.com/kicad/code/kicad/-/issues/17684 --- pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp | 9 ++++++++- pcbnew/pcb_text.cpp | 4 ++-- pcbnew/pcb_text.h | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp index a6d13ba16a..0feeb24ffe 100644 --- a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp +++ b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp @@ -3196,6 +3196,7 @@ void PCB_IO_KICAD_SEXPR_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 + bool hasPos = false; // By default, texts in footprints have a locked rotation (i.e. rot = -90 ... 90 deg) if( parentFP ) @@ -3212,6 +3213,7 @@ void PCB_IO_KICAD_SEXPR_PARSER::parsePCB_TEXT_effects( PCB_TEXT* aText ) { VECTOR2I pt; + hasPos = true; pt.x = parseBoardUnits( "X coordinate" ); pt.y = parseBoardUnits( "Y coordinate" ); aText->SetTextPos( pt ); @@ -3318,7 +3320,12 @@ void PCB_IO_KICAD_SEXPR_PARSER::parsePCB_TEXT_effects( PCB_TEXT* aText ) // Move and rotate the text to its board coordinates aText->Rotate( { 0, 0 }, parentFP->GetOrientation() ); - aText->Move( parentFP->GetPosition() ); + + // Only move offset from parent position if we read a position from the file. + // These positions are relative to the parent footprint. If we don't have a position + // then the text defaults to the parent position and moving again will double it. + if (hasPos) + aText->Move( parentFP->GetPosition() ); } } diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index 74bd33c108..ac22530931 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -47,8 +47,8 @@ PCB_TEXT::PCB_TEXT( BOARD_ITEM* parent, KICAD_T idtype ) : } -PCB_TEXT::PCB_TEXT( FOOTPRINT* aParent ) : - BOARD_ITEM( aParent, PCB_TEXT_T ), +PCB_TEXT::PCB_TEXT( FOOTPRINT* aParent, KICAD_T idtype) : + BOARD_ITEM( aParent, idtype ), EDA_TEXT( pcbIUScale ) { SetKeepUpright( true ); diff --git a/pcbnew/pcb_text.h b/pcbnew/pcb_text.h index 9f10c1893c..fc65e003a7 100644 --- a/pcbnew/pcb_text.h +++ b/pcbnew/pcb_text.h @@ -39,7 +39,7 @@ class PCB_TEXT : public BOARD_ITEM, public EDA_TEXT public: PCB_TEXT( BOARD_ITEM* parent, KICAD_T idtype = PCB_TEXT_T ); - PCB_TEXT( FOOTPRINT* aParent ); + PCB_TEXT( FOOTPRINT* aParent, KICAD_T idtype = PCB_TEXT_T ); // Do not create a copy constructor & operator=. // The ones generated by the compiler are adequate.