diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index f415676445..a5d68f3a82 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -595,8 +595,7 @@ void LIB_PART::RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel, wxDC* aD { wxLogWarning( _( "An attempt was made to remove the %s field from component %s in library %s." ), - GetChars( field->GetName() ), GetChars( GetName() ), - GetChars( GetLibraryName() ) ); + field->GetName( TRANSLATE_FIELD_NAME ), GetName(), GetLibraryName() ); return; } } @@ -894,7 +893,7 @@ LIB_FIELD* LIB_PART::FindField( const wxString& aFieldName ) { LIB_FIELD* field = ( LIB_FIELD* ) &item; - if( field->GetName() == aFieldName ) + if( field->GetName( NATIVE_FIELD_NAME ) == aFieldName ) return field; } diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index 0733c1f76e..347c2ca4ff 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -403,7 +403,8 @@ public: void GetFields( LIB_FIELDS& aList ); /** - * Findd a field within this part matching \a aFieldName and returns it or NULL if not found. + * Find a field within this part matching \a aFieldName and returns it + * or NULL if not found. */ LIB_FIELD* FindField( const wxString& aFieldName ); diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index a1476b1f77..eece3b0a0d 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -868,10 +868,13 @@ void DIALOG_FIELDS_EDITOR_GLOBAL::LoadFieldNames() // Force References to always be shown m_config->Write( "SymbolFieldEditor/Show/Reference", true ); - AddField( _( "Reference" ), true, true ); - AddField( _( "Value" ), true, true ); - AddField( _( "Footprint" ), true, true ); - AddField( _( "Datasheet" ), true, false ); + // *DO NOT* use translated mandatory field names: + // They are also used as keyword to find fields in component list. + // Changing that is not a basic change + AddField( "Reference", true, true ); + AddField( "Value", true, true ); + AddField( "Footprint", true, true ); + AddField( "Datasheet", true, false ); for( auto fieldName : userFieldNames ) AddField( fieldName, true, false ); diff --git a/eeschema/dialogs/dialog_spice_model.cpp b/eeschema/dialogs/dialog_spice_model.cpp index bb4ad8559a..1b82949dcf 100644 --- a/eeschema/dialogs/dialog_spice_model.cpp +++ b/eeschema/dialogs/dialog_spice_model.cpp @@ -244,7 +244,8 @@ bool DIALOG_SPICE_MODEL::TransferDataFromWindow() [&]( const SCH_FIELD& f ) { return f.GetName() == spiceField; } ), m_schfields->end() ); else m_libfields->erase( std::remove_if( m_libfields->begin(), m_libfields->end(), - [&]( const LIB_FIELD& f ) { return f.GetName() == spiceField; } ), m_libfields->end() ); + [&]( const LIB_FIELD& f ) { return f.GetName( NATIVE_FIELD_NAME ) == spiceField; } ), + m_libfields->end() ); } } @@ -281,7 +282,7 @@ bool DIALOG_SPICE_MODEL::TransferDataToWindow() // TODO: There must be a good way to template out these repetitive calls for( auto field : *m_libfields ) { - if( field.GetName() == spiceField && !field.GetText().IsEmpty() ) + if( field.GetName( NATIVE_FIELD_NAME ) == spiceField && !field.GetText().IsEmpty() ) { m_fieldsTmp[idx] = field.GetText(); break; @@ -778,7 +779,7 @@ LIB_FIELD& DIALOG_SPICE_MODEL::getLibField( int aFieldType ) const wxString& spiceField = NETLIST_EXPORTER_PSPICE::GetSpiceFieldName( (SPICE_FIELD) aFieldType ); auto fieldIt = std::find_if( m_libfields->begin(), m_libfields->end(), [&]( const LIB_FIELD& f ) { - return f.GetName() == spiceField; + return f.GetName( NATIVE_FIELD_NAME ) == spiceField; } ); // Found one, so return it diff --git a/eeschema/generate_alias_info.cpp b/eeschema/generate_alias_info.cpp index eea5c51250..add8959718 100644 --- a/eeschema/generate_alias_info.cpp +++ b/eeschema/generate_alias_info.cpp @@ -160,7 +160,7 @@ protected: wxString GetHtmlFieldRow( LIB_FIELD const & aField ) { - wxString name = aField.GetName(); + wxString name = aField.GetName( NATIVE_FIELD_NAME ); wxString text = aField.GetFullText( m_unit > 0 ? m_unit : 1 ); wxString fieldhtml = FieldFormat; diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index d26bb84cea..8e2014983a 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -538,7 +538,8 @@ void LIB_FIELD::SetText( const wxString& aText ) wxString LIB_FIELD::GetSelectMenuText( EDA_UNITS_T aUnits ) const { - return wxString::Format( _( "Field %s \"%s\"" ), GetName(), ShortenedShownText() ); + return wxString::Format( _( "Field %s \"%s\"" ), GetName( TRANSLATE_FIELD_NAME ), + ShortenedShownText() ); } @@ -623,7 +624,7 @@ void LIB_FIELD::GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList ) aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, BLUE ) ); // Display field name (ref, value ...) - aList.push_back( MSG_PANEL_ITEM( _( "Field" ), GetName(), BROWN ) ); + aList.push_back( MSG_PANEL_ITEM( _( "Field" ), GetName( TRANSLATE_FIELD_NAME ), BROWN ) ); // Display field text: aList.push_back( MSG_PANEL_ITEM( _( "Value" ), GetShownText(), BROWN ) ); diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index 4c097b5228..c50129ea9c 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -119,12 +119,16 @@ public: * names. The user definable fields will return FieldN where N is the ID of the field * when the m_name member is empty. * - * @param aTranslate True to return translated field name (default). False to return - * the english name (useful when the name is used as keyword in - * netlists ...) - * @return Name of the field. - */ - wxString GetName( bool aTranslate = true ) const; + * @param aTranslate true to return translated field name. + * note: has meaning mainly for mandatory fields or to return a default field name. + * Should be used only in messages (never when trying to find a field by name) + * false to return the english name. + * Normal option when the name is used as keyword in netlists. + * @return Name of the field. + */ + #define TRANSLATE_FIELD_NAME true + #define NATIVE_FIELD_NAME false + wxString GetName( bool aTranslate ) const; /** * Set a user definable field name to \a aName. diff --git a/eeschema/libedit/libfield.cpp b/eeschema/libedit/libfield.cpp index 2429c13a9f..fd4c094901 100644 --- a/eeschema/libedit/libfield.cpp +++ b/eeschema/libedit/libfield.cpp @@ -55,7 +55,7 @@ void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField ) if( aField->GetId() == VALUE ) caption = _( "Edit Component Name" ); else - caption.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) ); + caption.Printf( _( "Edit %s Field" ), aField->GetName( TRANSLATE_FIELD_NAME ) ); DIALOG_LIB_EDIT_ONE_FIELD dlg( this, caption, aField ); diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index c203b37201..9f103740f4 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -988,7 +988,7 @@ void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef ) { // Can no longer insert an empty name, since names are now keys. The // field index is not used beyond the first MANDATORY_FIELDS - if( field.GetName().IsEmpty() ) + if( field.GetName( NATIVE_FIELD_NAME ).IsEmpty() ) continue; // See if field already exists (mandatory fields always exist). @@ -1005,11 +1005,12 @@ void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef ) if( (unsigned) idx < MANDATORY_FIELDS ) schField = GetField( idx ); else - schField = FindField( field.GetName() ); + schField = FindField( field.GetName( NATIVE_FIELD_NAME ) ); if( !schField ) { - SCH_FIELD newField( wxPoint( 0, 0 ), GetFieldCount(), this, field.GetName() ); + SCH_FIELD newField( wxPoint( 0, 0 ), GetFieldCount(), this, + field.GetName( NATIVE_FIELD_NAME ) ); schField = AddField( newField ); }