From ad7d9ec956ca4ef9de5a4fdbb251e136fac0c5c8 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Tue, 13 Jun 2023 09:47:36 -0400 Subject: [PATCH] PCB: footprint properties dialog fields fixes --- pcbnew/dialogs/dialog_footprint_properties.cpp | 8 ++++++-- pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp | 5 ++++- pcbnew/footprint.cpp | 2 +- pcbnew/fp_text_grid_table.cpp | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pcbnew/dialogs/dialog_footprint_properties.cpp b/pcbnew/dialogs/dialog_footprint_properties.cpp index 340958763c..759b8be916 100644 --- a/pcbnew/dialogs/dialog_footprint_properties.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties.cpp @@ -567,10 +567,14 @@ void DIALOG_FOOTPRINT_PROPERTIES::OnAddField( wxCommandEvent& ) if( !m_itemsGrid->CommitPendingChanges() ) return; - PCB_FIELD* newField = new PCB_FIELD( m_footprint, m_fields->size() ); + int fieldId = (int) m_fields->size(); + PCB_FIELD* newField = + new PCB_FIELD( m_footprint, m_fields->size(), + TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldId, DO_TRANSLATE ) ); - newField->SetLayer( m_footprint->GetLayer() == F_Cu ? F_Fab : B_Fab ); newField->SetVisible( false ); + newField->SetLayer( m_footprint->GetLayer() == F_Cu ? F_Fab : B_Fab ); + newField->SetFPRelativePosition( { 0, 0 } ); newField->StyleFromSettings( m_frame->GetDesignSettings() ); m_fields->push_back( newField ); diff --git a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp index 33f38262f3..4d021dcbf0 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp @@ -621,8 +621,11 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnAddField( wxCommandEvent& event ) if( !m_itemsGrid->CommitPendingChanges() ) return; + int fieldId = (int) m_fields->size(); const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); - PCB_FIELD* newField = new PCB_FIELD( m_footprint, m_fields->size() ); + PCB_FIELD* newField = + new PCB_FIELD( m_footprint, m_fields->size(), + TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldId, 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 3998382e8b..4a09457bba 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -764,7 +764,7 @@ void FOOTPRINT::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aMode ) PCB_FIELD* field = static_cast( aBoardItem ); // Only user text can be removed this way. - wxCHECK_RET( field->IsMandatoryField(), + wxCHECK_RET( !field->IsMandatoryField(), wxT( "Please report this bug: Invalid remove operation on required text" ) ); for( auto it = m_fields.begin(); it != m_fields.end(); ++it ) { diff --git a/pcbnew/fp_text_grid_table.cpp b/pcbnew/fp_text_grid_table.cpp index 9620b4e8d6..5cdc7b61b9 100644 --- a/pcbnew/fp_text_grid_table.cpp +++ b/pcbnew/fp_text_grid_table.cpp @@ -157,7 +157,7 @@ wxGridCellAttr* FP_TEXT_GRID_TABLE::GetAttr( int aRow, int aCol, wxGridCellAttr: switch( aCol ) { case FPT_NAME: - if( aRow < 2 ) + if( aRow < MANDATORY_FIELDS ) { m_readOnlyAttr->IncRef(); return m_readOnlyAttr;