From d470ac9c2417778ec1225392e0c96ebc6e40b70c Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Tue, 25 Oct 2016 18:43:54 -0400 Subject: [PATCH] Eeschema: minor LIB_PART object changes. Replace LIB_PART::Conflicts() with an external test to for alias name conflicts. This was only use in one place so don't clutter the library API. Change LIB_PART::AddPart() return type from bool to void since it's not checked by any callers and differs from the equivalent schematic I/O plugin function. --- eeschema/class_library.cpp | 33 +------------------------ eeschema/class_library.h | 18 +++----------- eeschema/libfield.cpp | 50 ++++++++++++++++++++++++++------------ 3 files changed, 39 insertions(+), 62 deletions(-) diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp index c58aff1204..d86437288c 100644 --- a/eeschema/class_library.cpp +++ b/eeschema/class_library.cpp @@ -121,23 +121,6 @@ void PART_LIB::GetEntryTypePowerNames( wxArrayString& aNames ) } -bool PART_LIB::Conflicts( LIB_PART* aPart ) -{ - wxCHECK_MSG( aPart != NULL, false, - "Cannot test NULL component for conflicts in library " + GetName() ); - - for( size_t i=0; im_aliases.size(); i++ ) - { - LIB_ALIAS_MAP::iterator it = m_amap.find( aPart->m_aliases[i]->GetName() ); - - if( it != m_amap.end() ) - return true; - } - - return false; -} - - LIB_ALIAS* PART_LIB::FindAlias( const wxString& aName ) { LIB_ALIAS_MAP::iterator it = m_amap.find( aName ); @@ -218,20 +201,8 @@ bool PART_LIB::AddAlias( LIB_ALIAS* aAlias ) } -bool PART_LIB::AddPart( LIB_PART* aPart ) +void PART_LIB::AddPart( LIB_PART* aPart ) { - // Conflict detection: See if already existing aliases exist, - // and if yes, ask user for continue or abort - // Special case: if the library is the library cache of the project, - // old aliases are always removed to avoid conflict, - // and user is not prompted ) - if( Conflicts( aPart ) && !IsCache() ) - { - wxFAIL_MSG( "Cannot add component <" + aPart->GetName() + - "> to library <" + GetName() + "> due to name conflict." ); - return false; - } - // add a clone, not the caller's copy LIB_PART* my_part = new LIB_PART( *aPart ); @@ -247,8 +218,6 @@ bool PART_LIB::AddPart( LIB_PART* aPart ) isModified = true; ++m_mod_hash; - - return true; } diff --git a/eeschema/class_library.h b/eeschema/class_library.h index 959110130f..31db70da9c 100644 --- a/eeschema/class_library.h +++ b/eeschema/class_library.h @@ -427,14 +427,6 @@ public: */ void GetEntryTypePowerNames( wxArrayString& aNames ); - /** - * Checks \a aPart for name conflict in the library. - * - * @param aPart - The part to check. - * @return True if a conflict exists. Otherwise false. - */ - bool Conflicts( LIB_PART* aPart ); - /** * Find #LIB_ALIAS by \a aName. * @@ -470,15 +462,13 @@ public: /** * Add \a aPart entry to library. - * Note a part can have an alias list, - * so these alias will be added in library. - * Conflicts can happen if aliases are already existing. - * User is asked to choose what alias is removed (existing, or new) + * + * @note A #LIB_PART can have an alias list so these alias will be added in library. + * and the any existing duplicate aliases will be removed from the library. * * @param aPart - Part to add, caller retains ownership, a clone is added. - * @return bool - true iff successful. */ - bool AddPart( LIB_PART* aPart ); + void AddPart( LIB_PART* aPart ); /** * Safely remove \a aEntry from the library and return the next entry. diff --git a/eeschema/libfield.cpp b/eeschema/libfield.cpp index 33cd1b9556..d3d4eef42f 100644 --- a/eeschema/libfield.cpp +++ b/eeschema/libfield.cpp @@ -119,29 +119,47 @@ void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField ) parent->SetName( newFieldValue ); // Test the library for any conflicts with the any aliases in the current component. - if( parent->GetAliasCount() > 1 && lib && lib->Conflicts( parent ) ) + if( parent->GetAliasCount() > 1 && lib ) { - msg.Printf( _( - "The new component contains alias names that conflict with entries in the " - "component library '%s'.\n\n" - "Do you wish to remove all of the conflicting aliases from this component?" ), - GetChars( lib->GetName() ) - ); + bool conflicts = false; + wxArrayString libAliasNames, symbolAliasNames; - int rsp = wxMessageBox( msg, _( "Confirm" ), wxYES_NO | wxICON_QUESTION, this ); + lib->GetAliasNames( libAliasNames ); + symbolAliasNames = parent->GetAliasNames(); - if( rsp == wxNO ) + for( size_t i = 0; i < symbolAliasNames.GetCount(); i++ ) { - parent->SetName( fieldText ); - return; + if( libAliasNames.Index( symbolAliasNames[i] ) != wxNOT_FOUND ) + { + conflicts = true; + break; + } } - wxArrayString aliases = parent->GetAliasNames( false ); - - for( size_t i = 0; i < aliases.GetCount(); i++ ) + if( conflicts ) { - if( lib->FindAlias( aliases[ i ] ) != NULL ) - parent->RemoveAlias( aliases[ i ] ); + msg.Printf( _( "The new component contains alias names that conflict with " + "entries in the component library '%s'.\n\n" + "Do you wish to remove all of the conflicting aliases from " + "this component?" ), + GetChars( lib->GetName() ) + ); + + int rsp = wxMessageBox( msg, _( "Confirm" ), wxYES_NO | wxICON_QUESTION, this ); + + if( rsp == wxNO ) + { + parent->SetName( fieldText ); + return; + } + + wxArrayString aliases = parent->GetAliasNames( false ); + + for( size_t i = 0; i < aliases.GetCount(); i++ ) + { + if( lib->FindAlias( aliases[ i ] ) != NULL ) + parent->RemoveAlias( aliases[ i ] ); + } } }