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. // Ensure that the template fieldname does not match a fixed fieldname.
for( int i = 0; i < MANDATORY_FIELDS; ++i ) for( int i = 0; i < MANDATORY_FIELDS; ++i )
{ {
if( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) == aFieldName.m_Name ) if( GetCanonicalFieldName( i ) == aFieldName.m_Name )
return; return;
} }

View File

@ -334,14 +334,12 @@ void DIALOG_SYMBOL_FIELDS_TABLE::SetupColumnProperties( int aCol )
attr->SetReadOnly(); attr->SetReadOnly();
m_grid->SetColAttr( aCol, attr ); m_grid->SetColAttr( aCol, attr );
} }
else if( m_dataModel->GetColFieldName( aCol ) else if( m_dataModel->GetColFieldName( aCol ) == GetCanonicalFieldName( FOOTPRINT_FIELD ) )
== TEMPLATE_FIELDNAME::GetDefaultFieldName( FOOTPRINT_FIELD ) )
{ {
attr->SetEditor( new GRID_CELL_FPID_EDITOR( this, wxEmptyString ) ); attr->SetEditor( new GRID_CELL_FPID_EDITOR( this, wxEmptyString ) );
m_grid->SetColAttr( aCol, attr ); m_grid->SetColAttr( aCol, attr );
} }
else if( m_dataModel->GetColFieldName( aCol ) else if( m_dataModel->GetColFieldName( aCol ) == GetCanonicalFieldName( DATASHEET_FIELD ) )
== TEMPLATE_FIELDNAME::GetDefaultFieldName( DATASHEET_FIELD ) )
{ {
// set datasheet column viewer button // set datasheet column viewer button
attr->SetEditor( 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 ) bool FIELDS_EDITOR_GRID_DATA_MODEL::ColIsReference( int aCol )
{ {
wxCHECK( aCol >= 0 && aCol < (int) m_cols.size(), false ); 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 ) bool FIELDS_EDITOR_GRID_DATA_MODEL::ColIsValue( int aCol )
{ {
wxCHECK( aCol >= 0 && aCol < (int) m_cols.size(), false ); 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 ) 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 ) const SCH_REFERENCE& rhRef )
{ {
int refCol = GetFieldNameCol( TEMPLATE_FIELDNAME::GetDefaultFieldName( REFERENCE_FIELD ) ); int refCol = GetFieldNameCol( GetCanonicalFieldName( REFERENCE_FIELD ) );
bool matchFound = false; bool matchFound = false;
if( refCol == -1 ) if( refCol == -1 )
@ -790,8 +790,7 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::ApplyBomPreset( const BOM_PRESET& aPreset )
if( sortCol != -1 ) if( sortCol != -1 )
SetSorting( sortCol, aPreset.sortAsc ); SetSorting( sortCol, aPreset.sortAsc );
else else
SetSorting( GetFieldNameCol( TEMPLATE_FIELDNAME::GetDefaultFieldName( REFERENCE_FIELD ) ), SetSorting( GetFieldNameCol( GetCanonicalFieldName( REFERENCE_FIELD ) ), aPreset.sortAsc );
aPreset.sortAsc );
SetFilter( aPreset.filterString ); SetFilter( aPreset.filterString );
SetExcludeDNP( aPreset.excludeDNP ); SetExcludeDNP( aPreset.excludeDNP );

View File

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

View File

@ -391,7 +391,7 @@ void SCH_SEXPR_PLUGIN_CACHE::saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFor
wxString fieldName = aField->GetName(); wxString fieldName = aField->GetName();
if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS ) 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.Print( aNestLevel, "(property %s %s (at %s %s %g)",
aFormatter.Quotew( fieldName ).c_str(), 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 // If ID is stored in the file (old versions), it will overwrite this
for( int ii = 0; ii < MANDATORY_FIELDS; ++ii ) for( int ii = 0; ii < MANDATORY_FIELDS; ++ii )
{ {
if( !name.CmpNoCase( TEMPLATE_FIELDNAME::GetDefaultFieldName( ii ) ) ) if( !name.CmpNoCase( GetCanonicalFieldName( ii ) ) )
{ {
field->SetId( ii ); field->SetId( ii );
break; break;
@ -2025,7 +2025,7 @@ SCH_FIELD* SCH_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent )
{ {
for( int ii = 0; ii < MANDATORY_FIELDS; ++ii ) for( int ii = 0; ii < MANDATORY_FIELDS; ++ii )
{ {
if( name == TEMPLATE_FIELDNAME::GetDefaultFieldName( ii, false ) ) if( name == GetCanonicalFieldName( ii ) )
{ {
field->SetId( ii ); field->SetId( ii );
break; 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 // Fields in RAM must always have names, because we are trying to get
// less dependent on field ids and more dependent on names. // less dependent on field ids and more dependent on names.
// Plus assumptions are made in the field editors. // 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 // Ensure the VALUE field = the symbol name (can be not the case
// with malformed libraries: edited by hand, or converted from other tools) // 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 ); SCH_FIELD* symField = symbol->FindField( fpFieldName );
// Skip fields that are individually controlled // Skip fields that are individually controlled
if( fpFieldName == TEMPLATE_FIELDNAME::GetDefaultFieldName( REFERENCE_FIELD ) if( fpFieldName == GetCanonicalFieldName( REFERENCE_FIELD )
|| fpFieldName == TEMPLATE_FIELDNAME::GetDefaultFieldName( VALUE_FIELD ) || fpFieldName == GetCanonicalFieldName( VALUE_FIELD )
|| fpFieldName == TEMPLATE_FIELDNAME::GetDefaultFieldName( FOOTPRINT_FIELD ) ) || fpFieldName == GetCanonicalFieldName( FOOTPRINT_FIELD ) )
{ {
continue; continue;
} }

View File

@ -120,6 +120,16 @@ struct TEMPLATE_FIELDNAME
typedef std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES; 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 class TEMPLATES
{ {
public: public:

View File

@ -321,8 +321,7 @@ bool BOARD_NETLIST_UPDATER::updateFootprintParameters( FOOTPRINT* aPcbFootprint,
&& !m_isDryRun ) && !m_isDryRun )
{ {
aPcbFootprint->Footprint().SetText( aPcbFootprint->Footprint().SetText(
aNetlistComponent aNetlistComponent->GetFields()[GetCanonicalFieldName( FOOTPRINT_FIELD )] );
->GetFields()[TEMPLATE_FIELDNAME::GetDefaultFieldName( FOOTPRINT_FIELD )] );
} }
// Test for time stamp change. // 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 // Remove the ref/value/footprint fields that are individually handled
nlohmann::ordered_map<wxString, wxString> compFields = aNetlistComponent->GetFields(); nlohmann::ordered_map<wxString, wxString> compFields = aNetlistComponent->GetFields();
compFields.erase( TEMPLATE_FIELDNAME::GetDefaultFieldName( REFERENCE_FIELD ) ); compFields.erase( GetCanonicalFieldName( REFERENCE_FIELD ) );
compFields.erase( TEMPLATE_FIELDNAME::GetDefaultFieldName( VALUE_FIELD ) ); compFields.erase( GetCanonicalFieldName( VALUE_FIELD ) );
compFields.erase( TEMPLATE_FIELDNAME::GetDefaultFieldName( FOOTPRINT_FIELD ) ); compFields.erase( GetCanonicalFieldName( FOOTPRINT_FIELD ) );
if( fpFieldsAsMap != compFields ) 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_parent && m_parent->Type() == PCB_FOOTPRINT_T )
{ {
if( m_id >= 0 && m_id < MANDATORY_FIELDS ) if( m_id >= 0 && m_id < MANDATORY_FIELDS )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id ); return GetCanonicalFieldName( m_id );
else if( m_name.IsEmpty() && aUseDefaultName ) else if( m_name.IsEmpty() && aUseDefaultName )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id ); return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
else else
@ -68,7 +68,7 @@ wxString PCB_FIELD::GetCanonicalName() const
if( m_parent && m_parent->Type() == PCB_FOOTPRINT_T ) if( m_parent && m_parent->Type() == PCB_FOOTPRINT_T )
{ {
if( m_id < MANDATORY_FIELDS ) if( m_id < MANDATORY_FIELDS )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id, false ); return GetCanonicalFieldName( m_id );
else else
return m_name; return m_name;
} }
@ -88,7 +88,7 @@ wxString PCB_FIELD::GetCanonicalName() const
wxString PCB_FIELD::GetTextTypeDescription() const wxString PCB_FIELD::GetTextTypeDescription() const
{ {
if( m_id < MANDATORY_FIELDS ) if( m_id < MANDATORY_FIELDS )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id, false ); return GetCanonicalFieldName( m_id );
else else
return _( "User Field" ); return _( "User Field" );
} }