diff --git a/eeschema/dialogs/dialog_edit_component_in_lib.cpp b/eeschema/dialogs/dialog_edit_component_in_lib.cpp index 24eec9ae2c..c84b0f08b0 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_lib.cpp @@ -289,11 +289,28 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataFromWindow() // We need to keep the name and the value the same at the moment! wxString newName = m_fields->at( VALUE ).GetText(); + wxString oldName = m_libEntry->GetName(); + + if( oldName != newName ) + { + wxString libName = m_Parent->GetCurLib(); + + if( m_Parent->GetLibManager().PartExists( newName, libName ) ) + { + wxString msg; + + msg.Printf( _( "The name '%s' conflicts with an existing entry in the library '%s'." ), + newName, libName ); + DisplayErrorMessage( this, msg ); + return false; + } - if( m_libEntry->GetName() != newName ) m_Parent->SaveCopyInUndoList( m_libEntry, UR_LIB_RENAME ); + } else + { m_Parent->SaveCopyInUndoList( m_libEntry ); + } // The Y axis for components in lib is from bottom to top while the screen axis is top // to bottom: we must change the y coord sign when writing back to the library @@ -338,6 +355,11 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataFromWindow() m_libEntry->SetFootprintFilters( m_FootprintFilterListBox->GetStrings() ); + if( oldName != newName ) + m_Parent->UpdateAfterSymbolProperties( &oldName ); + else + m_Parent->RebuildView(); + return true; } diff --git a/eeschema/libedit/lib_edit_frame.h b/eeschema/libedit/lib_edit_frame.h index b17ae2dafe..a273764412 100644 --- a/eeschema/libedit/lib_edit_frame.h +++ b/eeschema/libedit/lib_edit_frame.h @@ -236,7 +236,7 @@ public: void OnUpdatePartNumber( wxUpdateUIEvent& event ); - void UpdateAfterSymbolProperties( wxString* aOldName, wxArrayString* aOldAliases ); + void UpdateAfterSymbolProperties( wxString* aOldName = nullptr ); void RebuildSymbolUnitsList(); void OnCloseWindow( wxCloseEvent& Event ); diff --git a/eeschema/libedit/lib_manager.cpp b/eeschema/libedit/lib_manager.cpp index d3c99b0ca4..5f33df371b 100644 --- a/eeschema/libedit/lib_manager.cpp +++ b/eeschema/libedit/lib_manager.cpp @@ -426,49 +426,16 @@ bool LIB_MANAGER::UpdatePart( LIB_PART* aPart, const wxString& aLibrary ) bool LIB_MANAGER::UpdatePartAfterRename( LIB_PART* aPart, const wxString& aOldName, const wxString& aLibrary ) { - // This is essentially a delete/update. - LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary ); auto partBuf = libBuf.GetBuffer( aOldName ); + wxCHECK( partBuf, false ); - // Save the original record so it is transferred to the new buffer - std::unique_ptr original( new LIB_PART( *partBuf->GetOriginal() ) ); + LIB_PART* bufferedPart = const_cast< LIB_PART* >( partBuf->GetPart() ); - // Save the screen object, so it is transferred to the new buffer - std::unique_ptr screen = partBuf->RemoveScreen(); - - if( partBuf->GetPart()->IsRoot() && libBuf.HasDerivedSymbols( aOldName ) ) - { - // Reparent derived symbols. - for( auto entry : libBuf.GetBuffers() ) - { - if( entry->GetPart()->IsRoot() ) - continue; - - if( entry->GetPart()->GetParent().lock() == original->SharedPtr() ) - { - if( !libBuf.DeleteBuffer( entry ) ) - return false; - - LIB_PART* reparentedPart = new LIB_PART( *entry->GetPart() ); - reparentedPart->SetParent( original.get() ); - libBuf.CreateBuffer( reparentedPart, new SCH_SCREEN( &m_frame.Kiway() ) ); - } - } - } - - if( !libBuf.DeleteBuffer( partBuf ) ) - return false; - - if( !UpdatePart( aPart, aLibrary ) ) - return false; - - partBuf = libBuf.GetBuffer( aPart->GetName() ); - partBuf->SetScreen( std::move( screen ) ); - wxCHECK( partBuf, false ); - partBuf->SetOriginal( original.release() ); // part buffer takes ownership of pointer + wxCHECK( bufferedPart, false ); + bufferedPart->SetName( aPart->GetName() ); SetCurrentPart( aPart->GetName() ); m_frame.SyncLibraries( false ); diff --git a/eeschema/libedit/libedit.cpp b/eeschema/libedit/libedit.cpp index 47f5059683..684f779597 100644 --- a/eeschema/libedit/libedit.cpp +++ b/eeschema/libedit/libedit.cpp @@ -505,7 +505,7 @@ void LIB_EDIT_FRAME::savePartAs() } -void LIB_EDIT_FRAME::UpdateAfterSymbolProperties( wxString* aOldName, wxArrayString* aOldAliases ) +void LIB_EDIT_FRAME::UpdateAfterSymbolProperties( wxString* aOldName ) { wxCHECK( m_my_part, /* void */ ); @@ -680,9 +680,15 @@ void LIB_EDIT_FRAME::fixDuplicateAliases( LIB_PART* aPart, const wxString& aLibr { wxCHECK( aPart, /* void */ ); + int i; wxString newName; - newName.Printf( "%s_copy", aPart->GetName() ); + // Append a number to the name until the name is unique in the library. + do + { + newName.Printf( "%s_%d", aPart->GetName(), i ); + i++; + } while( m_libMgr->PartExists( newName, aLibrary ) ); aPart->SetName( newName ); } diff --git a/eeschema/tools/lib_edit_tool.cpp b/eeschema/tools/lib_edit_tool.cpp index 678362bf82..2b115ee986 100644 --- a/eeschema/tools/lib_edit_tool.cpp +++ b/eeschema/tools/lib_edit_tool.cpp @@ -504,7 +504,7 @@ void LIB_EDIT_TOOL::editFieldProperties( LIB_FIELD* aField ) if( renamed ) { parent->SetName( newFieldValue ); - m_frame->UpdateAfterSymbolProperties( &oldFieldValue, nullptr ); + m_frame->UpdateAfterSymbolProperties( &oldFieldValue ); } else {