mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Track alt pin changes
Make sure that we are following the lib changes when updating Fixes https://gitlab.com/kicad/code/kicad/issues/21202
This commit is contained in:
parent
90621947bf
commit
7201918383
@ -288,6 +288,7 @@ wxString SCH_SYMBOL::GetDatasheet() const
|
||||
void SCH_SYMBOL::UpdatePins()
|
||||
{
|
||||
std::map<wxString, wxString> altPinMap;
|
||||
std::map<wxString, SCH_PIN::ALT> altPinDefs;
|
||||
std::map<wxString, std::set<SCH_PIN*>> pinUuidMap;
|
||||
std::set<SCH_PIN*> unassignedSchPins;
|
||||
std::set<SCH_PIN*> unassignedLibPins;
|
||||
@ -299,8 +300,15 @@ void SCH_SYMBOL::UpdatePins()
|
||||
unassignedSchPins.insert( pin.get() );
|
||||
|
||||
if( !pin->GetAlt().IsEmpty() )
|
||||
{
|
||||
altPinMap[ pin->GetNumber() ] = pin->GetAlt();
|
||||
|
||||
auto altDefIt = pin->GetAlternates().find( pin->GetAlt() );
|
||||
|
||||
if( altDefIt != pin->GetAlternates().end() )
|
||||
altPinDefs[ pin->GetNumber() ] = altDefIt->second;
|
||||
}
|
||||
|
||||
pin->SetLibPin( nullptr );
|
||||
}
|
||||
|
||||
@ -329,6 +337,7 @@ void SCH_SYMBOL::UpdatePins()
|
||||
auto it = ii->second.begin();
|
||||
pin = *it;
|
||||
ii->second.erase( it );
|
||||
pin->GetAlternates() = libPin->GetAlternates();
|
||||
pin->SetLibPin( libPin );
|
||||
pin->SetPosition( libPin->GetPosition() );
|
||||
|
||||
@ -337,7 +346,28 @@ void SCH_SYMBOL::UpdatePins()
|
||||
auto iii = altPinMap.find( libPin->GetNumber() );
|
||||
|
||||
if( iii != altPinMap.end() )
|
||||
pin->SetAlt( iii->second );
|
||||
{
|
||||
wxString altName = iii->second;
|
||||
|
||||
if( pin->GetAlternates().find( altName ) == pin->GetAlternates().end() )
|
||||
{
|
||||
auto defIt = altPinDefs.find( libPin->GetNumber() );
|
||||
|
||||
if( defIt != altPinDefs.end() )
|
||||
{
|
||||
for( const auto& [ name, alt ] : pin->GetAlternates() )
|
||||
{
|
||||
if( alt.m_Shape == defIt->second.m_Shape && alt.m_Type == defIt->second.m_Type )
|
||||
{
|
||||
altName = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pin->SetAlt( altName );
|
||||
}
|
||||
|
||||
m_pinMap[ libPin ] = pin;
|
||||
}
|
||||
@ -361,6 +391,7 @@ void SCH_SYMBOL::UpdatePins()
|
||||
}
|
||||
|
||||
m_pinMap[ libPin ] = pin;
|
||||
pin->GetAlternates() = libPin->GetAlternates();
|
||||
pin->SetLibPin( libPin );
|
||||
pin->SetPosition( libPin->GetPosition() );
|
||||
pin->SetNumber( libPin->GetNumber() );
|
||||
@ -368,7 +399,28 @@ void SCH_SYMBOL::UpdatePins()
|
||||
auto iii = altPinMap.find( libPin->GetNumber() );
|
||||
|
||||
if( iii != altPinMap.end() )
|
||||
pin->SetAlt( iii->second );
|
||||
{
|
||||
wxString altName = iii->second;
|
||||
|
||||
if( pin->GetAlternates().find( altName ) == pin->GetAlternates().end() )
|
||||
{
|
||||
auto defIt = altPinDefs.find( libPin->GetNumber() );
|
||||
|
||||
if( defIt != altPinDefs.end() )
|
||||
{
|
||||
for( const auto& [ name, alt ] : pin->GetAlternates() )
|
||||
{
|
||||
if( alt.m_Shape == defIt->second.m_Shape && alt.m_Type == defIt->second.m_Type )
|
||||
{
|
||||
altName = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pin->SetAlt( altName );
|
||||
}
|
||||
}
|
||||
|
||||
// If we have any pins left in the symbol that were not found in the library, remove them.
|
||||
|
@ -189,4 +189,30 @@ BOOST_AUTO_TEST_CASE( PinNumberingPower )
|
||||
BOOST_CHECK_EQUAL( pwr_name, "voltage_value" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( AlternatePinRenameUpdates )
|
||||
{
|
||||
SCH_PIN::ALT alt;
|
||||
alt.m_Name = wxS( "ALT1" );
|
||||
alt.m_Shape = GRAPHIC_PINSHAPE::INVERTED;
|
||||
alt.m_Type = ELECTRICAL_PINTYPE::PT_INPUT;
|
||||
m_lib_pin->GetAlternates()[ wxS( "ALT1" ) ] = alt;
|
||||
|
||||
m_parent_symbol->UpdatePins();
|
||||
m_sch_pin = m_parent_symbol->GetPins()[0];
|
||||
m_sch_pin->SetAlt( wxS( "ALT1" ) );
|
||||
|
||||
SCH_PIN::ALT altNew = alt;
|
||||
m_lib_pin->GetAlternates().erase( wxS( "ALT1" ) );
|
||||
altNew.m_Name = wxS( "ALT1_NEW" );
|
||||
m_lib_pin->GetAlternates()[ wxS( "ALT1_NEW" ) ] = altNew;
|
||||
|
||||
m_parent_symbol->SetLibSymbol( m_parent_part->Flatten().release() );
|
||||
m_parent_symbol->UpdatePins();
|
||||
|
||||
SCH_PIN* updatedPin = m_parent_symbol->GetPins()[0];
|
||||
|
||||
BOOST_CHECK_EQUAL( updatedPin->GetAlt(), "ALT1_NEW" );
|
||||
BOOST_CHECK( updatedPin->GetAlternates().count( wxS( "ALT1" ) ) == 0 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
x
Reference in New Issue
Block a user