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,49 +234,42 @@ 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(); wxString msg;
LIB_PART* part = GetLibPart( id );
if( part ) if( !aComponent->GetPartRef()->HasConversion() )
{ {
wxString msg; LIB_ID id = aComponent->GetPartRef()->GetLibId();
if( !part->HasConversion() ) msg.Printf( _( "No alternate body style found for symbol \"%s\" in library \"%s\"." ),
{ id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
msg.Printf( _( "No alternate body style found for symbol \"%s\" in library \"%s\"." ), DisplayError( this, msg );
id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() ); return;
DisplayError( this, msg );
return;
}
STATUS_FLAGS savedFlags = aComponent->GetFlags();
aComponent->SetConvert( aComponent->GetConvert() + 1 );
// ensure m_Convert = 1 or 2
// 1 = shape 1 = not converted
// 2 = shape 2 = first converted shape
// > 2 is not used but could be used for more shapes
// like multiple shapes for a programmable component
// When m_Convert = val max, return to the first shape
if( aComponent->GetConvert() > LIB_ITEM::LIB_CONVERT::DEMORGAN )
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();
aComponent->ClearFlags();
aComponent->SetFlags( savedFlags ); // Restore m_Flags (modified by SetConvert())
// If selected make sure all the now-included pins are selected
if( aComponent->IsSelected() )
m_toolManager->RunAction( EE_ACTIONS::addItemToSel, true, aComponent );
RefreshItem( aComponent );
OnModify();
} }
STATUS_FLAGS savedFlags = aComponent->GetFlags();
aComponent->SetConvert( aComponent->GetConvert() + 1 );
// ensure m_Convert = 1 or 2
// 1 = shape 1 = not converted
// 2 = shape 2 = first converted shape
// > 2 is not used but could be used for more shapes
// like multiple shapes for a programmable component
// When m_Convert = val max, return to the first shape
if( aComponent->GetConvert() > LIB_ITEM::LIB_CONVERT::DEMORGAN )
aComponent->SetConvert( LIB_ITEM::LIB_CONVERT::BASE );
TestDanglingEnds();
aComponent->ClearFlags();
aComponent->SetFlags( savedFlags ); // Restore m_Flags (modified by SetConvert())
// If selected make sure all the now-included pins are selected
if( aComponent->IsSelected() )
m_toolManager->RunAction( EE_ACTIONS::addItemToSel, true, aComponent );
RefreshItem( aComponent );
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();
} }
} }