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.
This commit is contained in:
Wayne Stambaugh 2016-10-25 18:43:54 -04:00
parent 4ee0b3827e
commit d470ac9c24
3 changed files with 39 additions and 62 deletions

View File

@ -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; i<aPart->m_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;
}

View File

@ -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.

View File

@ -119,12 +119,29 @@ 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?" ),
bool conflicts = false;
wxArrayString libAliasNames, symbolAliasNames;
lib->GetAliasNames( libAliasNames );
symbolAliasNames = parent->GetAliasNames();
for( size_t i = 0; i < symbolAliasNames.GetCount(); i++ )
{
if( libAliasNames.Index( symbolAliasNames[i] ) != wxNOT_FOUND )
{
conflicts = true;
break;
}
}
if( conflicts )
{
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() )
);
@ -144,6 +161,7 @@ void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField )
parent->RemoveAlias( aliases[ i ] );
}
}
}
if( !parent->HasAlias( m_aliasName ) )
m_aliasName = newFieldValue;