From 330c0f86debff101fe24e8d1aaa918b4763e989f Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 26 Sep 2023 11:30:02 -0700 Subject: [PATCH] Set pinmap after updating pins When duplicating and existing symbol, we must set the pins before setting the lib symbol as the lib symbol will generate a pin map that will be broken by the shift to new pins Fixes https://gitlab.com/kicad/code/kicad/-/issues/15728 (cherry picked from commit 12ebb2bbfac81305fc7533fed073b0a7667eb1aa) --- eeschema/sch_symbol.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 2cbeee0e6b..192d54eb00 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -177,9 +177,6 @@ SCH_SYMBOL::SCH_SYMBOL( const SCH_SYMBOL& aSymbol ) : m_onBoard = aSymbol.m_onBoard; m_DNP = aSymbol.m_DNP; - if( aSymbol.m_part ) - SetLibSymbol( new LIB_SYMBOL( *aSymbol.m_part.get() ) ); - const_cast( m_Uuid ) = aSymbol.m_Uuid; m_transform = aSymbol.m_transform; @@ -191,6 +188,18 @@ SCH_SYMBOL::SCH_SYMBOL( const SCH_SYMBOL& aSymbol ) : for( SCH_FIELD& field : m_fields ) field.SetParent( this ); + m_pins.clear(); + + // Copy (and re-parent) the pins + for( const std::unique_ptr& pin : aSymbol.m_pins ) + { + m_pins.emplace_back( std::make_unique( *pin ) ); + m_pins.back()->SetParent( this ); + } + + if( aSymbol.m_part ) + SetLibSymbol( new LIB_SYMBOL( *aSymbol.m_part ) ); + m_fieldsAutoplaced = aSymbol.m_fieldsAutoplaced; m_schLibSymbolName = aSymbol.m_schLibSymbolName; } @@ -403,8 +412,7 @@ void SCH_SYMBOL::UpdatePins() else { // This is a pin that was not found in the symbol, so create a new one. - pin = new SCH_PIN( libPin, this ); - m_pins.emplace_back( pin ); + pin = m_pins.emplace_back( std::make_unique( SCH_PIN( libPin, this ) ) ).get(); } m_pinMap[ libPin ] = pin;