Symbol editor: inheritance symbol editing bug fixes.

There is no need to create a new root symbol and re-parent all derived
symbols when renaming a root symbol.  Just rename the buffered root
symbol.

Test for duplicate symbol names when validating the properties dialog
information to prevent broken symbol pointers.

Fix a field drawing bug when editing derived symbols.

Fix bug to insure duplicate symbol names cannot exist in a library.

Fixes kicad/code/kicad#3654

Fixes kicad/code/kicad#3672
This commit is contained in:
Wayne Stambaugh 2019-12-16 10:11:06 -05:00
parent 6bc8005d60
commit 2b920ffa04
5 changed files with 37 additions and 42 deletions

View File

@ -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! // We need to keep the name and the value the same at the moment!
wxString newName = m_fields->at( VALUE ).GetText(); 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 ); m_Parent->SaveCopyInUndoList( m_libEntry, UR_LIB_RENAME );
}
else else
{
m_Parent->SaveCopyInUndoList( m_libEntry ); m_Parent->SaveCopyInUndoList( m_libEntry );
}
// The Y axis for components in lib is from bottom to top while the screen axis is top // 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 // 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() ); m_libEntry->SetFootprintFilters( m_FootprintFilterListBox->GetStrings() );
if( oldName != newName )
m_Parent->UpdateAfterSymbolProperties( &oldName );
else
m_Parent->RebuildView();
return true; return true;
} }

View File

@ -236,7 +236,7 @@ public:
void OnUpdatePartNumber( wxUpdateUIEvent& event ); void OnUpdatePartNumber( wxUpdateUIEvent& event );
void UpdateAfterSymbolProperties( wxString* aOldName, wxArrayString* aOldAliases ); void UpdateAfterSymbolProperties( wxString* aOldName = nullptr );
void RebuildSymbolUnitsList(); void RebuildSymbolUnitsList();
void OnCloseWindow( wxCloseEvent& Event ); void OnCloseWindow( wxCloseEvent& Event );

View File

@ -426,49 +426,16 @@ bool LIB_MANAGER::UpdatePart( LIB_PART* aPart, const wxString& aLibrary )
bool LIB_MANAGER::UpdatePartAfterRename( LIB_PART* aPart, const wxString& aOldName, bool LIB_MANAGER::UpdatePartAfterRename( LIB_PART* aPart, const wxString& aOldName,
const wxString& aLibrary ) const wxString& aLibrary )
{ {
// This is essentially a delete/update.
LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary ); LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
auto partBuf = libBuf.GetBuffer( aOldName ); auto partBuf = libBuf.GetBuffer( aOldName );
wxCHECK( partBuf, false ); wxCHECK( partBuf, false );
// Save the original record so it is transferred to the new buffer LIB_PART* bufferedPart = const_cast< LIB_PART* >( partBuf->GetPart() );
std::unique_ptr<LIB_PART> original( new LIB_PART( *partBuf->GetOriginal() ) );
// Save the screen object, so it is transferred to the new buffer wxCHECK( bufferedPart, false );
std::unique_ptr<SCH_SCREEN> 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
bufferedPart->SetName( aPart->GetName() );
SetCurrentPart( aPart->GetName() ); SetCurrentPart( aPart->GetName() );
m_frame.SyncLibraries( false ); m_frame.SyncLibraries( false );

View File

@ -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 */ ); wxCHECK( m_my_part, /* void */ );
@ -680,9 +680,15 @@ void LIB_EDIT_FRAME::fixDuplicateAliases( LIB_PART* aPart, const wxString& aLibr
{ {
wxCHECK( aPart, /* void */ ); wxCHECK( aPart, /* void */ );
int i;
wxString newName; 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 ); aPart->SetName( newName );
} }

View File

@ -504,7 +504,7 @@ void LIB_EDIT_TOOL::editFieldProperties( LIB_FIELD* aField )
if( renamed ) if( renamed )
{ {
parent->SetName( newFieldValue ); parent->SetName( newFieldValue );
m_frame->UpdateAfterSymbolProperties( &oldFieldValue, nullptr ); m_frame->UpdateAfterSymbolProperties( &oldFieldValue );
} }
else else
{ {