Readability.

This commit is contained in:
Jeff Young 2023-10-03 17:14:03 +01:00
parent 9b60e99660
commit 9f5e583ced
12 changed files with 34 additions and 28 deletions

View File

@ -218,7 +218,7 @@ void TEMPLATES::AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, bool
// Ensure that the template fieldname does not match a fixed fieldname.
for( int i = 0; i < MANDATORY_FIELDS; ++i )
{
if( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) == aFieldName.m_Name )
if( GetCanonicalFieldName( i ) == aFieldName.m_Name )
return;
}

View File

@ -334,14 +334,12 @@ void DIALOG_SYMBOL_FIELDS_TABLE::SetupColumnProperties( int aCol )
attr->SetReadOnly();
m_grid->SetColAttr( aCol, attr );
}
else if( m_dataModel->GetColFieldName( aCol )
== TEMPLATE_FIELDNAME::GetDefaultFieldName( FOOTPRINT_FIELD ) )
else if( m_dataModel->GetColFieldName( aCol ) == GetCanonicalFieldName( FOOTPRINT_FIELD ) )
{
attr->SetEditor( new GRID_CELL_FPID_EDITOR( this, wxEmptyString ) );
m_grid->SetColAttr( aCol, attr );
}
else if( m_dataModel->GetColFieldName( aCol )
== TEMPLATE_FIELDNAME::GetDefaultFieldName( DATASHEET_FIELD ) )
else if( m_dataModel->GetColFieldName( aCol ) == GetCanonicalFieldName( DATASHEET_FIELD ) )
{
// set datasheet column viewer button
attr->SetEditor(

View File

@ -231,13 +231,13 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::SetValue( int aRow, int aCol, const wxString
bool FIELDS_EDITOR_GRID_DATA_MODEL::ColIsReference( int aCol )
{
wxCHECK( aCol >= 0 && aCol < (int) m_cols.size(), false );
return m_cols[aCol].m_fieldName == TEMPLATE_FIELDNAME::GetDefaultFieldName( REFERENCE_FIELD );
return m_cols[aCol].m_fieldName == GetCanonicalFieldName( REFERENCE_FIELD );
}
bool FIELDS_EDITOR_GRID_DATA_MODEL::ColIsValue( int aCol )
{
wxCHECK( aCol >= 0 && aCol < (int) m_cols.size(), false );
return m_cols[aCol].m_fieldName == TEMPLATE_FIELDNAME::GetDefaultFieldName( VALUE_FIELD );
return m_cols[aCol].m_fieldName == GetCanonicalFieldName( VALUE_FIELD );
}
bool FIELDS_EDITOR_GRID_DATA_MODEL::ColIsQuantity( int aCol )
@ -347,7 +347,7 @@ bool FIELDS_EDITOR_GRID_DATA_MODEL::groupMatch( const SCH_REFERENCE& lhRef,
const SCH_REFERENCE& rhRef )
{
int refCol = GetFieldNameCol( TEMPLATE_FIELDNAME::GetDefaultFieldName( REFERENCE_FIELD ) );
int refCol = GetFieldNameCol( GetCanonicalFieldName( REFERENCE_FIELD ) );
bool matchFound = false;
if( refCol == -1 )
@ -790,8 +790,7 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::ApplyBomPreset( const BOM_PRESET& aPreset )
if( sortCol != -1 )
SetSorting( sortCol, aPreset.sortAsc );
else
SetSorting( GetFieldNameCol( TEMPLATE_FIELDNAME::GetDefaultFieldName( REFERENCE_FIELD ) ),
aPreset.sortAsc );
SetSorting( GetFieldNameCol( GetCanonicalFieldName( REFERENCE_FIELD ) ), aPreset.sortAsc );
SetFilter( aPreset.filterString );
SetExcludeDNP( aPreset.excludeDNP );

View File

@ -498,7 +498,7 @@ wxString LIB_FIELD::GetName( bool aUseDefaultName ) const
wxString LIB_FIELD::GetCanonicalName() const
{
if( m_id < MANDATORY_FIELDS )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
return GetCanonicalFieldName( m_id );
return m_name;
}

View File

@ -995,7 +995,7 @@ wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
{
if( m_id >= 0 && m_id < MANDATORY_FIELDS )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
return GetCanonicalFieldName( m_id );
else if( m_name.IsEmpty() && aUseDefaultName )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
else
@ -1027,7 +1027,7 @@ wxString SCH_FIELD::GetCanonicalName() const
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
{
if( m_id < MANDATORY_FIELDS )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id, false );
return GetCanonicalFieldName( m_id );
else
return m_name;
}

View File

@ -391,7 +391,7 @@ void SCH_SEXPR_PLUGIN_CACHE::saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFor
wxString fieldName = aField->GetName();
if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
fieldName = TEMPLATE_FIELDNAME::GetDefaultFieldName( aField->GetId(), false );
fieldName = GetCanonicalFieldName( aField->GetId() );
aFormatter.Print( aNestLevel, "(property %s %s (at %s %s %g)",
aFormatter.Quotew( fieldName ).c_str(),

View File

@ -833,7 +833,7 @@ LIB_FIELD* SCH_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol
// If ID is stored in the file (old versions), it will overwrite this
for( int ii = 0; ii < MANDATORY_FIELDS; ++ii )
{
if( !name.CmpNoCase( TEMPLATE_FIELDNAME::GetDefaultFieldName( ii ) ) )
if( !name.CmpNoCase( GetCanonicalFieldName( ii ) ) )
{
field->SetId( ii );
break;
@ -2025,7 +2025,7 @@ SCH_FIELD* SCH_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent )
{
for( int ii = 0; ii < MANDATORY_FIELDS; ++ii )
{
if( name == TEMPLATE_FIELDNAME::GetDefaultFieldName( ii, false ) )
if( name == GetCanonicalFieldName( ii ) )
{
field->SetId( ii );
break;

View File

@ -650,7 +650,7 @@ void SCH_LEGACY_PLUGIN_CACHE::loadField( std::unique_ptr<LIB_SYMBOL>& aSymbol,
// Fields in RAM must always have names, because we are trying to get
// less dependent on field ids and more dependent on names.
// Plus assumptions are made in the field editors.
field->m_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
field->m_name = GetCanonicalFieldName( id );
// Ensure the VALUE field = the symbol name (can be not the case
// with malformed libraries: edited by hand, or converted from other tools)

View File

@ -500,9 +500,9 @@ void BACK_ANNOTATE::applyChangelist()
SCH_FIELD* symField = symbol->FindField( fpFieldName );
// Skip fields that are individually controlled
if( fpFieldName == TEMPLATE_FIELDNAME::GetDefaultFieldName( REFERENCE_FIELD )
|| fpFieldName == TEMPLATE_FIELDNAME::GetDefaultFieldName( VALUE_FIELD )
|| fpFieldName == TEMPLATE_FIELDNAME::GetDefaultFieldName( FOOTPRINT_FIELD ) )
if( fpFieldName == GetCanonicalFieldName( REFERENCE_FIELD )
|| fpFieldName == GetCanonicalFieldName( VALUE_FIELD )
|| fpFieldName == GetCanonicalFieldName( FOOTPRINT_FIELD ) )
{
continue;
}

View File

@ -120,6 +120,16 @@ struct TEMPLATE_FIELDNAME
typedef std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES;
inline wxString GetCanonicalFieldName( int idx )
{
// While TEMPLATE_FIELDNAME::GetDefaultFieldName() still works for non-mandatory fields,
// it's confusing to call it through this function.
wxASSERT( idx < MANDATORY_FIELDS );
return TEMPLATE_FIELDNAME::GetDefaultFieldName( idx );
}
class TEMPLATES
{
public:

View File

@ -321,8 +321,7 @@ bool BOARD_NETLIST_UPDATER::updateFootprintParameters( FOOTPRINT* aPcbFootprint,
&& !m_isDryRun )
{
aPcbFootprint->Footprint().SetText(
aNetlistComponent
->GetFields()[TEMPLATE_FIELDNAME::GetDefaultFieldName( FOOTPRINT_FIELD )] );
aNetlistComponent->GetFields()[GetCanonicalFieldName( FOOTPRINT_FIELD )] );
}
// Test for time stamp change.
@ -367,9 +366,9 @@ bool BOARD_NETLIST_UPDATER::updateFootprintParameters( FOOTPRINT* aPcbFootprint,
// Remove the ref/value/footprint fields that are individually handled
nlohmann::ordered_map<wxString, wxString> compFields = aNetlistComponent->GetFields();
compFields.erase( TEMPLATE_FIELDNAME::GetDefaultFieldName( REFERENCE_FIELD ) );
compFields.erase( TEMPLATE_FIELDNAME::GetDefaultFieldName( VALUE_FIELD ) );
compFields.erase( TEMPLATE_FIELDNAME::GetDefaultFieldName( FOOTPRINT_FIELD ) );
compFields.erase( GetCanonicalFieldName( REFERENCE_FIELD ) );
compFields.erase( GetCanonicalFieldName( VALUE_FIELD ) );
compFields.erase( GetCanonicalFieldName( FOOTPRINT_FIELD ) );
if( fpFieldsAsMap != compFields )

View File

@ -49,7 +49,7 @@ wxString PCB_FIELD::GetName( bool aUseDefaultName ) const
if( m_parent && m_parent->Type() == PCB_FOOTPRINT_T )
{
if( m_id >= 0 && m_id < MANDATORY_FIELDS )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
return GetCanonicalFieldName( m_id );
else if( m_name.IsEmpty() && aUseDefaultName )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
else
@ -68,7 +68,7 @@ wxString PCB_FIELD::GetCanonicalName() const
if( m_parent && m_parent->Type() == PCB_FOOTPRINT_T )
{
if( m_id < MANDATORY_FIELDS )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id, false );
return GetCanonicalFieldName( m_id );
else
return m_name;
}
@ -88,7 +88,7 @@ wxString PCB_FIELD::GetCanonicalName() const
wxString PCB_FIELD::GetTextTypeDescription() const
{
if( m_id < MANDATORY_FIELDS )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id, false );
return GetCanonicalFieldName( m_id );
else
return _( "User Field" );
}