void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAliasOfPart( wxCommandEvent& event ) { wxString aliasname = m_PartAliasListCtrl->GetStringSelection(); if( aliasname.IsEmpty() ) return; if( aliasname.CmpNoCase( m_Parent->GetAliasName() ) == 0 ) { wxString msg; msg.Printf( _( "Alias <%s> cannot be removed while it is being edited!" ), GetChars( aliasname ) ); DisplayError( this, msg ); return; } m_PartAliasListCtrl->Delete( m_PartAliasListCtrl->GetSelection() ); LIB_COMPONENT* component = m_Parent->GetComponent(); if( component ) component->RemoveAlias( aliasname ); if( m_PartAliasListCtrl->IsEmpty() ) { m_ButtonDeleteAllAlias->Enable( false ); m_ButtonDeleteOneAlias->Enable( false ); } }
CMP_LIBRARY::~CMP_LIBRARY() { for( LIB_ALIAS_MAP::iterator it=aliases.begin(); it!=aliases.end(); it++ ) { LIB_ALIAS* alias = (*it).second; LIB_COMPONENT* component = alias->GetComponent(); alias = component->RemoveAlias( alias ); if( alias == NULL ) delete component; } }
LIB_ALIAS* CMP_LIBRARY::RemoveEntry( LIB_ALIAS* aEntry ) { wxCHECK_MSG( aEntry != NULL, NULL, wxT( "NULL pointer cannot be removed from library." ) ); LIB_ALIAS_MAP::iterator it = aliases.find( aEntry->GetName() ); if( it == aliases.end() ) return NULL; // If the entry pointer doesn't match the name it is mapped to in the library, we // have done something terribly wrong. wxCHECK_MSG( (*it).second == aEntry, NULL, wxT( "Pointer mismatch while attempting to remove entry <" ) + aEntry->GetName() + wxT( "> from library <" ) + GetName() + wxT( ">." ) ); LIB_ALIAS* alias = (LIB_ALIAS*) aEntry; LIB_COMPONENT* component = alias->GetComponent(); alias = component->RemoveAlias( alias ); if( alias == NULL ) { delete component; if( aliases.size() > 1 ) { LIB_ALIAS_MAP::iterator next = it; next++; if( next == aliases.end() ) next = aliases.begin(); alias = (*next).second; } } aliases.erase( it ); isModified = true; return alias; }