Pick better auto-generated netnames.

Fixes https://gitlab.com/kicad/code/kicad/issues/4312
This commit is contained in:
Jeff Young 2021-11-20 00:03:53 +00:00
parent c3552a940a
commit e48d4a653a
2 changed files with 31 additions and 9 deletions

View File

@ -143,7 +143,7 @@ bool CONNECTION_SUBGRAPH::ResolveDrivers( bool aCheckMultipleDrivers )
}
}
// For all other driver types, sort by name
// For all other driver types, sort by quality of name
std::sort( candidates.begin(), candidates.end(),
[&]( SCH_ITEM* a, SCH_ITEM* b ) -> bool
{
@ -160,10 +160,21 @@ bool CONNECTION_SUBGRAPH::ResolveDrivers( bool aCheckMultipleDrivers )
if( a == previousDriver )
return true;
else if( b == previousDriver )
if( b == previousDriver )
return false;
wxString a_name = GetNameForDriver( a );
wxString b_name = GetNameForDriver( b );
bool a_lowQualityName = a_name.Contains( "-Pad" );
bool b_lowQualityName = b_name.Contains( "-Pad" );
if( a_lowQualityName && !b_lowQualityName )
return false;
else if( b_lowQualityName && !a_lowQualityName )
return true;
else
return GetNameForDriver( a ) < GetNameForDriver( b );
return a_name < b_name;
} );
}
}

View File

@ -271,18 +271,29 @@ wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoC
if( aForceNoConnect || GetType() == ELECTRICAL_PINTYPE::PT_NC )
name = ( "unconnected-(" );
name << GetParentSymbol()->GetRef( &aPath );
bool annotated = true;
// Add timestamp for uninitialized symbols
if( name.Last() == '?' )
// Use timestamp for unannotated symbols
if( GetParentSymbol()->GetRef( &aPath, false ).Last() == '?' )
{
name << GetParentSymbol()->m_Uuid.AsString();
name << "-Pad" << m_libPin->GetNumber() << ")";
annotated = false;
}
name << "-Pad" << m_libPin->GetNumber() << ")";
else if( !m_libPin->GetShownName().IsEmpty()
&& m_libPin->GetShownName() != m_libPin->GetShownNumber() )
{
// Pin names might not be unique between different units so we must have the
// unit token in the reference designator
name << GetParentSymbol()->GetRef( &aPath, true );
name << "-" << m_libPin->GetShownName() << ")";
}
else
{
// Pin number are unique, so we skip the unit token
name << GetParentSymbol()->GetRef( &aPath, false );
name << "-Pad" << m_libPin->GetShownNumber() << ")";
}
if( annotated )
m_net_name_map[ aPath ] = std::make_pair( name, aForceNoConnect );