From 2ca16c0b290bf6e9b6efa2e9ede7c40c2d744a4c Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 16 Feb 2020 13:51:44 +0100 Subject: [PATCH] eeschema: fixes some issues related to translated and not translated field names. When searching for fields, the code was sometimes comparing translated and not translated names. This is an issue for mandatory fields, in non English languages. Translated field names should be used only in messages. --- eeschema/class_libentry.cpp | 5 ++--- eeschema/class_libentry.h | 3 ++- eeschema/dialogs/dialog_fields_editor_global.cpp | 14 +++++++++----- eeschema/dialogs/dialog_spice_model.cpp | 11 ++++++----- eeschema/generate_alias_info.cpp | 4 ++-- eeschema/lib_field.cpp | 5 +++-- eeschema/lib_field.h | 12 ++++++++---- eeschema/sch_component.cpp | 7 ++++--- eeschema/sch_legacy_plugin.cpp | 2 +- eeschema/tools/lib_edit_tool.cpp | 2 +- 10 files changed, 38 insertions(+), 27 deletions(-) diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index eaf08daf57..5b3189712c 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -586,8 +586,7 @@ void LIB_PART::RemoveDrawItem( LIB_ITEM* aItem ) { 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; } } @@ -877,7 +876,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 a2a0b6b60b..238269f618 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -261,7 +261,8 @@ public: void GetFields( LIB_FIELDS& aList ); /** - * Find 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 8388876e16..0a65e2bece 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -206,7 +206,6 @@ public: { SCH_COMPONENT* comp = m_componentRefs[ i ].GetComp(); timestamp_t compID = comp->GetTimeStamp(); - m_dataStore[ compID ][ aFieldName ] = comp->GetFieldText( aFieldName, m_frame ); } } @@ -915,18 +914,23 @@ 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( const wxString& fieldName : userFieldNames ) AddField( fieldName, true, false ); // Add any templateFieldNames which aren't already present in the userFieldNames for( const TEMPLATE_FIELDNAME& templateFieldName : m_parent->GetTemplateFieldNames() ) + { if( userFieldNames.count( templateFieldName.m_Name ) == 0 ) AddField( templateFieldName.m_Name, false, false ); + } } diff --git a/eeschema/dialogs/dialog_spice_model.cpp b/eeschema/dialogs/dialog_spice_model.cpp index a99ab3a34f..be1e6b0dd6 100644 --- a/eeschema/dialogs/dialog_spice_model.cpp +++ b/eeschema/dialogs/dialog_spice_model.cpp @@ -242,10 +242,11 @@ bool DIALOG_SPICE_MODEL::TransferDataFromWindow() if( m_useSchFields ) m_schfields->erase( std::remove_if( m_schfields->begin(), m_schfields->end(), - [&]( const SCH_FIELD& f ) { return f.GetName() == spiceField; } ), m_schfields->end() ); + [&]( 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() ); } } @@ -280,9 +281,9 @@ bool DIALOG_SPICE_MODEL::TransferDataToWindow() else if( m_libfields) { // TODO: There must be a good way to template out these repetitive calls - for( const auto& field : *m_libfields ) + for( const LIB_FIELD& 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; @@ -779,7 +780,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 e34d7c0f5f..f7e792162b 100644 --- a/eeschema/generate_alias_info.cpp +++ b/eeschema/generate_alias_info.cpp @@ -159,7 +159,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; @@ -225,7 +225,7 @@ protected: for( auto const& parentField : parentFields ) { - if( m_symbol->FindField( parentField.GetName() ) ) + if( m_symbol->FindField( parentField.GetName( NATIVE_FIELD_NAME ) ) ) continue; fieldtable += GetHtmlFieldRow( parentField ); diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index 09303c4ed1..e14eb0add3 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -404,7 +404,8 @@ void LIB_FIELD::SetName( const wxString& aName ) wxString LIB_FIELD::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( _( "Field %s \"%s\"" ), GetName(), ShortenedShownText() ); + return wxString::Format( _( "Field %s \"%s\"" ), GetName( TRANSLATE_FIELD_NAME ), + ShortenedShownText() ); } @@ -437,7 +438,7 @@ void LIB_FIELD::GetMsgPanelInfo( EDA_UNITS 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 e6a7492ccf..58a8656ea7 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -114,12 +114,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 ...) + * @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. */ - wxString GetName( bool aTranslate = true ) const; + #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/sch_component.cpp b/eeschema/sch_component.cpp index 8d0da15129..f585604af6 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -912,7 +912,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). @@ -929,11 +929,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 ); } diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index 890633e0f8..2a4047c6b7 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -2496,7 +2496,7 @@ LIB_PART* SCH_LEGACY_PLUGIN_CACHE::removeSymbol( LIB_PART* aPart ) { LIB_FIELD& field = static_cast( drawItem ); - if( firstChild->FindField( field.GetName() ) ) + if( firstChild->FindField( field.GetName( NATIVE_FIELD_NAME ) ) ) continue; } diff --git a/eeschema/tools/lib_edit_tool.cpp b/eeschema/tools/lib_edit_tool.cpp index f347c368fc..c0b8b86461 100644 --- a/eeschema/tools/lib_edit_tool.cpp +++ b/eeschema/tools/lib_edit_tool.cpp @@ -482,7 +482,7 @@ void LIB_EDIT_TOOL::editFieldProperties( 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( m_frame, caption, aField );