From e19bce2f93bf2fcbc0f6cb229b0e8d7a0f4cc01f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 22 Jan 2025 14:26:57 +0000 Subject: [PATCH] Reduce reliance on MANDATORY_FIELDS and their implied order. --- common/template_fieldnames.cpp | 4 +- eeschema/dialogs/dialog_change_symbols.cpp | 52 ++++++------ .../dialogs/dialog_symbol_fields_table.cpp | 48 +++++------ .../dialogs/dialog_update_symbol_fields.cpp | 20 +++-- eeschema/eeschema_jobs_handler.cpp | 13 +-- eeschema/fields_data_model.cpp | 10 +-- eeschema/lib_symbol.cpp | 26 +++--- .../netlist_exporter_xml.cpp | 15 ++-- eeschema/sch_field.cpp | 15 +++- eeschema/sch_io/altium/sch_io_altium.cpp | 6 +- .../cadstar/cadstar_sch_archive_loader.cpp | 16 ++-- eeschema/sch_io/eagle/sch_io_eagle.cpp | 2 +- .../easyedapro/sch_easyedapro_parser.cpp | 9 ++- .../kicad_legacy/sch_io_kicad_legacy.cpp | 22 +++-- .../sch_io_kicad_legacy_lib_cache.cpp | 45 +++++++---- .../sch_io/kicad_sexpr/sch_io_kicad_sexpr.cpp | 6 +- .../sch_io_kicad_sexpr_lib_cache.cpp | 2 +- .../kicad_sexpr/sch_io_kicad_sexpr_parser.cpp | 66 +++++++-------- eeschema/sch_label.cpp | 7 +- eeschema/sch_sheet.cpp | 23 +++--- eeschema/sch_sheet.h | 4 +- eeschema/sch_symbol.cpp | 81 +++++++++---------- eeschema/sch_symbol.h | 4 +- eeschema/sim/sim_model.cpp | 2 +- eeschema/symbol_editor/symbol_editor.cpp | 10 +-- eeschema/tools/backannotate.cpp | 4 +- include/template_fieldnames.h | 6 +- .../dialogs/dialog_footprint_properties.cpp | 5 +- .../dialog_footprint_properties_fp_editor.cpp | 5 +- pcbnew/footprint.cpp | 9 +-- pcbnew/kicad_clipboard.cpp | 6 +- .../netlist_reader/board_netlist_updater.cpp | 4 +- pcbnew/pcb_field.cpp | 19 +++-- pcbnew/pcb_field.h | 2 +- pcbnew/pcb_fields_grid_table.cpp | 4 +- .../pcb_io/easyeda/pcb_io_easyeda_parser.cpp | 2 +- pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.cpp | 2 +- pcbnew/tools/pcb_control.cpp | 2 +- qa/tests/eeschema/lib_field_test_utils.h | 2 +- qa/tests/eeschema/test_lib_part.cpp | 16 ++-- 40 files changed, 312 insertions(+), 284 deletions(-) diff --git a/common/template_fieldnames.cpp b/common/template_fieldnames.cpp index 129d61143f..33a0059221 100644 --- a/common/template_fieldnames.cpp +++ b/common/template_fieldnames.cpp @@ -236,9 +236,9 @@ void TEMPLATES::resolveTemplates() void TEMPLATES::AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, bool aGlobal ) { // Ensure that the template fieldname does not match a fixed fieldname. - for( int i = 0; i < MANDATORY_FIELDS; ++i ) + for( int fieldId : MANDATORY_FIELDS ) { - if( GetCanonicalFieldName( i ) == aFieldName.m_Name ) + if( GetCanonicalFieldName( fieldId ) == aFieldName.m_Name ) return; } diff --git a/eeschema/dialogs/dialog_change_symbols.cpp b/eeschema/dialogs/dialog_change_symbols.cpp index 3ce209c629..5d2c164637 100644 --- a/eeschema/dialogs/dialog_change_symbols.cpp +++ b/eeschema/dialogs/dialog_change_symbols.cpp @@ -101,7 +101,7 @@ DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS( SCH_EDIT_FRAME* aParent, SCH_SYMBO m_matchSizer->SetEmptyCellSize( wxSize( 0, 0 ) ); m_matchSizer->Layout(); - for( int i = 0; i < MANDATORY_FIELDS; ++i ) + for( int i = 0; i < MANDATORY_FIELD_COUNT; ++i ) { m_fieldsBox->Append( GetDefaultFieldName( i, DO_TRANSLATE ) ); @@ -308,10 +308,10 @@ void DIALOG_CHANGE_SYMBOLS::updateFieldsList() fields.clear(); symbol->GetFields( fields, false ); - for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i ) + for( SCH_FIELD* field : fields ) { - if( !fields[i]->IsPrivate() ) - fieldNames.insert( fields[i]->GetName() ); + if( !field->IsMandatory() && !field->IsPrivate() ) + fieldNames.insert( field->GetName() ); } if( m_mode == MODE::UPDATE && symbol->GetLibId().IsValid() ) @@ -324,10 +324,10 @@ void DIALOG_CHANGE_SYMBOLS::updateFieldsList() flattenedSymbol->GetFields( libFields ); - for( unsigned i = MANDATORY_FIELDS; i < libFields.size(); ++i ) + for( SCH_FIELD* libField : libFields ) { - if( !libFields[i]->IsPrivate() ) - fieldNames.insert( libFields[i]->GetName() ); + if( !libField->IsMandatory() && !libField->IsPrivate() ) + fieldNames.insert( libField->GetName() ); } libFields.clear(); // flattenedSymbol is about to go out of scope... @@ -353,10 +353,10 @@ void DIALOG_CHANGE_SYMBOLS::updateFieldsList() flattenedSymbol->GetFields( libFields ); - for( unsigned i = MANDATORY_FIELDS; i < libFields.size(); ++i ) + for( SCH_FIELD* libField : libFields ) { - if( !libFields[i]->IsPrivate() ) - fieldNames.insert( libFields[i]->GetName() ); + if( !libField->IsMandatory() && !libField->IsPrivate() ) + fieldNames.insert( libField->GetName() ); } libFields.clear(); // flattenedSymbol is about to go out of scope... @@ -384,7 +384,7 @@ void DIALOG_CHANGE_SYMBOLS::updateFieldsList() allChecked = false; } - for( unsigned ii = m_fieldsBox->GetCount() - 1; ii >= MANDATORY_FIELDS; --ii ) + for( unsigned ii = m_fieldsBox->GetCount() - 1; ii >= MANDATORY_FIELD_COUNT; --ii ) m_fieldsBox->Delete( ii ); for( const wxString& fieldName : fieldNames ) @@ -424,7 +424,7 @@ void DIALOG_CHANGE_SYMBOLS::onOkButtonClicked( wxCommandEvent& aEvent ) { if( m_fieldsBox->IsChecked( i ) ) { - if( i < MANDATORY_FIELDS ) + if( i < MANDATORY_FIELD_COUNT ) m_updateFields.insert( GetCanonicalFieldName( i ) ); else m_updateFields.insert( m_fieldsBox->GetString( i ) ); @@ -668,7 +668,7 @@ int DIALOG_CHANGE_SYMBOLS::processSymbols( SCH_COMMIT* aCommit, if( !doUpdate ) continue; - if( i < MANDATORY_FIELDS ) + if( i < MANDATORY_FIELD_COUNT ) libField = symbol->GetLibSymbolRef()->GetFieldById( (int) i ); else libField = symbol->GetLibSymbolRef()->FindField( field.GetName() ); @@ -735,7 +735,7 @@ int DIALOG_CHANGE_SYMBOLS::processSymbols( SCH_COMMIT* aCommit, if( resetPositions ) field.SetTextPos( symbol->GetPosition() + libField->GetTextPos() ); } - else if( i >= MANDATORY_FIELDS && removeExtras ) + else if( i >= MANDATORY_FIELD_COUNT && removeExtras ) { symbol->RemoveField( field.GetName() ); i--; @@ -745,25 +745,25 @@ int DIALOG_CHANGE_SYMBOLS::processSymbols( SCH_COMMIT* aCommit, std::vector libFields; symbol->GetLibSymbolRef()->GetFields( libFields ); - for( unsigned i = MANDATORY_FIELDS; i < libFields.size(); ++i ) + for( SCH_FIELD* libField : libFields ) { - const SCH_FIELD& libField = *libFields[i]; - - if( !alg::contains( m_updateFields, libField.GetCanonicalName() ) ) + if( libField->IsMandatory() ) continue; - if( !symbol->FindField( libField.GetName(), false ) ) + if( !alg::contains( m_updateFields, libField->GetCanonicalName() ) ) + continue; + + if( !symbol->FindField( libField->GetName(), false ) ) { - wxString fieldName = libField.GetCanonicalName(); - SCH_FIELD newField( VECTOR2I( 0, 0 ), symbol->GetFieldCount(), symbol, - fieldName ); + SCH_FIELD newField( VECTOR2I( 0, 0 ), symbol->GetNextFieldId(), symbol, + libField->GetCanonicalName() ); SCH_FIELD* schField = symbol->AddField( newField ); // Careful: the visible bit and position are also set by SetAttributes() - schField->SetAttributes( libField ); - schField->SetText( libField.GetText() ); - schField->SetTextPos( symbol->GetPosition() + libField.GetTextPos() ); - schField->SetPrivate( libField.IsPrivate() ); + schField->SetAttributes( *libField ); + schField->SetText( libField->GetText() ); + schField->SetTextPos( symbol->GetPosition() + libField->GetTextPos() ); + schField->SetPrivate( libField->IsPrivate() ); } if( resetPositions && frame->eeconfig()->m_AutoplaceFields.enable ) diff --git a/eeschema/dialogs/dialog_symbol_fields_table.cpp b/eeschema/dialogs/dialog_symbol_fields_table.cpp index dc501fd2de..5e7ccafe5f 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table.cpp @@ -680,29 +680,19 @@ void DIALOG_SYMBOL_FIELDS_TABLE::AddField( const wxString& aFieldName, const wxS void DIALOG_SYMBOL_FIELDS_TABLE::LoadFieldNames() { - // Add mandatory fields first - for( int i = 0; i < MANDATORY_FIELDS; ++i ) - { - bool show = false; - bool groupBy = false; + auto addMandatoryField = + [&]( int fieldId, bool show, bool groupBy ) + { + AddField( GetCanonicalFieldName( fieldId ), + GetDefaultFieldName( fieldId, DO_TRANSLATE ), show, groupBy ); + }; - switch( i ) - { - case REFERENCE_FIELD: - case VALUE_FIELD: - case FOOTPRINT_FIELD: - show = true; - groupBy = true; - break; - case DATASHEET_FIELD: - show = true; - groupBy = false; - break; - } - - AddField( GetCanonicalFieldName( i ), GetDefaultFieldName( i, DO_TRANSLATE ), show, - groupBy ); - } + // Add mandatory fields first show groupBy + addMandatoryField( REFERENCE_FIELD, true, true ); + addMandatoryField( VALUE_FIELD, true, true ); + addMandatoryField( FOOTPRINT_FIELD, true, true ); + addMandatoryField( DATASHEET_FIELD, true, false ); + addMandatoryField( DESCRIPTION_FIELD, false, false ); // Generated fields present only in the fields table AddField( FIELDS_EDITOR_GRID_DATA_MODEL::QUANTITY_VARIABLE, _( "Qty" ), true, false ); @@ -715,10 +705,10 @@ void DIALOG_SYMBOL_FIELDS_TABLE::LoadFieldNames() { SCH_SYMBOL* symbol = m_symbolsList[ i ].GetSymbol(); - for( int j = MANDATORY_FIELDS; j < symbol->GetFieldCount(); ++j ) + for( const SCH_FIELD& field : symbol->GetFields() ) { - if( !symbol->GetFields()[j].IsPrivate() ) - userFieldNames.insert( symbol->GetFields()[j].GetName() ); + if( !field.IsMandatory() && !field.IsPrivate() ) + userFieldNames.insert( field.GetName() ); } } @@ -780,7 +770,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnRemoveField( wxCommandEvent& event ) // Should never occur: "Remove Field..." button should be disabled if invalid selection // via OnFieldsCtrlSelectionChanged() wxCHECK_RET( row != -1, wxS( "Some user defined field must be selected first" ) ); - wxCHECK_RET( row >= MANDATORY_FIELDS, wxS( "Mandatory fields cannot be removed" ) ); + wxCHECK_RET( row >= MANDATORY_FIELD_COUNT, wxS( "Mandatory fields cannot be removed" ) ); wxString fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN ); wxString displayName = m_fieldsCtrl->GetTextValue( row, DISPLAY_NAME_COLUMN ); @@ -805,7 +795,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnRemoveField( wxCommandEvent& event ) // Safe to decrement row index because we always have mandatory fields. m_fieldsCtrl->SelectRow( --row ); - if( row < MANDATORY_FIELDS ) + if( row < MANDATORY_FIELD_COUNT ) { m_removeFieldButton->Enable( false ); m_renameFieldButton->Enable( false ); @@ -828,7 +818,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnRenameField( wxCommandEvent& event ) // Should never occur: "Rename Field..." button should be disabled if invalid selection // via OnFieldsCtrlSelectionChanged() wxCHECK_RET( row != -1, wxS( "Some user defined field must be selected first" ) ); - wxCHECK_RET( row >= MANDATORY_FIELDS, wxS( "Mandatory fields cannot be renamed" ) ); + wxCHECK_RET( row >= MANDATORY_FIELD_COUNT, wxS( "Mandatory fields cannot be renamed" ) ); wxCHECK_RET( !fieldName.IsEmpty(), wxS( "Field must have a name" ) ); int col = m_dataModel->GetFieldNameCol( fieldName ); @@ -894,7 +884,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnFieldsCtrlSelectionChanged( wxDataViewEvent& { int row = m_fieldsCtrl->GetSelectedRow(); - if( row >= MANDATORY_FIELDS ) + if( row >= MANDATORY_FIELD_COUNT ) { m_removeFieldButton->Enable( true ); m_renameFieldButton->Enable( true ); diff --git a/eeschema/dialogs/dialog_update_symbol_fields.cpp b/eeschema/dialogs/dialog_update_symbol_fields.cpp index eb48de54ee..54c066bf8c 100644 --- a/eeschema/dialogs/dialog_update_symbol_fields.cpp +++ b/eeschema/dialogs/dialog_update_symbol_fields.cpp @@ -46,7 +46,7 @@ DIALOG_UPDATE_SYMBOL_FIELDS::DIALOG_UPDATE_SYMBOL_FIELDS( SYMBOL_EDIT_FRAME* aPa m_parentSymbolReadOnly->SetValue( UnescapeString( m_symbol->GetParent().lock()->GetName() ) ); - for( int i = 0; i < MANDATORY_FIELDS; ++i ) + for( int i = 0; i < MANDATORY_FIELD_COUNT; ++i ) { m_fieldsBox->Append( GetDefaultFieldName( i, DO_TRANSLATE ) ); m_fieldsBox->Check( i, true ); @@ -88,27 +88,33 @@ void DIALOG_UPDATE_SYMBOL_FIELDS::updateFieldsList() flattenedParent->GetFields( libFields ); - for( unsigned i = MANDATORY_FIELDS; i < libFields.size(); ++i ) - fieldNames.insert( libFields[i]->GetName() ); + for( SCH_FIELD* libField : libFields ) + { + if( !libField->IsMandatory() ) + fieldNames.insert( libField->GetName() ); + } libFields.clear(); // flattenedPart is about to go out of scope... // Load non-mandatory fields from the editor symbol m_symbol->GetFields( libFields ); - for( unsigned i = MANDATORY_FIELDS; i < libFields.size(); ++i ) - fieldNames.insert( libFields[i]->GetName() ); + for( SCH_FIELD* libField : libFields ) + { + if( !libField->IsMandatory() ) + fieldNames.insert( libField->GetName() ); + } libFields.clear(); // Update the listbox widget - for( unsigned i = m_fieldsBox->GetCount() - 1; i >= MANDATORY_FIELDS; --i ) + for( unsigned i = m_fieldsBox->GetCount() - 1; i >= MANDATORY_FIELD_COUNT; --i ) m_fieldsBox->Delete( i ); for( const wxString& fieldName : fieldNames ) m_fieldsBox->Append( fieldName ); - for( unsigned i = MANDATORY_FIELDS; i < m_fieldsBox->GetCount(); ++i ) + for( unsigned i = MANDATORY_FIELD_COUNT; i < m_fieldsBox->GetCount(); ++i ) m_fieldsBox->Check( i, true ); } diff --git a/eeschema/eeschema_jobs_handler.cpp b/eeschema/eeschema_jobs_handler.cpp index 317b111340..7176163771 100644 --- a/eeschema/eeschema_jobs_handler.cpp +++ b/eeschema/eeschema_jobs_handler.cpp @@ -526,10 +526,10 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob ) FIELDS_EDITOR_GRID_DATA_MODEL dataModel( referenceList ); // Mandatory fields + quantity virtual field first - for( int i = 0; i < MANDATORY_FIELDS; ++i ) + for( int fieldId : MANDATORY_FIELDS ) { - dataModel.AddColumn( GetCanonicalFieldName( i ), GetDefaultFieldName( i, DO_TRANSLATE ), - false ); + dataModel.AddColumn( GetCanonicalFieldName( fieldId ), + GetDefaultFieldName( fieldId, DO_TRANSLATE ), false ); } // User field names in symbols second @@ -539,8 +539,11 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob ) { SCH_SYMBOL* symbol = referenceList[i].GetSymbol(); - for( int j = MANDATORY_FIELDS; j < symbol->GetFieldCount(); ++j ) - userFieldNames.insert( symbol->GetFields()[j].GetName() ); + for( SCH_FIELD& field : symbol->GetFields() ) + { + if( !field.IsMandatory() && !field.IsPrivate() ) + userFieldNames.insert( field.GetName() ); + } } for( const wxString& fieldName : userFieldNames ) diff --git a/eeschema/fields_data_model.cpp b/eeschema/fields_data_model.cpp index 7e4f57b23c..df6fe729a1 100644 --- a/eeschema/fields_data_model.cpp +++ b/eeschema/fields_data_model.cpp @@ -830,13 +830,13 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::ApplyData( } } - for( int ii = symbol.GetFields().size() - 1; ii >= MANDATORY_FIELDS; ii-- ) + for( int ii = symbol.GetFields().size() - 1; ii >= 0; ii-- ) { + if( symbol.GetFields()[ii].IsMandatory() || symbol.GetFields()[ii].IsPrivate() ) + continue; + if( fieldStore.count( symbol.GetFields()[ii].GetName() ) == 0 ) - { - if( !symbol.GetFields()[ii].IsPrivate() ) - symbol.GetFields().erase( symbol.GetFields().begin() + ii ); - } + symbol.GetFields().erase( symbol.GetFields().begin() + ii ); } } diff --git a/eeschema/lib_symbol.cpp b/eeschema/lib_symbol.cpp index 4efbd69d91..504ac090e2 100644 --- a/eeschema/lib_symbol.cpp +++ b/eeschema/lib_symbol.cpp @@ -107,10 +107,10 @@ LIB_SYMBOL::LIB_SYMBOL( const wxString& aName, LIB_SYMBOL* aParent, SYMBOL_LIB* // Add the MANDATORY_FIELDS in RAM only. These are assumed to be present // when the field editors are invoked. - m_drawings[SCH_FIELD_T].reserve( MANDATORY_FIELDS ); + m_drawings[SCH_FIELD_T].reserve( MANDATORY_FIELD_COUNT ); - for( int i = 0; i < MANDATORY_FIELDS; i++ ) - m_drawings[SCH_FIELD_T].push_back( new SCH_FIELD( this, i ) ); + for( int fieldId : MANDATORY_FIELDS ) + m_drawings[SCH_FIELD_T].push_back( new SCH_FIELD( this, fieldId ) ); // Ensure reference and value fields are visible when creating a lib symbol // whatever the SCH_FIELD Ctor default value is. @@ -351,15 +351,15 @@ std::unique_ptr< LIB_SYMBOL > LIB_SYMBOL::Flatten() const retv->SetLibId( m_libId ); // Now add the inherited part mandatory field (this) information. - for( int i = 0; i < MANDATORY_FIELDS; i++ ) + for( int fieldId : MANDATORY_FIELDS ) { - wxString tmp = GetFieldById( i )->GetText(); + wxString tmp = GetFieldById( fieldId )->GetText(); // If the field isn't defined then inherit the parent field value. if( tmp.IsEmpty() ) - retv->GetFieldById( i )->SetText( retv->GetFieldById( i )->GetText() ); + retv->GetFieldById( fieldId )->SetText( retv->GetFieldById( fieldId )->GetText() ); else - *retv->GetFieldById( i ) = *GetFieldById( i ); + *retv->GetFieldById( fieldId ) = *GetFieldById( fieldId ); } // Grab all the rest of derived symbol fields. @@ -1068,9 +1068,9 @@ void LIB_SYMBOL::SetFields( const std::vector& aFieldsList ) void LIB_SYMBOL::GetFields( std::vector& aList, bool aVisibleOnly ) { // Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T - for( int id = 0; id < MANDATORY_FIELDS; ++id ) + for( int fieldId : MANDATORY_FIELDS ) { - SCH_FIELD* field = GetFieldById( id ); + SCH_FIELD* field = GetFieldById( fieldId ); if( aVisibleOnly ) { @@ -1101,8 +1101,8 @@ void LIB_SYMBOL::GetFields( std::vector& aList, bool aVisibleOnly ) void LIB_SYMBOL::CopyFields( std::vector& aList ) { // Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T - for( int id = 0; id < MANDATORY_FIELDS; ++id ) - aList.push_back( *GetFieldById( id ) ); + for( int fieldId : MANDATORY_FIELDS ) + aList.push_back( *GetFieldById( fieldId ) ); // Now grab all the rest of fields. for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] ) @@ -1248,7 +1248,7 @@ void LIB_SYMBOL::RunOnChildren( const std::function& aFunctio int LIB_SYMBOL::UpdateFieldOrdinals() { int retv = 0; - int lastOrdinal = MANDATORY_FIELDS; + int lastOrdinal = MANDATORY_FIELD_COUNT; for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] ) { @@ -1273,7 +1273,7 @@ int LIB_SYMBOL::UpdateFieldOrdinals() int LIB_SYMBOL::GetNextAvailableFieldId() const { - int retv = MANDATORY_FIELDS; + int retv = MANDATORY_FIELD_COUNT; while( GetFieldById( retv ) ) retv += 1; diff --git a/eeschema/netlist_exporters/netlist_exporter_xml.cpp b/eeschema/netlist_exporters/netlist_exporter_xml.cpp index 5fd3c4c636..db76f51e9e 100644 --- a/eeschema/netlist_exporters/netlist_exporter_xml.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_xml.cpp @@ -162,7 +162,7 @@ void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_SYMBOL* aSymbol, // All non-mandatory fields for( SCH_FIELD& field : symbol2->GetFields() ) { - if( field.IsMandatory() ) + if( field.IsMandatory() || field.IsPrivate() ) continue; if( unit < minUnit || fields.count( field.GetName() ) == 0 ) @@ -200,7 +200,7 @@ void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_SYMBOL* aSymbol, for( SCH_FIELD& field : aSymbol->GetFields() ) { - if( field.IsMandatory() ) + if( field.IsMandatory() || field.IsPrivate() ) continue; if( m_resolveTextVars ) @@ -346,15 +346,18 @@ XNODE* NETLIST_EXPORTER_XML::makeSymbols( unsigned aCtl ) std::vector& fields = symbol->GetFields(); - for( size_t jj = MANDATORY_FIELDS; jj < fields.size(); ++jj ) + for( SCH_FIELD& field : fields ) { + if( field.IsMandatory() || field.IsPrivate() ) + continue; + xcomp->AddChild( xproperty = node( wxT( "property" ) ) ); - xproperty->AddAttribute( wxT( "name" ), fields[jj].GetCanonicalName() ); + xproperty->AddAttribute( wxT( "name" ), field.GetCanonicalName() ); if( m_resolveTextVars ) - xproperty->AddAttribute( wxT( "value" ), fields[jj].GetShownText( &sheet, false ) ); + xproperty->AddAttribute( wxT( "value" ), field.GetShownText( &sheet, false ) ); else - xproperty->AddAttribute( wxT( "value" ), fields[jj].GetText() ); + xproperty->AddAttribute( wxT( "value" ), field.GetText() ); } for( const SCH_FIELD& sheetField : sheet.Last()->GetFields() ) diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 9389b67ffc..74a2459a2b 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -1508,9 +1508,18 @@ VECTOR2I SCH_FIELD::GetParentPosition() const bool SCH_FIELD::IsMandatory() const { if( m_parent && m_parent->Type() == SCH_SHEET_T ) - return m_id >= 0 && m_id < SHEET_MANDATORY_FIELDS; + { + return m_id == SHEETNAME + || m_id == SHEETFILENAME; + } else - return m_id >= 0 && m_id < MANDATORY_FIELDS; + { + return m_id == REFERENCE_FIELD + || m_id == VALUE_FIELD + || m_id == FOOTPRINT_FIELD + || m_id == DATASHEET_FIELD + || m_id == DESCRIPTION_FIELD; + } } @@ -1591,7 +1600,7 @@ double SCH_FIELD::Similarity( const SCH_ITEM& aOther ) const if( GetId() != field.GetId() ) { // We don't allow swapping of mandatory fields, so these cannot be the same item - if( GetId() < MANDATORY_FIELDS || field.GetId() < MANDATORY_FIELDS ) + if( IsMandatory() || field.IsMandatory() ) return 0.0; else similarity *= 0.5; diff --git a/eeschema/sch_io/altium/sch_io_altium.cpp b/eeschema/sch_io/altium/sch_io_altium.cpp index 91ab41a395..3bd7385a0f 100644 --- a/eeschema/sch_io/altium/sch_io_altium.cpp +++ b/eeschema/sch_io/altium/sch_io_altium.cpp @@ -4055,11 +4055,9 @@ void SCH_IO_ALTIUM::ParseParameter( const std::map& aPropert } else { - int fieldIdx = 0; + int fieldIdx = symbol->GetNextFieldId(); wxString fieldName = elem.name.Upper(); - fieldIdx = symbol->GetFieldCount(); - if( fieldName.IsEmpty() ) { int disambiguate = 1; @@ -4128,7 +4126,7 @@ void SCH_IO_ALTIUM::ParseLibParameter( const std::map& aProp } else { - int fieldIdx = libSymbol->GetFieldCount(); + int fieldIdx = libSymbol->GetNextAvailableFieldId(); wxString fieldNameStem = elem.name; wxString fieldName = fieldNameStem; int disambiguate = 1; diff --git a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp index 208de84549..d6924298ff 100644 --- a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp @@ -789,9 +789,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances() if( !partField ) { - int fieldID = symbol->GetFieldCount(); - partField = symbol->AddField( SCH_FIELD( VECTOR2I(), fieldID, symbol, - PartNameFieldName ) ); + partField = symbol->AddField( SCH_FIELD( VECTOR2I(), symbol->GetNextFieldId(), + symbol, PartNameFieldName ) ); } wxASSERT( partField->GetName() == PartNameFieldName ); @@ -818,9 +817,9 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances() if( !attrField ) { - int fieldID = symbol->GetFieldCount(); - attrField = symbol->AddField( SCH_FIELD( VECTOR2I(), fieldID, symbol, - attrName ) ); + attrField = symbol->AddField( SCH_FIELD( VECTOR2I(), + symbol->GetNextFieldId(), + symbol, attrName ) ); } wxASSERT( attrField->GetName() == attrName ); @@ -1600,9 +1599,8 @@ CADSTAR_SCH_ARCHIVE_LOADER::addNewFieldToSymbol( const wxString& aF if( existingField != nullptr ) return existingField; - int newfieldID = aKiCadSymbol->GetFieldCount(); - SCH_FIELD* newfield = new SCH_FIELD( aKiCadSymbol.get(), newfieldID ); - newfield->SetName( aFieldName ); + SCH_FIELD* newfield = new SCH_FIELD( aKiCadSymbol.get(), + aKiCadSymbol->GetNextAvailableFieldId(), aFieldName ); newfield->SetVisible( false ); aKiCadSymbol->AddField( newfield ); /* diff --git a/eeschema/sch_io/eagle/sch_io_eagle.cpp b/eeschema/sch_io/eagle/sch_io_eagle.cpp index 9b6bdf68b5..4c2685d679 100644 --- a/eeschema/sch_io/eagle/sch_io_eagle.cpp +++ b/eeschema/sch_io/eagle/sch_io_eagle.cpp @@ -1879,7 +1879,7 @@ void SCH_IO_EAGLE::loadInstance( const std::unique_ptr& aInstance, if( lastField ) newFieldPosition = lastField->GetPosition(); - SCH_FIELD newField( newFieldPosition, symbol->GetFieldCount(), symbol.get() ); + SCH_FIELD newField( newFieldPosition, symbol->GetNextFieldId(), symbol.get() ); newField.SetName( attrName ); diff --git a/eeschema/sch_io/easyedapro/sch_easyedapro_parser.cpp b/eeschema/sch_io/easyedapro/sch_easyedapro_parser.cpp index ce4a952ded..8481828fab 100644 --- a/eeschema/sch_io/easyedapro/sch_easyedapro_parser.cpp +++ b/eeschema/sch_io/easyedapro/sch_easyedapro_parser.cpp @@ -1295,8 +1295,9 @@ void SCH_EASYEDAPRO_PARSER::ParseSchematic( SCHEMATIC* aSchematic, SCH_SHEET* aR if( !text ) { - text = schSym->AddField( - SCH_FIELD( schSym.get(), schSym->GetFieldCount(), attrKey ) ); + text = schSym->AddField( SCH_FIELD( schSym.get(), + schSym->GetNextFieldId(), + attrKey ) ); } wxString value = *valOpt; @@ -1366,8 +1367,8 @@ void SCH_EASYEDAPRO_PARSER::ParseSchematic( SCHEMATIC* aSchematic, SCH_SHEET* aR if( !text ) { - text = schSym->AddField( - SCH_FIELD( schSym.get(), schSym->GetFieldCount(), attrKey ) ); + text = schSym->AddField( SCH_FIELD( schSym.get(), schSym->GetNextFieldId(), + attrKey ) ); } text->SetPosition( schSym->GetPosition() ); diff --git a/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy.cpp b/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy.cpp index 0964920bbf..4fdcb83ee7 100644 --- a/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy.cpp +++ b/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy.cpp @@ -1302,7 +1302,7 @@ SCH_SYMBOL* SCH_IO_KICAD_LEGACY::loadSymbol( LINE_READER& aReader ) // The first MANDATOR_FIELDS _must_ be constructed within the SCH_SYMBOL // constructor. This assert is simply here to guard against a change in that // constructor. - wxASSERT( symbol->GetFieldCount() >= MANDATORY_FIELDS ); + wxASSERT( symbol->GetFieldCount() >= MANDATORY_FIELD_COUNT ); // We need to check for an existing field by name that happens to have the same // name and index as any field that was made mandatory after this point, e.g. Description @@ -1313,9 +1313,9 @@ SCH_SYMBOL* SCH_IO_KICAD_LEGACY::loadSymbol( LINE_READER& aReader ) if( !existingField ) { // Ignore the _supplied_ fieldNdx. It is not important anymore if within the - // user defined fields region (i.e. >= MANDATORY_FIELDS). + // user defined fields region (i.e. >= MANDATORY_FIELD_COUNT). // We freely renumber the index to fit the next available field slot. - index = symbol->GetFieldCount(); // new has this index after insertion + index = symbol->GetNextFieldId(); // new has this index after insertion SCH_FIELD field( VECTOR2I( 0, 0 ), index, symbol.get(), name ); symbol->AddField( field ); @@ -1755,16 +1755,22 @@ void SCH_IO_KICAD_LEGACY::saveSymbol( SCH_SYMBOL* aSymbol ) // Fixed fields: // Save mandatory fields even if they are blank, // because the visibility, size and orientation are set from library editor. - for( unsigned i = 0; i < MANDATORY_FIELDS; ++i ) - saveField( &aSymbol->GetFields()[i] ); + for( SCH_FIELD& field : aSymbol->GetFields() ) + { + if( field.IsMandatory() ) + saveField( &field ); + } // User defined fields: // The *policy* about which user defined fields are symbol of a symbol is now // only in the dialog editors. No policy should be enforced here, simply // save all the user defined fields, they are present because a dialog editor // thought they should be. If you disagree, go fix the dialog editors. - for( int i = MANDATORY_FIELDS; i < aSymbol->GetFieldCount(); ++i ) - saveField( &aSymbol->GetFields()[i] ); + for( SCH_FIELD& field : aSymbol->GetFields() ) + { + if( !field.IsMandatory() ) + saveField( &field ); + } // Unit number, position, box ( old standard ) m_out->Print( 0, "\t%-4d %-4d %-4d\n", aSymbol->GetUnit(), @@ -1808,7 +1814,7 @@ void SCH_IO_KICAD_LEGACY::saveField( SCH_FIELD* aField ) aField->IsBold() ? 'B' : 'N' ); // Save field name, if the name is user definable - if( aField->GetId() >= MANDATORY_FIELDS ) + if( !aField->IsMandatory() ) m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() ); m_out->Print( 0, "\n" ); diff --git a/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp b/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp index ae9b605491..6e88717413 100644 --- a/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp +++ b/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp @@ -215,11 +215,18 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::loadDocs() LIB_SYMBOL_MAP::iterator it = m_symbols.find( aliasName ); if( it == m_symbols.end() ) + { wxLogWarning( "Symbol '%s' not found in library:\n\n" - "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(), - reader.LineNumber(), (int) (line - reader.Line() ) ); + "'%s'\n\nat line %d offset %d", + aliasName, + fn.GetFullPath(), + reader.LineNumber(), + (int) (line - reader.Line() ) ); + } else + { symbol = it->second; + } // Read the current alias associated doc. // if the alias does not exist, just skip the description @@ -499,20 +506,20 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::loadAliases( std::unique_ptr& aS LIB_SYMBOL* newSymbol = new LIB_SYMBOL( newAliasName ); // Inherit the parent mandatory field attributes. - for( int id = 0; id < MANDATORY_FIELDS; ++id ) + for( int fieldId : MANDATORY_FIELDS ) { - SCH_FIELD* field = newSymbol->GetFieldById( id ); + SCH_FIELD* field = newSymbol->GetFieldById( fieldId ); - // the MANDATORY_FIELDS are exactly that in RAM. + // the MANDATORY_FIELD_COUNT are exactly that in RAM. wxASSERT( field ); - SCH_FIELD* parentField = aSymbol->GetFieldById( id ); + SCH_FIELD* parentField = aSymbol->GetFieldById( fieldId ); wxASSERT( parentField ); *field = *parentField; - if( id == VALUE_FIELD ) + if( fieldId == VALUE_FIELD ) field->SetText( newAliasName ); field->SetParent( newSymbol ); @@ -662,7 +669,7 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::loadField( std::unique_ptr& aSym } // Fields in RAM must always have names. - if( id >= 0 && id < MANDATORY_FIELDS ) + if( field->IsMandatory() ) { // Fields in RAM must always have names, because we are trying to get // less dependent on field ids and more dependent on names. @@ -1525,22 +1532,28 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMA // may have their own save policy so there is a separate loop for them. // Empty fields are saved, because the user may have set visibility, // size and orientation - for( int i = 0; i < MANDATORY_FIELDS; ++i ) - saveField( fields[i], aFormatter ); + for( SCH_FIELD* field : fields ) + { + if( field->IsMandatory() ) + saveField( field, aFormatter ); + } // User defined fields: // may have their own save policy so there is a separate loop for them. - int fieldId = MANDATORY_FIELDS; // really wish this would go away. + int fieldId = MANDATORY_FIELD_COUNT; // really wish this would go away. - for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i ) + for( SCH_FIELD* field : fields ) { + if( field->IsMandatory() ) + continue; + // There is no need to save empty fields, i.e. no reason to preserve field // names now that fields names come in dynamically through the template // fieldnames. - if( !fields[i]->GetText().IsEmpty() ) + if( !field->GetText().IsEmpty() ) { - fields[i]->SetId( fieldId++ ); - saveField( fields[i], aFormatter ); + field->SetId( fieldId++ ); + saveField( field, aFormatter ); } } @@ -1719,7 +1732,7 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::saveField( const SCH_FIELD* aField, // Translated names were stored in legacy files, so it's important not to save the // default names as they weren't yet canonical. - if( id >= MANDATORY_FIELDS + if( !aField->IsMandatory() && !aField->GetName().IsEmpty() && aField->GetName() != GetUserFieldName( id, !DO_TRANSLATE ) ) { diff --git a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr.cpp b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr.cpp index fb7bb9f0be..7e398b5f68 100644 --- a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr.cpp +++ b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr.cpp @@ -92,7 +92,7 @@ void SCH_IO_KICAD_SEXPR::init( SCHEMATIC* aSchematic, const std::map MANDATORY_FIELDS or SHEET_MANDATORY_FIELDS + m_nextFreeFieldId = 100; // number arbitrarily > MANDATORY_FIELD_COUNT or SHEET_MANDATORY_FIELD_COUNT } @@ -741,7 +741,7 @@ void SCH_IO_KICAD_SEXPR::saveSymbol( SCH_SYMBOL* aSymbol, const SCHEMATIC& aSche KICAD_FORMAT::FormatUuid( m_out, aSymbol->m_Uuid ); - m_nextFreeFieldId = MANDATORY_FIELDS; + m_nextFreeFieldId = MANDATORY_FIELD_COUNT; for( SCH_FIELD& field : aSymbol->GetFields() ) { @@ -1016,7 +1016,7 @@ void SCH_IO_KICAD_SEXPR::saveSheet( SCH_SHEET* aSheet, const SCH_SHEET_LIST& aSh KICAD_FORMAT::FormatUuid( m_out, aSheet->m_Uuid ); - m_nextFreeFieldId = SHEET_MANDATORY_FIELDS; + m_nextFreeFieldId = SHEET_MANDATORY_FIELD_COUNT; for( SCH_FIELD& field : aSheet->GetFields() ) saveField( &field ); diff --git a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.cpp b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.cpp index ae2a717fe6..0b796e685d 100644 --- a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.cpp +++ b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.cpp @@ -149,7 +149,7 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMAT else aSymbol->GetEmbeddedFiles()->ClearEmbeddedFonts(); - int nextFreeFieldId = MANDATORY_FIELDS; + int nextFreeFieldId = MANDATORY_FIELD_COUNT; std::vector fields; std::string name = aFormatter.Quotew( aSymbol->GetLibId().GetLibItemName().wx_str() ); std::string unitName = aSymbol->GetLibId().GetLibItemName(); diff --git a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.cpp b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.cpp index 43b3167e04..cfeb839831 100644 --- a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.cpp +++ b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.cpp @@ -314,8 +314,8 @@ LIB_SYMBOL* SCH_IO_KICAD_SEXPR_PARSER::parseLibSymbol( LIB_SYMBOL_MAP& aSymbolLi // Make sure the mandatory field IDs are reserved as already read, // the field parser will set the field IDs to the correct value if // the field name matches a mandatory field name - for( int i = 0; i < MANDATORY_FIELDS; i++ ) - m_fieldIDsRead.insert( i ); + for( int fieldId : MANDATORY_FIELDS ) + m_fieldIDsRead.insert( fieldId ); token = NextTok(); @@ -957,7 +957,7 @@ SCH_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr wxString name; wxString value; - auto field = std::make_unique( aSymbol.get(), MANDATORY_FIELDS ); + auto field = std::make_unique( aSymbol.get(), aSymbol->GetNextAvailableFieldId() ); // By default, fieds are visible. // Invisible fields have the hide style or keyword specified in file @@ -989,11 +989,11 @@ SCH_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr // Correctly set the ID based on canonical (untranslated) field name // If ID is stored in the file (old versions), it will overwrite this - for( int ii = 0; ii < MANDATORY_FIELDS; ++ii ) + for( int fieldId : MANDATORY_FIELDS ) { - if( !name.CmpNoCase( GetCanonicalFieldName( ii ) ) ) + if( name.CmpNoCase( GetCanonicalFieldName( fieldId ) ) == 0 ) { - field->SetId( ii ); + field->SetId( fieldId ); break; } } @@ -1025,8 +1025,8 @@ SCH_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr { int id = parseInt( "field ID" ); - // Only set an ID that isn't a MANDATORY_FIELDS ID - if( id >= MANDATORY_FIELDS ) + // Only set an ID that isn't a MANDATORY_FIELD ID + if( id >= MANDATORY_FIELD_COUNT ) field->SetId( id ); NeedRIGHT(); @@ -1064,7 +1064,7 @@ SCH_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr // Due to an bug when in #LIB_SYMBOL::Flatten, duplicate ids slipped through when writing // files. This section replaces duplicate #SCH_FIELD indices on load. - if( ( field->GetId() >= MANDATORY_FIELDS ) && m_fieldIDsRead.count( field->GetId() ) ) + if( ( field->GetId() >= MANDATORY_FIELD_COUNT ) && m_fieldIDsRead.count( field->GetId() ) ) { int nextAvailableId = field->GetId() + 1; @@ -2214,15 +2214,14 @@ SCH_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent ) // Empty property values are valid. wxString value = FromUTF8(); - int mandatoryFieldCount = 0; + int nextFieldId = 0; if( aParent->Type() == SCH_SYMBOL_T ) - mandatoryFieldCount = MANDATORY_FIELDS; + nextFieldId = MANDATORY_FIELD_COUNT; else if( aParent->Type() == SCH_SHEET_T ) - mandatoryFieldCount = SHEET_MANDATORY_FIELDS; + nextFieldId = SHEET_MANDATORY_FIELD_COUNT; - std::unique_ptr field = std::make_unique( VECTOR2I( -1, -1 ), - mandatoryFieldCount, + std::unique_ptr field = std::make_unique( VECTOR2I( -1, -1 ), nextFieldId, aParent, name ); field->SetText( value ); field->SetVisible( true ); @@ -2232,11 +2231,11 @@ SCH_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent ) // If ID is stored in the file (old versions), it will overwrite this if( aParent->Type() == SCH_SYMBOL_T ) { - for( int ii = 0; ii < MANDATORY_FIELDS; ++ii ) + for( int fieldId : MANDATORY_FIELDS ) { - if( name == GetCanonicalFieldName( ii ) ) + if( name == GetCanonicalFieldName( fieldId ) ) { - field->SetId( ii ); + field->SetId( fieldId ); field->SetPrivate( false ); break; } @@ -2244,26 +2243,21 @@ SCH_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent ) } else if( aParent->Type() == SCH_SHEET_T ) { - for( int ii = 0; ii < SHEET_MANDATORY_FIELDS; ++ii ) + for( int fieldId : SHEET_MANDATORY_FIELDS ) { - if( name == SCH_SHEET::GetDefaultFieldName( ii, !DO_TRANSLATE ) ) + if( name == SCH_SHEET::GetDefaultFieldName( fieldId, !DO_TRANSLATE ) ) { - field->SetId( ii ); + field->SetId( fieldId ); field->SetPrivate( false ); break; } - // Legacy support for old field names - else if( !name.CmpNoCase( wxT( "Sheet name" ) ) ) - { - field->SetId( SHEETNAME ); - break; - } - else if( !name.CmpNoCase( wxT( "Sheet file" ) ) ) - { - field->SetId( SHEETFILENAME ); - break; - } } + + // Legacy support for old field names + if( name.CmpNoCase( wxT( "Sheet name" ) ) == 0 ) + field->SetId( SHEETNAME ); + else if( name.CmpNoCase( wxT( "Sheet file" ) ) == 0 ) + field->SetId( SHEETFILENAME ); } for( token = NextTok(); token != T_RIGHT; token = NextTok() ) @@ -2281,7 +2275,7 @@ SCH_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent ) int id = parseInt( "field ID" ); // Only set an ID that isn't a mandatory field ID - if( id >= mandatoryFieldCount ) + if( id >= nextFieldId ) field->SetId( id ); NeedRIGHT(); @@ -2974,8 +2968,8 @@ SCH_SYMBOL* SCH_IO_KICAD_SEXPR_PARSER::parseSchematicSymbol() // Make sure the mandatory field IDs are reserved as already read, // the field parser will set the field IDs to the correct value if // the field name matches a mandatory field name - for( int i = 0; i < MANDATORY_FIELDS; i++ ) - m_fieldIDsRead.insert( i ); + for( int fieldId : MANDATORY_FIELDS ) + m_fieldIDsRead.insert( fieldId ); for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { @@ -3258,7 +3252,7 @@ SCH_SYMBOL* SCH_IO_KICAD_SEXPR_PARSER::parseSchematicSymbol() break; } - if( ( field->GetId() >= MANDATORY_FIELDS ) && m_fieldIDsRead.count( field->GetId() ) ) + if( ( field->GetId() >= MANDATORY_FIELD_COUNT ) && m_fieldIDsRead.count( field->GetId() ) ) { int nextAvailableId = field->GetId() + 1; @@ -3531,7 +3525,7 @@ SCH_SHEET* SCH_IO_KICAD_SEXPR_PARSER::parseSheet() // the first available ID after the mandatory fields if( field->GetId() < 0 ) - field->SetId( SHEET_MANDATORY_FIELDS ); + field->SetId( SHEET_MANDATORY_FIELD_COUNT ); while( !fieldIDsRead.insert( field->GetId() ).second ) field->SetId( field->GetId() + 1 ); diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 68f26cc977..2dd93929f6 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -669,7 +669,12 @@ void SCH_LABEL_BASE::GetIntersheetRefs( const SCH_SHEET_PATH* aPath, void SCH_LABEL_BASE::GetContextualTextVars( wxArrayString* aVars ) const { for( const SCH_FIELD& field : m_fields ) - aVars->push_back( field.GetCanonicalName().Upper() ); + { + if( field.IsMandatory() ) + aVars->push_back( field.GetCanonicalName().Upper() ); + else + aVars->push_back( field.GetName() ); + } aVars->push_back( wxT( "OP" ) ); aVars->push_back( wxT( "CONNECTION_TYPE" ) ); diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 9fd57243e0..f28d3af617 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -265,20 +265,14 @@ bool SCH_SHEET::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, in return true; } - for( int i = 0; i < SHEET_MANDATORY_FIELDS; ++i ) + for( const SCH_FIELD& field : m_fields ) { - if( token->IsSameAs( m_fields[i].GetCanonicalName().Upper() ) ) - { - *token = m_fields[i].GetShownText( aPath, false, aDepth + 1 ); - return true; - } - } + wxString fieldName = field.IsMandatory() ? field.GetCanonicalName().Upper() + : field.GetName(); - for( size_t i = SHEET_MANDATORY_FIELDS; i < m_fields.size(); ++i ) - { - if( token->IsSameAs( m_fields[i].GetName() ) ) + if( token->IsSameAs( fieldName ) ) { - *token = m_fields[i].GetShownText( aPath, false, aDepth + 1 ); + *token = field.GetShownText( aPath, false, aDepth + 1 ); return true; } } @@ -417,8 +411,11 @@ void SCH_SHEET::SetFields( const std::vector& aFields ) } ); // After mandatory fields, the rest should be sequential user fields - for( int ii = SHEET_MANDATORY_FIELDS; ii < static_cast( m_fields.size() ); ++ii ) - m_fields[ii].SetId( ii ); + for( int ii = 0; ii < static_cast( m_fields.size() ); ++ii ) + { + if( !m_fields[ii].IsMandatory() ) + m_fields[ii].SetId( ii ); + } // Make sure that we get the UNIX variant of the file path SetFileName( m_fields[SHEETFILENAME].GetText() ); diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 737be3108b..78c77498c7 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -46,9 +46,11 @@ enum SHEET_FIELD_TYPE SHEETFILENAME, /// The first 2 are mandatory, and must be instantiated in SCH_SHEET - SHEET_MANDATORY_FIELDS + SHEET_MANDATORY_FIELD_COUNT }; +#define SHEET_MANDATORY_FIELDS { SHEETNAME, SHEETFILENAME } + /** * Sheet symbol placed in a schematic, and is the entry point for a sub schematic. diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index bd9d03e9ad..90d5e714f1 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -975,11 +975,14 @@ SCH_FIELD* SCH_SYMBOL::AddField( const SCH_FIELD& aField ) void SCH_SYMBOL::RemoveField( const wxString& aFieldName ) { - for( unsigned i = MANDATORY_FIELDS; i < m_fields.size(); ++i ) + for( unsigned ii = 0; ii < m_fields.size(); ++ii ) { - if( aFieldName == m_fields[i].GetName( false ) ) + if( m_fields[ii].IsMandatory() ) + continue; + + if( aFieldName == m_fields[ii].GetName( false ) ) { - m_fields.erase( m_fields.begin() + i ); + m_fields.erase( m_fields.begin() + ii ); return; } } @@ -989,19 +992,20 @@ void SCH_SYMBOL::RemoveField( const wxString& aFieldName ) SCH_FIELD* SCH_SYMBOL::FindField( const wxString& aFieldName, bool aIncludeDefaultFields, bool aCaseInsensitive ) { - unsigned start = aIncludeDefaultFields ? 0 : MANDATORY_FIELDS; - - for( unsigned i = start; i < m_fields.size(); ++i ) + for( SCH_FIELD& field : m_fields ) { + if( field.IsMandatory() && !aIncludeDefaultFields ) + continue; + if( aCaseInsensitive ) { - if( aFieldName.Upper() == m_fields[i].GetName( false ).Upper() ) - return &m_fields[i]; + if( aFieldName.Upper() == field.GetName( false ).Upper() ) + return &field; } else { - if( aFieldName == m_fields[i].GetName( false ) ) - return &m_fields[i]; + if( aFieldName == field.GetName( false ) ) + return &field; } } @@ -1032,8 +1036,8 @@ void SCH_SYMBOL::UpdateFields( const SCH_SHEET_PATH* aPath, bool aUpdateStyle, b if( !schField ) { - wxString fieldName = libField->GetCanonicalName(); - SCH_FIELD newField( VECTOR2I( 0, 0 ), GetFieldCount(), this, fieldName ); + SCH_FIELD newField( VECTOR2I( 0, 0 ), GetNextFieldId(), this, + libField->GetCanonicalName() ); schField = AddField( newField ); } } @@ -1357,11 +1361,16 @@ void SCH_SYMBOL::SwapData( SCH_ITEM* aItem ) void SCH_SYMBOL::GetContextualTextVars( wxArrayString* aVars ) const { - for( int i = 0; i < MANDATORY_FIELDS; ++i ) - aVars->push_back( m_fields[i].GetCanonicalName().Upper() ); + for( const SCH_FIELD& field : m_fields ) + { + if( field.IsPrivate() ) + continue; - for( size_t i = MANDATORY_FIELDS; i < m_fields.size(); ++i ) - aVars->push_back( m_fields[i].GetName() ); + if( field.IsMandatory() ) + aVars->push_back( field.GetCanonicalName().Upper() ); + else + aVars->push_back( field.GetName() ); + } aVars->push_back( wxT( "OP" ) ); aVars->push_back( wxT( "FOOTPRINT_LIBRARY" ) ); @@ -1471,47 +1480,30 @@ bool SCH_SYMBOL::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, i wxString upperToken = token->Upper(); - for( int i = 0; i < MANDATORY_FIELDS; ++i ) + for( const SCH_FIELD& field : m_fields ) { - wxString field = m_fields[i].GetCanonicalName(); + wxString fieldName = field.IsMandatory() ? field.GetCanonicalName() + : field.GetName(); - wxString textToken = m_fields[i].GetText(); + wxString textToken = field.GetText(); textToken.Replace( " ", wxEmptyString ); - wxString tokenString = "${" + field + "}"; + wxString tokenString = "${" + fieldName + "}"; // If the field data is just a reference to the field, don't resolve if( textToken.IsSameAs( tokenString, false ) ) return true; - if( token->IsSameAs( field, false ) ) + if( token->IsSameAs( fieldName, false ) ) { - if( i == REFERENCE_FIELD ) + if( field.GetId() == REFERENCE_FIELD ) *token = GetRef( aPath, true ); else - *token = m_fields[ i ].GetShownText( aPath, false, aDepth + 1 ); + *token = field.GetShownText( aPath, false, aDepth + 1 ); return true; } } - for( size_t i = MANDATORY_FIELDS; i < m_fields.size(); ++i ) - { - wxString field = m_fields[ i ].GetName(); - - wxString textToken = m_fields[i].GetText(); - textToken.Replace( " ", wxEmptyString ); - wxString tokenString = "${" + field + "}"; - - if( textToken.IsSameAs( tokenString, false ) ) - return true; - - if( token->IsSameAs( field, false ) ) - { - *token = m_fields[ i ].GetShownText( aPath, false, aDepth + 1 ); - return true; - } - } - // Consider missing simulation fields as empty, not un-resolved if( token->IsSameAs( wxT( "SIM.DEVICE" ) ) || token->IsSameAs( wxT( "SIM.TYPE" ) ) @@ -2481,9 +2473,12 @@ bool SCH_SYMBOL::operator==( const SCH_SYMBOL& aSymbol ) const if( GetFieldCount() != aSymbol.GetFieldCount() ) return false; - for( int i = VALUE_FIELD; i < GetFieldCount(); i++ ) + for( int ii = 0; ii < GetFieldCount(); ii++ ) { - if( GetFields()[i].GetText().Cmp( aSymbol.GetFields()[i].GetText() ) != 0 ) + if( ii == REFERENCE_FIELD ) + continue; + + if( GetFields()[ii].GetText().Cmp( aSymbol.GetFields()[ii].GetText() ) != 0 ) return false; } diff --git a/eeschema/sch_symbol.h b/eeschema/sch_symbol.h index 169ee9495d..2f102aeb73 100644 --- a/eeschema/sch_symbol.h +++ b/eeschema/sch_symbol.h @@ -571,7 +571,9 @@ public: /** * Return the number of fields in this symbol. */ - int GetFieldCount() const { return (int)m_fields.size(); } + int GetFieldCount() const { return (int )m_fields.size(); } + + int GetNextFieldId() const { return (int) m_fields.size(); } /** * Automatically orient all the fields in the symbol. diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index 8f933d4924..4cdbd07b66 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -474,7 +474,7 @@ void SIM_MODEL::WriteFields( std::vector& aFields ) const if( IsStoredInValue() ) SetFieldValue( aFields, SIM_VALUE_FIELD, m_serializer->GenerateValue(), false ); - int lastFreeId = MANDATORY_FIELDS; + int lastFreeId = MANDATORY_FIELD_COUNT; // Search for the first available value: for( auto& fld : aFields ) diff --git a/eeschema/symbol_editor/symbol_editor.cpp b/eeschema/symbol_editor/symbol_editor.cpp index 7cc4eff39e..bc4a11a6c0 100644 --- a/eeschema/symbol_editor/symbol_editor.cpp +++ b/eeschema/symbol_editor/symbol_editor.cpp @@ -433,20 +433,20 @@ void SYMBOL_EDIT_FRAME::CreateNewSymbol( const wxString& aInheritFrom ) new_symbol.SetParent( parent ); // Inherit the parent mandatory field attributes. - for( int id = 0; id < MANDATORY_FIELDS; ++id ) + for( int fieldId : MANDATORY_FIELDS ) { - SCH_FIELD* field = new_symbol.GetFieldById( id ); + SCH_FIELD* field = new_symbol.GetFieldById( fieldId ); - // the MANDATORY_FIELDS are exactly that in RAM. + // the MANDATORY_FIELD_COUNT are exactly that in RAM. wxCHECK( field, /* void */ ); - SCH_FIELD* parentField = parent->GetFieldById( id ); + SCH_FIELD* parentField = parent->GetFieldById( fieldId ); wxCHECK( parentField, /* void */ ); *field = *parentField; - switch( id ) + switch( fieldId ) { case REFERENCE_FIELD: // parent's reference already copied diff --git a/eeschema/tools/backannotate.cpp b/eeschema/tools/backannotate.cpp index da36e83ba2..3ea118bd4f 100644 --- a/eeschema/tools/backannotate.cpp +++ b/eeschema/tools/backannotate.cpp @@ -527,8 +527,8 @@ void BACK_ANNOTATE::applyChangelist() if( !m_dryRun ) { - SCH_FIELD newField( symbol->GetPosition(), symbol->GetFieldCount(), symbol, - fpFieldName ); + SCH_FIELD newField( symbol->GetPosition(), symbol->GetNextFieldId(), + symbol, fpFieldName ); newField.SetText( fpFieldValue ); newField.SetVisible( false ); // Don't clutter up the schematic symbol->AddField( newField ); diff --git a/include/template_fieldnames.h b/include/template_fieldnames.h index 9e1d99ea40..c2db03a370 100644 --- a/include/template_fieldnames.h +++ b/include/template_fieldnames.h @@ -47,9 +47,11 @@ enum MANDATORY_FIELD_T { /// The first 5 are mandatory, and must be instantiated in SCH_COMPONENT, LIB_PART, and /// FOOTPRINT constructors - MANDATORY_FIELDS + MANDATORY_FIELD_COUNT }; +#define MANDATORY_FIELDS { REFERENCE_FIELD, VALUE_FIELD, FOOTPRINT_FIELD, DATASHEET_FIELD, DESCRIPTION_FIELD } + // A helper to call GetDefaultFieldName with or without translation. // Translation should be used only to display field names in dialogs #define DO_TRANSLATE true @@ -72,7 +74,7 @@ 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 ); + wxASSERT( idx < MANDATORY_FIELD_COUNT ); return GetDefaultFieldName( idx, !DO_TRANSLATE ); } diff --git a/pcbnew/dialogs/dialog_footprint_properties.cpp b/pcbnew/dialogs/dialog_footprint_properties.cpp index 52f280d4ba..b1e35c239e 100644 --- a/pcbnew/dialogs/dialog_footprint_properties.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties.cpp @@ -642,9 +642,8 @@ void DIALOG_FOOTPRINT_PROPERTIES::OnAddField( wxCommandEvent& ) if( !m_itemsGrid->CommitPendingChanges() ) return; - int fieldId = m_fields->at( m_fields->size() - 1 ).GetId() + 1; - PCB_FIELD newField( m_footprint, fieldId, GetUserFieldName( m_fields->GetNumberRows(), - DO_TRANSLATE ) ); + PCB_FIELD newField( m_footprint, m_footprint->GetNextFieldId(), + GetUserFieldName( m_fields->GetNumberRows(), DO_TRANSLATE ) ); newField.SetVisible( false ); newField.SetLayer( m_footprint->GetLayer() == F_Cu ? F_Fab : B_Fab ); diff --git a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp index c9061d7cbc..ac40d2e303 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp @@ -634,9 +634,8 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnAddField( wxCommandEvent& event ) const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); - int fieldId = m_fields->at( m_fields->size() - 1 ).GetId() + 1; - PCB_FIELD newField( m_footprint, fieldId, GetUserFieldName( m_fields->GetNumberRows(), - DO_TRANSLATE ) ); + PCB_FIELD newField( m_footprint, m_footprint->GetNextFieldId(), + GetUserFieldName( m_fields->GetNumberRows(), DO_TRANSLATE ) ); // Set active layer if legal; otherwise copy layer from previous text item if( LSET::AllTechMask().test( m_frame->GetActiveLayer() ) ) diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index e4e7fb6997..1a09c3880d 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -340,10 +340,7 @@ void FOOTPRINT::Serialize( google::protobuf::Any &aContainer ) const for( const PCB_FIELD* item : m_fields ) { - if( !item ) - continue; - - if( item->GetId() < MANDATORY_FIELDS ) + if( !item || item->IsMandatory() ) continue; google::protobuf::Any* itemMsg = def->add_items(); @@ -499,7 +496,7 @@ bool FOOTPRINT::Deserialize( const google::protobuf::Any &aContainer ) // Footprint items for( PCB_FIELD* field : m_fields ) { - if( field && !field->IsMandatoryField() ) + if( field && !field->IsMandatory() ) Remove( field ); } @@ -666,7 +663,7 @@ void FOOTPRINT::RemoveField( const wxString& aFieldName ) { for( unsigned i = 0; i < m_fields.size(); ++i ) { - if( m_fields[i] && m_fields[i]->IsMandatoryField() ) + if( m_fields[i] && m_fields[ i ]->IsMandatory() ) continue; if( aFieldName == m_fields[i]->GetName( false ) ) diff --git a/pcbnew/kicad_clipboard.cpp b/pcbnew/kicad_clipboard.cpp index 7e3fbfcda0..2a0fa6f725 100644 --- a/pcbnew/kicad_clipboard.cpp +++ b/pcbnew/kicad_clipboard.cpp @@ -232,7 +232,7 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri if( PCB_FIELD* field = dynamic_cast( item ) ) { - if( field->IsMandatoryField() ) + if( field->IsMandatory() ) continue; } @@ -284,7 +284,7 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri if( const PCB_FIELD* field = dynamic_cast( item ) ) { - if( field->IsMandatoryField() ) + if( field->IsMandatory() ) can_add = false; } @@ -408,7 +408,7 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri // will already have its own mandatory fields. if( PCB_FIELD* field = dynamic_cast( copy ) ) { - if( field->IsMandatoryField() ) + if( field->IsMandatory() ) field->SetId( footprint->GetNextFieldId() ); } diff --git a/pcbnew/netlist_reader/board_netlist_updater.cpp b/pcbnew/netlist_reader/board_netlist_updater.cpp index 7e7930f633..da3770f4a3 100644 --- a/pcbnew/netlist_reader/board_netlist_updater.cpp +++ b/pcbnew/netlist_reader/board_netlist_updater.cpp @@ -498,7 +498,7 @@ bool BOARD_NETLIST_UPDATER::updateFootprintParameters( FOOTPRINT* aPcbFootprint, // Remove fields that aren't present in the symbol for( PCB_FIELD* field : aPcbFootprint->GetFields() ) { - if( field->IsMandatoryField() ) + if( field->IsMandatory() ) continue; if( compFields.count( field->GetName() ) == 0 ) @@ -549,7 +549,7 @@ bool BOARD_NETLIST_UPDATER::updateFootprintParameters( FOOTPRINT* aPcbFootprint, for( PCB_FIELD* field : aPcbFootprint->GetFields() ) { - if( field->IsMandatoryField() ) + if( field->IsMandatory() ) continue; if( compFields.count( field->GetName() ) == 0 ) diff --git a/pcbnew/pcb_field.cpp b/pcbnew/pcb_field.cpp index 1333e6e871..3696e710b0 100644 --- a/pcbnew/pcb_field.cpp +++ b/pcbnew/pcb_field.cpp @@ -72,7 +72,7 @@ bool PCB_FIELD::Deserialize( const google::protobuf::Any &aContainer ) setId( field.id().id() ); // Mandatory fields have a blank Name in the KiCad object - if( m_id >= MANDATORY_FIELDS ) + if( !IsMandatory() ) SetName( wxString( field.name().c_str(), wxConvUTF8 ) ); if( field.has_text() ) @@ -93,7 +93,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 ) + if( IsMandatory() ) return GetCanonicalFieldName( m_id ); else if( m_name.IsEmpty() && aUseDefaultName ) return GetUserFieldName( m_id, !DO_TRANSLATE ); @@ -112,7 +112,7 @@ wxString PCB_FIELD::GetCanonicalName() const { if( m_parent && m_parent->Type() == PCB_FOOTPRINT_T ) { - if( m_id < MANDATORY_FIELDS ) + if( IsMandatory() ) return GetCanonicalFieldName( m_id ); else return m_name; @@ -130,9 +130,18 @@ wxString PCB_FIELD::GetCanonicalName() const } +bool PCB_FIELD::IsMandatory() const +{ + return m_id == REFERENCE_FIELD + || m_id == VALUE_FIELD + || m_id == DATASHEET_FIELD + || m_id == DESCRIPTION_FIELD; +} + + wxString PCB_FIELD::GetTextTypeDescription() const { - if( m_id < MANDATORY_FIELDS ) + if( IsMandatory() ) return GetCanonicalFieldName( m_id ); else return _( "User Field" ); @@ -233,7 +242,7 @@ double PCB_FIELD::Similarity( const BOARD_ITEM& aOther ) const const PCB_FIELD& other = static_cast( aOther ); - if( m_id < MANDATORY_FIELDS || other.m_id < MANDATORY_FIELDS ) + if( IsMandatory() || other.IsMandatory() ) { if( m_id == other.m_id ) return 1.0; diff --git a/pcbnew/pcb_field.h b/pcbnew/pcb_field.h index e68def3ab9..b6dcdb08eb 100644 --- a/pcbnew/pcb_field.h +++ b/pcbnew/pcb_field.h @@ -70,7 +70,7 @@ public: bool IsDatasheet() const { return m_id == DATASHEET_FIELD; } bool IsComponentClass() const { return GetName() == wxT( "Component Class" ); } - bool IsMandatoryField() const { return m_id < MANDATORY_FIELDS; } + bool IsMandatory() const; wxString GetTextTypeDescription() const override; diff --git a/pcbnew/pcb_fields_grid_table.cpp b/pcbnew/pcb_fields_grid_table.cpp index 1254dbe595..5109db3969 100644 --- a/pcbnew/pcb_fields_grid_table.cpp +++ b/pcbnew/pcb_fields_grid_table.cpp @@ -150,7 +150,7 @@ int PCB_FIELDS_GRID_TABLE::GetMandatoryRowCount() const for( const PCB_FIELD& field : *this ) { - if( field.IsMandatoryField() ) + if( field.IsMandatory() ) mandatoryRows++; } @@ -233,7 +233,7 @@ wxGridCellAttr* PCB_FIELDS_GRID_TABLE::GetAttr( int aRow, int aCol, switch( aCol ) { case PFC_NAME: - if( aRow < MANDATORY_FIELDS - 1 ) // -1 because we don't expose FOOTPRINT_FIELD + if( aRow < GetMandatoryRowCount() ) { m_readOnlyAttr->IncRef(); return enhanceAttr( m_readOnlyAttr, aRow, aCol, aKind ); diff --git a/pcbnew/pcb_io/easyeda/pcb_io_easyeda_parser.cpp b/pcbnew/pcb_io/easyeda/pcb_io_easyeda_parser.cpp index 8268cac332..755836b376 100644 --- a/pcbnew/pcb_io/easyeda/pcb_io_easyeda_parser.cpp +++ b/pcbnew/pcb_io/easyeda/pcb_io_easyeda_parser.cpp @@ -660,7 +660,7 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer( /*if( etransform ) { - PCB_FIELD field( footprint, footprint->GetFieldCount(), "3D Transform" ); + PCB_FIELD field( footprint, footprint->GetNextFieldId(), "3D Transform" ); field.SetLayer( Cmts_User ); field.SetVisible( false ); field.SetText( *etransform ); diff --git a/pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.cpp b/pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.cpp index 10553b9e07..3f74556393 100644 --- a/pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.cpp +++ b/pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.cpp @@ -1303,7 +1303,7 @@ wxXmlNode* PCB_IO_IPC2581::generateBOMSection( wxXmlNode* aEcadNode ) { // We don't need ref, footprint or datasheet in the BOM characteristics. Just value // and any additional fields the user has added. Ref and footprint are captured above. - if( prop->IsMandatoryField() && !prop->IsValue() ) + if( prop->IsMandatory() && !prop->IsValue() ) continue; ( *bom_iter )->m_props->emplace( prop->GetName(), prop->GetText() ); diff --git a/pcbnew/tools/pcb_control.cpp b/pcbnew/tools/pcb_control.cpp index e2f23e647d..d6f6cbcae6 100644 --- a/pcbnew/tools/pcb_control.cpp +++ b/pcbnew/tools/pcb_control.cpp @@ -879,7 +879,7 @@ static void pasteFootprintItemsToFootprintEditor( FOOTPRINT* aClipFootprint, BOA // for( PCB_FIELD* field : aClipFootprint->GetFields() ) { - if( field->IsMandatoryField() ) + if( field->IsMandatory() ) { if( PCB_GROUP* parentGroup = field->GetParentGroup() ) parentGroup->RemoveItem( field ); diff --git a/qa/tests/eeschema/lib_field_test_utils.h b/qa/tests/eeschema/lib_field_test_utils.h index 786a9e9fc9..ee25533553 100644 --- a/qa/tests/eeschema/lib_field_test_utils.h +++ b/qa/tests/eeschema/lib_field_test_utils.h @@ -85,7 +85,7 @@ bool FieldNameIdMatches( const SCH_FIELD& aField, const std::string& aExpectedNa */ bool AreDefaultFieldsCorrect( const std::vector& aFields ) { - const unsigned expectedCount = MANDATORY_FIELD_T::MANDATORY_FIELDS; + const unsigned expectedCount = MANDATORY_FIELD_T::MANDATORY_FIELD_COUNT; if( aFields.size() < expectedCount ) { diff --git a/qa/tests/eeschema/test_lib_part.cpp b/qa/tests/eeschema/test_lib_part.cpp index 8de34b6e15..8204a3d9f6 100644 --- a/qa/tests/eeschema/test_lib_part.cpp +++ b/qa/tests/eeschema/test_lib_part.cpp @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE( DefaultProperties ) BOOST_AUTO_TEST_CASE( DefaultDrawings ) { // default drawings exist - BOOST_CHECK_EQUAL( m_part_no_data.GetDrawItems().size(), MANDATORY_FIELDS ); + BOOST_CHECK_EQUAL( m_part_no_data.GetDrawItems().size(), MANDATORY_FIELD_COUNT ); BOOST_CHECK_EQUAL( m_part_no_data.GetPins().size(), 0 ); } @@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE( DefaultFields ) BOOST_CHECK_PREDICATE( KI_TEST::AreDefaultFieldsCorrect, ( fields ) ); // but no more (we didn't set them) - BOOST_CHECK_EQUAL( fields.size(), MANDATORY_FIELDS ); + BOOST_CHECK_EQUAL( fields.size(), MANDATORY_FIELD_COUNT ); // also check the default field accessors BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches, @@ -138,10 +138,10 @@ BOOST_AUTO_TEST_CASE( AddedFields ) BOOST_CHECK_PREDICATE( KI_TEST::AreDefaultFieldsCorrect, ( fields ) ); // and our new one - BOOST_REQUIRE_EQUAL( fields.size(), MANDATORY_FIELDS + 1 ); + BOOST_REQUIRE_EQUAL( fields.size(), MANDATORY_FIELD_COUNT + 1 ); BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches, - ( fields[MANDATORY_FIELDS] )( newFieldName )( 42 ) ); + ( fields[MANDATORY_FIELD_COUNT] )( newFieldName )( 42 ) ); // Check by-id lookup @@ -628,12 +628,12 @@ BOOST_AUTO_TEST_CASE( Inheritance ) BOOST_CHECK( *parent == *ref ); ref->SetName( "child" ); - SCH_FIELD* field = new SCH_FIELD( nullptr, MANDATORY_FIELDS, "Manufacturer" ); + SCH_FIELD* field = new SCH_FIELD( nullptr, MANDATORY_FIELD_COUNT, "Manufacturer" ); field->SetText( "KiCad" ); child->AddField( field ); field->SetParent( child.get() ); - field = new SCH_FIELD( nullptr, MANDATORY_FIELDS, "Manufacturer" ); + field = new SCH_FIELD( nullptr, MANDATORY_FIELD_COUNT, "Manufacturer" ); field->SetText( "KiCad" ); ref->AddField( field ); field->SetParent( ref.get() ); @@ -641,12 +641,12 @@ BOOST_AUTO_TEST_CASE( Inheritance ) BOOST_CHECK( *ref == *child->Flatten() ); ref->SetName( "grandchild" ); - field = new SCH_FIELD( nullptr, MANDATORY_FIELDS + 1, "MPN" ); + field = new SCH_FIELD( nullptr, MANDATORY_FIELD_COUNT + 1, "MPN" ); field->SetText( "123456" ); grandChild->AddField( field ); field->SetParent( grandChild.get() ); - field = new SCH_FIELD( nullptr, MANDATORY_FIELDS + 1, "MPN" ); + field = new SCH_FIELD( nullptr, MANDATORY_FIELD_COUNT + 1, "MPN" ); field->SetText( "123456" ); ref->AddField( field ); field->SetParent( ref.get() );