Separate LIB_PIN and SCH_PIN GetShownName/Number processing.

SCH_PIN wasn't handling the legacy empty string token (~), but
more importantly this will allow text variable resolution specific
to the schematic.

Fixes https://gitlab.com/kicad/code/kicad/issues/8625
This commit is contained in:
Jeff Young 2021-06-17 10:37:13 +01:00
parent b10f156dd0
commit 0484ca5564
8 changed files with 44 additions and 25 deletions

View File

@ -431,10 +431,10 @@ std::string FormatProbeItem( EDA_ITEM* aItem, SCH_SYMBOL* aSymbol )
SCH_PIN* pin = (SCH_PIN*) aItem; SCH_PIN* pin = (SCH_PIN*) aItem;
aSymbol = pin->GetParentSymbol(); aSymbol = pin->GetParentSymbol();
if( !pin->GetNumber().IsEmpty() ) if( !pin->GetShownNumber().IsEmpty() )
{ {
return StrPrintf( "$PIN: \"%s\" $PART: \"%s\"", return StrPrintf( "$PIN: \"%s\" $PART: \"%s\"",
TO_UTF8( pin->GetNumber() ), TO_UTF8( pin->GetShownNumber() ),
TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) ); TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
} }
else else

View File

@ -584,7 +584,7 @@ int ERC_TESTER::TestMultUnitPinConflicts()
continue; continue;
wxString name = pin->GetParentSymbol()->GetRef( &subgraph->m_sheet ) + wxString name = pin->GetParentSymbol()->GetRef( &subgraph->m_sheet ) +
+ ":" + pin->GetNumber(); + ":" + pin->GetShownNumber();
if( !pinToNetMap.count( name ) ) if( !pinToNetMap.count( name ) )
{ {
@ -597,7 +597,9 @@ int ERC_TESTER::TestMultUnitPinConflicts()
ercItem->SetErrorMessage( wxString::Format( ercItem->SetErrorMessage( wxString::Format(
_( "Pin %s is connected to both %s and %s" ), _( "Pin %s is connected to both %s and %s" ),
pin->GetNumber(), netName, pinToNetMap[name].first ) ); pin->GetShownNumber(),
netName,
pinToNetMap[name].first ) );
ercItem->SetItems( pin, pinToNetMap[name].second ); ercItem->SetItems( pin, pinToNetMap[name].second );
ercItem->SetIsSheetSpecific(); ercItem->SetIsSheetSpecific();

View File

@ -168,7 +168,7 @@ void NETLIST_EXPORTER_BASE::CreatePinList( SCH_SYMBOL* aSymbol,
continue; continue;
} }
m_sortedSymbolPinList.emplace_back( pin->GetNumber(), netName ); m_sortedSymbolPinList.emplace_back( pin->GetShownNumber(), netName );
} }
} }
} }
@ -254,7 +254,7 @@ void NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol, LIB_SY
continue; continue;
} }
m_sortedSymbolPinList.emplace_back( pin->GetNumber(), netName ); m_sortedSymbolPinList.emplace_back( pin->GetShownNumber(), netName );
} }
} }
} }

View File

@ -144,7 +144,7 @@ bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f )
wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second ); wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
if( ref_a == ref_b ) if( ref_a == ref_b )
return a.first->GetNumber() < b.first->GetNumber(); return a.first->GetShownNumber() < b.first->GetShownNumber();
return ref_a < ref_b; return ref_a < ref_b;
} ); } );
@ -158,7 +158,7 @@ bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f )
wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second ); wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second ); wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
return ref_a == ref_b && a.first->GetNumber() == b.first->GetNumber(); return ref_a == ref_b && a.first->GetShownNumber() == b.first->GetShownNumber();
} ), } ),
sorted_items.end() ); sorted_items.end() );
@ -170,7 +170,7 @@ bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f )
SCH_SHEET_PATH sheet = pair.second; SCH_SHEET_PATH sheet = pair.second;
wxString refText = pin->GetParentSymbol()->GetRef( &sheet ); wxString refText = pin->GetParentSymbol()->GetRef( &sheet );
wxString pinText = pin->GetNumber(); wxString pinText = pin->GetShownNumber();
// Skip power symbols and virtual symbols // Skip power symbols and virtual symbols
if( refText[0] == wxChar( '#' ) ) if( refText[0] == wxChar( '#' ) )

View File

