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.
This commit is contained in:
jean-pierre charras 2020-02-16 13:51:44 +01:00
parent 021eb2f3a8
commit 2ca16c0b29
10 changed files with 38 additions and 27 deletions

View File

@ -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;
}

View File

@ -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 );

View File

@ -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 );
}
}

View File

@ -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

View File

@ -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 );

View File

@ -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 ) );

View File

@ -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.

View File

@ -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 );
}

View File

@ -2496,7 +2496,7 @@ LIB_PART* SCH_LEGACY_PLUGIN_CACHE::removeSymbol( LIB_PART* aPart )
{
LIB_FIELD& field = static_cast<LIB_FIELD&>( drawItem );
if( firstChild->FindField( field.GetName() ) )
if( firstChild->FindField( field.GetName( NATIVE_FIELD_NAME ) ) )
continue;
}

View File

@ -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 );