@ -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_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 other fields */ ) ;
// Update the reference -- just the prefix for now.
m_prefix = refDesPrefix ( m_part - > GetReferenceField ( ) . GetText ( ) ) ;
if ( aSheet )
SetRef ( aSheet , m_part - > GetReferenceField ( ) . GetText ( ) + wxT ( " ? " ) ) ;
else
m_prefix = m_part - > GetReferenceField ( ) . GetText ( ) + wxT ( " ? " ) ;
SetRef ( aSheet , refDesUnannotated ( m_prefix ) ) ;
// Inherit the include in bill of materials and board netlist settings from library symbol.
m_inBom = aPart . GetIncludeInBom ( ) ;
@ -454,7 +476,7 @@ const wxString SCH_COMPONENT::GetRef( const SCH_SHEET_PATH* sheet, bool aInclude
}
if ( ref . IsEmpty ( ) )
ref = m_prefix ;
ref = refDesUnannotated ( m_prefix ) ;
if ( aIncludeUnit & & GetUnitCount ( ) > 1 )
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 )
{
wxString text = aReferenceString ;
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 ;
return ! refDesPrefix ( aReferenceString ) . IsEmpty ( ) ;
}
@ -514,20 +526,10 @@ void SCH_COMPONENT::SetRef( const SCH_SHEET_PATH* sheet, const wxString& ref )
rf - > SetText ( ref ) ; // for drawing.
// Reinit the m_prefix member if needed
wxString prefix = ref ;
if ( IsReferenceStringValid ( prefix ) )
{
while ( prefix . Last ( ) = = ' ? ' | | wxIsdigit ( prefix . Last ( ) ) )
prefix . RemoveLast ( ) ;
}
else
{
prefix = wxT ( " U " ) ; // Set to default ref prefix
}
m_prefix = refDesPrefix ( ref ) ;
if ( m_prefix ! = prefix )
m_prefix = prefix ;
if ( m_prefix . IsEmpty ( ) )
m_prefix = wxT ( " U " ) ;
// Power symbols have references starting with # and are not included in netlists
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
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
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
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 )
{
// Build a reference with no annotation,
// i.e. a reference ended by only one '?'
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 ( " ? " ) ) ;
// Build a reference with no annotation, i.e. a reference ending with a single '?'
wxString defRef = refDesUnannotated ( m_prefix ) ;
if ( aSheetPath )
{