From 023a445e9fcdc6f57759e9e4609502dfc69b61f3 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 21 Nov 2018 19:50:26 +0000 Subject: [PATCH] Make sure original part record always has the write library nickname. Fixes: lp:1804293 * https://bugs.launchpad.net/kicad/+bug/1804293 --- eeschema/libedit/lib_manager.cpp | 33 +++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/eeschema/libedit/lib_manager.cpp b/eeschema/libedit/lib_manager.cpp index 6d5da07cb0..1efe7a3a73 100644 --- a/eeschema/libedit/lib_manager.cpp +++ b/eeschema/libedit/lib_manager.cpp @@ -360,14 +360,20 @@ LIB_PART* LIB_MANAGER::GetBufferedPart( const wxString& aAlias, const wxString& try { LIB_ALIAS* alias = symTable()->LoadSymbol( aLibrary, aAlias ); - wxCHECK( alias, nullptr ); + + if( alias == nullptr ) + THROW_IO_ERROR( _( "Symbol not found." ) ); + bufferedPart = new LIB_PART( *alias->GetPart(), nullptr ); libBuf.CreateBuffer( bufferedPart, new SCH_SCREEN( &m_frame.Kiway() ) ); } catch( const IO_ERROR& e ) { - DisplayErrorMessage( &m_frame, wxString::Format( _( "Cannot load " - "symbol \"%s\" from library \"%s\"" ), aAlias, aLibrary ), e.What() ); + wxString msg = wxString::Format( _( "Error loading symbol \"%s\" from library \"%s\"." ), + aAlias, + aLibrary); + DisplayErrorMessage( &m_frame, msg, e.What() ); + bufferedPart = nullptr; } } @@ -397,6 +403,8 @@ bool LIB_MANAGER::UpdatePart( LIB_PART* aPart, const wxString& aLibrary ) auto partBuf = libBuf.GetBuffer( aPart->GetName() ); LIB_PART* partCopy = new LIB_PART( *aPart, nullptr ); + partCopy->SetLibId( LIB_ID( aLibrary, aPart->GetLibId().GetLibItemName() ) ); + if( partBuf ) { libBuf.UpdateBuffer( partBuf, partCopy ); @@ -415,14 +423,15 @@ bool LIB_MANAGER::UpdatePart( LIB_PART* aPart, const wxString& aLibrary ) bool LIB_MANAGER::UpdatePartAfterRename( LIB_PART* aPart, const wxString& oldAlias, const wxString& aLibrary ) { - // This is essentially a delete/update, but we have to make a copy of the "original" - // LIB_PART from the old buffer to give to the new one. + // This is essentially a delete/update. LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary ); auto partBuf = libBuf.GetBuffer( oldAlias ); wxCHECK( partBuf, false ); + // Save the original record so it is transferred to the new buffer std::unique_ptr original( new LIB_PART( *partBuf->GetOriginal() ) ); + // Save the screen object, so it is transferred to the new buffer std::unique_ptr screen = partBuf->RemoveScreen(); @@ -720,6 +729,13 @@ void LIB_MANAGER::PART_BUFFER::SetPart( LIB_PART* aPart ) wxASSERT( aPart ); delete m_part; m_part = aPart; + + // If the part moves libraries then the original moves with it + if( m_original->GetLibId().GetLibNickname() != m_part->GetLibId().GetLibNickname() ) + { + m_original->SetLibId( LIB_ID( m_part->GetLibId().GetLibNickname(), + m_original->GetLibId().GetLibItemName() ) ); + } } @@ -729,6 +745,13 @@ void LIB_MANAGER::PART_BUFFER::SetOriginal( LIB_PART* aPart ) wxASSERT( aPart ); delete m_original; m_original = aPart; + + // The original is not allowed to have a different library than its part + if( m_original->GetLibId().GetLibNickname() != m_part->GetLibId().GetLibNickname() ) + { + m_original->SetLibId( LIB_ID( m_part->GetLibId().GetLibNickname(), + m_original->GetLibId().GetLibItemName() ) ); + } }