eeschema: fixes 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. From master branch.
This commit is contained in:
parent
6b78fdf822
commit
c7230a6f77
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 ) );
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue