Don't confuse annotation prefix *letters* with root annotation.
Given a symbol U12A, some parts of the code were assuming the prefix was 'U' while others were assuming 'U12'. Further complication arose when there were '?' in the library version. Fixes https://gitlab.com/kicad/code/kicad/issues/8223
This commit is contained in:
parent
2ae264751f
commit
f7ae819430
|
@ -92,6 +92,29 @@ static LIB_PART* dummy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxString refDesPrefix( const wxString& aSource )
|
||||||
|
{
|
||||||
|
wxString result;
|
||||||
|
size_t sourceLen = aSource.length();
|
||||||
|
|
||||||
|
for( size_t i = 0; i < sourceLen; ++i )
|
||||||
|
{
|
||||||
|
if( aSource[i] == '?' || wxIsdigit( aSource[i] ) )
|
||||||
|
break;
|
||||||
|
|
||||||
|
result += aSource[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxString refDesUnannotated( const wxString& aSource )
|
||||||
|
{
|
||||||
|
return refDesPrefix( aSource ) + wxT( "?" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SCH_COMPONENT::SCH_COMPONENT( const wxPoint& aPos, SCH_ITEM* aParent ) :
|
SCH_COMPONENT::SCH_COMPONENT( const wxPoint& aPos, SCH_ITEM* aParent ) :
|
||||||
SCH_ITEM( aParent, SCH_COMPONENT_T )
|
SCH_ITEM( aParent, SCH_COMPONENT_T )
|
||||||
{
|
{
|
||||||
|
@ -124,11 +147,10 @@ SCH_COMPONENT::SCH_COMPONENT( const LIB_PART& aPart, const LIB_ID& aLibId,
|
||||||
true, /* reset ref */
|
true, /* reset ref */
|
||||||
true /* reset other fields */ );
|
true /* reset other fields */ );
|
||||||
|
|
||||||
// Update the reference -- just the prefix for now.
|
m_prefix = refDesPrefix( m_part->GetReferenceField().GetText() );
|
||||||
|
|
||||||
if( aSheet )
|
if( aSheet )
|
||||||
SetRef( aSheet, m_part->GetReferenceField().GetText() + wxT( "?" ) );
|
SetRef( aSheet, refDesUnannotated( m_prefix ) );
|
||||||
else
|
|
||||||
m_prefix = m_part->GetReferenceField().GetText() + wxT( "?" );
|
|
||||||
|
|
||||||
// Inherit the include in bill of materials and board netlist settings from library symbol.
|
// Inherit the include in bill of materials and board netlist settings from library symbol.
|
||||||
m_inBom = aPart.GetIncludeInBom();
|
m_inBom = aPart.GetIncludeInBom();
|
||||||
|
@ -454,7 +476,7 @@ const wxString SCH_COMPONENT::GetRef( const SCH_SHEET_PATH* sheet, bool aInclude
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ref.IsEmpty() )
|
if( ref.IsEmpty() )
|
||||||
ref = m_prefix;
|
ref = refDesUnannotated( m_prefix );
|
||||||
|
|
||||||
if( aIncludeUnit && GetUnitCount() > 1 )
|
if( aIncludeUnit && GetUnitCount() > 1 )
|
||||||
ref += LIB_PART::SubReference( GetUnit() );
|
ref += LIB_PART::SubReference( GetUnit() );
|
||||||
|
@ -465,17 +487,7 @@ const wxString SCH_COMPONENT::GetRef( const SCH_SHEET_PATH* sheet, bool aInclude
|
||||||
|
|
||||||
bool SCH_COMPONENT::IsReferenceStringValid( const wxString& aReferenceString )
|
bool SCH_COMPONENT::IsReferenceStringValid( const wxString& aReferenceString )
|
||||||
{
|
{
|
||||||
wxString text = aReferenceString;
|
return !refDesPrefix( aReferenceString ).IsEmpty();
|
||||||
bool ok = true;
|
|
||||||
|
|
||||||
// Try to unannotate this reference
|
|
||||||
while( !text.IsEmpty() && ( text.Last() == '?' || wxIsdigit( text.Last() ) ) )
|
|
||||||
text.RemoveLast();
|
|
||||||
|
|
||||||
if( text.IsEmpty() )
|
|
||||||
ok = false;
|
|
||||||
|
|
||||||
return ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -514,20 +526,10 @@ void SCH_COMPONENT::SetRef( const SCH_SHEET_PATH* sheet, const wxString& ref )
|
||||||
rf->SetText( ref ); // for drawing.
|
rf->SetText( ref ); // for drawing.
|
||||||
|
|
||||||
// Reinit the m_prefix member if needed
|
// Reinit the m_prefix member if needed
|
||||||
wxString prefix = ref;
|
m_prefix = refDesPrefix( ref );
|
||||||
|
|
||||||
if( IsReferenceStringValid( prefix ) )
|
if( m_prefix.IsEmpty() )
|
||||||
{
|
m_prefix = wxT( "U" );
|
||||||
while( prefix.Last() == '?' || wxIsdigit( prefix.Last() ) )
|
|
||||||
prefix.RemoveLast();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
prefix = wxT( "U" ); // Set to default ref prefix
|
|
||||||
}
|
|
||||||
|
|
||||||
if( m_prefix != prefix )
|
|
||||||
m_prefix = prefix;
|
|
||||||
|
|
||||||
// Power symbols have references starting with # and are not included in netlists
|
// Power symbols have references starting with # and are not included in netlists
|
||||||
m_isInNetlist = ! ref.StartsWith( wxT( "#" ) );
|
m_isInNetlist = ! ref.StartsWith( wxT( "#" ) );
|
||||||
|
@ -579,7 +581,7 @@ void SCH_COMPONENT::SetUnitSelection( const SCH_SHEET_PATH* aSheet, int aUnitSel
|
||||||
}
|
}
|
||||||
|
|
||||||
// didn't find it; better add it
|
// didn't find it; better add it
|
||||||
AddHierarchicalReference( path, m_prefix, aUnitSelection );
|
AddHierarchicalReference( path, refDesUnannotated( m_prefix ), aUnitSelection );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -636,7 +638,7 @@ void SCH_COMPONENT::SetValue( const SCH_SHEET_PATH* sheet, const wxString& aValu
|
||||||
}
|
}
|
||||||
|
|
||||||
// didn't find it; better add it
|
// didn't find it; better add it
|
||||||
AddHierarchicalReference( path, m_prefix, m_unit, aValue, wxEmptyString );
|
AddHierarchicalReference( path, refDesUnannotated( m_prefix ), m_unit, aValue, wxEmptyString );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -686,7 +688,8 @@ void SCH_COMPONENT::SetFootprint( const SCH_SHEET_PATH* sheet, const wxString& a
|
||||||
}
|
}
|
||||||
|
|
||||||
// didn't find it; better add it
|
// didn't find it; better add it
|
||||||
AddHierarchicalReference( path, m_prefix, m_unit, wxEmptyString, aFootprint );
|
AddHierarchicalReference( path, refDesUnannotated( m_prefix ), m_unit, wxEmptyString,
|
||||||
|
aFootprint );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1035,19 +1038,8 @@ bool SCH_COMPONENT::ResolveTextVar( wxString* token, int aDepth ) const
|
||||||
|
|
||||||
void SCH_COMPONENT::ClearAnnotation( const SCH_SHEET_PATH* aSheetPath )
|
void SCH_COMPONENT::ClearAnnotation( const SCH_SHEET_PATH* aSheetPath )
|
||||||
{
|
{
|
||||||
// Build a reference with no annotation,
|
// Build a reference with no annotation, i.e. a reference ending with a single '?'
|
||||||
// i.e. a reference ended by only one '?'
|
wxString defRef = refDesUnannotated( m_prefix );
|
||||||
wxString defRef = m_prefix;
|
|
||||||
|
|
||||||
if( !IsReferenceStringValid( defRef ) )
|
|
||||||
{ // This is a malformed reference: reinit this reference
|
|
||||||
m_prefix = defRef = wxT("U"); // Set to default ref prefix
|
|
||||||
}
|
|
||||||
|
|
||||||
while( defRef.Last() == '?' )
|
|
||||||
defRef.RemoveLast();
|
|
||||||
|
|
||||||
defRef.Append( wxT( "?" ) );
|
|
||||||
|
|
||||||
if( aSheetPath )
|
if( aSheetPath )
|
||||||
{
|
{
|
||||||
|
|
|
@ -673,12 +673,12 @@ private:
|
||||||
LIB_ID m_lib_id; ///< Name and library the symbol was loaded from, i.e. 74xx:74LS00.
|
LIB_ID m_lib_id; ///< Name and library the symbol was loaded from, i.e. 74xx:74LS00.
|
||||||
int m_unit; ///< The unit for multiple part per package symbols.
|
int m_unit; ///< The unit for multiple part per package symbols.
|
||||||
int m_convert; ///< The alternate body style for symbols that have more than
|
int m_convert; ///< The alternate body style for symbols that have more than
|
||||||
///< one body style defined. Primarily used for symbols that
|
///< one body style defined. Primarily used for symbols that
|
||||||
///< have a De Morgan conversion.
|
///< have a De Morgan conversion.
|
||||||
wxString m_prefix; ///< C, R, U, Q etc - the first character which typically indicates
|
wxString m_prefix; ///< C, R, U, Q etc - the first character(s) which typically
|
||||||
///< what the symbol is. Determined, upon placement, from the
|
///< indicate what the symbol is. Determined, upon placement,
|
||||||
///< library symbol. Created upon file load, by the first
|
///< from the library symbol. Created upon file load, by the
|
||||||
///< non-digits in the reference fields.
|
///< first non-digits in the reference fields.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name used to look up a symbol in the symbol library embedded in a schematic.
|
* The name used to look up a symbol in the symbol library embedded in a schematic.
|
||||||
|
|
Loading…
Reference in New Issue