From 5ce22d967325d4e4430ff50018c800d0d9d5c019 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 15 Mar 2023 17:55:18 +0100 Subject: [PATCH] Symbol editor: fix incorrect position of fields when loading a symbol from schematic. In symbol editor, symbols are always shown not mirrored, not rotated. So if the loaded symbol from schematic was rotated/mirrored, the position of fields must be recalculated for the rotation 0, no mirror. --- eeschema/symbol_editor/symbol_edit_frame.cpp | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index 909319a402..c18682c880 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -1428,6 +1428,11 @@ void SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic( SCH_SYMBOL* aSymbol ) std::unique_ptr symbol = aSymbol->GetLibSymbolRef()->Flatten(); wxCHECK( symbol, /* void */ ); + // Take in account the symbol orientation and mirroring. to calculate the field + // positions in symbol editor (i.e. no rotation, no mirroring) + int orientation = aSymbol->GetOrientation() & ~( SYM_MIRROR_X | SYM_MIRROR_Y ); + int mirror = aSymbol->GetOrientation() & ( SYM_MIRROR_X | SYM_MIRROR_Y ); + std::vector fullSetOfFields; for( int i = 0; i < (int) aSymbol->GetFields().size(); ++i ) @@ -1441,6 +1446,33 @@ void SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic( SCH_SYMBOL* aSymbol ) libField.SetText( field.GetText() ); libField.SetAttributes( field ); + + // The inverse transform is mirroring before, rotate after + switch( mirror ) + { + default:; break; + case SYM_MIRROR_X: pos.y = -pos.y; break; + case SYM_MIRROR_Y: pos.x = -pos.x; break; + } + + switch( orientation ) + { + default: + case SYM_ORIENT_0: break; + case SYM_ORIENT_90: + std::swap( pos.x, pos.y ); + pos.x = - pos.x; + break; + case SYM_ORIENT_270: + std::swap( pos.x, pos.y ); + pos.y = - pos.y; + break; + case SYM_ORIENT_180: + pos.x = - pos.x; + pos.y = - pos.y; + break; + } + libField.SetPosition( VECTOR2I( pos.x, -pos.y ) ); fullSetOfFields.emplace_back( std::move( libField ) );