Make sure original part record always has the write library nickname.

Fixes: lp:1804293
* https://bugs.launchpad.net/kicad/+bug/1804293

(cherry picked from commit 023a445e9f)
This commit is contained in:
Jeff Young 2018-11-21 19:50:26 +00:00
parent 82c9e54735
commit 03132cabee
1 changed files with 30 additions and 7 deletions

View File

@ -359,14 +359,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;
}
}
@ -396,6 +402,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 );
@ -416,14 +424,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 );
LIB_PART* original = new LIB_PART( *partBuf->GetOriginal() );
// Save the original record so it is transferred to the new buffer
std::unique_ptr<LIB_PART> original( new LIB_PART( *partBuf->GetOriginal() ) );
// Save the screen object, so it is transferred to the new buffer
std::unique_ptr<SCH_SCREEN> screen = partBuf->RemoveScreen();
@ -436,7 +445,7 @@ bool LIB_MANAGER::UpdatePartAfterRename( LIB_PART* aPart, const wxString& oldAli
partBuf = libBuf.GetBuffer( aPart->GetName() );
partBuf->SetScreen( std::move( screen ) );
wxCHECK( partBuf, false );
partBuf->SetOriginal( original ); // part buffer takes ownership of pointer
partBuf->SetOriginal( original.release() ); // part buffer takes ownership of pointer
return true;
}
@ -713,6 +722,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() ) );
}
}
@ -722,6 +738,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() ) );
}
}