@ -695,7 +695,7 @@ XNODE* NETLIST_EXPORTER_XML::makeListOfNets( unsigned aCtl )
wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet ); wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet );
if( refA == refB ) if( refA == refB )
return a.m_Pin->GetNumber() < b.m_Pin->GetNumber(); return a.m_Pin->GetShownNumber() < b.m_Pin->GetShownNumber();
return refA < refB; return refA < refB;
} ); } );
@ -710,14 +710,15 @@ XNODE* NETLIST_EXPORTER_XML::makeListOfNets( unsigned aCtl )
wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet ); wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet );
wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet ); wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet );
return refA == refB && a.m_Pin->GetNumber() == b.m_Pin->GetNumber(); return refA == refB
&& a.m_Pin->GetShownNumber() == b.m_Pin->GetShownNumber();
} ), } ),
net_record->m_Nodes.end() ); net_record->m_Nodes.end() );
for( const NET_NODE& netNode : net_record->m_Nodes ) for( const NET_NODE& netNode : net_record->m_Nodes )
{ {
wxString refText = netNode.m_Pin->GetParentSymbol()->GetRef( &netNode.m_Sheet ); wxString refText = netNode.m_Pin->GetParentSymbol()->GetRef( &netNode.m_Sheet );
wxString pinText = netNode.m_Pin->GetNumber(); wxString pinText = netNode.m_Pin->GetShownNumber();
// Skip power symbols and virtual symbols // Skip power symbols and virtual symbols
if( refText[0] == wxChar( '#' ) ) if( refText[0] == wxChar( '#' ) )
@ -741,8 +742,7 @@ XNODE* NETLIST_EXPORTER_XML::makeListOfNets( unsigned aCtl )
wxString pinName = netNode.m_Pin->GetShownName(); wxString pinName = netNode.m_Pin->GetShownName();
wxString pinType = netNode.m_Pin->GetCanonicalElectricalTypeName(); wxString pinType = netNode.m_Pin->GetCanonicalElectricalTypeName();
// ~ is a char used to code empty strings in libs. if( !pinName.IsEmpty() )
if( pinName != "~" && !pinName.IsEmpty() )
xnode->AddAttribute( "pinfunction", pinName ); xnode->AddAttribute( "pinfunction", pinName );
if( netNode.m_NoConnect ) if( netNode.m_NoConnect )
@ -774,5 +774,5 @@ XNODE* NETLIST_EXPORTER_XML::node( const wxString& aName,
static bool sortPinsByNumber( LIB_PIN* aPin1, LIB_PIN* aPin2 ) static bool sortPinsByNumber( LIB_PIN* aPin1, LIB_PIN* aPin2 )
{ {
// return "lhs < rhs" // return "lhs < rhs"
return UTIL::RefDesStringCompare( aPin1->GetNumber(), aPin2->GetNumber() ) < 0; return UTIL::RefDesStringCompare( aPin1->GetShownNumber(), aPin2->GetShownNumber() ) < 0;
} }

View File

@ -87,10 +87,24 @@ wxString SCH_PIN::GetName() const
wxString SCH_PIN::GetShownName() const wxString SCH_PIN::GetShownName() const
{ {
if( !m_alt.IsEmpty() ) wxString name = m_libPin->GetName();
return m_alt;
return m_libPin->GetShownName(); if( !m_alt.IsEmpty() )
name = m_alt;
if( name == "~" )
return wxEmptyString;
else
return name;
}
wxString SCH_PIN::GetShownNumber() const
{
if( m_number == "~" )
return wxEmptyString;
else
return m_number;
} }
@ -184,8 +198,7 @@ void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList )
aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg ) ); aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg ) );
aList.push_back( MSG_PANEL_ITEM( _( "Name" ), GetShownName() ) ); aList.push_back( MSG_PANEL_ITEM( _( "Name" ), GetShownName() ) );
msg = GetNumber().IsEmpty() ? wxT( "?" ) : GetShownNumber(); aList.push_back( MSG_PANEL_ITEM( _( "Number" ), GetShownNumber() ) );
aList.push_back( MSG_PANEL_ITEM( _( "Number" ), msg ) );
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), ElectricalPinTypeGetText( GetType() ) ) ); aList.push_back( MSG_PANEL_ITEM( _( "Type" ), ElectricalPinTypeGetText( GetType() ) ) );
msg = PinShapeGetText( GetShape() ); msg = PinShapeGetText( GetShape() );

View File

@ -106,7 +106,7 @@ public:
wxString GetShownName() const; wxString GetShownName() const;
wxString GetNumber() const { return m_number; } wxString GetNumber() const { return m_number; }
wxString GetShownNumber() const { return m_number; } wxString GetShownNumber() const;
void SetNumber( const wxString& aNumber ) { m_number = aNumber; } void SetNumber( const wxString& aNumber ) { m_number = aNumber; }

View File

@ -531,7 +531,7 @@ void BACK_ANNOTATE::processNetNameChange( const wxString& aRef, SCH_PIN* aPin,
msg.Printf( _( "Change %s pin %s net label from '%s' to '%s'." ), msg.Printf( _( "Change %s pin %s net label from '%s' to '%s'." ),
aRef, aRef,
aPin->GetNumber(), aPin->GetShownNumber(),
aOldName, aOldName,
aNewName ); aNewName );
@ -554,15 +554,19 @@ void BACK_ANNOTATE::processNetNameChange( const wxString& aRef, SCH_PIN* aPin,
if( schPin->IsPowerConnection() ) if( schPin->IsPowerConnection() )
{ {
msg.Printf( _( "Net %s cannot be changed to '%s' because it is driven by a power " msg.Printf( _( "Net %s cannot be changed to %s because it is driven by a power pin." ),
"pin." ), aOldName, aNewName ); aOldName,
aNewName );
m_reporter.ReportHead( msg, RPT_SEVERITY_ERROR ); m_reporter.ReportHead( msg, RPT_SEVERITY_ERROR );
break; break;
} }
++m_changesCount; ++m_changesCount;
msg.Printf( _( "Add label '%s' to %s pin %s net." ), aNewName, aRef, aPin->GetNumber() ); msg.Printf( _( "Add label '%s' to %s pin %s net." ),
aNewName,
aRef,
aPin->GetShownNumber() );
if( !m_dryRun ) if( !m_dryRun )
{ {