Eeschema: simplify updating symbol alternate body style.

Move updating the pin maps from external code to the SCH_COMPONENT object
when changing the symbol body style (DeMorgan).  This is a vein attempt
to make the SCH_COMPONENT object self contained so we don't have to depend
on the caller needing to figure out how to keep internal objects synced.
This commit is contained in:
Wayne Stambaugh 2020-05-05 16:42:38 -04:00
parent 9c99286385
commit 00716e362a
2 changed files with 37 additions and 40 deletions

View File

@ -234,18 +234,15 @@ void SCH_EDIT_FRAME::SelectUnit( SCH_COMPONENT* aComponent, int aUnit )
void SCH_EDIT_FRAME::ConvertPart( SCH_COMPONENT* aComponent ) void SCH_EDIT_FRAME::ConvertPart( SCH_COMPONENT* aComponent )
{ {
if( !aComponent ) if( !aComponent || !aComponent->GetPartRef() )
return; return;
LIB_ID id = aComponent->GetLibId();
LIB_PART* part = GetLibPart( id );
if( part )
{
wxString msg; wxString msg;
if( !part->HasConversion() ) if( !aComponent->GetPartRef()->HasConversion() )
{ {
LIB_ID id = aComponent->GetPartRef()->GetLibId();
msg.Printf( _( "No alternate body style found for symbol \"%s\" in library \"%s\"." ), msg.Printf( _( "No alternate body style found for symbol \"%s\" in library \"%s\"." ),
id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() ); id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
DisplayError( this, msg ); DisplayError( this, msg );
@ -265,9 +262,6 @@ void SCH_EDIT_FRAME::ConvertPart( SCH_COMPONENT* aComponent )
if( aComponent->GetConvert() > LIB_ITEM::LIB_CONVERT::DEMORGAN ) if( aComponent->GetConvert() > LIB_ITEM::LIB_CONVERT::DEMORGAN )
aComponent->SetConvert( LIB_ITEM::LIB_CONVERT::BASE ); aComponent->SetConvert( LIB_ITEM::LIB_CONVERT::BASE );
// The alternate symbol may cause a change in the connection status so test the
// connections so the connection indicators are drawn correctly.
aComponent->UpdatePins();
TestDanglingEnds(); TestDanglingEnds();
aComponent->ClearFlags(); aComponent->ClearFlags();
aComponent->SetFlags( savedFlags ); // Restore m_Flags (modified by SetConvert()) aComponent->SetFlags( savedFlags ); // Restore m_Flags (modified by SetConvert())
@ -279,4 +273,3 @@ void SCH_EDIT_FRAME::ConvertPart( SCH_COMPONENT* aComponent )
RefreshItem( aComponent ); RefreshItem( aComponent );
OnModify(); OnModify();
} }
}

View File

@ -283,7 +283,6 @@ void SCH_COMPONENT::UpdatePins()
if( m_part ) if( m_part )
{ {
SCH_PIN_MAP map;
unsigned i = 0; unsigned i = 0;
for( LIB_PIN* libPin = m_part->GetNextPin(); libPin; libPin = m_part->GetNextPin( libPin ) ) for( LIB_PIN* libPin = m_part->GetNextPin(); libPin; libPin = m_part->GetNextPin( libPin ) )
@ -329,9 +328,14 @@ void SCH_COMPONENT::UpdateUnit( int aUnit )
void SCH_COMPONENT::SetConvert( int aConvert ) void SCH_COMPONENT::SetConvert( int aConvert )
{ {
wxCHECK( m_part && m_part->HasConversion(), /* void */ );
if( m_convert != aConvert ) if( m_convert != aConvert )
{ {
m_convert = aConvert; m_convert = aConvert;
// The convert may have a different pin layout so the update the pin map.
UpdatePins();
SetModified(); SetModified();
} }
} }